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
5 changes: 5 additions & 0 deletions .changeset/wild-papers-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webpack-cli": patch
---

Resolve configuration path for cache build dependencies.
12 changes: 10 additions & 2 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2597,12 +2597,20 @@ class WebpackCLI {
configuration.cache.buildDependencies.defaultConfig = [];
}

const normalizeConfigPath = (configPath: string) =>
configPath.startsWith("file://") ? fileURLToPath(configPath) : path.resolve(configPath);

if (Array.isArray(configPath)) {
for (const oneOfConfigPath of configPath) {
configuration.cache.buildDependencies.defaultConfig.push(oneOfConfigPath);
configuration.cache.buildDependencies.defaultConfig.push(
normalizeConfigPath(oneOfConfigPath),
);
}
} else {
configuration.cache.buildDependencies.defaultConfig.push(configPath);
configuration.cache.buildDependencies.defaultConfig.push(
// TODO fix `file:` support on webpack side and remove it in the next major release
normalizeConfigPath(configPath),
);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/build/cache/base-override.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
name: "base-override",
};
23 changes: 23 additions & 0 deletions test/build/cache/base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require("node:path");

module.exports = {
mode: "development",
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
},
infrastructureLogging: {
debug: /cache/,
},
entry: {
app: "./src/main.js",
},
output: {
filename: "[name].bundle.js",
chunkFilename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
publicPath: "/",
},
};
140 changes: 140 additions & 0 deletions test/build/cache/cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require("node:fs");
const path = require("node:path");
const url = require("node:url");
const { isWindows, processKill, run, runWatch } = require("../../utils/test-utils");

describe("cache", () => {
Expand Down Expand Up @@ -219,6 +220,145 @@ describe("cache", () => {
expect(stdout).toBeTruthy();
});

it("should work with relative path to configuration without build dependencies", async () => {
fs.rmSync(
path.join(
__dirname,
"../../../node_modules/.cache/webpack/no-build-dependencies-development",
),
{ recursive: true, force: true },
);

let { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
"./no-build-dependencies.config.js",
]);

expect(exitCode).toBe(0);
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();

({ exitCode, stderr, stdout } = await run(__dirname, [
"-c",
"./no-build-dependencies.config.js",
]));

expect(exitCode).toBe(0);
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
});

it("should work with file path to configuration without build dependencies", async () => {
fs.rmSync(
path.join(
__dirname,
"../../../node_modules/.cache/webpack/no-build-dependencies-file-development",
),
{ recursive: true, force: true },
);

let { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
path.resolve(__dirname, "./no-build-dependencies-file.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();

({ exitCode, stderr, stdout } = await run(__dirname, [
"-c",
path.resolve(__dirname, "./no-build-dependencies-file.config.js"),
]));

expect(exitCode).toBe(0);
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
});

it("should work with absolute path to configuration without build dependencies", async () => {
fs.rmSync(
path.join(
__dirname,
"../../../node_modules/.cache/webpack/no-build-dependencies-absolute-development",
),
{ recursive: true, force: true },
);

let { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
url
.pathToFileURL(path.resolve(__dirname, "./no-build-dependencies-absolute.config.js"))
.toString(),
]);

expect(exitCode).toBe(0);
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();

({ exitCode, stderr, stdout } = await run(__dirname, [
"-c",
url
.pathToFileURL(path.resolve(__dirname, "./no-build-dependencies-absolute.config.js"))
.toString(),
]));

expect(exitCode).toBe(0);
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
});

it("should work with multiple configuration and merge", async () => {
fs.rmSync(
path.join(__dirname, "../../../node_modules/.cache/webpack/base-override-development"),
{ recursive: true, force: true },
);

let { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
"./base.config.js",
"-c",
url.pathToFileURL(path.resolve(__dirname, "./base-override.config.js")).toString(),
"--merge",
]);

expect(exitCode).toBe(0);
expect(stderr.match(/No pack exists at/g)).toHaveLength(1);
expect(stderr.match(/Stored pack/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();

({ exitCode, stderr, stdout } = await run(__dirname, [
"-c",
"./base.config.js",
"-c",
url.pathToFileURL(path.resolve(__dirname, "./base-override.config.js")).toString(),
"--merge",
]));

expect(exitCode).toBe(0);
expect(stderr.match(/restore cache container:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content metadata:/g)).toHaveLength(1);
expect(stderr.match(/restore cache content \d+ \(.+\):/g)).toHaveLength(1);
expect(stderr).toBeTruthy();
expect(stdout).toBeTruthy();
});

if (!isWindows) {
it("should graceful shutdown", async () => {
fs.rmSync(
Expand Down
13 changes: 13 additions & 0 deletions test/build/cache/no-build-dependencies-absolute.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
name: "no-build-dependencies-absolute",
entry: {
app: "./src/main.js",
},
mode: "development",
cache: {
type: "filesystem",
},
infrastructureLogging: {
debug: /cache/,
},
};
13 changes: 13 additions & 0 deletions test/build/cache/no-build-dependencies-file.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
name: "no-build-dependencies-file",
entry: {
app: "./src/main.js",
},
mode: "development",
cache: {
type: "filesystem",
},
infrastructureLogging: {
debug: /cache/,
},
};
13 changes: 13 additions & 0 deletions test/build/cache/no-build-dependencies.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
name: "no-build-dependencies",
entry: {
app: "./src/main.js",
},
mode: "development",
cache: {
type: "filesystem",
},
infrastructureLogging: {
debug: /cache/,
},
};
Loading