| | |
| | | "use strict"; |
| | | |
| | | const { groupBy } = require("./util/ArrayHelpers"); |
| | | const createSchemaValidation = require("./util/create-schema-validation"); |
| | | |
| | | /** @typedef {import("watchpack").TimeInfoEntries} TimeInfoEntries */ |
| | | /** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */ |
| | | /** @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"), |
| | | () => require("../schemas/plugins/WatchIgnorePlugin.json"), |
| | | { |
| | | name: "Watch Ignore Plugin", |
| | | baseDataPath: "options" |
| | | } |
| | | ); |
| | | |
| | | const IGNORE_TIME_ENTRY = "ignore"; |
| | | |
| | | class IgnoringWatchFileSystem { |
| | | /** |
| | | * Creates an instance of IgnoringWatchFileSystem. |
| | | * @param {WatchFileSystem} wfs original file system |
| | | * @param {WatchIgnorePluginOptions["paths"]} paths ignored paths |
| | | */ |
| | |
| | | files = [...files]; |
| | | dirs = [...dirs]; |
| | | /** |
| | | * Returns true, if path is ignored. |
| | | * @param {string} path path to check |
| | | * @returns {boolean} true, if path is ignored |
| | | */ |
| | |
| | | |
| | | class WatchIgnorePlugin { |
| | | /** |
| | | * Creates an instance of WatchIgnorePlugin. |
| | | * @param {WatchIgnorePluginOptions} options options |
| | | */ |
| | | constructor(options) { |
| | | validate(options); |
| | | this.paths = options.paths; |
| | | /** @type {WatchIgnorePluginOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | compiler.hooks.validate.tap(PLUGIN_NAME, () => { |
| | | compiler.validate( |
| | | () => require("../schemas/plugins/WatchIgnorePlugin.json"), |
| | | this.options, |
| | | { |
| | | name: "Watch Ignore Plugin", |
| | | baseDataPath: "options" |
| | | }, |
| | | (options) => |
| | | require("../schemas/plugins/WatchIgnorePlugin.check")(options) |
| | | ); |
| | | }); |
| | | compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => { |
| | | compiler.watchFileSystem = new IgnoringWatchFileSystem( |
| | | /** @type {WatchFileSystem} */ |
| | | (compiler.watchFileSystem), |
| | | this.paths |
| | | this.options.paths |
| | | ); |
| | | }); |
| | | } |