@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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
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
+
5
26
  ## 0.26.0 (2026-10-20)
6
27
 
7
28
  ### Breaking Changes
@@ -16,6 +37,7 @@
16
37
 
17
38
  ### Enhancements
18
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)).
19
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)).
20
42
 
21
43
  ### Bug Fixes
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
@@ -596,11 +600,11 @@ Widgets provide a file-based discovery system for building self-contained UI com
596
600
  ```text
597
601
  widgets/
598
602
  hello-world/
599
- widget.json # Static discovery metadata (required)
600
- widget.ts # Runtime values entry point (optional)
601
- render.tsx # UI component entry point (optional)
602
- render.scss # Optional styles (bundled inline when imported from render.tsx)
603
- 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
604
608
  ```
605
609
 
606
610
  ### Why two entries?
@@ -609,13 +613,15 @@ Widgets use a dual-entry pattern, similar in spirit to how blocks split metadata
609
613
 
610
614
  | Concern | Lives in | Reason |
611
615
  | ------------------------------------------------------------------ | ----------------- | -------------------------------------------------------------------------------------------------------------------------------- |
612
- | 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 |
613
617
  | Translatable metadata (`title`, `description`, `help`, `keywords`) | `widget.json` | translated server-side via `textdomain`, so the host receives localized strings without a JS runtime |
614
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` |
615
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 |
616
- | `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 |
617
623
 
618
- 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`.
619
625
 
620
626
  ### `widget.json` — static discovery metadata
621
627
 
@@ -627,6 +633,9 @@ Rule of thumb: anything the host needs before loading a widget's module — iden
627
633
  "help": {
628
634
  "content": "A short note for compact surfaces such as tooltips."
629
635
  },
636
+ "example": {
637
+ "attributes": { "greeting": "World", "showDate": true }
638
+ },
630
639
  "category": "demo",
631
640
  "textdomain": "my-plugin"
632
641
  }
@@ -638,15 +647,18 @@ Rule of thumb: anything the host needs before loading a widget's module — iden
638
647
  - **`title`** (optional): Human-readable title. Translated server-side using `textdomain`.
639
648
  - **`description`** (optional): Short description. Translated server-side using `textdomain`.
640
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.
641
652
  - **`keywords`** (optional): Search aliases. Translated server-side using `textdomain`.
642
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.
643
655
  - **`category`** (optional): Grouping category for filtering
644
656
  - **`presentation`** (optional): Rendering intent (`framed`, `content-bleed`, `full-bleed`)
645
- - **`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
646
658
 
647
659
  ### `widget.ts` — runtime values
648
660
 
649
- 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.
650
662
 
651
663
  ```ts
652
664
  import type { WidgetAttributeField } from '@wordpress/widget-primitives';
@@ -658,26 +670,19 @@ type HelloWorldAttributes = {
658
670
  };
659
671
 
660
672
  const widget = {
661
- name: 'my-plugin/hello-world',
662
673
  attributes: [ { id: 'greeting', Edit: GreetingControl } ] satisfies Partial<
663
674
  WidgetAttributeField< HelloWorldAttributes >
664
675
  >[],
665
- example: {
666
- attributes: {
667
- greeting: 'World',
668
- showDate: true,
669
- },
670
- },
671
676
  };
672
677
 
673
678
  export default widget;
674
679
  ```
675
680
 
676
- 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`.
677
682
 
678
683
  ### `render.tsx` — UI component
679
684
 
680
- 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.
681
686
 
682
687
  ```tsx
683
688
  interface HelloWorldRenderProps {
@@ -699,15 +704,15 @@ export default function HelloWorld( { attributes }: HelloWorldRenderProps ) {
699
704
  }
700
705
  ```
701
706
 
702
- 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.
703
708
 
704
709
  ### Widgets Build Output
705
710
 
706
711
  The build system generates:
707
712
 
708
- - `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
709
714
  - `build/widgets/{widget-name}/render.min.asset.php` — Asset metadata for render module
710
- - `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
711
716
  - `build/widgets/{widget-name}/widget.min.asset.php` — Asset metadata for widget module
712
717
  - `build/widgets/registry.php` — Widget registry data
713
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
+ }