Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bundle-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
- '**.js'
- '**.ts'
- '**.tsx'
- '**.mts'
- '**.cts'
- '**.cjs'
- '**.mjs'
- '**.css'
Expand Down
6 changes: 3 additions & 3 deletions lint-staged.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
'*.{cjs,js,json,jsx,mjs,ts,tsx,yml,yaml}': [ 'wp-scripts format' ],
'**/*.{cjs,js,jsx,mjs,ts,tsx}': [
'*.{cjs,cts,js,json,jsx,mjs,mts,ts,tsx,yml,yaml}': [ 'wp-scripts format' ],
'**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}': [
() => 'npm run prelint:js',
'node ./tools/eslint/lint-js.cjs',
],
Expand All @@ -9,7 +9,7 @@ module.exports = {
'packages/*/package.json': [ 'wp-scripts lint-pkg-json' ],
'{docs/toc.json,tools/docs/*.cjs,packages/{*/README.md,components/src/*/**/README.md,block-library/src/*/README.md}}':
[ 'npm run docs:gen' ],
'packages/**/*.{js,jsx,ts,tsx,json}': [
'packages/**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx,json}': [
'npm run docs:api-ref',
'npm run docs:blocks',
'npm run docs:blocks-detail',
Expand Down
4 changes: 4 additions & 0 deletions packages/docgen/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Resolve relative imports through `.mjs`, `.cjs`, `.mts` and `.cts` ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).

## 2.55.0 (2026-09-10)

### Enhancements
Expand Down
11 changes: 10 additions & 1 deletion packages/docgen/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ const isSymbolIgnore = require( './is-symbol-ignore' );
/**
* Helpers functions.
*/
const extensions = [ '.js', '.jsx', '.ts', '.tsx' ];
const extensions = [
'.js',
'.jsx',
'.mjs',
'.cjs',
'.ts',
'.tsx',
'.mts',
'.cts',
];
const relativeToAbsolute = ( basePath, relativePath ) => {
const target = path.join( path.dirname( basePath ), relativePath );
const extension = path.extname( target );
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

- Switch `test-unit` from Jest to `@vitest/eslint-plugin` recommended rules with explicit imports at the 27.0.0 boundary. Jest consumers must configure `eslint-plugin-jest` directly. ([#82843](https://github.com/WordPress/gutenberg/pull/82843)).

### Enhancements

- `recommended`: Apply the TypeScript rules and parser to `.mts` and `.cts` files ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- `recommended`: Resolve imports through `.mjs`, `.cjs`, `.mts` and `.cts`, and exempt `.d.mts` and `.d.cts` from the TypeScript resolver settings alongside `.d.ts` ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- `no-i18n-in-save`: Recognise the `.mjs`, `.cjs`, `.mts` and `.cts` spellings of `save` and `deprecated` ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).

## 26.0.0 (2026-09-10)

### Breaking Changes
Expand Down
15 changes: 12 additions & 3 deletions packages/eslint-plugin/configs/recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,23 @@ if ( isPackageInstalled( 'typescript' ) ) {
'import/resolver': {
[ require.resolve( 'eslint-import-resolver-typescript' ) ]:
{
extensions: [ '.js', '.jsx', '.ts', '.tsx' ],
extensions: [
'.js',
'.jsx',
'.mjs',
'.cjs',
'.ts',
'.tsx',
'.mts',
'.cts',
],
},
},
},
ignores: [ '**/*.d.ts' ],
ignores: [ '**/*.d.ts', '**/*.d.mts', '**/*.d.cts' ],
},
{
files: [ '**/*.ts', '**/*.tsx' ],
files: [ '**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts' ],
languageOptions: {
parser: tseslint.parser,
},
Expand Down
8 changes: 8 additions & 0 deletions packages/eslint-plugin/rules/no-i18n-in-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ module.exports = {
const normalizedFilename = filename.replace( /\\/g, '/' );
const isDeprecatedFile =
normalizedFilename.includes( '/deprecated.js' ) ||
normalizedFilename.includes( '/deprecated.mjs' ) ||
normalizedFilename.includes( '/deprecated.cjs' ) ||
normalizedFilename.includes( '/deprecated.ts' ) ||
normalizedFilename.includes( '/deprecated.mts' ) ||
normalizedFilename.includes( '/deprecated.cts' ) ||
Comment thread
manzoorwanijk marked this conversation as resolved.
Resolved
normalizedFilename.includes( '/deprecated.jsx' ) ||
normalizedFilename.includes( '/deprecated.tsx' );

Expand All @@ -35,7 +39,11 @@ module.exports = {

const isSaveFile =
normalizedFilename.endsWith( '/save.js' ) ||
normalizedFilename.endsWith( '/save.mjs' ) ||
normalizedFilename.endsWith( '/save.cjs' ) ||
normalizedFilename.endsWith( '/save.ts' ) ||
normalizedFilename.endsWith( '/save.mts' ) ||
normalizedFilename.endsWith( '/save.cts' ) ||
normalizedFilename.endsWith( '/save.jsx' ) ||
normalizedFilename.endsWith( '/save.tsx' );

Expand Down
3 changes: 3 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

- `lint-md-docs`: Detect `.markdownlint.jsonc` so the bundled default config is not used when one is present ([#81917](https://github.com/WordPress/gutenberg/pull/81917)).
- `format`: Format `.cjs` and `.mjs` files when expanding a directory ([#82731](https://github.com/WordPress/gutenberg/pull/82731)).
- `format`: Format `.cts` and `.mts` files when expanding a directory ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- The default ESLint config now lints `.jsx`, `.ts`, `.tsx`, `.mts` and `.cts` files, which ESLint's own file discovery skips ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- `build` and `start`: Discover `.cjs`, `.cts` and `.mts` entry points, resolve them from extensionless imports, and transpile `.cjs` and `.cts` modules ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- The bundled `wp-prettier` dependency has been upgraded from `3.0.3` to `3.9.6` ([#82731](https://github.com/WordPress/gutenberg/pull/82731)).

### Bug Fixes
Expand Down
10 changes: 8 additions & 2 deletions packages/scripts/config/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ const config = [
ignores: [ '**/build/**', '**/node_modules/**', '**/vendor/**' ],
},

/*
* ESLint's default file discovery covers only `.js`, `.mjs` and `.cjs`.
* Every other extension has to be named before any config below applies.
*/
{ files: [ '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts' ] },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that ESLint was skipping .jsx files until now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. wp-scripts lint-js was silently skipping .jsx in consumer projects. Flat config only discovers .js, .mjs and .cjs by default; recommended registers .ts/.tsx via its files entry, but nothing registered .jsx.


// Base recommended config from @wordpress/eslint-plugin.
...wpPlugin.configs.recommended,

// Unit test overrides.
...wpPlugin.configs[ 'test-unit' ].map( ( c ) => ( {
...c,
files: [
'**/@(test|__tests__)/**/*.{js,jsx,ts,tsx,mjs,cjs}',
'**/*.@(test|spec).{js,jsx,ts,tsx,mjs,cjs}',
'**/@(test|__tests__)/**/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}',
'**/*.@(test|spec).{js,jsx,ts,tsx,mjs,cjs,mts,cts}',
],
} ) ),
];
Expand Down
15 changes: 12 additions & 3 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ const baseConfig = {
alias: {
'lodash-es': 'lodash',
},
extensions: [ '.jsx', '.ts', '.tsx', '...' ],
extensions: [
'.jsx',
'.mjs',
'.cjs',
'.ts',
'.tsx',
'.mts',
'.cts',
'...',
],
},
optimization: {
// Only concatenate modules in production, when not analyzing bundles.
Expand Down Expand Up @@ -153,7 +162,7 @@ const baseConfig = {
module: {
rules: [
{
test: /\.m?(j|t)sx?$/,
test: /\.[cm]?(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
Expand Down Expand Up @@ -254,7 +263,7 @@ if ( ! isProduction ) {
// Add source-map-loader if devtool is set, whether in dev mode or not.
if ( baseConfig.devtool ) {
baseConfig.module.rules.unshift( {
test: /\.(j|t)sx?$/,
test: /\.[cm]?(j|t)sx?$/,
exclude: [ /node_modules/ ],
use: require.resolve( 'source-map-loader' ),
enforce: 'pre',
Expand Down
2 changes: 2 additions & 0 deletions packages/scripts/scripts/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ if ( fileArgs.length === 0 ) {
const globArgs = dirGlob( fileArgs, {
extensions: [
'cjs',
'cts',
'js',
'json',
'jsx',
'mjs',
'mts',
'ts',
'tsx',
'yml',
Expand Down
100 changes: 100 additions & 0 deletions packages/scripts/scripts/test/format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { execFileSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { rimrafSync } from 'rimraf';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';

const currentDirectory = path.dirname( fileURLToPath( import.meta.url ) );
const scriptPath = path.resolve( currentDirectory, '..', 'format.js' );

/*
* One source file per module extension the script globs for. An extension the
* glob misses leaves its file unformatted instead of failing the run.
*/
const FIXTURES = {
'entry.js': {
input: 'const value = {a:1};\nexport default value\n',
expected: 'const value = { a: 1 };\nexport default value;\n',
},
'entry.jsx': {
input: "const element = <div className='a' />;\nexport default element\n",
expected:
'const element = <div className="a" />;\nexport default element;\n',
},
'entry.cjs': {
input: 'const value = {a:1};\nmodule.exports = value\n',
expected: 'const value = { a: 1 };\nmodule.exports = value;\n',
},
'entry.mjs': {
input: 'const value = {a:1};\nexport default value\n',
expected: 'const value = { a: 1 };\nexport default value;\n',
},
'entry.ts': {
input: 'const value: {a:number} = {a:1};\nexport default value\n',
expected:
'const value: { a: number } = { a: 1 };\nexport default value;\n',
},
'entry.tsx': {
input: "const element = <div className='a' />;\nexport default element\n",
expected:
'const element = <div className="a" />;\nexport default element;\n',
},
'entry.cts': {
input: 'const value: {a:number} = {a:1};\nexport = value\n',
expected: 'const value: { a: number } = { a: 1 };\nexport = value;\n',
},
'entry.mts': {
input: 'const value: {a:number} = {a:1};\nexport default value\n',
expected:
'const value: { a: number } = { a: 1 };\nexport default value;\n',
},
};

describe( 'format script', () => {
let workingDirectory;

beforeEach( () => {
workingDirectory = fs.mkdtempSync(
path.join( os.tmpdir(), 'wp-scripts-format-' )
);
// The script resolves the project root from the nearest `package.json`.
fs.writeFileSync(
path.join( workingDirectory, 'package.json' ),
'{ "name": "format-fixture", "version": "0.0.0" }\n'
);
for ( const [ fileName, { input } ] of Object.entries( FIXTURES ) ) {
fs.writeFileSync( path.join( workingDirectory, fileName ), input );
}
} );

afterEach( () => {
rimrafSync( workingDirectory );
} );

it( 'formats every supported module extension in a directory', () => {
execFileSync( process.execPath, [ scriptPath, '.' ], {
cwd: workingDirectory,
} );

const formatted = Object.fromEntries(
Object.keys( FIXTURES ).map( ( fileName ) => [
fileName,
fs.readFileSync(
path.join( workingDirectory, fileName ),
'utf8'
),
] )
);

expect( formatted ).toEqual(
Object.fromEntries(
Object.entries( FIXTURES ).map( ( [ fileName, fixture ] ) => [
fileName,
fixture.expected,
] )
)
);
} );
} );
4 changes: 2 additions & 2 deletions packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function getWebpackEntryPoints( buildType ) {

// Detects the proper file extension used in the defined source directory.
const [ entryFilepath ] = glob(
`${ entryName }.?(m)[jt]s?(x)`,
`${ entryName }.?([cm])[jt]s?(x)`,
{
absolute: true,
cwd: fromProjectRoot( getProjectSourcePath() ),
Expand Down Expand Up @@ -317,7 +317,7 @@ function getWebpackEntryPoints( buildType ) {

// 3. Checks whether a standard file name can be detected in the defined source directory,
// and converts the discovered file to entry point.
const [ entryFile ] = glob( 'index.[jt]s?(x)', {
const [ entryFile ] = glob( 'index.@([cm]ts|js|jsx|ts|tsx)', {
absolute: true,
cwd: fromProjectRoot( getProjectSourcePath() ),
} );
Expand Down
2 changes: 2 additions & 0 deletions packages/wp-build/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Enhancements

- Carry a widget's `attributes` from `widget.json` into `build/widgets/registry.php` ([#82485](https://github.com/WordPress/gutenberg/pull/82485)).
- Build `.cjs`, `.mts` and `.cts` source files, including route and widget entry points, and rewrite their local imports to the emitted `.mjs` or `.cjs` extension ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).
- Import route stage, inspector and canvas files by their full file name, so a route entry no longer depends on esbuild extending an extensionless path ([#83071](https://github.com/WordPress/gutenberg/pull/83071)).

## 0.23.0 (2026-09-10)

Expand Down
7 changes: 5 additions & 2 deletions packages/wp-build/lib/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ async function transpilePackage( packageName ) {
// Ideally we should remove this exception and move away from emotion.
const needsEmotionPlugin = packageName === 'components';
const emotionPlugin = babel( {
filter: /\.[jt]sx?$/,
filter: /\.[cm]?[jt]sx?$/,
config: {
plugins: [ styleRuntimeRequire.resolve( '@emotion/babel-plugin' ) ],
},
Expand Down Expand Up @@ -1387,7 +1387,10 @@ async function transpilePackage( packageName ) {
// Replace extension: make sure that file extension is always `.mjs` or `.cjs`.
const newExt =
build.initialOptions.format === 'cjs' ? '.cjs' : '.mjs';
relativePath = relativePath.replace( /\.[jt]sx?$/, newExt );
relativePath = relativePath.replace(
/\.[cm]?[jt]sx?$/,
newExt
);

return {
path: relativePath,
Expand Down
Loading
Loading