@wordpress/build 0.26.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,32 +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
  );
58
- const resolveDir = path.dirname( args.path );
59
59
  // A relative specifier keeps the checkout path out of the source map.
60
60
  const specifier =
61
61
  './' +
62
62
  path
63
- .relative( resolveDir, targetPath )
63
+ .relative( path.dirname( id ), targetPath )
64
64
  .split( path.sep )
65
65
  .join( '/' );
66
66
  return {
67
- contents: `export { default } from ${ JSON.stringify(
67
+ code: `export { default } from ${ JSON.stringify(
68
68
  specifier
69
69
  ) };`,
70
- loader: 'js',
71
- resolveDir,
70
+ moduleType: 'js',
72
71
  };
73
- } );
72
+ },
74
73
  },
75
74
  };
76
75
  }
@@ -151,7 +150,7 @@ export const workerCode = '/* Placeholder - run npm run build to generate actual
151
150
  * @param {string} options.buildDir Path to the CJS build directory.
152
151
  * @param {string} options.buildModuleDir Path to the ESM build-module directory.
153
152
  * @param {string[]} options.target esbuild target configuration.
154
- * @param {Object} options.wasmInlinePlugin The WASM inline plugin for esbuild.
153
+ * @param {Object} options.wasmInlinePlugin The WASM inline plugin for Rolldown.
155
154
  */
156
155
  export async function buildWorkers(
157
156
  packageDir,
@@ -178,32 +177,39 @@ export async function buildWorkers(
178
177
  // Build ESM worker for build-module (primary for browser use).
179
178
  if ( packageJson.module ) {
180
179
  workerBuilds.push(
181
- esbuild.build( {
182
- entryPoints: [ workerEntryPoint ],
183
- outfile: path.join(
184
- buildModuleDir,
185
- `${ workerOutputName }.mjs`
186
- ),
187
- bundle: true,
188
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
189
- // (ASCII output would escape high bytes as \uXXXX).
190
- charset: 'utf8',
191
- format: 'esm',
180
+ buildWithConcurrency( {
181
+ input: workerEntryPoint,
182
+ // wasm-vips uses eval, don't warn about it
183
+ checks: { eval: false },
192
184
  platform: 'browser',
193
- target,
194
- sourcemap: true,
185
+ // Rolldown's default conditions lack esbuild's module condition.
186
+ resolve: {
187
+ conditionNames: [ 'module', 'browser', 'default' ],
188
+ },
195
189
  // Bundle everything - workers need to be self-contained.
196
- external: [],
197
190
  plugins: [
198
191
  wasmInlinePlugin,
199
192
  ...( resolveMap
200
193
  ? [ createModuleRedirectPlugin( resolveMap ) ]
201
194
  : [] ),
202
195
  ],
203
- define: {
204
- 'process.env.NODE_ENV': JSON.stringify(
205
- 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`
206
208
  ),
209
+ format: 'esm',
210
+ minify: false,
211
+ sourcemap: true,
212
+ codeSplitting: false,
207
213
  },
208
214
  } )
209
215
  );
