Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/check-package-changelogs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ jobs:
- interface
- style-runtime
- ui
- undo-manager
- views
- widget-dashboard
- widget-primitives
# Other packages
- theme
- components
- private-apis
- widget-dashboard
- widget-primitives
- wp-build
steps:
- name: 'Get PR commit count'
Expand Down
4 changes: 4 additions & 0 deletions packages/admin-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 2.5.0 (2026-07-01)

## 2.4.0 (2026-06-24)
Expand Down
1 change: 1 addition & 0 deletions packages/admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"./package.json": "./package.json"
},
"wpScript": false,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can appreciate the explicitness, but do we need these explicit false values? Or just lean on this being an opt-in behavior that defaults to false ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this explicitness is good, but I think the extraction plugin should not expect the property to be explicitly set to false.

"types": "build-types",
"sideEffects": [
"src/**/*.module.css"
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))
- Update `@ariakit/react` to `0.4.32` ([#79860](https://github.com/WordPress/gutenberg/pull/79860)).

## 17.1.0 (2026-07-01)
Expand Down
1 change: 1 addition & 0 deletions packages/dataviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"./build-style/": "./build-style/"
},
"wpScript": false,
"types": "build-types",
"sideEffects": false,
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/dependency-extraction-webpack-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Determine bundled packages from `wpScript: false` in `package.json` instead of a hardcoded list. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

### Bug Fixes

- Extract dynamically imported external modules that webpack code-splits into their own async chunk in the module build ([#79633](https://github.com/WordPress/gutenberg/pull/79633)).
Expand Down
148 changes: 134 additions & 14 deletions packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,137 @@
const WORDPRESS_NAMESPACE = '@wordpress/';
const BUNDLED_PACKAGES = [
'@wordpress/admin-ui',
'@wordpress/dataviews',
'@wordpress/dataviews/wp',
'@wordpress/fields',
'@wordpress/grid',
'@wordpress/icons',
'@wordpress/interface',
'@wordpress/style-runtime',
'@wordpress/ui',
'@wordpress/undo-manager',
'@wordpress/views',
];
const { readFileSync, existsSync } = require( 'fs' );
const path = require( 'path' );
const { createRequire } = require( 'module' );

const packageJsonCache = new Map();
const packagePathCache = new Map();

/**
* Find the nearest package root directory by walking up from the given directory.
* Looks for a directory containing package.json.
*
* @param {string} startDir The directory to start searching from.
* @return {string} The package root directory, or the start directory if no package.json found.
*/
function findPackageRoot( startDir ) {
let current = startDir;
const root = path.parse( current ).root;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more reasonable stopping point we should stop at, like cwd or project root somehow, rather than filesystem root? I suppose in practice this isn't much of an actual concern.


while ( current !== root ) {
const packageJsonPath = path.join( current, 'package.json' );
if ( existsSync( packageJsonPath ) ) {
return current;
}
current = path.dirname( current );
}

// Fallback to the start directory if no package.json found.
return startDir;
}

/**
* Reads package.json info using Node's module resolution.
*
* @param {string} fullPackageName The full package name (e.g. '@wordpress/blocks').
* @param {string|null} resolveDir Optional directory context for resolution.
* @return {{wpScript?: boolean, wpScriptModuleExports?: string|Object}|null} Package metadata when resolvable.
*/
function getPackageInfo( fullPackageName, resolveDir = null ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot here that repeats from what we have in @wordpress/build as well. As there, a lot of this will be simplified with findPackageJSON in newer versions of Node. We could always refactor later, but with recent almost-unblocking of #72973 (comment), we could also consider to wait? Not sure how much that helps simplify this code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toward simplifying the shared code, I wonder if there's libraries that help or if we should create our own. Some combination of resolve-pkg, read-pkg, and/or find-up for example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the approach that we used in license check

function resolvePackagePath( packageName, fromDir ) {
// Use findPackageJSON when available (Node.js 22.14.0+)
if ( findPackageJSON ) {

const packageRoot = resolveDir
? findPackageRoot( resolveDir )
: process.cwd();
const cacheKey = `${ fullPackageName }@${ packageRoot }`;

if ( packageJsonCache.has( cacheKey ) ) {
return packageJsonCache.get( cacheKey );
}

const contextPath = path.join( packageRoot, 'package.json' );
const contextRequire = createRequire( contextPath );

let resolved;
try {
resolved = contextRequire.resolve(
`${ fullPackageName }/package.json`
);
} catch ( error ) {
const code = error.code;
if (
code === 'MODULE_NOT_FOUND' ||
code === 'ERR_PACKAGE_PATH_NOT_EXPORTED'
) {
packageJsonCache.set( cacheKey, null );
return null;
}
throw error;
}

const result = getPackageInfoFromFile( resolved );
packageJsonCache.set( cacheKey, result );

return result;
}

/**
* Reads package.json info from an explicit file path.
*
* @param {string} packageJsonPath Absolute path to package.json file.
* @return {{wpScript?: boolean, wpScriptModuleExports?: string|Object}|null} Package metadata when resolvable.
*/
function getPackageInfoFromFile( packageJsonPath ) {
if ( packagePathCache.has( packageJsonPath ) ) {
return packagePathCache.get( packageJsonPath );
}
const packageJson = JSON.parse( readFileSync( packageJsonPath, 'utf8' ) );
packagePathCache.set( packageJsonPath, packageJson );
return packageJson;
}

/**
* Read package metadata for an import request.
*
* @param {string} request Module request (the module name in `import from`).
* @return {{wpScript?: boolean, wpScriptModuleExports?: string|Object}|undefined} Package metadata when resolvable.
*/
function getPackageMetadata( request ) {
const packageName = getPackageNameFromRequest( request );

if ( ! packageName ) {
return;
}

return getPackageInfo( packageName );
}

/**
* Determine whether a package should stay bundled in script builds.
* Packages are bundled only when they explicitly opt out of script registration
* via `wpScript: false`.
*
* @param {string} request Module request (the module name in `import from`).
* @return {boolean} True when package should remain bundled in scripts.
*/
function isBundledPackageForScripts( request ) {
const packageMetadata = getPackageMetadata( request );
if ( ! packageMetadata ) {
return false;
}

return packageMetadata.wpScript !== true;
}

/**
* Extract package name (`@scope/name`) from an import request.
*
* @param {string} request Module request (the module name in `import from`).
* @return {string|undefined} Package name when request is namespaced.
*/
function getPackageNameFromRequest( request ) {
const parts = request.split( '/' );
if ( parts[ 0 ]?.startsWith( '@' ) && parts.length >= 2 ) {
return `${ parts[ 0 ] }/${ parts[ 1 ] }`;
}
}

/**
* Default request to global transformation
Expand Down Expand Up @@ -55,7 +175,7 @@ function defaultRequestToExternal( request ) {
return 'ReactRefreshRuntime';
}

if ( BUNDLED_PACKAGES.includes( request ) ) {
if ( isBundledPackageForScripts( request ) ) {
return undefined;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/dependency-extraction-webpack-plugin/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ describe( 'defaultRequestToExternal', () => {
).toEqual( [ 'wp', 'someFuturePackage' ] );
} );

test( 'Keeps bundled @wordpress packages internal', () => {
expect( defaultRequestToExternal( '@wordpress/ui' ) ).toBeUndefined();
} );

test( 'Externalizes wpScript packages', () => {
expect( defaultRequestToExternal( '@wordpress/undo-manager' ) ).toEqual(
[ 'wp', 'undoManager' ]
);
} );

test( 'Handles react request', () => {
expect( defaultRequestToExternal( 'react' ) ).toBe( 'React' );
} );
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 0.42.0 (2026-07-01)

## 0.41.0 (2026-06-24)
Expand Down
1 change: 1 addition & 0 deletions packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"./package.json": "./package.json"
},
"wpScript": false,
"types": "build-types",
"sideEffects": [
"build-style/**",
Expand Down
4 changes: 4 additions & 0 deletions packages/icons/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 15.1.0 (2026-07-01)

## 15.0.0 (2026-06-24)
Expand Down
1 change: 1 addition & 0 deletions packages/icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"./package.json": "./package.json"
},
"wpScript": false,
"types": "build-types",
"sideEffects": false,
"dependencies": {
Expand Down
4 changes: 4 additions & 0 deletions packages/interface/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 9.35.0 (2026-07-01)

## 9.34.0 (2026-06-24)
Expand Down
1 change: 1 addition & 0 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"./package.json": "./package.json",
"./build-style/": "./build-style/"
},
"wpScript": false,
"sideEffects": [
"build-style/**",
"src/**/*.scss",
Expand Down
4 changes: 4 additions & 0 deletions packages/style-runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 0.6.0 (2026-07-01)

## 0.5.0 (2026-06-24)
Expand Down
1 change: 1 addition & 0 deletions packages/style-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"./package.json": "./package.json"
},
"wpScript": false,
"types": "build-types",
"sideEffects": false,
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions packages/views/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

## Unreleased

### Internal

- Declare `wpScript: false` to mark the package as bundled rather than externalized. ([#79945](https://github.com/WordPress/gutenberg/pull/79945))

## 1.17.0 (2026-07-01)
1 change: 1 addition & 0 deletions packages/views/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"./package.json": "./package.json"
},
"wpScript": false,
"types": "build-types",
"dependencies": {
"@wordpress/core-data": "file:../core-data",
Expand Down
Loading