Merge pull request #11134 from webpack/feature/check-asset-casing

add error when trying to write assets that only differ in casing
This commit is contained in:
Tobias Koppers 2020-07-08 10:53:53 +02:00 committed by GitHub
commit 06608f9ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -14,7 +14,6 @@ const {
AsyncSeriesHook
} = require("tapable");
const { SizeOnlySource } = require("webpack-sources");
const Cache = require("./Cache");
const Compilation = require("./Compilation");
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
@ -24,6 +23,7 @@ const RequestShortener = require("./RequestShortener");
const ResolverFactory = require("./ResolverFactory");
const Stats = require("./Stats");
const Watching = require("./Watching");
const WebpackError = require("./WebpackError");
const { Logger } = require("./logging/Logger");
const { join, dirname, mkdirp } = require("./util/fs");
const { makePathsRelative } = require("./util/identifier");
@ -480,6 +480,7 @@ class Compiler {
const assets = compilation.getAssets();
compilation.assets = { ...compilation.assets };
const caseInsensitiveMap = new Map();
asyncLib.forEachLimit(
assets,
15,
@ -498,6 +499,19 @@ class Compiler {
targetFile
);
const caseInsensitiveTargetPath = targetPath.toLowerCase();
if (caseInsensitiveMap.has(caseInsensitiveTargetPath)) {
const other = caseInsensitiveMap.get(caseInsensitiveTargetPath);
const err = new WebpackError(`Prevent writing to file that only differs in casing from already written file.
This will lead to a race-condition and corrupted files on case-insensitive file systems.
${targetPath}
${other}`);
err.file = file;
return callback(err);
} else {
caseInsensitiveMap.set(caseInsensitiveTargetPath, targetPath);
}
// check if the target file has already been written by this Compiler
const targetFileGeneration = this._assetEmittingWrittenFiles.get(
targetPath

View File

@ -0,0 +1 @@
module.exports = [[/only differs in casing/, /a\.js/, /A\.js/]];

View File

@ -0,0 +1,10 @@
/** @type {import("../../../../").Configuration} */
module.exports = {
entry: {
a: "./index.js?1",
A: "./index.js?2"
},
output: {
filename: "[name].js"
}
};