@wordpress/build 0.21.0 → 0.23.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.
@@ -0,0 +1,58 @@
1
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import glob from 'fast-glob';
5
+ import { afterEach, describe, expect, it } from 'vitest';
6
+ import { getSourceFileGlob, isTestSourceFile } from '../source-files.mjs';
7
+
8
+ describe( 'source file discovery', () => {
9
+ let temporaryDirectory;
10
+
11
+ afterEach( () => {
12
+ if ( temporaryDirectory ) {
13
+ rmSync( temporaryDirectory, { force: true, recursive: true } );
14
+ temporaryDirectory = undefined;
15
+ }
16
+ } );
17
+
18
+ it( 'returns a glob that expands to every supported source extension', async () => {
19
+ temporaryDirectory = mkdtempSync(
20
+ path.join( os.tmpdir(), 'wordpress-build-source-files-' )
21
+ );
22
+ const sourceDirectory = path.join( temporaryDirectory, 'src' );
23
+ mkdirSync( sourceDirectory );
24
+
25
+ for ( const extension of [ 'js', 'jsx', 'mjs', 'ts', 'tsx', 'css' ] ) {
26
+ writeFileSync(
27
+ path.join( sourceDirectory, `index.${ extension }` ),
28
+ ''
29
+ );
30
+ }
31
+
32
+ const sourceFiles = await glob( getSourceFileGlob( 'src/**/*' ), {
33
+ cwd: temporaryDirectory,
34
+ } );
35
+
36
+ expect( sourceFiles.sort() ).toEqual( [
37
+ 'src/index.js',
38
+ 'src/index.jsx',
39
+ 'src/index.mjs',
40
+ 'src/index.ts',
41
+ 'src/index.tsx',
42
+ ] );
43
+ } );
44
+
45
+ it.each( [
46
+ 'packages/example/src/test/component.jsx',
47
+ 'packages/example/src/component.test.jsx',
48
+ 'packages/example/src/component.spec.mjs',
49
+ ] )( 'identifies development-only source: %s', ( filename ) => {
50
+ expect( isTestSourceFile( filename ) ).toBe( true );
51
+ } );
52
+
53
+ it( 'keeps production JSX source', () => {
54
+ expect( isTestSourceFile( 'packages/example/src/component.jsx' ) ).toBe(
55
+ false
56
+ );
57
+ } );
58
+ } );
@@ -0,0 +1,34 @@
1
+ import { expect, test } from 'vitest';
2
+ // The test config supplies this module from wp-build's real CSS transform.
3
+ // eslint-disable-next-line import/no-unresolved
4
+ import styles from 'virtual:wp-build-style-injection';
5
+ // eslint-disable-next-line import/no-unresolved
6
+ import 'virtual:wp-build-ordinary-style-injection';
7
+
8
+ test( 'injects wp-build generated styles in Browser Mode', () => {
9
+ const fixture = document.createElement( 'div' );
10
+ fixture.className = styles.fixture;
11
+ document.body.append( fixture );
12
+
13
+ try {
14
+ expect( globalThis.getComputedStyle( fixture ).color ).toBe(
15
+ 'rgb(1, 2, 3)'
16
+ );
17
+ } finally {
18
+ fixture.remove();
19
+ }
20
+ } );
21
+
22
+ test( 'injects wp-build generated ordinary styles in Browser Mode', () => {
23
+ const fixture = document.createElement( 'div' );
24
+ fixture.className = 'ordinary-fixture';
25
+ document.body.append( fixture );
26
+
27
+ try {
28
+ expect( globalThis.getComputedStyle( fixture ).backgroundColor ).toBe(
29
+ 'rgb(4, 5, 6)'
30
+ );
31
+ } finally {
32
+ fixture.remove();
33
+ }
34
+ } );
@@ -0,0 +1,11 @@
1
+ import { expect, test } from 'vitest';
2
+ // The test config supplies this module from wp-build's real CSS transform.
3
+ // eslint-disable-next-line import/no-unresolved
4
+ import styles from 'virtual:wp-build-style-injection';
5
+
6
+ test( 'does not inject wp-build generated styles in jsdom', () => {
7
+ expect( styles.fixture ).toBeTruthy();
8
+ expect( document.head ).not.toHaveTextContent(
9
+ '--wp-build-style-injection-test'
10
+ );
11
+ } );
@@ -34,13 +34,13 @@ export function getAllWidgets( rootDir ) {
34
34
 
35
35
  /**
36
36
  * @typedef {Object} WidgetActionMetadata
37
- * @property {string} id Stable identifier, local to the widget type.
38
- * @property {string} label Human-readable label. Translatable.
39
- * @property {string} [icon] Registered icon name (`collection/icon-name`).
40
- * @property {'high'|'low'} [relevance] How relevant the action is among the widget's actions.
41
- * @property {string} href Destination the action points at.
42
- * @property {string|boolean} [download] Download the destination; a string sets the filename.
43
- * @property {boolean} [openInNewTab] Open the destination in a new browser tab.
37
+ * @property {string} id Stable identifier, local to the widget type.
38
+ * @property {string} label Human-readable label. Translatable.
39
+ * @property {string} [icon] Registered icon name (`collection/icon-name`).
40
+ * @property {'high'|'medium'|'low'} [relevance] How relevant the action is among the widget's actions.
41
+ * @property {string} href Destination the action points at.
42
+ * @property {string|boolean} [download] Download the destination; a string sets the filename.
43
+ * @property {boolean} [openInNewTab] Open the destination in a new browser tab.
44
44
  */
45
45
 
46
46
  /**
@@ -333,7 +333,6 @@ export const workerCode = ${ JSON.stringify( workerContent ) };
333
333
  target,
334
334
  jsx: 'automatic',
335
335
  jsxImportSource: 'react',
336
- loader: { '.js': 'jsx' },
337
336
  plugins,
338
337
  } )
339
338
  );
@@ -356,7 +355,6 @@ export const workerCode = ${ JSON.stringify( workerContent ) };
356
355
  target,
357
356
  jsx: 'automatic',
358
357
  jsxImportSource: 'react',
359
- loader: { '.js': 'jsx' },
360
358
  plugins,
361
359
  } )
362
360
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/build",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "Build tool for WordPress plugins.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -36,8 +36,10 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@emotion/babel-plugin": "^11.13.5",
39
- "@wordpress/style-runtime": "^0.9.0",
39
+ "@wordpress/browserslist-config": "^6.55.0",
40
+ "@wordpress/style-runtime": "^0.11.0",
40
41
  "autoprefixer": "^10.4.21",
42
+ "browserslist": "^4.28.4",
41
43
  "browserslist-to-esbuild": "^2.1.1",
42
44
  "change-case": "^4.1.2",
43
45
  "chokidar": "^4.0.0",
@@ -53,13 +55,14 @@
53
55
  "sass-embedded": "^1.97.2"
54
56
  },
55
57
  "devDependencies": {
56
- "@types/node": "^20.19.39"
58
+ "@types/node": "^24.13.3",
59
+ "vitest": "^5.0.0"
57
60
  },
58
61
  "peerDependencies": {
59
62
  "@wordpress/boot": ">=0.3.0 <1.0.0",
60
63
  "@wordpress/private-apis": "^1.0.0",
61
64
  "@wordpress/route": ">=0.2.0 <1.0.0",
62
- "@wordpress/theme": ">=0.8.0 <2.0.0"
65
+ "@wordpress/theme": ">=0.8.0 <3.0.0"
63
66
  },
64
67
  "peerDependenciesMeta": {
65
68
  "@wordpress/boot": {
@@ -78,5 +81,5 @@
78
81
  "publishConfig": {
79
82
  "access": "public"
80
83
  },
81
- "gitHead": "989764d42ff93e33684aaf0b96a5b7f3d9bbff52"
84
+ "gitHead": "485f42ae8a1c58ceea18371a507fd4acfa86fbd8"
82
85
  }
@@ -146,8 +146,12 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts( $hook_suf
146
146
  // Get all registered routes
147
147
  $routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_routes();
148
148
 
149
- // Get boot module asset file for dependencies
149
+ // Get boot module asset file for dependencies. Plugins that build their own
150
+ // boot module use it; everyone else falls back to the copy bundled with Core.
150
151
  $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
152
+ if ( ! file_exists( $asset_file ) ) {
153
+ $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
154
+ }
151
155
  if ( file_exists( $asset_file ) ) {
152
156
  $asset = require $asset_file;
153
157
 
@@ -283,7 +287,7 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
283
287
  }
284
288
 
285
289
  /* Hide legacy admin elements */
286
- body.js #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
290
+ body.js #wpbody-content > div:not(#{{PAGE_SLUG}}-wp-admin-app):not(#screen-meta) {
287
291
  display: none;
288
292
  }
