@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.
package/CHANGELOG.md CHANGED
@@ -2,11 +2,59 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.27.0 (2026-11-04)
6
+
7
+ ### Enhancements
8
+
9
+ - Copy `example` from `widget.json` into `build/widgets/registry.php`, next to `attributes`, so a widget's example attributes reach the server registry without a metadata module ([#85240](https://github.com/WordPress/gutenberg/pull/85240)).
10
+ - Limit concurrent `esbuild` build jobs to half of the available CPU parallelism ([#79889](https://github.com/WordPress/gutenberg/pull/79889)).
11
+
12
+ ### Bug Fixes
13
+
14
+ - Derive CSS module class names from the stylesheet's CSS as well as its path, so two builds of a package share class names only where their CSS is identical. This stops an older bundled copy of a package from styling a newer copy's elements. All CSS module class names change once with this release ([#85900](https://github.com/WordPress/gutenberg/pull/85900)).
15
+
16
+ ### Internal
17
+
18
+ - Pass `false` instead of an empty string as `$src` in `wp_register_script()` in page templates ([#86106](https://github.com/WordPress/gutenberg/pull/86106)).
19
+ - Update the Vitest development dependency to 5.0.5 ([#86173](https://github.com/WordPress/gutenberg/pull/86173)).
20
+ - Bundle and transpile with Rolldown instead of esbuild ([#85476](https://github.com/WordPress/gutenberg/pull/85476)).
21
+ - Load design token fallback plugins from the new `@wordpress/theme-build-tools` dependency instead of the `@wordpress/theme` entry points ([#83568](https://github.com/WordPress/gutenberg/pull/83568)).
22
+ - Declare `@wordpress/theme` as an optional peer dependency again, so the fallback plugins use the version the consumer installs ([#85388](https://github.com/WordPress/gutenberg/pull/85388)).
23
+ - Point the page templates' preload comments at the TypeScript `entities.ts` in `@wordpress/core-data` ([#85070](https://github.com/WordPress/gutenberg/pull/85070)).
24
+ - Note beside `applyTemplateReplacements()` that Gutenberg's PHPStan analysis of the PHP templates keeps a sample value for each placeholder, which must be updated along with it ([#66693](https://github.com/WordPress/gutenberg/pull/66693)).
25
+
26
+ ## 0.26.0 (2026-10-20)
27
+
28
+ ### Breaking Changes
29
+
30
+ - Remove the automatic Babel processing for `packages/components`, including the Emotion transform, implicit project Babel configuration support, and build-time dependencies. Projects that rely on these transforms must run Babel separately before `@wordpress/build` ([#84707](https://github.com/WordPress/gutenberg/pull/84707)).
31
+ - Raise the minimum required Node.js version to `>=22.13.0`, for stable `require(esm)` support ([#84313](https://github.com/WordPress/gutenberg/pull/84313)).
32
+
33
+ ### New Features
34
+
35
+ - Support importing `.svg` files from JavaScript. The SVG is inlined into the bundle (and into transpiled packages) and the import resolves to a `data:` URI ([#85147](https://github.com/WordPress/gutenberg/pull/85147)).
36
+ - Add a `{prefix}_{page_slug}_wp_admin_preload_paths` filter to the generated wp-admin page template, so a page can preload the REST API requests its JavaScript issues on mount ([#77353](https://github.com/WordPress/gutenberg/pull/77353)).
37
+
38
+ ### Enhancements
39
+
40
+ - Expose a script's exports on its global as read-only data properties, holding the same values, instead of esbuild's getters, which forwarded to the getters of the module's own exports. Every use of a script's export by another script went through them, which was costly while the page loads ([#85180](https://github.com/WordPress/gutenberg/pull/85180)).
41
+ - Resolve development bundles with the `development` and `module` export conditions, enabling runtime diagnostics such as unsupported Emotion component selectors ([#84707](https://github.com/WordPress/gutenberg/pull/84707)).
42
+
43
+ ### Bug Fixes
44
+
45
+ - Check that `SCRIPT_DEBUG` is defined before reading it in the generated `build/scripts.php` and `build/styles.php`, like the other generated files, so they no longer throw an `Error` when loaded without WordPress defining the constant ([#83633](https://github.com/WordPress/gutenberg/pull/83633)).
46
+ - Add `generate_animated_image_subsizes` to the page template `/?_fields=` preload path, keeping it in sync with the `_fields` list in `@wordpress/core-data` ([#80385](https://github.com/WordPress/gutenberg/pull/80385)).
47
+
48
+ ### Internal
49
+
50
+ - Publish only runtime files, dropping `tsconfig.json`, the TypeScript build cache (`.cache`) and the test files from the package ([#84164](https://github.com/WordPress/gutenberg/pull/84164)).
51
+
5
52
  ## 0.25.0 (2026-10-07)
6
53
 
7
54
  ### Bug Fixes
8
55
 
9
56
  - Add the `@babel/core` dependency, a peer of `esbuild-plugin-babel` ([#83765](https://github.com/WordPress/gutenberg/pull/83765)).
57
+ - Keep the build machine's absolute paths out of worker source maps when `wpWorkers` redirects a module with `resolve`, so the output is reproducible across checkouts ([#84163](https://github.com/WordPress/gutenberg/pull/84163)).
10
58
 
11
59
  ### Internal
12
60
 
package/README.md CHANGED
@@ -6,7 +6,7 @@ Build tool for WordPress plugins.
6
6
 
7
7
  `@wordpress/build` is an opinionated build system designed for WordPress plugins. It provides:
8
8
 
9
- - **Transpilation**: Converts TypeScript/JSX source code to both CommonJS (`build/`) and ESM (`build-module/`) formats using esbuild
9
+ - **Transpilation**: Converts TypeScript/JSX source code to both CommonJS (`build/`) and ESM (`build-module/`) formats using Rolldown
10
10
  - **Style Compilation**: Processes SCSS files and CSS modules, generating LTR and RTL versions
11
11
  - **Bundling**: Creates browser-ready bundles for WordPress scripts and modules
12
12
  - **PHP Generation**: Automatically generates PHP registration files for scripts, modules, and styles
@@ -52,6 +52,10 @@ or via npm script:
52
52
  }
53
53
  ```
54
54
 
55
+ ### Build Concurrency
56
+
57
+ By default, `wp-build` limits concurrent Rolldown build jobs to half of the available CPU parallelism, rounded up. This prevents large projects from starting every package, route, and widget bundle at once.
58
+
55
59
  ### Testing Generated Styles
56
60
 
57
61
  Generated CSS output skips automatic style injection in Node-based environments
@@ -441,6 +445,18 @@ This configuration:
441
445
  - **Vendors**: React, lodash, jQuery, moment are always externalized to their standard globals
442
446
  - **Asset files**: `.asset.php` files are always generated for WordPress dependency management
443
447
 
448
+ ## SVG imports
449
+
450
+ SVG files can be imported from JavaScript. The file is inlined into the JavaScript and the import resolves to a `data:` URI:
451
+
452
+ ```js
453
+ import logo from './logo.svg';
454
+
455
+ const Example = () => <img src={ logo } alt="" />;
456
+ ```
457
+
458
+ Because the SVG travels with the JavaScript, it works in bundles and in transpiled packages (`build/`, `build-module/`) without a public path or an extra file to ship. Other image formats are not supported yet.
459
+
444
460
  ## Output Structure
445
461
 
446
462
  The built tool generates several files in the `build/` directory, but the primary output is the PHP registration file.
@@ -584,11 +600,11 @@ Widgets provide a file-based discovery system for building self-contained UI com
584
600
  ```text
585
601
  widgets/
586
602
  hello-world/
587
- widget.json # Static discovery metadata (required)
588
- widget.ts # Runtime values entry point (optional)
589
- render.tsx # UI component entry point (optional)
590
- render.scss # Optional styles (bundled inline when imported from render.tsx)
591
- package.json # Optional npm dependencies manifest
603
+ widget.json # Static discovery metadata (required)
604
+ widget.ts # Runtime values entry point (optional)
605
+ render.tsx # UI component entry point (optional)
606
+ style.module.css # Optional styles, imported from render.tsx and injected at runtime
607
+ package.json # Optional npm dependencies manifest
592
608
  ```
593
609
 
594
610
  ### Why two entries?
@@ -597,13 +613,15 @@ Widgets use a dual-entry pattern, similar in spirit to how blocks split metadata
597
613
 
598
614
  | Concern | Lives in | Reason |
599
615
  | ------------------------------------------------------------------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
600
- | Identity (`name`) | both (must match) | server needs it to register; client uses it to resolve the runtime entry |
616
+ | Identity (`name`) | `widget.json` | server needs it to register; the record carries it to the client |
601
617
  | Translatable metadata (`title`, `description`, `help`, `keywords`) | `widget.json` | translated server-side via `textdomain`, so the host receives localized strings without a JS runtime |
602
618
  | Framing (`category`, `presentation`) | `widget.json` | plain JSON the host reads without a JS runtime |
619
+ | Icon and actions (`icon`, `actions`) | `widget.json` | plain JSON; the icon is a registered name resolved client-side, action labels are translated server-side via `textdomain` |
603
620
  | Attribute schema (types, options, labels, `relevance`) | `widget.json` | plain JSON; labels translated server-side via `textdomain`; a `widget.ts` entry with the same `id` adds what JSON cannot express |
604
- | `example`, attribute props that need code | `widget.ts` | runtime values |
621
+ | `example` attributes | `widget.json` | plain JSON; a `widget.ts` `example` wins when its values need code |
622
+ | Attribute props that need code | `widget.ts` | runtime values |
605
623
 
606
- Rule of thumb: anything the host needs before loading a widget's module — identity, translatable copy, framing, attribute schema — goes in `widget.json`, which the build forwards to `build/widgets/registry.php` and exposes through the REST API. Anything that needs code (`example`, an attribute's `Edit` component or custom validator) goes in `widget.ts`.
624
+ Rule of thumb: anything the host needs before loading a widget's module — identity, translatable copy, framing, attribute schema, example attributes — goes in `widget.json`, which the build forwards to `build/widgets/registry.php` and exposes through the REST API. Anything that needs code (an attribute's `Edit` component or custom validator, an `example` with runtime values) goes in `widget.ts`.
607
625
 
608
626
  ### `widget.json` — static discovery metadata
609
627
 
@@ -615,6 +633,9 @@ Rule of thumb: anything the host needs before loading a widget's module — iden
615
633
  "help": {
616
634
  "content": "A short note for compact surfaces such as tooltips."
617
635
  },
636
+ "example": {
637
+ "attributes": { "greeting": "World", "showDate": true }
638
+ },
618
639
  "category": "demo",
619
640
  "textdomain": "my-plugin"
620
641
  }
@@ -626,15 +647,18 @@ Rule of thumb: anything the host needs before loading a widget's module — iden
626
647
  - **`title`** (optional): Human-readable title. Translated server-side using `textdomain`.
627
648
  - **`description`** (optional): Short description. Translated server-side using `textdomain`.
628
649
  - **`help`** (optional): Contextual help note for compact surfaces. An object with `content` (may carry `<em>`/`<strong>`) and optional `links` (`label`, `href`). Translated server-side using `textdomain`.
650
+ - **`icon`** (optional): Registered icon name (`collection/icon-name`), resolved client-side through the site's icon registry. A name that does not match the shape is dropped at registration.
651
+ - **`actions`** (optional): Declarative actions, each with `id`, `label` and `href`, plus optional `icon`, `relevance` (`high`, `medium`, `low`), `download` and `openInNewTab`. Labels are translated server-side using `textdomain`. A relative `href` naming a file in the widget directory resolves to its URL at registration; `data:` and `javascript:` hrefs are rejected.
629
652
  - **`keywords`** (optional): Search aliases. Translated server-side using `textdomain`.
630
653
  - **`attributes`** (optional): Attribute schema, one entry per attribute with the JSON-expressible subset of a DataViews `Field` (`id`, `type`, `label`, `elements`, `isValid` without `custom`, ...) plus an optional `relevance` (`high`, `medium`, `low`). `type` may name a registered field type. `label`, `header`, `description`, `placeholder`, and option labels and descriptions are translated server-side using `textdomain`.
654
+ - **`example`** (optional): Structured example, `{ "attributes": { … } }`: the attributes hosts preview the widget with, and apply to a new instance created without any. JSON values only; an `example` in `widget.ts` wins over it.
631
655
  - **`category`** (optional): Grouping category for filtering
632
656
  - **`presentation`** (optional): Rendering intent (`framed`, `content-bleed`, `full-bleed`)
633
- - **`textdomain`** (optional): Gettext text domain for translating `title`, `description`, `help`, `keywords`, and attribute labels
657
+ - **`textdomain`** (optional): Gettext text domain for translating `title`, `description`, `help`, `keywords`, action labels and attribute labels
634
658
 
635
659
  ### `widget.ts` — runtime values
636
660
 
637
- Optional. Exports a default object with what needs code: `example` data, and attribute entries that add an `Edit` component or a custom validator to a `widget.json` attribute with the same `id`. The build system injects the `render_module` handle at registration time, so authors don't need to declare it.
661
+ Optional. Exports a default object with what needs code: attribute entries that add an `Edit` component or a custom validator to a `widget.json` attribute with the same `id`, and an `example` whose values only exist at runtime, which wins over the `widget.json` one. The build system injects the `render_module` handle at registration time, so authors don't need to declare it.
638
662
 
639
663
  ```ts
640
664
  import type { WidgetAttributeField } from '@wordpress/widget-primitives';
@@ -646,26 +670,19 @@ type HelloWorldAttributes = {
646
670
  };
647
671
 
648
672
  const widget = {
649
- name: 'my-plugin/hello-world',
650
673
  attributes: [ { id: 'greeting', Edit: GreetingControl } ] satisfies Partial<
651
674
  WidgetAttributeField< HelloWorldAttributes >
652
675
  >[],
653
- example: {
654
- attributes: {
655
- greeting: 'World',
656
- showDate: true,
657
- },
658
- },
659
676
  };
660
677
 
661
678
  export default widget;
662
679
  ```
663
680
 
664
- Entries merge by `id` with the `widget.json` schema: the JSON value wins a shared key, the module adds the rest, and `isValid` merges rule by rule so JSON rules and a module `custom` validator coexist. A widget whose attributes are plain data needs no `widget.ts`.
681
+ Entries merge by `id` with the `widget.json` schema: the JSON value wins a shared key, the module adds the rest, and `isValid` merges rule by rule so JSON rules and a module `custom` validator coexist. A widget whose attributes and example are plain data needs no `widget.ts`.
665
682
 
666
683
  ### `render.tsx` — UI component
667
684
 
668
- The render entry receives `attributes` matching the schema declared in `widget.json`. It is bundled with CSS support (import `.scss` / `.css` directly).
685
+ The render entry receives `attributes` matching the schema declared in `widget.json` and, when the host allows edits, `setAttributes`. Styles are imported from the entry, as a CSS Module (`style.module.css`) or a plain `.css` / `.scss` file, and injected at runtime.
669
686
 
670
687
  ```tsx
671
688
  interface HelloWorldRenderProps {
@@ -687,15 +704,15 @@ export default function HelloWorld( { attributes }: HelloWorldRenderProps ) {
687
704
  }
688
705
  ```
689
706
 
690
- All non-JSON entries are optional. The build system checks for files with extensions in priority order: `.tsx`, `.ts`, `.jsx`, `.js`, `.mjs`.
707
+ All non-JSON entries are optional. Either entry may use any of `.js`, `.jsx`, `.mjs`, `.cjs`, `.ts`, `.tsx`, `.mts` or `.cts`; ship one file per entry.
691
708
 
692
709
  ### Widgets Build Output
693
710
 
694
711
  The build system generates:
695
712
 
696
- - `build/widgets/{widget-name}/render.min.js` + `render.js` — Bundled UI component (ESM)
713
+ - `build/widgets/{widget-name}/render.min.js` + `render.js` — Bundled UI component (ESM), when the widget ships a `render.*` entry
697
714
  - `build/widgets/{widget-name}/render.min.asset.php` — Asset metadata for render module
698
- - `build/widgets/{widget-name}/widget.min.js` + `widget.js` — Bundled metadata (ESM)
715
+ - `build/widgets/{widget-name}/widget.min.js` + `widget.js` — Bundled metadata (ESM), when the widget ships a `widget.*` entry
699
716
  - `build/widgets/{widget-name}/widget.min.asset.php` — Asset metadata for widget module
700
717
  - `build/widgets/registry.php` — Widget registry data
701
718
  - `build/widgets.php` — Script module registration logic
@@ -4,7 +4,7 @@ module.exports = [
4
4
  rules: {
5
5
  // Console should be allowed in a build tool.
6
6
  'no-console': 'off',
7
- // These rules are designed for source files processed by esbuild,
7
+ // These rules are designed for source files processed by the build,
8
8
  // not for the build script itself, which runs directly in Node.js.
9
9
  '@wordpress/no-wp-process-env': 'off',
10
10
  '@wordpress/wp-global-usage': 'off',
@@ -0,0 +1,87 @@
1
+ import os from 'node:os';
2
+ import { build } from 'rolldown';
3
+
4
+ /**
5
+ * @typedef {Object} QueuedBuild
6
+ * @property {() => Promise<unknown> | unknown} task Task to run.
7
+ * @property {(value: unknown) => void} resolve Promise resolver.
8
+ * @property {(reason?: unknown) => void} reject Promise rejecter.
9
+ */
10
+
11
+ let buildConcurrency = 1;
12
+ let activeBuilds = 0;
13
+ /** @type {QueuedBuild[]} */
14
+ const queuedBuilds = [];
15
+
16
+ /**
17
+ * Get the default number of concurrent esbuild builds: half of the available
18
+ * parallelism, rounded up.
19
+ *
20
+ * @param {number} availableParallelism Available parallelism to use.
21
+ * @return {number} Default build concurrency.
22
+ */
23
+ export function getDefaultBuildConcurrency(
24
+ availableParallelism = os.availableParallelism()
25
+ ) {
26
+ return Math.max( 1, Math.ceil( availableParallelism / 2 ) );
27
+ }
28
+
29
+ /**
30
+ * Set the maximum number of concurrent esbuild builds.
31
+ *
32
+ * @param {number} concurrency Build concurrency.
33
+ */
34
+ export function setBuildConcurrency( concurrency ) {
35
+ buildConcurrency = concurrency;
36
+ runNextBuilds();
37
+ }
38
+
39
+ /**
40
+ * Runs a Rolldown build while respecting the global wp-build concurrency limit.
41
+ *
42
+ * @param {import('rolldown').BuildOptions} buildOptions Rolldown build options.
43
+ * @return {Promise<import('rolldown').RolldownOutput>} Rolldown build output.
44
+ */
45
+ export function buildWithConcurrency( buildOptions ) {
46
+ return enqueueBuild( () => build( buildOptions ) );
47
+ }
48
+
49
+ /**
50
+ * Runs an arbitrary async task while respecting the build concurrency limit.
51
+ *
52
+ * @template T
53
+ * @param {() => Promise<T> | T} task Task to run.
54
+ * @return {Promise<T>} Task result.
55
+ */
56
+ export function enqueueBuild( task ) {
57
+ return new Promise( ( resolve, reject ) => {
58
+ queuedBuilds.push( {
59
+ task,
60
+ resolve: ( value ) =>
61
+ resolve( /** @type {T | PromiseLike<T>} */ ( value ) ),
62
+ reject,
63
+ } );
64
+ runNextBuilds();
65
+ } );
66
+ }
67
+
68
+ /**
69
+ * Starts queued build tasks while capacity is available.
70
+ */
71
+ function runNextBuilds() {
72
+ while ( activeBuilds < buildConcurrency && queuedBuilds.length > 0 ) {
73
+ const queuedBuild = queuedBuilds.shift();
74
+ if ( ! queuedBuild ) {
75
+ return;
76
+ }
77
+ const { task, resolve, reject } = queuedBuild;
78
+ activeBuilds++;
79
+ Promise.resolve()
80
+ .then( task )
81
+ .then( resolve, reject )
82
+ .finally( () => {
83
+ activeBuilds--;
84
+ runNextBuilds();
85
+ } );
86
+ }
87
+ }