@wordpress/build 0.23.1-next.v.202608281122.0 → 0.24.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.
@@ -1,4 +1,13 @@
1
- const SOURCE_EXTENSIONS = [ 'js', 'jsx', 'mjs', 'ts', 'tsx' ];
1
+ const SOURCE_EXTENSIONS = [
2
+ 'js',
3
+ 'jsx',
4
+ 'mjs',
5
+ 'cjs',
6
+ 'ts',
7
+ 'tsx',
8
+ 'mts',
9
+ 'cts',
10
+ ];
2
11
  const TEST_FILE_PATTERNS = [
3
12
  /\/(benchmark|__mocks__|__tests__|test|storybook|stories)\/.+/,
4
13
  new RegExp( `\\.(spec|test)\\.(${ SOURCE_EXTENSIONS.join( '|' ) })$` ),
@@ -0,0 +1,34 @@
1
+ import { afterEach, describe, expect, it, vi } from 'vitest';
2
+ import browserslist from 'browserslist';
3
+ import wordpressBrowserslistConfig from '@wordpress/browserslist-config';
4
+ import { getBrowserslistQueries } from '../browserslist.mjs';
5
+
6
+ describe( 'browserslist targeting', () => {
7
+ let findConfigSpy;
8
+
9
+ afterEach( () => {
10
+ findConfigSpy.mockRestore();
11
+ } );
12
+
13
+ it( 'falls back to @wordpress/browserslist-config when the project has no config', () => {
14
+ findConfigSpy = vi
15
+ .spyOn( browserslist, 'findConfig' )
16
+ .mockReturnValue( undefined );
17
+
18
+ expect( getBrowserslistQueries() ).toEqual(
19
+ wordpressBrowserslistConfig
20
+ );
21
+ } );
22
+
23
+ it( 'uses the project browserslist config when one is present', () => {
24
+ findConfigSpy = vi
25
+ .spyOn( browserslist, 'findConfig' )
26
+ .mockReturnValue( {
27
+ defaults: [ 'last 1 chrome version' ],
28
+ } );
29
+
30
+ expect( getBrowserslistQueries() ).toEqual( [
31
+ 'last 1 chrome version',
32
+ ] );
33
+ } );
34
+ } );
@@ -0,0 +1,69 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { compileInlineStyle } from '../compile-inline-style.mjs';
3
+
4
+ async function compileStyleModule() {
5
+ return compileInlineStyle( { minify: false } )(
6
+ '.fixture { color: rgb(1, 2, 3); }',
7
+ import.meta.dirname,
8
+ `${ import.meta.dirname }/fixture.css`
9
+ );
10
+ }
11
+
12
+ function executeStyleModule( source, processValue ) {
13
+ let injectedStyleCount = 0;
14
+ const document = {
15
+ createElement: () => ( {
16
+ appendChild() {},
17
+ setAttribute() {},
18
+ } ),
19
+ createTextNode: () => ( {} ),
20
+ head: {
21
+ appendChild: () => {
22
+ injectedStyleCount++;
23
+ },
24
+ querySelector: () => null,
25
+ },
26
+ };
27
+
28
+ new Function( 'document', 'process', source )( document, processValue );
29
+
30
+ return injectedStyleCount;
31
+ }
32
+
33
+ describe( 'compileInlineStyle', () => {
34
+ test( 'applies design token fallbacks by default', async () => {
35
+ const source = await compileInlineStyle( { minify: false } )(
36
+ '.fixture { gap: var(--wpds-dimension-gap-sm); }',
37
+ import.meta.dirname,
38
+ `${ import.meta.dirname }/fixture.css`
39
+ );
40
+
41
+ expect( source ).toContain( 'var(--wpds-dimension-gap-sm, 8px)' );
42
+ } );
43
+
44
+ test( 'skips generated style injection in test mode', async () => {
45
+ const source = await compileStyleModule();
46
+
47
+ expect(
48
+ executeStyleModule( source, {
49
+ env: { NODE_ENV: 'test' },
50
+ } )
51
+ ).toBe( 0 );
52
+ } );
53
+
54
+ test( 'injects generated styles outside test mode', async () => {
55
+ const source = await compileStyleModule();
56
+
57
+ expect(
58
+ executeStyleModule( source, {
59
+ env: { NODE_ENV: 'development' },
60
+ } )
61
+ ).toBe( 1 );
62
+ } );
63
+
64
+ test( 'injects generated styles when process is absent', async () => {
65
+ const source = await compileStyleModule();
66
+
67
+ expect( executeStyleModule( source, undefined ) ).toBe( 1 );
68
+ } );
69
+ } );
@@ -1,26 +1,31 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { describe, expect, it } from 'vitest';
1
4
  import { getPackageInfo } from '../package-utils.mjs';
2
5
 
6
+ const testDirectory = path.dirname( fileURLToPath( import.meta.url ) );
7
+
3
8
  describe( 'getPackageInfo() resolve-miss contract', () => {
4
9
  it( 'returns null (does not throw) for an unresolvable scoped package', () => {
5
10
  expect( () =>
6
- getPackageInfo( '@does-not-exist/nope', __dirname )
11
+ getPackageInfo( '@does-not-exist/nope', testDirectory )
7
12
  ).not.toThrow();
8
13
 
9
14
  expect(
10
- getPackageInfo( '@does-not-exist/nope', __dirname )
15
+ getPackageInfo( '@does-not-exist/nope', testDirectory )
11
16
  ).toBeNull();
12
17
  } );
13
18
 
14
19
  it( 'returns the cached null on a repeated miss', () => {
15
- const first = getPackageInfo( '@still-missing/pkg', __dirname );
16
- const second = getPackageInfo( '@still-missing/pkg', __dirname );
20
+ const first = getPackageInfo( '@still-missing/pkg', testDirectory );
21
+ const second = getPackageInfo( '@still-missing/pkg', testDirectory );
17
22
 
18
23
  expect( first ).toBeNull();
19
24
  expect( second ).toBeNull();
20
25
  } );
21
26
 
22
27
  it( 'still resolves an installed package that exposes its package.json', () => {
23
- const info = getPackageInfo( '@wordpress/build', __dirname );
28
+ const info = getPackageInfo( '@wordpress/build', testDirectory );
24
29
 
25
30
  expect( info ).toMatchObject( { name: '@wordpress/build' } );
26
31
  } );
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from 'vitest';
1
2
  import { renderTemplateToString as generateTemplate } from '../php-generator.mjs';
2
3
 
3
4
  describe( 'page-wp-admin.php template', () => {
@@ -14,3 +15,26 @@ describe( 'page-wp-admin.php template', () => {
14
15
  );
15
16
  } );
16
17
  } );
18
+
19
+ describe( 'page.php template', () => {
20
+ it( 'guards the admin_init interceptor with authentication and the configured capability', async () => {
21
+ const generatedPage = await generateTemplate( 'page.php.template', {
22
+ '{{PAGE_SLUG}}': 'example',
23
+ '{{PAGE_SLUG_UNDERSCORE}}': 'example',
24
+ '{{PREFIX}}': 'wp',
25
+ '{{CAPABILITY}}': 'edit_theme_options',
26
+ } );
27
+
28
+ const interceptor = generatedPage.slice(
29
+ generatedPage.indexOf( 'function wp_example_intercept_render()' )
30
+ );
31
+
32
+ expect( interceptor ).toContain( 'is_user_logged_in()' );
33
+ expect( interceptor ).toContain(
34
+ "current_user_can( 'edit_theme_options' )"
35
+ );
36
+ expect( interceptor.indexOf( 'current_user_can' ) ).toBeLessThan(
37
+ interceptor.indexOf( 'wp_example_render_page()' )
38
+ );
39
+ } );
40
+ } );
@@ -2,6 +2,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import glob from 'fast-glob';
5
+ import { afterEach, describe, expect, it } from 'vitest';
5
6
  import { getSourceFileGlob, isTestSourceFile } from '../source-files.mjs';
6
7
 
7
8
  describe( 'source file discovery', () => {
@@ -21,7 +22,17 @@ describe( 'source file discovery', () => {
21
22
  const sourceDirectory = path.join( temporaryDirectory, 'src' );
22
23
  mkdirSync( sourceDirectory );
23
24
 
24
- for ( const extension of [ 'js', 'jsx', 'mjs', 'ts', 'tsx', 'css' ] ) {
25
+ for ( const extension of [
26
+ 'js',
27
+ 'jsx',
28
+ 'mjs',
29
+ 'cjs',
30
+ 'ts',
31
+ 'tsx',
32
+ 'mts',
33
+ 'cts',
34
+ 'css',
35
+ ] ) {
25
36
  writeFileSync(
26
37
  path.join( sourceDirectory, `index.${ extension }` ),
27
38
  ''
@@ -33,9 +44,12 @@ describe( 'source file discovery', () => {
33
44
  } );
34
45
 
35
46
  expect( sourceFiles.sort() ).toEqual( [
47
+ 'src/index.cjs',
48
+ 'src/index.cts',
36
49
  'src/index.js',
37
50
  'src/index.jsx',
38
51
  'src/index.mjs',
52
+ 'src/index.mts',
39
53
  'src/index.ts',
40
54
  'src/index.tsx',
41
55
  ] );
@@ -45,6 +59,8 @@ describe( 'source file discovery', () => {
45
59
  'packages/example/src/test/component.jsx',
46
60
  'packages/example/src/component.test.jsx',
47
61
  'packages/example/src/component.spec.mjs',
62
+ 'packages/example/src/component.test.mts',
63
+ 'packages/example/src/component.spec.cts',
48
64
  ] )( 'identifies development-only source: %s', ( filename ) => {
49
65
  expect( isTestSourceFile( filename ) ).toBe( true );
50
66
  } );
@@ -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
+ } );
@@ -43,6 +43,15 @@ export function getAllWidgets( rootDir ) {
43
43
  * @property {boolean} [openInNewTab] Open the destination in a new browser tab.
44
44
  */
45
45
 
46
+ /**
47
+ * @typedef {Object} WidgetAttributeMetadata
48
+ * @property {string} id Attribute key, unique within the widget.
49
+ * @property {string} [type] DataViews field type, or a registered field type name.
50
+ * @property {string} [label] Human-readable label. Translatable.
51
+ * @property {string} [description] Longer description. Translatable.
52
+ * @property {'high'|'medium'|'low'} [relevance] How prominently a host surfaces the attribute.
53
+ */
54
+
46
55
  /**
47
56
  * @typedef {Object} WidgetMetadata
48
57
  * @property {string} name Widget namespaced identifier.
@@ -51,6 +60,7 @@ export function getAllWidgets( rootDir ) {
51
60
  * @property {WidgetHelpMetadata} [help] Contextual help note for compact surfaces.
52
61
  * @property {string} [icon] Registered icon name (`collection/icon-name`).
53
62
  * @property {WidgetActionMetadata[]} [actions] Declarative actions the widget exposes.
63
+ * @property {WidgetAttributeMetadata[]} [attributes] Attribute schema, the JSON-expressible subset of a DataViews `Field`.
54
64
  * @property {string} [category] Grouping category.
55
65
  * @property {'framed' | 'content-bleed' | 'full-bleed'} [presentation] Authoring intent about how the widget wants to render.
56
66
  * @property {string[]} [keywords] Search aliases used to match the widget.
@@ -96,7 +106,16 @@ export function getWidgetMetadata( rootDir, widgetName ) {
96
106
  * Supported source extensions for widget entry files, in priority order.
97
107
  * Must stay aligned with SOURCE_EXTENSIONS in build.mjs.
98
108
  */
99
- const WIDGET_EXTENSIONS = [ 'tsx', 'ts', 'jsx', 'js', 'mjs' ];
109
+ const WIDGET_EXTENSIONS = [
110
+ 'tsx',
111
+ 'ts',
112
+ 'mts',
113
+ 'cts',
114
+ 'jsx',
115
+ 'js',
116
+ 'mjs',
117
+ 'cjs',
118
+ ];
100
119
 
101
120
  /**
102
121
  * @typedef {Object} WidgetFiles
@@ -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.23.1-next.v.202608281122.0",
3
+ "version": "0.24.0",
4
4
  "description": "Build tool for WordPress plugins.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -20,8 +20,7 @@
20
20
  "url": "https://github.com/WordPress/gutenberg/issues"
21
21
  },
22
22
  "engines": {
23
- "node": ">=20.10.0",
24
- "npm": ">=10.2.3"
23
+ "node": ">=20.10.0"
25
24
  },
26
25
  "type": "module",
27
26
  "module": "./lib/build.mjs",
@@ -36,8 +35,10 @@
36
35
  },
37
36
  "dependencies": {
38
37
  "@emotion/babel-plugin": "^11.13.5",
39
- "@wordpress/style-runtime": "^0.10.1-next.v.202608281122.0",
38
+ "@wordpress/browserslist-config": "^6.56.0",
39
+ "@wordpress/style-runtime": "^0.12.0",
40
40
  "autoprefixer": "^10.4.21",
41
+ "browserslist": "^4.28.7",
41
42
  "browserslist-to-esbuild": "^2.1.1",
42
43
  "change-case": "^4.1.2",
43
44
  "chokidar": "^4.0.0",
@@ -53,7 +54,9 @@
53
54
  "sass-embedded": "^1.97.2"
54
55
  },
55
56
  "devDependencies": {
56
- "@types/node": "^20.19.39"
57
+ "@types/node": "^24.13.3",
58
+ "@wordpress/theme": "^2.2.0",
59
+ "vitest": "^5.0.0"
57
60
  },
58
61
  "peerDependencies": {
59
62
  "@wordpress/boot": ">=0.3.0 <1.0.0",
@@ -78,5 +81,5 @@
78
81
  "publishConfig": {
79
82
  "access": "public"
80
83
  },
81
- "gitHead": "de479d415171765f7b573c81aeec5334ff506a12"
84
+ "gitHead": "56d8058eda6e30c4cc8bfc37818fa6ed972f7dc2"
82
85
  }
@@ -332,6 +332,22 @@ function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
332
332
  function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
333
333
  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
334
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
+
335
351
  {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page();
336
352
  exit;
337
353
  }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig.json",
3
- "extends": "../../tsconfig.base.json",
3
+ "extends": "@wordpress/monorepo-tools/tsconfig/base.json",
4
4
  "compilerOptions": {
5
5
  "module": "node16",
6
6
  "moduleResolution": "node16",
@@ -17,7 +17,10 @@
17
17
  "noEmit": true,
18
18
  "outDir": ".cache"
19
19
  },
20
- "references": [ { "path": "../style-runtime/tsconfig.build.json" } ],
20
+ "references": [
21
+ { "path": "../style-runtime/tsconfig.build.json" },
22
+ { "path": "../theme/tsconfig.plugins.json" }
23
+ ],
21
24
  "include": [ "." ],
22
25
  "exclude": [
23
26
  // Excluded to maintain consistency with bin/tsconfig.json