Dependency extraction webpack plugin: use package.json wpScript value to determine bundling - #79945
Dependency extraction webpack plugin: use package.json wpScript value to determine bundling#79945simison wants to merge 7 commits into
package.json wpScript value to determine bundling#79945Conversation
This comment was marked as resolved.
This comment was marked as resolved.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.67 MB |
@retrofox could you confirm if we want to bundle these packages? That helps to do bigger API changes for now, rather than externalizing to Gutenberg via |
|
Flaky tests detected in 7236183. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28872527954
|
There was a problem hiding this comment.
Pull request overview
Updates @wordpress/dependency-extraction-webpack-plugin to determine which @wordpress/* packages should remain bundled based on each package’s package.json metadata (wpScript: false), replacing the previous hardcoded BUNDLED_PACKAGES list. This aligns dependency extraction behavior with wp-build and updates affected packages/workflows accordingly.
Changes:
- Replace the hardcoded bundled list with runtime resolution of
wpScriptfrom each package’spackage.json. - Add
wpScript: false(and changelog entries) to legacy bundled packages that lacked it. - Update the changelog-check workflow list to treat
@wordpress/undo-manageras externalized and include widget packages.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/views/package.json | Marks @wordpress/views as bundled via wpScript: false. |
| packages/views/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/style-runtime/package.json | Marks @wordpress/style-runtime as bundled via wpScript: false. |
| packages/style-runtime/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/interface/package.json | Marks @wordpress/interface as bundled via wpScript: false. |
| packages/interface/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/icons/package.json | Marks @wordpress/icons as bundled via wpScript: false. |
| packages/icons/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/fields/package.json | Marks @wordpress/fields as bundled via wpScript: false. |
| packages/fields/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/dataviews/package.json | Marks @wordpress/dataviews as bundled via wpScript: false. |
| packages/dataviews/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/admin-ui/package.json | Marks @wordpress/admin-ui as bundled via wpScript: false. |
| packages/admin-ui/CHANGELOG.md | Documents the wpScript: false metadata change. |
| packages/dependency-extraction-webpack-plugin/lib/util.js | Implements bundled detection by reading wpScript from resolved package.json. |
| packages/dependency-extraction-webpack-plugin/test/util.js | Adds tests for bundled vs externalized behavior based on wpScript. |
| packages/dependency-extraction-webpack-plugin/CHANGELOG.md | Notes the change from hardcoded list to wpScript: false metadata. |
| .github/workflows/check-package-changelogs.yml | Updates the workflow package list to match the new bundling/externalization set. |
Comments suppressed due to low confidence (1)
packages/dependency-extraction-webpack-plugin/lib/util.js:182
isBundledPackageForScripts()runs before the@wordpress/namespace check, so scoped non-WordPress imports (e.g.@foo/bar) will still triggerrequire.resolve(<pkg>/package.json)and JSON parsing even though they can never be externalized here; this can add unnecessary I/O during builds.
if ( isBundledPackageForScripts( request ) ) {
return undefined;
}
if ( request.startsWith( WORDPRESS_NAMESPACE ) ) {
| */ | ||
| function findPackageRoot( startDir ) { | ||
| let current = startDir; | ||
| const root = path.parse( current ).root; |
There was a problem hiding this comment.
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.
| * @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 ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
We could use the approach that we used in license check
gutenberg/packages/scripts/utils/license.js
Lines 387 to 389 in 1222f40
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "wpScript": false, |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
IMHO, this explicitness is good, but I think the extraction plugin should not expect the property to be explicitly set to false.
|
Heads up on a downstream compatibility concern from Jetpack. CC: @anomiex I asked Claude to see how this can affect Jetpack monorepo: Jetpack consumes this plugin via The issue is that the plugin version and the package versions don't necessarily move together outside this monorepo. Our lockfile currently has DEWP 6.50.0 alongside The reverse order is harmless — packages gaining Would it be possible to bump the peer/minimum versions of the affected packages in Separately: is there a stable replacement for the |
It gets even worse if you consider sub-dependencies. We still have |
Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
I think it would be useful for all sorts of reasons to document somewhere, so might need generating somehow. |
What?
Follow-up to convo at
Replaces the hardcoded
BUNDLED_PACKAGESlist in@wordpress/dependency-extraction-webpack-pluginwith package metadata (wpScript: false) as the source of truth for bundled packages.When
wpScriptistrueor missing, the package gets externalised. Thus, one needs to specifically opt-in to bundling just like previously withBUNDLED_PACKAGES, or use Webpack configs like these:Updates the changelog workflow to treat
@wordpress/undo-manageras externalized (it was incorrectly bundled before, see notes).Adds
wpScript: falseto the legacy bundled packages that lacked it.Keeps existing
wpScript: falsein@wordpress/widget-dashboardand@wordpress/widget-primitives; these were not listed inBUNDLED_PACKAGESpreviously but are now effectively bundled. They're pretty new experimental packages, so I'm assuming we want to keep bundling them?Why?
BUNDLED_PACKAGESduplicated logic thatwp-buildalready derives frompackage.json, so the two bundlers could drift. We already had a concrete example:@wordpress/undo-managerwas listed as bundled in dependency-extraction, butwp-buildexternalizes it because it haswpScript: true.Using
wpScript: falsemakes bundling explicit and keeps webpack (@wordpress/scripts) and esbuild (wp-build) aligned on the same rule: packages are bundled only when they opt out of WordPress script registration.How?
I'm mostly duplicating the logic from WP Build to the Dependency Extraction plugin: I could make one depend on another or move the utils to yet another shared package, but since these are just script tools, it felt like copying is fine. (Also,
@wordpress/buildis ESM + Node >=20.10, whiledependency-extractionsupports Node >=18.12 and is CJS.)I added
wpScript: falseto packages we're continuing to bundle.Testing Instructions
npm run test:unit packages/dependency-extraction-webpack-plugin/test/util.js@wordpress/undo-manager, which is now externalised.@wordpress/widget-dashboard, which is now bundled (already hadwpScript: false).@wordpress/widget-primitives, which is now bundled (already hadwpScript: false).Use of AI Tools
yes