@@ -220,23 +226,32 @@ export async function buildWorkers(
220
226
  // unused or misleading CJS artifacts.
221
227
  if ( packageJson.main ) {
222
228
  workerBuilds.push(
223
- esbuild.build( {
224
- entryPoints: [ workerEntryPoint ],
225
- outfile: path.join( buildDir, `${ workerOutputName }.cjs` ),
226
- bundle: true,
227
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
228
- // (ASCII output would escape high bytes as \uXXXX).
229
- charset: 'utf8',
230
- format: 'cjs',
229
+ buildWithConcurrency( {
230
+ input: workerEntryPoint,
231
+ // wasm-vips uses eval, don't warn about it
232
+ checks: { eval: false },
231
233
  platform: 'node',
232
- target,
233
- sourcemap: true,
234
- external: [],
234
+ resolve: {
235
+ conditionNames: [ 'module', 'node', 'default' ],
236
+ },
235
237
  plugins: [ wasmInlinePlugin ],
236
- define: {
237
- 'process.env.NODE_ENV': JSON.stringify(
238
- 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`
239
250
  ),
251
+ format: 'cjs',
252
+ minify: false,
253
+ sourcemap: true,
254
+ codeSplitting: false,
240
255
  },
241
256
  } )
242
257
  );
@@ -260,7 +275,7 @@ export async function buildWorkers(
260
275
  * @param {string} options.buildDir Path to the CJS build directory.
261
276
  * @param {string} options.buildModuleDir Path to the ESM build-module directory.
262
277
  * @param {string[]} options.target esbuild target configuration.
263
- * @param {Array} options.plugins esbuild plugins for transpilation.
278
+ * @param {Array} options.plugins Rolldown plugins for transpilation.
264
279
  */
265
280
  export async function generateWorkerCode(
266
281
  packageDir,
@@ -323,48 +338,43 @@ export const workerCode = ${ JSON.stringify( workerContent ) };
323
338
  // build-module/worker-code.mjs (and build/worker-code.cjs if applicable)
324
339
  // reflect the actual worker code in a single build run.
325
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$/, '' );
326
345
  const retranspileBuilds = [];
327
346
 
328
347
  if ( packageJson.module ) {
329
348
  retranspileBuilds.push(
330
- esbuild.build( {
331
- entryPoints: [ workerCodeSrcFile ],
332
- outdir: buildModuleDir,
333
- outbase: srcDir,
334
- outExtension: { '.js': '.mjs' },
335
- bundle: true,
336
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
337
- // (ASCII output would escape high bytes as \uXXXX).
338
- charset: 'utf8',
349
+ buildWithConcurrency( {
350
+ input: { [ workerCodeEntryName ]: workerCodeSrcFile },
339
351
  platform: 'neutral',
340
- format: 'esm',
341
- sourcemap: true,
342
- target,
343
- jsx: 'automatic',
344
- jsxImportSource: 'react',
352
+ transform: { target },
345
353
  plugins,
354
+ output: {
355
+ dir: buildModuleDir,
356
+ entryFileNames: '[name].mjs',
357
+ format: 'esm',
358
+ sourcemap: true,
359
+ },
346
360
  } )
347
361
  );
348
362
  }
349
363
 
350
364
  if ( packageJson.main ) {
351
365
  retranspileBuilds.push(
352
- esbuild.build( {
353
- entryPoints: [ workerCodeSrcFile ],
354
- outdir: buildDir,
355
- outbase: srcDir,
356
- outExtension: { '.js': '.cjs' },
357
- bundle: true,
358
- // Emit UTF-8 so binary-encoded inlined WASM stays compact
359
- // (ASCII output would escape high bytes as \uXXXX).
360
- charset: 'utf8',
366
+ buildWithConcurrency( {
367
+ input: { [ workerCodeEntryName ]: workerCodeSrcFile },
361
368
  platform: 'node',
362
- format: 'cjs',
363
- sourcemap: true,
364
- target,
365
- jsx: 'automatic',
366
- jsxImportSource: 'react',
369
+ transform: { target },
367
370
  plugins,
371
+ output: {
372
+ dir: buildDir,
373
+ entryFileNames: '[name].cjs',
374
+ format: 'cjs',
375
+ exports: 'named',
376
+ sourcemap: true,
377
+ },
368
378
  } )
369
379
  );
370
380
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@wordpress/build",
3
- "version": "0.26.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",
@@ -41,30 +41,30 @@
41
41
  "wp-build": "./lib/build.mjs"
42
42
  },
43
43
  "dependencies": {
44
- "@wordpress/browserslist-config": "^7.0.0",
45
- "@wordpress/style-runtime": "^0.14.0",
44
+ "@wordpress/browserslist-config": "^7.1.0",
45
+ "@wordpress/style-runtime": "^0.15.0",
46
+ "@wordpress/theme-build-tools": "^1.0.0",
46
47
  "autoprefixer": "^10.4.21",
47
48
  "browserslist": "^4.28.7",
48
49
  "browserslist-to-esbuild": "^2.1.1",
49
50
  "change-case": "^4.1.2",
50
51
  "chokidar": "^4.0.0",
51
52
  "cssnano": "^6.0.1",
52
- "esbuild": "^0.27.2",
53
- "esbuild-sass-plugin": "^3.3.1",
54
53
  "fast-glob": "^3.2.7",
55
54
  "moment-timezone": "^0.5.40",
56
55
  "postcss": "^8.4.38",
57
56
  "postcss-modules": "^6.0.1",
57
+ "rolldown": "^1.2.15",
58
58
  "rtlcss": "^4.3.0",
59
59
  "sass-embedded": "^1.97.2"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^24.13.3",
63
- "@wordpress/theme": "^3.0.0",
64
- "vitest": "^5.0.3"
63
+ "@wordpress/theme": "^4.0.0",
64
+ "vitest": "^5.0.5"
65
65
  },
66
66
  "peerDependencies": {
67
- "@wordpress/theme": ">=0.8.0 <3.0.0"
67
+ "@wordpress/theme": "^3.0.0 || ^4.0.0"
68
68
  },
69
69
  "peerDependenciesMeta": {
70
70
  "@wordpress/theme": {
@@ -74,5 +74,5 @@
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  },
77
- "gitHead": "8d30f92cbbde3ddf781c8799443c649befbbcb88"
77
+ "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
78
78
  }
@@ -87,7 +87,7 @@ 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
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',
@@ -170,7 +170,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
170
170
  // This script serves two purposes:
171
171
  // 1. It ensures all the globals that are made available to the modules are loaded.
172
172
  // 2. It initializes the boot module as an inline script.
173
- 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 );
174
174
 
175
175
  $init_modules = {{INIT_MODULES_JSON}};
176
176
 
@@ -88,7 +88,7 @@ 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
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',
@@ -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}};