Skip to content

Commit bb4f8eb

Browse files
authoredJun 4, 2023
fix: regression for custom configurations (#3834)
1 parent 14b9c18 commit bb4f8eb

File tree

11 files changed

+1059
-17
lines changed

11 files changed

+1059
-17
lines changed
 

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"webpack": "5.x.x"
5454
},
5555
"devDependencies": {
56+
"@babel/core": "^7.22.1",
57+
"@babel/preset-env": "^7.22.4",
58+
"@babel/register": "^7.15.8",
5659
"@commitlint/cli": "^17.1.2",
5760
"@commitlint/config-conventional": "^17.1.0",
5861
"@types/jest": "^29.4.0",

‎packages/webpack-cli/src/webpack-cli.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,7 @@ class WebpackCLI implements IWebpackCLI {
18021802
const interpret = require("interpret");
18031803
const loadConfigByPath = async (configPath: string, argv: Argv = {}) => {
18041804
const ext = path.extname(configPath).toLowerCase();
1805-
let interpreted = interpret.jsVariants[ext];
1806-
1805+
let interpreted = Object.keys(interpret.jsVariants).find((variant) => variant === ext);
18071806
// Fallback `.cts` to `.ts`
18081807
// TODO implement good `.mts` support after https://github.com/gulpjs/rechoir/issues/43
18091808
// For ESM and `.mts` you need to use: 'NODE_OPTIONS="--loader ts-node/esm" webpack-cli --config ./webpack.config.mts'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// eslint-disable-next-line node/no-unpublished-require
2+
const { run } = require("../../../utils/test-utils");
3+
4+
describe("webpack cli", () => {
5+
it("should support mjs config format", async () => {
6+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.babel.js"]);
7+
8+
console.log(stderr);
9+
10+
expect(exitCode).toBe(0);
11+
expect(stderr).toBeFalsy();
12+
expect(stdout).toBeTruthy();
13+
});
14+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("You know who");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"engines": {
3+
"node": ">=14.15.0"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
mode: "development",
5+
entry: "./main.js",
6+
output: {
7+
path: path.resolve(__dirname, "dist"),
8+
filename: "foo.bundle.js",
9+
},
10+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// eslint-disable-next-line node/no-unpublished-require
2+
const { run } = require("../../../utils/test-utils");
3+
4+
describe("webpack cli", () => {
5+
it("should support mjs config format", async () => {
6+
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.babel.js"]);
7+
8+
expect(exitCode).toBe(0);
9+
expect(stderr).toBeFalsy();
10+
expect(stdout).toBeTruthy();
11+
});
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("You know who");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "module",
3+
"engines": {
4+
"node": ">=14.15.0"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* eslint-disable */
2+
import { fileURLToPath } from "url";
3+
import path from "path";
4+
5+
export default {
6+
mode: "development",
7+
entry: "./main.js",
8+
output: {
9+
path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "dist"),
10+
filename: "foo.bundle.js",
11+
},
12+
};

‎yarn.lock

+994-15
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.