@wordpress/build 0.25.0 → 0.27.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.
@@ -8,10 +8,10 @@
8
8
  */
9
9
  import { readFile, writeFile, access } from 'fs/promises';
10
10
  import path from 'path';
11
- import esbuild from 'esbuild';
11
+ import { buildWithConcurrency } from './build-concurrency.mjs';
12
12
 
13
13
  /**
14
- * Creates an esbuild plugin that redirects module loads based on filename patterns.
14
+ * Creates a Rolldown plugin that redirects module loads based on filename patterns.
15
15
  *
16
16
  * This is useful when bundling workers for Blob URL contexts where certain
17
17
  * ES module entry points use `import.meta.url` (which resolves to an invalid
@@ -30,11 +30,11 @@ import esbuild from 'esbuild';
30
30
  * }
31
31
  *
32
32
  * @param {Object} resolveMap An object mapping source filenames to target
33
- * filenames. When esbuild loads a file whose path
33
+ * filenames. When Rolldown loads a file whose path
34
34
  * ends with a source key, the plugin rewrites it
35
35
  * to re-export from the corresponding target file
36
36
  * in the same directory.
37
- * @return {Object} An esbuild plugin.
37
+ * @return {import('rolldown').Plugin} A Rolldown plugin.
38
38
  */
39
39
  function createModuleRedirectPlugin( resolveMap ) {
40
40
  // Build a single regex that matches any of the source filenames.
@@ -45,23 +45,31 @@ function createModuleRedirectPlugin( resolveMap ) {
45
45
 
46
46
  return {
47
47
  name: 'module-redirect',
48
- setup( build ) {
49
- build.onLoad( { filter: pattern }, ( args ) => {
48
+ load: {
49
+ filter: { id: pattern },
50
+ handler( id ) {
50
51
  // Find which key matched.
51
52
  const matchedKey = Object.keys( resolveMap ).find( ( key ) =>
52
- args.path.endsWith( key )
53
+ id.endsWith( key )
53
54
  );
54
- const targetPath = args.path.replace(
55
+ const targetPath = id.replace(
55
56
  matchedKey,
56
57
  resolveMap[ matchedKey ]
57
58
  );
59
+ // A relative specifier keeps the checkout path out of the source map.
60
+ const specifier =
61
+ './' +
62
+ path
63
+ .relative( path.dirname( id ), targetPath )
64
+ .split( path.sep )
65
+ .join( '/' );
58
66
  return {
59
- contents: `export { default } from ${ JSON.stringify(
60
- targetPath
67
+ code: `export { default } from ${ JSON.stringify(
68
+ specifier
61
69
  ) };`,
62
- loader: 'js',
70
+ moduleType: 'js',
63
71
  };
64
- } );
72
+ },
65
73
  },
66
74
  };
67
75
  }
@@ -142,7 +150,7 @@ export const workerCode = '/* Placeholder - run npm run build to generate actual
142
150
  * @param {string} options.buildDir Path to the CJS build directory.
143
151
  * @param {string} options.buildModuleDir Path to the ESM build-module directory.
144
152
  * @param {string[]} options.target esbuild target configuration.
145
- * @param {Object} options.wasmInlinePlugin The WASM inline plugin for esbuild.
153
+ * @param {Object} options.wasmInlinePlugin The WASM inline plugin for Rolldown.
146
154
  */
147
155
  export async function buildWorkers(
148
156
  packageDir,
@@ -169,32 +177,39 @@ export async function buildWorkers(
169
177
  // Build ESM worker for build-module (primary for browser use).
170
178
  if ( packageJson.module ) {
171
179
  workerBuilds.push(
172
- esbuild.build( {
173
- entryPoints: [ workerEntryPoint ],
174
- outfile: path.join(
175
- buildModuleDir,
176
- `${ workerOutputName }.mjs`
177
- ),
178
- bundle: true,
179
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
180
- // (ASCII output would escape high bytes as \uXXXX).
181
- charset: 'utf8',
182
- format: 'esm',
180
+ buildWithConcurrency( {
181
+ input: workerEntryPoint,
182
+ // wasm-vips uses eval, don't warn about it
183
+ checks: { eval: false },
183
184
  platform: 'browser',
184
- target,
185
- sourcemap: true,
185
+ // Rolldown's default conditions lack esbuild's module condition.
186
+ resolve: {
187
+ conditionNames: [ 'module', 'browser', 'default' ],
188
+ },
186
189
  // Bundle everything - workers need to be self-contained.
187
- external: [],
188
190
  plugins: [
189
191
  wasmInlinePlugin,
190
192
  ...( resolveMap
191
193
  ? [ createModuleRedirectPlugin( resolveMap ) ]
192
194
  : [] ),
193
195
  ],
194
- define: {
195
- 'process.env.NODE_ENV': JSON.stringify(
196
- process.env.NODE_ENV || 'production'
196
+ transform: {
197
+ target,
198
+ define: {
199
+ 'process.env.NODE_ENV': JSON.stringify(
200
+ process.env.NODE_ENV || 'production'
201
+ ),
202
+ },
203
+ },
204
+ output: {
205
+ file: path.join(
206
+ buildModuleDir,
207
+ `${ workerOutputName }.mjs`
197
208
  ),
209
+ format: 'esm',
210
+ minify: false,
211
+ sourcemap: true,
212
+ codeSplitting: false,
198
213
  },
199
214
  } )
200
215
  );
@@ -211,23 +226,32 @@ export async function buildWorkers(
211
226
  // unused or misleading CJS artifacts.
212
227
  if ( packageJson.main ) {
213
228
  workerBuilds.push(
214
- esbuild.build( {
215
- entryPoints: [ workerEntryPoint ],
216
- outfile: path.join( buildDir, `${ workerOutputName }.cjs` ),
217
- bundle: true,
218
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
219
- // (ASCII output would escape high bytes as \uXXXX).
220
- charset: 'utf8',
221
- format: 'cjs',
229
+ buildWithConcurrency( {
230
+ input: workerEntryPoint,
231
+ // wasm-vips uses eval, don't warn about it
232
+ checks: { eval: false },
222
233
  platform: 'node',
223
- target,
224
- sourcemap: true,
225
- external: [],
234
+ resolve: {
235
+ conditionNames: [ 'module', 'node', 'default' ],
236
+ },
226
237
  plugins: [ wasmInlinePlugin ],
227
- define: {
228
- 'process.env.NODE_ENV': JSON.stringify(
229
- process.env.NODE_ENV || 'production'
238
+ transform: {
239
+ target,
240
+ define: {
241
+ 'process.env.NODE_ENV': JSON.stringify(
242
+ process.env.NODE_ENV || 'production'
243
+ ),
244
+ },
245
+ },
246
+ output: {
247
+ file: path.join(
248
+ buildDir,
249
+ `${ workerOutputName }.cjs`
230
250
  ),
251
+ format: 'cjs',
252
+ minify: false,
253
+ sourcemap: true,
254
+ codeSplitting: false,
231
255
  },
232
256
  } )
233
257
  );
@@ -251,7 +275,7 @@ export async function buildWorkers(
251
275
  * @param {string} options.buildDir Path to the CJS build directory.
252
276
  * @param {string} options.buildModuleDir Path to the ESM build-module directory.
253
277
  * @param {string[]} options.target esbuild target configuration.
254
- * @param {Array} options.plugins esbuild plugins for transpilation.
278
+ * @param {Array} options.plugins Rolldown plugins for transpilation.
255
279
  */
256
280
  export async function generateWorkerCode(
257
281
  packageDir,
@@ -314,48 +338,43 @@ export const workerCode = ${ JSON.stringify( workerContent ) };
314
338
  // build-module/worker-code.mjs (and build/worker-code.cjs if applicable)
315
339
  // reflect the actual worker code in a single build run.
316
340
  const workerCodeSrcFile = path.join( packageDir, 'src', 'worker-code.ts' );
341
+ // Name the entry after its path in `src`, so the output mirrors it.
342
+ const workerCodeEntryName = path
343
+ .relative( srcDir, workerCodeSrcFile )
344
+ .replace( /\.ts$/, '' );
317
345
  const retranspileBuilds = [];
318
346
 
319
347
  if ( packageJson.module ) {
320
348
  retranspileBuilds.push(
321
- esbuild.build( {
322
- entryPoints: [ workerCodeSrcFile ],
323
- outdir: buildModuleDir,
324
- outbase: srcDir,
325
- outExtension: { '.js': '.mjs' },
326
- bundle: true,
327
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
328
- // (ASCII output would escape high bytes as \uXXXX).
329
- charset: 'utf8',
349
+ buildWithConcurrency( {
350
+ input: { [ workerCodeEntryName ]: workerCodeSrcFile },
330
351
  platform: 'neutral',
331
- format: 'esm',
332
- sourcemap: true,
333
- target,
334
- jsx: 'automatic',
335
- jsxImportSource: 'react',
352
+ transform: { target },
336
353
  plugins,
354
+ output: {
355
+ dir: buildModuleDir,
356
+ entryFileNames: '[name].mjs',
357
+ format: 'esm',
358
+ sourcemap: true,
359
+ },
337
360
  } )
338
361
  );
339
362
  }
340
363
 
341
364
  if ( packageJson.main ) {
342
365
  retranspileBuilds.push(
343
- esbuild.build( {
344
- entryPoints: [ workerCodeSrcFile ],
345
- outdir: buildDir,
346
- outbase: srcDir,
347
- outExtension: { '.js': '.cjs' },
348
- bundle: true,
349
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
350
- // (ASCII output would escape high bytes as \uXXXX).
351
- charset: 'utf8',
366
+ buildWithConcurrency( {
367
+ input: { [ workerCodeEntryName ]: workerCodeSrcFile },
352
368
  platform: 'node',
353
- format: 'cjs',
354
- sourcemap: true,
355
- target,
356
- jsx: 'automatic',
357
- jsxImportSource: 'react',
369
+ transform: { target },
358
370
  plugins,
371
+ output: {
372
+ dir: buildDir,
373
+ entryFileNames: '[name].cjs',
374
+ format: 'cjs',
375
+ exports: 'named',
376
+ sourcemap: true,
377
+ },
359
378
  } )
360
379
  );
361
380
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@wordpress/build",
3
- "version": "0.25.0",
3
+ "version": "0.27.0",
4
4
  "description": "Build tool for WordPress plugins.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
7
7
  "keywords": [
8
8
  "wordpress",
9
9
  "build",
10
- "esbuild",
10
+ "rolldown",
11
11
  "bundler"
12
12
  ],
13
13
  "homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/wp-build/README.md",
@@ -20,8 +20,15 @@
20
20
  "url": "https://github.com/WordPress/gutenberg/issues"
21
21
  },
22
22
  "engines": {
23
- "node": ">=20.10.0"
23
+ "node": ">=22.13.0"
24
24
  },
25
+ "files": [
26
+ "eslint-overrides.cjs",
27
+ "lib",
28
+ "templates",
29
+ "*.md",
30
+ "!**/test/**"
31
+ ],
25
32
  "type": "module",
26
33
  "module": "./lib/build.mjs",
27
34
  "exports": {
@@ -34,33 +41,30 @@
34
41
  "wp-build": "./lib/build.mjs"
35
42
  },
36
43
  "dependencies": {
37
- "@babel/core": "^7.25.7",
38
- "@emotion/babel-plugin": "^11.13.5",
39
- "@wordpress/browserslist-config": "^6.57.0",
40
- "@wordpress/style-runtime": "^0.13.0",
44
+ "@wordpress/browserslist-config": "^7.1.0",
45
+ "@wordpress/style-runtime": "^0.15.0",
46
+ "@wordpress/theme-build-tools": "^1.0.0",
41
47
  "autoprefixer": "^10.4.21",
42
48
  "browserslist": "^4.28.7",
43
49
  "browserslist-to-esbuild": "^2.1.1",
44
50
  "change-case": "^4.1.2",
45
51
  "chokidar": "^4.0.0",
46
52
  "cssnano": "^6.0.1",
47
- "esbuild": "^0.27.2",
48
- "esbuild-plugin-babel": "^0.2.3",
49
- "esbuild-sass-plugin": "^3.3.1",
50
53
  "fast-glob": "^3.2.7",
51
54
  "moment-timezone": "^0.5.40",
52
55
  "postcss": "^8.4.38",
53
56
  "postcss-modules": "^6.0.1",
57
+ "rolldown": "^1.2.15",
54
58
  "rtlcss": "^4.3.0",
55
59
  "sass-embedded": "^1.97.2"
56
60
  },
57
61
  "devDependencies": {
58
62
  "@types/node": "^24.13.3",
59
- "@wordpress/theme": "^2.3.0",
60
- "vitest": "^5.0.3"
63
+ "@wordpress/theme": "^4.0.0",
64
+ "vitest": "^5.0.5"
61
65
  },
62
66
  "peerDependencies": {
63
- "@wordpress/theme": ">=0.8.0 <3.0.0"
67
+ "@wordpress/theme": "^3.0.0 || ^4.0.0"
64
68
  },
65
69
  "peerDependenciesMeta": {
66
70
  "@wordpress/theme": {
@@ -70,5 +74,5 @@
70
74
  "publishConfig": {
71
75
  "access": "public"
72
76
  },
73
- "gitHead": "12441e2520c78b2254a792a8cba40c34110be060"
77
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
74
78
  }
@@ -87,13 +87,25 @@ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_menu_items() {
87
87
  */
88
88
  function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_data() {
89
89
  // Define paths to preload - same for all pages
90
- // This must exactly match the _fields list in packages/core-data/src/entities.js,
90
+ // This must exactly match the _fields list in packages/core-data/src/entities.ts,
91
91
  // same fields in the same order, or the preload is never consumed.
92
92
  $preload_paths = array(
93
- '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
93
+ '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
94
94
  array( '/wp/v2/settings', 'OPTIONS' ),
95
95
  );
96
96
 
97
+ /**
98
+ * Filters the REST API paths preloaded for this page.
99
+ *
100
+ * Each entry is either a string path (GET) or a `[ path, method ]` tuple.
101
+ * Pages that know which requests their JS will issue on mount can add
102
+ * them here so the responses are embedded in the initial HTML rather
103
+ * than fetched over the network after hydration.
104
+ *
105
+ * @param array<string|string[]> $preload_paths Paths to preload.
106
+ */
107
+ $preload_paths = apply_filters( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_preload_paths', $preload_paths );
108
+
97
109
  // Use rest_preload_api_request to gather the preloaded data
98
110
  $preload_data = array_reduce(
99
111
  $preload_paths,
@@ -158,7 +170,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
158
170
  // This script serves two purposes:
159
171
  // 1. It ensures all the globals that are made available to the modules are loaded.
160
172
  // 2. It initializes the boot module as an inline script.
161
- wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
173
+ wp_register_script( '{{PAGE_SLUG}}-wp-admin-prerequisites', false, $asset['dependencies'], $asset['version'], true );
162
174
 
163
175
  $init_modules = {{INIT_MODULES_JSON}};
164
176
 
@@ -88,10 +88,10 @@ function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items() {
88
88
  */
89
89
  function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data() {
90
90
  // Define paths to preload - same for all pages
91
- // This must exactly match the _fields list in packages/core-data/src/entities.js,
91
+ // This must exactly match the _fields list in packages/core-data/src/entities.ts,
92
92
  // same fields in the same order, or the preload is never consumed.
93
93
  $preload_paths = array(
94
- '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
94
+ '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
95
95
  array( '/wp/v2/settings', 'OPTIONS' ),
96
96
  );
97
97
 
@@ -164,7 +164,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
164
164
  // This script serves two purposes:
165
165
  // 1. It ensures all the globals that are made available to the modules are loaded.
166
166
  // 2. It initializes the boot module as an inline script.
167
- wp_register_script( '{{PAGE_SLUG}}-prerequisites', '', $asset['dependencies'], $asset['version'], true );
167
+ wp_register_script( '{{PAGE_SLUG}}-prerequisites', false, $asset['dependencies'], $asset['version'], true );
168
168
 
169
169
  // Add inline script to initialize the app
170
170
  $init_modules = {{INIT_MODULES_JSON}};
@@ -52,7 +52,7 @@ function {{PREFIX}}_override_script( $scripts, $handle, $src, $deps = array(), $
52
52
  function {{PREFIX}}_register_package_scripts( $scripts ) {
53
53
  // Load build constants
54
54
  $build_constants = require __DIR__ . '/constants.php';
55
- $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
55
+ $default_version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $build_constants['version'];
56
56
  $extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
57
57
 
58
58
  $scripts_dir = __DIR__ . '/scripts';
@@ -42,8 +42,8 @@ function {{PREFIX}}_override_style( $styles, $handle, $src, $deps = array(), $ve
42
42
  function {{PREFIX}}_register_package_styles( $styles ) {
43
43
  // Load build constants
44
44
  $build_constants = require __DIR__ . '/constants.php';
45
- $default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
46
- $suffix = SCRIPT_DEBUG ? '' : '.min';
45
+ $default_version = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? time() : $build_constants['version'];
46
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
47
47
 
48
48
  $styles_dir = __DIR__ . '/styles';
49
49
  $styles_file = $styles_dir . '/registry.php';