289
293
  body.js #wpfooter {
@@ -324,10 +328,14 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_render_page() {
324
328
  );
325
329
  ?>
326
330
  </div>
331
+ <?php
332
+ // Core's pre-CSS Modules Boot layout uses this class for viewport sizing.
333
+ // Remove it when the minimum supported WordPress version includes the Boot
334
+ // changes from Gutenberg #81756.
335
+ ?>
327
336
  <div id="{{PAGE_SLUG}}-wp-admin-app" class="boot-layout-container"></div>
328
337
  <?php
329
338
  }
330
339
 
331
340
  // Hook the enqueue function to admin_enqueue_scripts
332
341
  add_action( 'admin_enqueue_scripts', '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_enqueue_scripts' );
333
-
@@ -152,8 +152,12 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
152
152
  $menu_items = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items();
153
153
  $routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes();
154
154
 
155
- // Get boot module asset file for dependencies
155
+ // Get boot module asset file for dependencies. Plugins that build their own
156
+ // boot module use it; everyone else falls back to the copy bundled with Core.
156
157
  $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
158
+ if ( ! file_exists( $asset_file ) ) {
159
+ $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
160
+ }
157
161
  if ( file_exists( $asset_file ) ) {
158
162
  $asset = require $asset_file;
159
163
 
@@ -328,6 +332,22 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
328
332
  function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
329
333
  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
330
334
  if ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}' === $_GET['page'] ) {
335
+ // The page renders outside the menu page callback flow, so it must
336
+ // enforce authentication and capability checks itself. Without this,
337
+ // any admin entry point firing `admin_init` (such as admin-post.php,
338
+ // which serves logged-out requests) would render the page for
339
+ // unauthenticated visitors.
340
+ if ( ! is_user_logged_in() ) {
341
+ auth_redirect();
342
+ }
343
+
344
+ if ( ! current_user_can( '{{CAPABILITY}}' ) ) {
345
+ wp_die(
346
+ __( 'Sorry, you are not allowed to access this page.' ),
347
+ 403
348
+ );
349
+ }
350
+
331
351
  {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page();
332
352
  exit;
333
353
  }
package/tsconfig.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "noEmit": true,
18
18
  "outDir": ".cache"
19
19
  },
20
- "references": [ { "path": "../style-runtime" } ],
20
+ "references": [ { "path": "../style-runtime/tsconfig.build.json" } ],
21
21
  "include": [ "." ],
22
22
  "exclude": [
23
23
  // Excluded to maintain consistency with bin/tsconfig.json