Skip to content

Commit

Permalink
add default cache names in multicompiler mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Apr 12, 2024
1 parent 513126d commit a46748e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/MultiCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ module.exports = class MultiCompiler {
new WebpackError(
`${
compiler.name
? `Compiler with name "${compiler.name}" doesn't use cache name. `
? `Compiler with name "${compiler.name}" doesn't use unique cache name. `
: ""
}Please set "cache.name" option.`
}Please set unique "cache.name" option.`
)
);
}
Expand Down
14 changes: 12 additions & 2 deletions lib/config/normalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,26 @@ const keyedNestedConfig = (value, fn, customKeys) => {
const getNormalizedWebpackMultiCompilerOptions = options => {
/** @type {Array<WebpackOptions>} */
const resultedOptions = [];
/** @type {Set<string>} */
const cacheNames = new Set();

for (let i = 0; i < options.length; i++) {
const config = options[i];
resultedOptions.push({
...config,
cache: optionalNestedConfig(config.cache, cache => {
if (typeof cache === "boolean") return cache;
if (i === 0 || cache.type !== "filesystem" || "name" in cache)
if (cache.type !== "filesystem") return { ...cache };
const name = cache.name ? cache.name : defaultCacheName;
if (i === 0) {
cacheNames.add(name);
return { ...cache };
return { ...cache, name: `${defaultCacheName}__compiler${i + 1}__` };
}
if (cacheNames.has(name)) {
return { ...cache, name: `${name}__compiler${i + 1}__` };
}
cacheNames.add(cache.name);
return { ...cache };
})
});
}
Expand Down
7 changes: 4 additions & 3 deletions test/ConfigTestCases.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ const describeCases = config => {
(options.experiments && options.experiments.outputModule
? ".mjs"
: ".js");
if (config.cache) {
if (config.cache || options.cache) {
options.cache = {
cacheDirectory,
name: `config-${idx}`,
...config.cache
name: options.cache ? options.cache.name : `config-${idx}`,
...config.cache,
...options.cache
};
options.infrastructureLogging = {
debug: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = [
/Please set "cache\.name" option/,
/Compiler with name "3rd compiler" doesn't use cache name/
/Please set unique "cache\.name" option/,
/Compiler with name "3rd compiler" doesn't use unique cache name/
];

0 comments on commit a46748e

Please sign in to comment.