feat: refactoring project
This commit is contained in:
35
node_modules/webpack/lib/WatchIgnorePlugin.js
generated
vendored
35
node_modules/webpack/lib/WatchIgnorePlugin.js
generated
vendored
@@ -9,9 +9,12 @@ const { groupBy } = require("./util/ArrayHelpers");
|
||||
const createSchemaValidation = require("./util/create-schema-validation");
|
||||
|
||||
/** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
|
||||
/** @typedef {import("../declarations/WebpackOptions").WatchOptions} WatchOptions */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
|
||||
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
||||
|
||||
/** @typedef {import("./util/fs").WatchMethod} WatchMethod */
|
||||
/** @typedef {import("./util/fs").Watcher} Watcher */
|
||||
const validate = createSchemaValidation(
|
||||
require("../schemas/plugins/WatchIgnorePlugin.check.js"),
|
||||
() => require("../schemas/plugins/WatchIgnorePlugin.json"),
|
||||
@@ -26,13 +29,14 @@ const IGNORE_TIME_ENTRY = "ignore";
|
||||
class IgnoringWatchFileSystem {
|
||||
/**
|
||||
* @param {WatchFileSystem} wfs original file system
|
||||
* @param {(string|RegExp)[]} paths ignored paths
|
||||
* @param {WatchIgnorePluginOptions["paths"]} paths ignored paths
|
||||
*/
|
||||
constructor(wfs, paths) {
|
||||
this.wfs = wfs;
|
||||
this.paths = paths;
|
||||
}
|
||||
|
||||
/** @type {WatchMethod} */
|
||||
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
||||
files = Array.from(files);
|
||||
dirs = Array.from(dirs);
|
||||
@@ -45,8 +49,16 @@ class IgnoringWatchFileSystem {
|
||||
p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
|
||||
);
|
||||
|
||||
const [ignoredFiles, notIgnoredFiles] = groupBy(files, ignored);
|
||||
const [ignoredDirs, notIgnoredDirs] = groupBy(dirs, ignored);
|
||||
const [ignoredFiles, notIgnoredFiles] = groupBy(
|
||||
/** @type {Array<string>} */
|
||||
(files),
|
||||
ignored
|
||||
);
|
||||
const [ignoredDirs, notIgnoredDirs] = groupBy(
|
||||
/** @type {Array<string>} */
|
||||
(dirs),
|
||||
ignored
|
||||
);
|
||||
|
||||
const watcher = this.wfs.watch(
|
||||
notIgnoredFiles,
|
||||
@@ -57,15 +69,17 @@ class IgnoringWatchFileSystem {
|
||||
(err, fileTimestamps, dirTimestamps, changedFiles, removedFiles) => {
|
||||
if (err) return callback(err);
|
||||
for (const path of ignoredFiles) {
|
||||
fileTimestamps.set(path, IGNORE_TIME_ENTRY);
|
||||
/** @type {TimeInfoEntries} */
|
||||
(fileTimestamps).set(path, IGNORE_TIME_ENTRY);
|
||||
}
|
||||
|
||||
for (const path of ignoredDirs) {
|
||||
dirTimestamps.set(path, IGNORE_TIME_ENTRY);
|
||||
/** @type {TimeInfoEntries} */
|
||||
(dirTimestamps).set(path, IGNORE_TIME_ENTRY);
|
||||
}
|
||||
|
||||
callback(
|
||||
err,
|
||||
null,
|
||||
fileTimestamps,
|
||||
dirTimestamps,
|
||||
changedFiles,
|
||||
@@ -95,7 +109,9 @@ class IgnoringWatchFileSystem {
|
||||
getInfo:
|
||||
watcher.getInfo &&
|
||||
(() => {
|
||||
const info = watcher.getInfo();
|
||||
const info =
|
||||
/** @type {NonNullable<Watcher["getInfo"]>} */
|
||||
(watcher.getInfo)();
|
||||
const { fileTimeInfoEntries, contextTimeInfoEntries } = info;
|
||||
for (const path of ignoredFiles) {
|
||||
fileTimeInfoEntries.set(path, IGNORE_TIME_ENTRY);
|
||||
@@ -126,7 +142,8 @@ class WatchIgnorePlugin {
|
||||
apply(compiler) {
|
||||
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
|
||||
compiler.watchFileSystem = new IgnoringWatchFileSystem(
|
||||
compiler.watchFileSystem,
|
||||
/** @type {WatchFileSystem} */
|
||||
(compiler.watchFileSystem),
|
||||
this.paths
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user