Skip to content

Commit

Permalink
PICKME: Add support for mjs, cjs, mts, and cts extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Sep 12, 2024
1 parent d3b54f4 commit 3172472
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion bin/packages/build-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 ) => {
Expand Down
2 changes: 1 addition & 1 deletion bin/packages/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### 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
Expand All @@ -10,7 +14,7 @@

### Enhancements

- Inlines CSS files imported from other CSS files before optimization in the `build` command ([#61121](https://github.com/WordPress/gutenberg/pull/61121)).
- Inlines CSS files imported from other CSS files before optimization in the `build` command ([#61121](https://github.com/WordPress/gutenberg/pull/61121)).

### Bug Fixes

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 @@ -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.
Expand Down Expand Up @@ -154,7 +163,7 @@ const baseConfig = {
module: {
rules: [
{
test: /\.m?(j|t)sx?$/,
test: /\.(m|c)?(j|t)sx?$/,
exclude: /node_modules/,
use: [
{
Expand Down Expand Up @@ -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',
},
Expand Down

0 comments on commit 3172472

Please sign in to comment.