Skip to content

Commit 8577f98

Browse files
manzoorwanijkmirka
authored andcommitted
Scripts: Resolve default configs without hoisted dependencies (WordPress#83902)
Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org>
1 parent 67785fb commit 8577f98

5 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎packages/scripts/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Bug Fixes
66

77
- Add the `stylelint-scss` dependency, a peer of `@wordpress/stylelint-config` ([#83765](https://github.com/WordPress/gutenberg/pull/83765)).
8+
- `build`, `start` and `lint-pkg-json`: Resolve the default browserslist and npm-package-json-lint configs when dependencies are not hoisted to the project root (npm `install-strategy=linked`, pnpm). `lint-pkg-json` now defaults to `config/npmpackagejsonlint.js`; `config/npmpackagejsonlint.json` stays for projects that reference it ([#83902](https://github.com/WordPress/gutenberg/pull/83902)).
89

910
## 36.0.0 (2026-09-23)
1011

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// A JSON `extends` resolves from the linted package, not from this file.
2+
module.exports = require( '@wordpress/npm-package-json-lint-config' );
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createRequire } from 'node:module';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { describe, expect, it } from 'vitest';
5+
6+
const require = createRequire( import.meta.url );
7+
8+
const configDirectory = path.resolve(
9+
path.dirname( fileURLToPath( import.meta.url ) ),
10+
'..'
11+
);
12+
13+
describe( 'shipped configs', () => {
14+
it( 'inlines the npm-package-json-lint preset instead of extending it', () => {
15+
const config = require(
16+
path.join( configDirectory, 'npmpackagejsonlint.js' )
17+
);
18+
19+
expect( config ).not.toHaveProperty( 'extends' );
20+
expect( config ).toEqual(
21+
require( '@wordpress/npm-package-json-lint-config' )
22+
);
23+
} );
24+
} );

‎packages/scripts/config/webpack.config.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' );
55
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
66
const webpack = require( 'webpack' );
77
const browserslist = require( 'browserslist' );
8+
const browserslistConfig = require( '@wordpress/browserslist-config' );
89
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
910
const ReactRefreshWebpackPlugin = require( '@pmmmwh/react-refresh-webpack-plugin' );
1011
const TerserPlugin = require( 'terser-webpack-plugin' );
@@ -14,7 +15,6 @@ const postcssPlugins = require( '@wordpress/postcss-plugins-preset' );
1415
const PhpFilePathsPlugin = require( '../plugins/php-file-paths-plugin' );
1516
const RtlCssPlugin = require( '../plugins/rtlcss-webpack-plugin' );
1617
const {
17-
fromConfigRoot,
1818
hasBabelConfig,
1919
hasArgInCLI,
2020
hasCssnanoConfig,
@@ -32,7 +32,8 @@ const isProduction = process.env.NODE_ENV === 'production';
3232
const mode = isProduction ? 'production' : 'development';
3333
let target = 'browserslist';
3434
if ( ! browserslist.findConfig( '.' ) ) {
35-
target += ':' + fromConfigRoot( '.browserslistrc' );
35+
// Pass queries, not a config `extends`, which resolves from the consumer's cwd.
36+
target += ':' + browserslistConfig.join( ', ' );
3637
}
3738
const hasReactFastRefresh = hasArgInCLI( '--hot' ) && ! isProduction;
3839
const hasBlocksManifest = getAsBooleanFromENV( 'WP_BLOCKS_MANIFEST' );

‎packages/scripts/scripts/lint-pkg-json.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const hasLintConfig =
2828
hasPackageProp( 'npmPackageJsonLintConfig' );
2929

3030
const defaultConfigArgs = ! hasLintConfig
31-
? [ '--configFile', fromConfigRoot( 'npmpackagejsonlint.json' ) ]
31+
? [ '--configFile', fromConfigRoot( 'npmpackagejsonlint.js' ) ]
3232
: [];
3333

3434
// See: https://github.com/tclindner/npm-package-json-lint/#cli-commands-and-configuration.

0 commit comments

Comments
 (0)