Skip to content
Merged
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
3 changes: 2 additions & 1 deletion projects/js-packages/webpack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ By default, the following additional dependencies are extracted:
- `@automattic/jetpack-connection`: Handle `jetpack-connection` provided by PHP package [automattic/jetpack-connection](https://packagist.org/packages/automattic/jetpack-connection).
- `@automattic/jetpack-shared-stores`: Handle `jetpack-shared-stores` provided by PHP package [automattic/jetpack-assets](https://packagist.org/packages/automattic/jetpack-assets). The shared data stores resolve to one externalized bundle so they register only once.

One additional option is recognized:
Two additional options are recognized:

- `requestMap`: An easier way to specify additional dependencies to extract, rather than redefining `requestToHandle` and `requestToExternal`. Key is the dependency, value is an object with `handle` and `external` keys corresponding to the return values of `requestToHandle` and `requestToExternal`.
- `bundleWpUiDeps`: Bundle `@wordpress/theme` and `@wordpress/private-apis` instead of externalizing them to the `wp-theme` and `wp-private-apis` script handles. Defaults to `false`. It is meant for entries that bundle `@wordpress/ui`, which is built against a newer `@wordpress/theme` than the one WordPress core registers. A bundled `@wordpress/private-apis` can only unlock private APIs that were locked inside the same bundle. So do not use this option on an entry that unlocks private APIs from an external `wp-*` script, for example bundled `@wordpress/dataviews` with an external `wp-components`. Your own `requestMap` still wins over it.

##### `DuplicatePackageCheckerPlugin( options )`

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

DependencyExtractionPlugin: Add a `bundleWpUiDeps` option to bundle `@wordpress/theme` and `@wordpress/private-apis`.
26 changes: 24 additions & 2 deletions projects/js-packages/webpack-config/src/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,30 @@ const defaultRequestMap = {
},
};

const DependencyExtractionPlugin = ( { requestMap, ...options } = {} ) => {
const finalRequestMap = { ...defaultRequestMap, ...requestMap };
// A bundled @wordpress/private-apis unlocks only what its own bundle locked. So never bundle it
// without @wordpress/theme, or in an entry that unlocks private APIs of an external wp-* script.
const wpUiRequestMap = {
'@wordpress/theme': { external: false },
'@wordpress/private-apis': { external: false },
};

/**
* Build the DependencyExtractionWebpackPlugin.
*
* @param {object} options - Plugin options, passed through except for the two below.
* @param {object} options.requestMap - Per-request `{ external, handle }` overrides. Wins over every default.
* @param {boolean} options.bundleWpUiDeps - Bundle `@wordpress/theme` and `@wordpress/private-apis` instead of
* externalizing them. Off by default. For an entry that bundles
* `@wordpress/ui`, which is built against a newer `@wordpress/theme`
* than core's `wp-theme`.
* @return {object[]} The plugin.
*/
const DependencyExtractionPlugin = ( { requestMap, bundleWpUiDeps = false, ...options } = {} ) => {
const finalRequestMap = {
...defaultRequestMap,
...( bundleWpUiDeps ? wpUiRequestMap : {} ),
...requestMap,
};

const requestToExternal = request => {
return finalRequestMap[ request ]?.external;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Replace the duplicated DependencyExtractionPlugin requestMap block with an opt-in bundleWpUiDeps option. No build output changes.


10 changes: 1 addition & 9 deletions projects/packages/search/tools/webpack.dashboard.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@ module.exports = {
...jetpackWebpackConfig.StandardPlugins( {
DependencyExtractionPlugin: {
injectPolyfill: true,
// Match Boost / Jetpack AI admin: @wordpress/ui pulls these in transitively;
// they are not reliably registered as WP script handles in all contexts, so
// bundle them together instead of externalizing. Both must be bundled jointly
// so @wordpress/theme's module-init lock() lands on the same private-apis
// consent map. See PR #48173.
requestMap: {
'@wordpress/theme': { external: false },
'@wordpress/private-apis': { external: false },
},
bundleWpUiDeps: true,
},
} ),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Replace the duplicated DependencyExtractionPlugin requestMap block with an opt-in bundleWpUiDeps option. No build output changes.


8 changes: 1 addition & 7 deletions projects/plugins/boost/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,7 @@ module.exports = [
filename: 'jetpack-boost.css',
},
DependencyExtractionPlugin: {
requestMap: {
// Bundle @wordpress/theme and @wordpress/private-apis inline —
// they're transitive deps of @wordpress/ui but aren't registered
// as script handles in WP core, so externalizing them breaks enqueue.
'@wordpress/theme': { external: false },
'@wordpress/private-apis': { external: false },
},
bundleWpUiDeps: true,
},
} ),
new webpack.ProvidePlugin( {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Replace the duplicated DependencyExtractionPlugin requestMap block with an opt-in bundleWpUiDeps option. No build output changes.


11 changes: 1 addition & 10 deletions projects/plugins/jetpack/tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,7 @@ module.exports = [
plugins: [
...sharedWebpackConfig.plugins,
...jetpackWebpackConfig.DependencyExtractionPlugin( {
// Match the AI admin build: @wordpress/ui (pulled in via the licensing
// activation screen) drags in @wordpress/theme and @wordpress/private-apis.
// They are not registered as WP script handles on the main Jetpack admin
// path (WP < 7.0 has no core wp-theme, and this page does not load the
// wp-build-polyfills shim), so bundle them instead of externalizing to
// avoid the whole dashboard script failing to enqueue.
requestMap: {
'@wordpress/theme': { external: false },
'@wordpress/private-apis': { external: false },
},
bundleWpUiDeps: true,
} ),
],
externals: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Replace the duplicated DependencyExtractionPlugin requestMap block with an opt-in bundleWpUiDeps option. No build output changes.


6 changes: 1 addition & 5 deletions projects/plugins/protect/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ module.exports = [
plugins: [
...jetpackWebpackConfig.StandardPlugins( {
DependencyExtractionPlugin: {
// Bundled, never one without the other — see #48173.
requestMap: {
'@wordpress/theme': { external: false },
'@wordpress/private-apis': { external: false },
},
bundleWpUiDeps: true,
},
} ),
],
Expand Down
Loading