Skip to content
Open
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
1 change: 1 addition & 0 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"include": ["packages/**"],
"reporter": ["html", "json", "cobertura"],
"source-map": true,
"hook-require": false,
"exclude-after-remap": false
}
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineConfig([
"test/build/config/error-array/webpack.config.js",
"test/build/config-format/esm-require-await/webpack.config.js",
"test/configtest/with-config-path/syntax-error.config.js",
"test/build/config-format/esm-require/webpack.config.js",
"test/build/config-format/auto/webpack.config.js",
]),
{
extends: [config],
Expand Down
44 changes: 44 additions & 0 deletions test/build/config-format/auto/auto.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { existsSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { run } from "../../../utils/test-utils.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe("auto loading different formats of configuration", () => {
it("should support configuration (Node.js build-in support)", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.js"], {
nodeOptions: [],
});

expect(stderr).toContain(
"Reparsing as ES module because module syntax was detected. This incurs a performance overhead.",
);
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support configuration (Node.js build-in support) with `mjs` extension", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.mjs"], {
nodeOptions: [],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support configuration (Node.js build-in support) with `cjs` extension", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.cjs"], {
nodeOptions: [],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "module",
"engines": {
"node": ">=18.12.0"
}
Expand Down
13 changes: 13 additions & 0 deletions test/build/config-format/auto/webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require("node:path");

const mode = "development";
const config = {
mode,
entry: "./main.js",
output: {
path: path.resolve("dist"),
filename: "foo.bundle.js",
},
};

module.exports = config;
13 changes: 13 additions & 0 deletions test/build/config-format/auto/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as path from "node:path";

const mode = "development";
const config = {
mode,
entry: "./main.js",
output: {
path: path.resolve("dist"),
filename: "foo.bundle.js",
},
};

export default config;
13 changes: 13 additions & 0 deletions test/build/config-format/auto/webpack.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as path from "node:path";

const mode = "development";
const config = {
mode,
entry: "./main.js",
output: {
path: path.resolve("dist"),
filename: "foo.bundle.js",
},
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ describe("webpack cli", () => {
});

it("should log error without transpilation", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"]);
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["--disable-interpret"], {
nodeOptions: [
// Disable typescript strip types for tests
...(major >= 24 ? ["--no-experimental-strip-types"] : []),
],
});

expect(exitCode).toBe(2);
expect(stderr).toContain(`Failed to load '${resolve(__dirname, "webpack.config.ts")}' config`);
Expand Down
18 changes: 0 additions & 18 deletions test/build/config-format/esm-require-await/index.test.js

This file was deleted.

18 changes: 0 additions & 18 deletions test/build/config-format/esm-require/index.test.js

This file was deleted.

1 change: 0 additions & 1 deletion test/build/config-format/esm-require/main.js

This file was deleted.

11 changes: 0 additions & 11 deletions test/build/config-format/esm-require/webpack.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions test/build/config-format/esm-top-level-await/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { run } = require("../../../utils/test-utils");

describe("webpack cli", () => {
it("should support mjs config format using `require`", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.mjs"]);

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { fileURLToPath } from "url";
import path from "path";
import path from "node:path";
import { fileURLToPath } from "node:url";

// eslint-disable-next-line unicorn/no-unnecessary-await
const mode = await "development";

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"type": "module",
"engines": {
"node": ">=18.12.0"
}
Expand Down
74 changes: 74 additions & 0 deletions test/build/config-format/typescript-auto/typescript.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { existsSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { run } from "../../../utils/test-utils.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe("typescript configuration", () => {
it("should support typescript configuration (Node.js build-in support)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], {
// Fallback to `ts-node/esm` for old Node.js versions
nodeOptions:
major >= 22
? []
: [
"--no-deprecation",
"--import=data:text/javascript,import { register } from 'node:module'; import { pathToFileURL } from 'node:url'; register('ts-node/esm', pathToFileURL('./'));",
],
});

if (major >= 22) {
// No `type` in `the package.json` but Node.js support `require` ECMA modules
expect(stderr).toContain(
"Reparsing as ES module because module syntax was detected. This incurs a performance overhead.",
);
} else {
expect(stderr).toBeFalsy();
}

expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript configuration (Node.js build-in support) with `mts` extension", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.mts"], {
// Fallback to `ts-node/esm` for old Node.js versions
nodeOptions:
major >= 22
? []
: [
"--no-deprecation",
"--import=data:text/javascript,import { register } from 'node:module'; import { pathToFileURL } from 'node:url'; register('ts-node/esm', pathToFileURL('./'));",
],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript configuration (Node.js build-in support) with `cts` extension", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.cts"], {
// Fallback to `ts-node/esm` for old Node.js versions
nodeOptions:
major >= 22
? []
: [
"--no-deprecation",
"--import=data:text/javascript,import { register } from 'node:module'; import { pathToFileURL } from 'node:url'; register('ts-node/esm', pathToFileURL('./'));",
],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});
});

This file was deleted.

93 changes: 93 additions & 0 deletions test/build/config-format/typescript-cjs/typescript.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { existsSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { run } from "../../../utils/test-utils.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

describe("typescript commonjs configuration", () => {
it("should support typescript commonjs configuration (Node.js build-in support)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], {
// Fallback to `ts-node/register` for old Node.js versions
nodeOptions: major >= 22 ? [] : ["--require=ts-node/register"],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript commonjs configuration (using `--require=ts-node/register`)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], {
nodeOptions: [
"--require=ts-node/register",
// Disable typescript strip types for tests
...(major >= 22 ? ["--no-experimental-strip-types"] : []),
],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript commonjs configuration (using `--require=ts-node/register` and disable `interpret`)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(
__dirname,
["-c", "./webpack.config.ts", "--disable-interpret"],
{
nodeOptions: [
"--require=ts-node/register",
// Disable typescript strip types for tests
...(major >= 22 ? ["--no-experimental-strip-types"] : []),
],
},
);

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript commonjs configuration (using `--import=ts-node/register` and disable `interpret`)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(
__dirname,
["-c", "./webpack.config.ts", "--disable-interpret"],
{
nodeOptions: [
"--import=ts-node/register",
// Disable typescript strip types for tests
...(major >= 22 ? ["--no-experimental-strip-types"] : []),
],
},
);

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});

it("should support typescript commonjs configuration (using `interpret`)", async () => {
const [major] = process.versions.node.split(".").map(Number);
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "./webpack.config.ts"], {
nodeOptions: [
// Disable typescript strip types for tests
...(major >= 22 ? ["--no-experimental-strip-types"] : []),
],
});

expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(exitCode).toBe(0);
expect(existsSync(resolve(__dirname, "dist/foo.bundle.js"))).toBeTruthy();
});
});
Loading
Loading