mirror of https://github.com/webpack/webpack.git
Merge pull request #14704 from webpack/issue-14700
fix: remove links in clean plugin
This commit is contained in:
commit
4876a16dcb
|
@ -16,6 +16,7 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./logging/Logger").Logger} Logger */
|
||||
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
||||
/** @typedef {import("./util/fs").StatsCallback} StatsCallback */
|
||||
|
||||
/** @typedef {(function(string):boolean)|RegExp} IgnoreItem */
|
||||
/** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */
|
||||
|
@ -102,6 +103,20 @@ const getDiffToOldAssets = (currentAssets, oldAssets) => {
|
|||
return diff;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OutputFileSystem} fs filesystem
|
||||
* @param {string} filename path to file
|
||||
* @param {StatsCallback} callback callback for provided filename
|
||||
* @returns {void}
|
||||
*/
|
||||
const doStat = (fs, filename, callback) => {
|
||||
if ("lstat" in fs) {
|
||||
fs.lstat(filename, callback);
|
||||
} else {
|
||||
fs.stat(filename, callback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {OutputFileSystem} fs filesystem
|
||||
* @param {string} outputPath output path
|
||||
|
@ -150,7 +165,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|||
log(`${filename} will be kept`);
|
||||
return process.nextTick(callback);
|
||||
}
|
||||
fs.stat(path, (err, stats) => {
|
||||
doStat(fs, path, (err, stats) => {
|
||||
if (err) return handleError(err);
|
||||
if (!stats.isDirectory()) {
|
||||
push({
|
||||
|
|
|
@ -93,6 +93,7 @@ const path = require("path");
|
|||
* @property {function(string, Callback): void=} rmdir
|
||||
* @property {function(string, Callback): void=} unlink
|
||||
* @property {function(string, StatsCallback): void} stat
|
||||
* @property {function(string, StatsCallback): void=} lstat
|
||||
* @property {function(string, BufferOrStringCallback): void} readFile
|
||||
* @property {(function(string, string): string)=} join
|
||||
* @property {(function(string, string): string)=} relative
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
it("should compile and run the test", function() {});
|
|
@ -0,0 +1,16 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
module.exports = () => {
|
||||
try {
|
||||
fs.symlinkSync(
|
||||
path.join(__dirname, "index.js"),
|
||||
path.join(__dirname, ".testlink"),
|
||||
"file"
|
||||
);
|
||||
fs.unlinkSync(path.join(__dirname, ".testlink"));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,41 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const readDir = require("../enabled/readdir");
|
||||
|
||||
/** @type {import("../../../../").Configuration} */
|
||||
module.exports = {
|
||||
output: {
|
||||
clean: true
|
||||
},
|
||||
plugins: [
|
||||
compiler => {
|
||||
let once = true;
|
||||
compiler.hooks.environment.tap("Test", () => {
|
||||
if (once) {
|
||||
const outputPath = compiler.options.output.path;
|
||||
const originalPath = path.join(outputPath, "file.ext");
|
||||
fs.writeFileSync(originalPath, "");
|
||||
const customDir = path.join(outputPath, "this/dir/should/be/removed");
|
||||
fs.mkdirSync(customDir, { recursive: true });
|
||||
fs.symlinkSync(
|
||||
originalPath,
|
||||
path.join(customDir, "file-link.ext"),
|
||||
"file"
|
||||
);
|
||||
once = false;
|
||||
}
|
||||
});
|
||||
compiler.hooks.afterEmit.tap("Test", compilation => {
|
||||
const outputPath = compilation.getPath(compiler.outputPath, {});
|
||||
expect(readDir(outputPath)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"directories": Array [],
|
||||
"files": Array [
|
||||
"bundle0.js",
|
||||
],
|
||||
}
|
||||
`);
|
||||
});
|
||||
}
|
||||
]
|
||||
};
|
|
@ -8348,6 +8348,10 @@ declare interface OutputFileSystem {
|
|||
arg0: string,
|
||||
arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void
|
||||
) => void;
|
||||
lstat?: (
|
||||
arg0: string,
|
||||
arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: IStats) => void
|
||||
) => void;
|
||||
readFile: (
|
||||
arg0: string,
|
||||
arg1: (arg0?: null | NodeJS.ErrnoException, arg1?: string | Buffer) => void
|
||||
|
|
Loading…
Reference in New Issue