@wordpress/build 0.10.1-next.v.202603161435.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/lib/build.mjs +70 -41
- package/package.json +2 -2
- package/templates/module-registration.php.template +15 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
## 0.
|
|
5
|
+
## 0.11.0 (2026-04-01)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- Derive `data-wp-hash` from the transformed CSS instead of the raw source to prevent style mismatches when multiple build pipelines process the same source file ([#76743](https://github.com/WordPress/gutenberg/pull/76743)).
|
|
10
|
+
|
|
11
|
+
## 0.10.0 (2026-03-18)
|
|
6
12
|
|
|
7
13
|
### Breaking Changes
|
|
8
14
|
|
package/lib/build.mjs
CHANGED
|
@@ -118,22 +118,27 @@ const PAGES = WP_PLUGIN_CONFIG.pages || [];
|
|
|
118
118
|
* are considered true while all other values are false.
|
|
119
119
|
*
|
|
120
120
|
* @param {string|undefined} value The configuration value to interpret.
|
|
121
|
-
* @return {boolean} Boolean interpretation of the given configuration value.
|
|
121
|
+
* @return {boolean|undefined} Boolean interpretation of the given configuration value, or undefined if not set.
|
|
122
122
|
*/
|
|
123
123
|
const boolConfigVal = ( value ) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
if ( value === undefined ) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return [ 'true', '1' ].includes( value.toLowerCase() );
|
|
127
128
|
};
|
|
128
129
|
|
|
129
130
|
const baseDefine = {
|
|
130
131
|
'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify(
|
|
131
|
-
boolConfigVal( process.env.IS_GUTENBERG_PLUGIN )
|
|
132
|
-
boolConfigVal(
|
|
132
|
+
boolConfigVal( process.env.IS_GUTENBERG_PLUGIN ) ??
|
|
133
|
+
boolConfigVal(
|
|
134
|
+
process.env.npm_package_config_IS_GUTENBERG_PLUGIN
|
|
135
|
+
) ??
|
|
136
|
+
false
|
|
133
137
|
),
|
|
134
138
|
'globalThis.IS_WORDPRESS_CORE': JSON.stringify(
|
|
135
|
-
boolConfigVal( process.env.IS_WORDPRESS_CORE )
|
|
136
|
-
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE )
|
|
139
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
140
|
+
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE ) ??
|
|
141
|
+
false
|
|
137
142
|
),
|
|
138
143
|
};
|
|
139
144
|
const getDefine = ( scriptDebug ) => ( {
|
|
@@ -177,12 +182,6 @@ function getSassOptions( workingDir ) {
|
|
|
177
182
|
|
|
178
183
|
function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
|
|
179
184
|
return async function styleType( cssText, _dirname, filePath ) {
|
|
180
|
-
// Always hash the untransformed code.
|
|
181
|
-
const hash = createHash( 'sha1' )
|
|
182
|
-
.update( cssText )
|
|
183
|
-
.digest( 'hex' )
|
|
184
|
-
.slice( 0, 10 );
|
|
185
|
-
|
|
186
185
|
let moduleExports = null;
|
|
187
186
|
|
|
188
187
|
// Transform the code: token fallbacks, CSS modules and minification.
|
|
@@ -209,6 +208,13 @@ function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
|
|
|
209
208
|
map: false,
|
|
210
209
|
} );
|
|
211
210
|
|
|
211
|
+
// Hash the transformed CSS so that the dedup key reflects the actual
|
|
212
|
+
// injected content, including mangled CSS module class names.
|
|
213
|
+
const hash = createHash( 'sha1' )
|
|
214
|
+
.update( css )
|
|
215
|
+
.digest( 'hex' )
|
|
216
|
+
.slice( 0, 10 );
|
|
217
|
+
|
|
212
218
|
let cssModule = `if (typeof document !== 'undefined' && process.env.NODE_ENV !== 'test' && !document.head.querySelector("style[data-wp-hash='${ hash }']")) {
|
|
213
219
|
const style = document.createElement("style");
|
|
214
220
|
style.setAttribute("data-wp-hash", "${ hash }");
|
|
@@ -341,7 +347,10 @@ function transformPhpContent( content, transforms ) {
|
|
|
341
347
|
* class prefixes, etc.). When building for WordPress Core, it's not
|
|
342
348
|
* necessary to perform these steps.
|
|
343
349
|
*/
|
|
344
|
-
if (
|
|
350
|
+
if (
|
|
351
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
352
|
+
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE )
|
|
353
|
+
) {
|
|
345
354
|
return content;
|
|
346
355
|
}
|
|
347
356
|
|
|
@@ -583,6 +592,15 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
583
592
|
const entryPoint = path.join( packageDir, exportPath );
|
|
584
593
|
const baseFileName = path.basename( fileName );
|
|
585
594
|
|
|
595
|
+
// Skip non-minified build for WASM-inlined workers (e.g., vips).
|
|
596
|
+
// These are ~16MB of base64-encoded WASM with no debugging value
|
|
597
|
+
// over the minified version.
|
|
598
|
+
const isWasmWorker =
|
|
599
|
+
packageJson.wpWorkers &&
|
|
600
|
+
Object.keys( packageJson.wpWorkers ).some(
|
|
601
|
+
( key ) => key.replace( /^\.\//, '' ) === fileName
|
|
602
|
+
);
|
|
603
|
+
|
|
586
604
|
builds.push(
|
|
587
605
|
esbuild.build( {
|
|
588
606
|
entryPoints: [ entryPoint ],
|
|
@@ -605,31 +623,36 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
605
623
|
true // Generate asset file for minified build
|
|
606
624
|
),
|
|
607
625
|
],
|
|
608
|
-
} ),
|
|
609
|
-
esbuild.build( {
|
|
610
|
-
entryPoints: [ entryPoint ],
|
|
611
|
-
outfile: path.join(
|
|
612
|
-
rootBuildModuleDir,
|
|
613
|
-
`${ fileName }.js`
|
|
614
|
-
),
|
|
615
|
-
bundle: true,
|
|
616
|
-
sourcemap: true,
|
|
617
|
-
format: 'esm',
|
|
618
|
-
target,
|
|
619
|
-
platform: 'browser',
|
|
620
|
-
minify: false,
|
|
621
|
-
define: getDefine( true ),
|
|
622
|
-
plugins: [
|
|
623
|
-
wordpressExternalsPlugin(
|
|
624
|
-
`${ baseFileName }.min`,
|
|
625
|
-
'esm',
|
|
626
|
-
[],
|
|
627
|
-
false // Skip asset file for non-minified build
|
|
628
|
-
),
|
|
629
|
-
],
|
|
630
626
|
} )
|
|
631
627
|
);
|
|
632
628
|
|
|
629
|
+
if ( ! isWasmWorker ) {
|
|
630
|
+
builds.push(
|
|
631
|
+
esbuild.build( {
|
|
632
|
+
entryPoints: [ entryPoint ],
|
|
633
|
+
outfile: path.join(
|
|
634
|
+
rootBuildModuleDir,
|
|
635
|
+
`${ fileName }.js`
|
|
636
|
+
),
|
|
637
|
+
bundle: true,
|
|
638
|
+
sourcemap: true,
|
|
639
|
+
format: 'esm',
|
|
640
|
+
target,
|
|
641
|
+
platform: 'browser',
|
|
642
|
+
minify: false,
|
|
643
|
+
define: getDefine( true ),
|
|
644
|
+
plugins: [
|
|
645
|
+
wordpressExternalsPlugin(
|
|
646
|
+
`${ baseFileName }.min`,
|
|
647
|
+
'esm',
|
|
648
|
+
[],
|
|
649
|
+
false // Skip asset file for non-minified build
|
|
650
|
+
),
|
|
651
|
+
],
|
|
652
|
+
} )
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
633
656
|
const scriptModuleId =
|
|
634
657
|
exportName === '.'
|
|
635
658
|
? `@${ packageNamespace }/${ packageName }`
|
|
@@ -639,6 +662,7 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
639
662
|
id: scriptModuleId,
|
|
640
663
|
path: `${ packageName }/${ fileName }`,
|
|
641
664
|
asset: `${ packageName }/${ fileName }.min.asset.php`,
|
|
665
|
+
min_only: isWasmWorker,
|
|
642
666
|
} );
|
|
643
667
|
}
|
|
644
668
|
}
|
|
@@ -901,6 +925,7 @@ async function generateModuleRegistrationPhp( modules, replacements ) {
|
|
|
901
925
|
`\t\t'id' => '${ module.id }',\n` +
|
|
902
926
|
`\t\t'path' => '${ module.path }',\n` +
|
|
903
927
|
`\t\t'asset' => '${ module.asset }',\n` +
|
|
928
|
+
( module.min_only ? `\t\t'min_only' => true,\n` : '' ) +
|
|
904
929
|
`\t),`
|
|
905
930
|
)
|
|
906
931
|
.join( '\n' );
|
|
@@ -1807,7 +1832,7 @@ async function buildAll( baseUrlExpression ) {
|
|
|
1807
1832
|
|
|
1808
1833
|
// When building for WordPress Core, exclude experimental pages.
|
|
1809
1834
|
const isCoreBuild =
|
|
1810
|
-
boolConfigVal( process.env.IS_WORDPRESS_CORE )
|
|
1835
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
1811
1836
|
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE );
|
|
1812
1837
|
const activePages = isCoreBuild
|
|
1813
1838
|
? normalizedPages.filter( ( page ) => ! page.experimental )
|
|
@@ -2127,9 +2152,13 @@ async function main() {
|
|
|
2127
2152
|
},
|
|
2128
2153
|
'base-url': {
|
|
2129
2154
|
type: 'string',
|
|
2130
|
-
default:
|
|
2131
|
-
|
|
2132
|
-
|
|
2155
|
+
default:
|
|
2156
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
2157
|
+
boolConfigVal(
|
|
2158
|
+
process.env.npm_package_config_IS_WORDPRESS_CORE
|
|
2159
|
+
)
|
|
2160
|
+
? "includes_url( 'build/' )"
|
|
2161
|
+
: 'plugin_dir_url( __FILE__ )',
|
|
2133
2162
|
},
|
|
2134
2163
|
},
|
|
2135
2164
|
strict: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Build tool for WordPress plugins.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "2cea90674d11aa521ec3f71652fb3a6a4c383969"
|
|
81
81
|
}
|
|
@@ -10,6 +10,16 @@
|
|
|
10
10
|
* Register all script modules.
|
|
11
11
|
*/
|
|
12
12
|
function {{PREFIX}}_register_script_modules() {
|
|
13
|
+
// Ensure this only runs once. wp_default_scripts can fire multiple times,
|
|
14
|
+
// and each wp_deregister_script_module() call also dequeues the module.
|
|
15
|
+
// If a module was enqueued between calls, repeated deregister/register
|
|
16
|
+
// cycles would lose the enqueue state.
|
|
17
|
+
static $already_registered = false;
|
|
18
|
+
if ( $already_registered ) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
$already_registered = true;
|
|
22
|
+
|
|
13
23
|
// Load build constants
|
|
14
24
|
$build_constants = require __DIR__ . '/constants.php';
|
|
15
25
|
$modules_dir = __DIR__ . '/modules';
|
|
@@ -21,9 +31,13 @@ function {{PREFIX}}_register_script_modules() {
|
|
|
21
31
|
|
|
22
32
|
$modules = require $modules_file;
|
|
23
33
|
$base_url = $build_constants['build_url'] . 'modules/';
|
|
24
|
-
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
25
34
|
|
|
26
35
|
foreach ( $modules as $module ) {
|
|
36
|
+
// WASM-only modules (e.g., vips worker) only have .min.js; use it even when SCRIPT_DEBUG is `true`.
|
|
37
|
+
$extension = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && empty( $module['min_only'] ) )
|
|
38
|
+
? '.js'
|
|
39
|
+
: '.min.js';
|
|
40
|
+
|
|
27
41
|
$asset_path = $modules_dir . '/' . $module['asset'];
|
|
28
42
|
$asset = file_exists( $asset_path ) ? require $asset_path : array();
|
|
29
43
|
|