@wordpress/build 0.8.1-next.v.202602271551.0 → 0.8.1
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/.eslintrc.cjs +6 -0
- package/CHANGELOG.md +7 -0
- package/lib/build.mjs +106 -32
- package/package.json +2 -2
- package/templates/module-registration.php.template +40 -38
- package/templates/page-wp-admin.php.template +245 -236
- package/templates/page.php.template +264 -278
- package/templates/routes-page-functions.php.template +12 -16
- package/templates/routes-registration.php.template +49 -45
- package/templates/script-registration.php.template +65 -69
- package/templates/style-registration.php.template +52 -56
package/.eslintrc.cjs
CHANGED
|
@@ -4,5 +4,11 @@ module.exports = {
|
|
|
4
4
|
rules: {
|
|
5
5
|
// Console should be allowed in a build tool
|
|
6
6
|
'no-console': 'off',
|
|
7
|
+
/*
|
|
8
|
+
* These rules are designed for source files processed by esbuild, not for the build script itself,
|
|
9
|
+
* which runs directly in Node.js.
|
|
10
|
+
*/
|
|
11
|
+
'@wordpress/no-wp-process-env': 'off',
|
|
12
|
+
'@wordpress/wp-global-usage': 'off',
|
|
7
13
|
},
|
|
8
14
|
};
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
### Enhancements
|
|
6
|
+
|
|
7
|
+
- Avoid unexpected results when typecasting `IS_GUTENBERG_PLUGIN` and `IS_WORDPRESS_CORE` values to Booleans ([#75844](https://github.com/WordPress/gutenberg/pull/75844)).
|
|
8
|
+
- Skip PHP transforms during builds when building for WordPress Core ([#75844](https://github.com/WordPress/gutenberg/pull/75844)).
|
|
9
|
+
|
|
10
|
+
## 0.9.0 (2026-03-04)
|
|
11
|
+
|
|
5
12
|
## 0.8.0 (2026-02-18)
|
|
6
13
|
|
|
7
14
|
## 0.7.0 (2026-01-29)
|
package/lib/build.mjs
CHANGED
|
@@ -113,12 +113,32 @@ const HANDLE_PREFIX = WP_PLUGIN_CONFIG.handlePrefix || PACKAGE_NAMESPACE;
|
|
|
113
113
|
const EXTERNAL_NAMESPACES = WP_PLUGIN_CONFIG.externalNamespaces || {};
|
|
114
114
|
const PAGES = WP_PLUGIN_CONFIG.pages || [];
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Interprets a configuration value as a boolean, where `"true"` and `"1"`
|
|
118
|
+
* are considered true while all other values are false.
|
|
119
|
+
*
|
|
120
|
+
* @param {string|undefined} value The configuration value to interpret.
|
|
121
|
+
* @return {boolean|undefined} Boolean interpretation of the given configuration value, or undefined if not set.
|
|
122
|
+
*/
|
|
123
|
+
const boolConfigVal = ( value ) => {
|
|
124
|
+
if ( value === undefined ) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
return [ 'true', '1' ].includes( value.toLowerCase() );
|
|
128
|
+
};
|
|
129
|
+
|
|
116
130
|
const baseDefine = {
|
|
117
131
|
'globalThis.IS_GUTENBERG_PLUGIN': JSON.stringify(
|
|
118
|
-
|
|
132
|
+
boolConfigVal( process.env.IS_GUTENBERG_PLUGIN ) ??
|
|
133
|
+
boolConfigVal(
|
|
134
|
+
process.env.npm_package_config_IS_GUTENBERG_PLUGIN
|
|
135
|
+
) ??
|
|
136
|
+
false
|
|
119
137
|
),
|
|
120
138
|
'globalThis.IS_WORDPRESS_CORE': JSON.stringify(
|
|
121
|
-
|
|
139
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
140
|
+
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE ) ??
|
|
141
|
+
false
|
|
122
142
|
),
|
|
123
143
|
};
|
|
124
144
|
const getDefine = ( scriptDebug ) => ( {
|
|
@@ -194,7 +214,7 @@ function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
|
|
|
194
214
|
map: false,
|
|
195
215
|
} );
|
|
196
216
|
|
|
197
|
-
let cssModule = `if (typeof document !== 'undefined' &&
|
|
217
|
+
let cssModule = `if (typeof document !== 'undefined' && !document.head.querySelector("style[data-wp-hash='${ hash }']")) {
|
|
198
218
|
const style = document.createElement("style");
|
|
199
219
|
style.setAttribute("data-wp-hash", "${ hash }");
|
|
200
220
|
style.appendChild(document.createTextNode(${ JSON.stringify( css ) }));
|
|
@@ -228,6 +248,7 @@ function createStyleBundlingPlugins( workingDir ) {
|
|
|
228
248
|
// Handle CSS modules (.module.css and .module.scss)
|
|
229
249
|
sassPlugin( {
|
|
230
250
|
embedded: true,
|
|
251
|
+
sourceMap: false,
|
|
231
252
|
filter: /\.module\.(css|scss)$/,
|
|
232
253
|
transform: compileInlineStyle( { cssModules: true } ),
|
|
233
254
|
type: inlineStyle,
|
|
@@ -237,6 +258,7 @@ function createStyleBundlingPlugins( workingDir ) {
|
|
|
237
258
|
// Note: .module.css and .module.scss already handled by plugin above
|
|
238
259
|
sassPlugin( {
|
|
239
260
|
embedded: true,
|
|
261
|
+
sourceMap: false,
|
|
240
262
|
filter: /\.(css|scss)$/,
|
|
241
263
|
transform: compileInlineStyle(),
|
|
242
264
|
type: inlineStyle,
|
|
@@ -264,8 +286,11 @@ const wasmInlinePlugin = {
|
|
|
264
286
|
try {
|
|
265
287
|
const resolved = require.resolve( args.path );
|
|
266
288
|
return {
|
|
267
|
-
path:
|
|
289
|
+
path: normalizePath(
|
|
290
|
+
path.relative( ROOT_DIR, resolved )
|
|
291
|
+
),
|
|
268
292
|
namespace: 'wasm-inline',
|
|
293
|
+
pluginData: { resolvedPath: resolved },
|
|
269
294
|
};
|
|
270
295
|
} catch {
|
|
271
296
|
// If resolution fails, let other plugins handle it.
|
|
@@ -279,7 +304,9 @@ const wasmInlinePlugin = {
|
|
|
279
304
|
build.onLoad(
|
|
280
305
|
{ filter: /.*/, namespace: 'wasm-inline' },
|
|
281
306
|
async ( args ) => {
|
|
282
|
-
const wasmBuffer = await readFile(
|
|
307
|
+
const wasmBuffer = await readFile(
|
|
308
|
+
args.pluginData.resolvedPath
|
|
309
|
+
);
|
|
283
310
|
const base64 = wasmBuffer.toString( 'base64' );
|
|
284
311
|
const dataUrl = `data:application/wasm;base64,${ base64 }`;
|
|
285
312
|
|
|
@@ -313,6 +340,19 @@ function transformPhpContent( content, transforms ) {
|
|
|
313
340
|
|
|
314
341
|
content = content.toString();
|
|
315
342
|
|
|
343
|
+
/*
|
|
344
|
+
* Transforms are used to modify PHP files that are committed to version
|
|
345
|
+
* control in their wordpress-develop state (`wp_` function prefixes, `WP_`
|
|
346
|
+
* class prefixes, etc.). When building for WordPress Core, it's not
|
|
347
|
+
* necessary to perform these steps.
|
|
348
|
+
*/
|
|
349
|
+
if (
|
|
350
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
351
|
+
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE )
|
|
352
|
+
) {
|
|
353
|
+
return content;
|
|
354
|
+
}
|
|
355
|
+
|
|
316
356
|
if ( prefixFunctions.length ) {
|
|
317
357
|
content = content.replace(
|
|
318
358
|
new RegExp( prefixFunctions.join( '|' ), 'g' ),
|
|
@@ -551,6 +591,15 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
551
591
|
const entryPoint = path.join( packageDir, exportPath );
|
|
552
592
|
const baseFileName = path.basename( fileName );
|
|
553
593
|
|
|
594
|
+
// Skip non-minified build for WASM-inlined workers (e.g., vips).
|
|
595
|
+
// These are ~16MB of base64-encoded WASM with no debugging value
|
|
596
|
+
// over the minified version.
|
|
597
|
+
const isWasmWorker =
|
|
598
|
+
packageJson.wpWorkers &&
|
|
599
|
+
Object.keys( packageJson.wpWorkers ).some(
|
|
600
|
+
( key ) => key.replace( /^\.\//, '' ) === fileName
|
|
601
|
+
);
|
|
602
|
+
|
|
554
603
|
builds.push(
|
|
555
604
|
esbuild.build( {
|
|
556
605
|
entryPoints: [ entryPoint ],
|
|
@@ -573,31 +622,36 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
573
622
|
true // Generate asset file for minified build
|
|
574
623
|
),
|
|
575
624
|
],
|
|
576
|
-
} ),
|
|
577
|
-
esbuild.build( {
|
|
578
|
-
entryPoints: [ entryPoint ],
|
|
579
|
-
outfile: path.join(
|
|
580
|
-
rootBuildModuleDir,
|
|
581
|
-
`${ fileName }.js`
|
|
582
|
-
),
|
|
583
|
-
bundle: true,
|
|
584
|
-
sourcemap: true,
|
|
585
|
-
format: 'esm',
|
|
586
|
-
target,
|
|
587
|
-
platform: 'browser',
|
|
588
|
-
minify: false,
|
|
589
|
-
define: getDefine( true ),
|
|
590
|
-
plugins: [
|
|
591
|
-
wordpressExternalsPlugin(
|
|
592
|
-
`${ baseFileName }.min`,
|
|
593
|
-
'esm',
|
|
594
|
-
[],
|
|
595
|
-
false // Skip asset file for non-minified build
|
|
596
|
-
),
|
|
597
|
-
],
|
|
598
625
|
} )
|
|
599
626
|
);
|
|
600
627
|
|
|
628
|
+
if ( ! isWasmWorker ) {
|
|
629
|
+
builds.push(
|
|
630
|
+
esbuild.build( {
|
|
631
|
+
entryPoints: [ entryPoint ],
|
|
632
|
+
outfile: path.join(
|
|
633
|
+
rootBuildModuleDir,
|
|
634
|
+
`${ fileName }.js`
|
|
635
|
+
),
|
|
636
|
+
bundle: true,
|
|
637
|
+
sourcemap: true,
|
|
638
|
+
format: 'esm',
|
|
639
|
+
target,
|
|
640
|
+
platform: 'browser',
|
|
641
|
+
minify: false,
|
|
642
|
+
define: getDefine( true ),
|
|
643
|
+
plugins: [
|
|
644
|
+
wordpressExternalsPlugin(
|
|
645
|
+
`${ baseFileName }.min`,
|
|
646
|
+
'esm',
|
|
647
|
+
[],
|
|
648
|
+
false // Skip asset file for non-minified build
|
|
649
|
+
),
|
|
650
|
+
],
|
|
651
|
+
} )
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
|
|
601
655
|
const scriptModuleId =
|
|
602
656
|
exportName === '.'
|
|
603
657
|
? `@${ packageNamespace }/${ packageName }`
|
|
@@ -607,6 +661,7 @@ async function bundlePackage( packageName, options = {} ) {
|
|
|
607
661
|
id: scriptModuleId,
|
|
608
662
|
path: `${ packageName }/${ fileName }`,
|
|
609
663
|
asset: `${ packageName }/${ fileName }.min.asset.php`,
|
|
664
|
+
min_only: isWasmWorker,
|
|
610
665
|
} );
|
|
611
666
|
}
|
|
612
667
|
}
|
|
@@ -869,6 +924,7 @@ async function generateModuleRegistrationPhp( modules, replacements ) {
|
|
|
869
924
|
`\t\t'id' => '${ module.id }',\n` +
|
|
870
925
|
`\t\t'path' => '${ module.path }',\n` +
|
|
871
926
|
`\t\t'asset' => '${ module.asset }',\n` +
|
|
927
|
+
( module.min_only ? `\t\t'min_only' => true,\n` : '' ) +
|
|
872
928
|
`\t),`
|
|
873
929
|
)
|
|
874
930
|
.join( '\n' );
|
|
@@ -1769,11 +1825,23 @@ async function buildAll( baseUrlExpression ) {
|
|
|
1769
1825
|
id: page.id,
|
|
1770
1826
|
init: page.init || [],
|
|
1771
1827
|
title: page.title || undefined,
|
|
1828
|
+
experimental: page.experimental || false,
|
|
1772
1829
|
};
|
|
1773
1830
|
} );
|
|
1774
1831
|
|
|
1775
|
-
|
|
1776
|
-
|
|
1832
|
+
// When building for WordPress Core, exclude experimental pages.
|
|
1833
|
+
const isCoreBuild =
|
|
1834
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
1835
|
+
boolConfigVal( process.env.npm_package_config_IS_WORDPRESS_CORE );
|
|
1836
|
+
const activePages = isCoreBuild
|
|
1837
|
+
? normalizedPages.filter( ( page ) => ! page.experimental )
|
|
1838
|
+
: normalizedPages;
|
|
1839
|
+
|
|
1840
|
+
const activePageIds = new Set( activePages.map( ( p ) => p.id ) );
|
|
1841
|
+
const activeRoutes = routes.filter( ( r ) => activePageIds.has( r.page ) );
|
|
1842
|
+
|
|
1843
|
+
const pageData = activePages.map( ( page ) => {
|
|
1844
|
+
const pageRoutes = activeRoutes.filter( ( r ) => r.page === page.id );
|
|
1777
1845
|
return {
|
|
1778
1846
|
slug: page.id,
|
|
1779
1847
|
routes: pageRoutes,
|
|
@@ -1838,8 +1906,8 @@ async function buildAll( baseUrlExpression ) {
|
|
|
1838
1906
|
generateScriptRegistrationPhp( scripts, phpReplacements ),
|
|
1839
1907
|
generateStyleRegistrationPhp( styles, phpReplacements ),
|
|
1840
1908
|
generateConstantsPhp( phpReplacements ),
|
|
1841
|
-
generateRoutesRegistry(
|
|
1842
|
-
generateRoutesPhp(
|
|
1909
|
+
generateRoutesRegistry( activeRoutes, phpReplacements ),
|
|
1910
|
+
generateRoutesPhp( activeRoutes, phpReplacements ),
|
|
1843
1911
|
generatePagesPhp( pageData, phpReplacements ),
|
|
1844
1912
|
] );
|
|
1845
1913
|
console.log( ' ✔ Generated build/build.php' );
|
|
@@ -2128,7 +2196,13 @@ async function main() {
|
|
|
2128
2196
|
},
|
|
2129
2197
|
'base-url': {
|
|
2130
2198
|
type: 'string',
|
|
2131
|
-
default:
|
|
2199
|
+
default:
|
|
2200
|
+
boolConfigVal( process.env.IS_WORDPRESS_CORE ) ??
|
|
2201
|
+
boolConfigVal(
|
|
2202
|
+
process.env.npm_package_config_IS_WORDPRESS_CORE
|
|
2203
|
+
)
|
|
2204
|
+
? "includes_url( 'build/' )"
|
|
2205
|
+
: 'plugin_dir_url( __FILE__ )',
|
|
2132
2206
|
},
|
|
2133
2207
|
},
|
|
2134
2208
|
strict: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/build",
|
|
3
|
-
"version": "0.8.1
|
|
3
|
+
"version": "0.8.1",
|
|
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": "adb6623c9f32490cfc73c7ac7f122578c1f10c65"
|
|
81
81
|
}
|
|
@@ -6,44 +6,46 @@
|
|
|
6
6
|
* @package {{PREFIX}}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
$modules = require $modules_file;
|
|
24
|
-
$base_url = $build_constants['build_url'] . 'modules/';
|
|
25
|
-
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
26
|
-
|
|
27
|
-
foreach ( $modules as $module ) {
|
|
28
|
-
$asset_path = $modules_dir . '/' . $module['asset'];
|
|
29
|
-
$asset = file_exists( $asset_path ) ? require $asset_path : array();
|
|
30
|
-
|
|
31
|
-
// Deregister first to override any previously registered version
|
|
32
|
-
// (e.g., Core's default modules when running as a plugin).
|
|
33
|
-
wp_deregister_script_module( $module['id'] );
|
|
34
|
-
|
|
35
|
-
wp_register_script_module(
|
|
36
|
-
$module['id'],
|
|
37
|
-
$base_url . $module['path'] . $extension,
|
|
38
|
-
$asset['module_dependencies'] ?? array(),
|
|
39
|
-
$asset['version'] ?? false,
|
|
40
|
-
array(
|
|
41
|
-
'fetchpriority' => 'low',
|
|
42
|
-
'in_footer' => true,
|
|
43
|
-
)
|
|
44
|
-
);
|
|
45
|
-
}
|
|
9
|
+
/**
|
|
10
|
+
* Register all script modules.
|
|
11
|
+
*/
|
|
12
|
+
function {{PREFIX}}_register_script_modules() {
|
|
13
|
+
// Load build constants
|
|
14
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
15
|
+
$modules_dir = __DIR__ . '/modules';
|
|
16
|
+
$modules_file = $modules_dir . '/registry.php';
|
|
17
|
+
|
|
18
|
+
if ( ! file_exists( $modules_file ) ) {
|
|
19
|
+
return;
|
|
46
20
|
}
|
|
47
21
|
|
|
48
|
-
|
|
22
|
+
$modules = require $modules_file;
|
|
23
|
+
$base_url = $build_constants['build_url'] . 'modules/';
|
|
24
|
+
|
|
25
|
+
foreach ( $modules as $module ) {
|
|
26
|
+
// WASM-only modules (e.g., vips worker) only have .min.js; use it even when SCRIPT_DEBUG is `true`.
|
|
27
|
+
$extension = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && empty( $module['min_only'] ) )
|
|
28
|
+
? '.js'
|
|
29
|
+
: '.min.js';
|
|
30
|
+
|
|
31
|
+
$asset_path = $modules_dir . '/' . $module['asset'];
|
|
32
|
+
$asset = file_exists( $asset_path ) ? require $asset_path : array();
|
|
33
|
+
|
|
34
|
+
// Deregister first to override any previously registered version
|
|
35
|
+
// (e.g., Core's default modules when running as a plugin).
|
|
36
|
+
wp_deregister_script_module( $module['id'] );
|
|
37
|
+
|
|
38
|
+
wp_register_script_module(
|
|
39
|
+
$module['id'],
|
|
40
|
+
$base_url . $module['path'] . $extension,
|
|
41
|
+
$asset['module_dependencies'] ?? array(),
|
|
42
|
+
$asset['version'] ?? false,
|
|
43
|
+
array(
|
|
44
|
+
'fetchpriority' => 'low',
|
|
45
|
+
'in_footer' => true,
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
add_action( 'wp_default_scripts', '{{PREFIX}}_register_script_modules' );
|