diff --git a/bin/packages/build-worker.js b/bin/packages/build-worker.js index 06e30efc6c6dc9..5c431730fab423 100644 --- a/bin/packages/build-worker.js +++ b/bin/packages/build-worker.js @@ -153,7 +153,7 @@ async function buildJS( file ) { JS_ENVIRONMENTS ) ) { const destPath = getBuildPath( - file.replace( /\.tsx?$/, '.js' ), + file.replace( /\.([mt])?tsx?$/, '.$1js' ), buildDir ); const babelOptions = getBabelConfig( @@ -189,6 +189,10 @@ const BUILD_TASK_BY_EXTENSION = { '.js': buildJS, '.ts': buildJS, '.tsx': buildJS, + '.cjs': buildJS, + '.cts': buildJS, + '.mjs': buildJS, + '.mts': buildJS, }; module.exports = async ( file, callback ) => { diff --git a/bin/packages/build.js b/bin/packages/build.js index 61914bab5700a7..a1ad5dba37e237 100755 --- a/bin/packages/build.js +++ b/bin/packages/build.js @@ -215,7 +215,7 @@ if ( files.length ) { stream = glob.stream( [ - `${ PACKAGES_DIR }/*/src/**/*.{js,ts,tsx}`, + `${ PACKAGES_DIR }/*/src/**/*.{js,ts,tsx,mts,mjs,cjs,cts}`, `${ PACKAGES_DIR }/*/src/*.scss`, `${ PACKAGES_DIR }/block-library/src/**/*.js`, `${ PACKAGES_DIR }/block-library/src/*/style.scss`, diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 43fe001351bc2c..9ab38960546f68 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -2,12 +2,15 @@ ## Unreleased - ### Breaking Changes - Updated `stylelint` dependency to `^16.8.2` ([#64828](https://github.com/WordPress/gutenberg/pull/64828)). - Switched default config from `@wordpress/stylelint-config/scss` to use `@wordpress/stylelint-config/scss-stylistic` to keep stylistic rules ([#64828](https://github.com/WordPress/gutenberg/pull/64828)). +### Enhancements + +- Add support for mjs, cjs, mts, and cts file extensions ([#65101](https://github.com/WordPress/gutenberg/pull/65101)). + ## 29.0.0 (2024-09-05) ### Breaking Changes diff --git a/packages/scripts/config/webpack.config.js b/packages/scripts/config/webpack.config.js index 91ef19fc27ed6b..6c73114213fce2 100644 --- a/packages/scripts/config/webpack.config.js +++ b/packages/scripts/config/webpack.config.js @@ -111,7 +111,16 @@ const baseConfig = { alias: { 'lodash-es': 'lodash', }, - extensions: [ '.jsx', '.ts', '.tsx', '...' ], + extensions: [ + '.jsx', + '.ts', + '.tsx', + '.mjs', + '.mts', + '.cjs', + '.cts', + '...', + ], }, optimization: { // Only concatenate modules in production, when not analyzing bundles. @@ -154,7 +163,7 @@ const baseConfig = { module: { rules: [ { - test: /\.m?(j|t)sx?$/, + test: /\.(m|c)?(j|t)sx?$/, exclude: /node_modules/, use: [ { @@ -209,7 +218,7 @@ const baseConfig = { }, { test: /\.svg$/, - issuer: /\.(j|t)sx?$/, + issuer: /\.(m|c)?(j|t)sx?$/, use: [ '@svgr/webpack', 'url-loader' ], type: 'javascript/auto', },