rename filesModified -> modifiedFiles
avoid creating additional arrays by allowing Iterable on WatchFileSystem interface
This commit is contained in:
parent
77f01de81a
commit
2f1a0176b3
|
@ -190,7 +190,7 @@ class Compiler {
|
|||
this.immutablePaths = new Set();
|
||||
|
||||
/** @type {Set<string>} */
|
||||
this.filesModified = undefined;
|
||||
this.modifiedFiles = undefined;
|
||||
/** @type {Set<string>} */
|
||||
this.removedFiles = undefined;
|
||||
/** @type {Map<string, FileSystemInfoEntry | null>} */
|
||||
|
@ -798,7 +798,7 @@ class Compiler {
|
|||
childCompiler.inputFileSystem = this.inputFileSystem;
|
||||
childCompiler.outputFileSystem = null;
|
||||
childCompiler.resolverFactory = this.resolverFactory;
|
||||
childCompiler.filesModified = this.filesModified;
|
||||
childCompiler.modifiedFiles = this.modifiedFiles;
|
||||
childCompiler.removedFiles = this.removedFiles;
|
||||
childCompiler.fileTimestamps = this.fileTimestamps;
|
||||
childCompiler.contextTimestamps = this.contextTimestamps;
|
||||
|
|
|
@ -20,6 +20,8 @@ class IgnoringWatchFileSystem {
|
|||
}
|
||||
|
||||
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
||||
files = Array.from(files);
|
||||
dirs = Array.from(dirs);
|
||||
const ignored = path =>
|
||||
this.paths.some(p =>
|
||||
p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
|
||||
|
@ -36,7 +38,7 @@ class IgnoringWatchFileSystem {
|
|||
missing,
|
||||
startTime,
|
||||
options,
|
||||
(err, fileTimestamps, dirTimestamps, removedFiles) => {
|
||||
(err, fileTimestamps, dirTimestamps, changedFiles, removedFiles) => {
|
||||
if (err) return callback(err);
|
||||
for (const path of ignoredFiles) {
|
||||
fileTimestamps.set(path, IGNORE_TIME_ENTRY);
|
||||
|
@ -46,7 +48,13 @@ class IgnoringWatchFileSystem {
|
|||
dirTimestamps.set(path, IGNORE_TIME_ENTRY);
|
||||
}
|
||||
|
||||
callback(err, fileTimestamps, dirTimestamps, removedFiles);
|
||||
callback(
|
||||
err,
|
||||
fileTimestamps,
|
||||
dirTimestamps,
|
||||
changedFiles,
|
||||
removedFiles
|
||||
);
|
||||
},
|
||||
callbackUndelayed
|
||||
);
|
||||
|
|
|
@ -46,6 +46,9 @@ class Watching {
|
|||
this.watchOptions.aggregateTimeout || 200;
|
||||
this.compiler = compiler;
|
||||
this.running = true;
|
||||
this.watcher = undefined;
|
||||
this.pausedWatcher = undefined;
|
||||
this._done = this._done.bind(this);
|
||||
this.compiler.readRecords(err => {
|
||||
if (err) return this._done(err);
|
||||
|
||||
|
@ -149,9 +152,9 @@ class Watching {
|
|||
process.nextTick(() => {
|
||||
if (!this.closed) {
|
||||
this.watch(
|
||||
Array.from(compilation.fileDependencies),
|
||||
Array.from(compilation.contextDependencies),
|
||||
Array.from(compilation.missingDependencies)
|
||||
compilation.fileDependencies,
|
||||
compilation.contextDependencies,
|
||||
compilation.missingDependencies
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -161,6 +164,12 @@ class Watching {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Iterable<string>} files watched files
|
||||
* @param {Iterable<string>} dirs watched directories
|
||||
* @param {Iterable<string>} missing watched existance entries
|
||||
* @returns {void}
|
||||
*/
|
||||
watch(files, dirs, missing) {
|
||||
this.pausedWatcher = null;
|
||||
this.watcher = this.compiler.watchFileSystem.watch(
|
||||
|
@ -169,16 +178,26 @@ class Watching {
|
|||
missing,
|
||||
this.startTime,
|
||||
this.watchOptions,
|
||||
(err, fileTimeInfoEntries, contextTimeInfoEntries, removedFiles) => {
|
||||
(
|
||||
err,
|
||||
fileTimeInfoEntries,
|
||||
contextTimeInfoEntries,
|
||||
changedFiles,
|
||||
removedFiles
|
||||
) => {
|
||||
this.pausedWatcher = this.watcher;
|
||||
this.watcher = null;
|
||||
if (err) {
|
||||
this.compiler.modifiedFiles = undefined;
|
||||
this.compiler.removedFiles = undefined;
|
||||
this.compiler.fileTimestamps = undefined;
|
||||
this.compiler.contextTimestamps = undefined;
|
||||
return this.handler(err);
|
||||
}
|
||||
this.compiler.fileTimestamps = fileTimeInfoEntries;
|
||||
this.compiler.contextTimestamps = contextTimeInfoEntries;
|
||||
this.compiler.removedFiles = removedFiles;
|
||||
this.compiler.filesModified = filesModified;
|
||||
this.compiler.modifiedFiles = changedFiles;
|
||||
if (!this.suspended) {
|
||||
this._invalidate();
|
||||
}
|
||||
|
@ -198,6 +217,8 @@ class Watching {
|
|||
this.callbacks.push(callback);
|
||||
}
|
||||
if (this.watcher) {
|
||||
this.compiler.modifiedFiles = this.watcher.aggregatedChanges;
|
||||
this.compiler.removedFiles = this.watcher.aggregatedRemovals;
|
||||
this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
|
||||
this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
|
||||
}
|
||||
|
@ -238,9 +259,10 @@ class Watching {
|
|||
const finalCallback = () => {
|
||||
this.compiler.running = false;
|
||||
this.compiler.watchMode = false;
|
||||
this.compiler.modifiedFiles = undefined;
|
||||
this.compiler.removedFiles = undefined;
|
||||
this.compiler.fileTimestamps = undefined;
|
||||
this.compiler.contextTimestamps = undefined;
|
||||
this.compiler.removedFiles = undefined;
|
||||
this.compiler.cache.shutdown(err => {
|
||||
this.compiler.hooks.watchClose.call();
|
||||
if (callback !== undefined) callback(err);
|
||||
|
|
|
@ -7,6 +7,16 @@
|
|||
|
||||
const Watchpack = require("watchpack");
|
||||
|
||||
/** @typedef {import("../FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
||||
|
||||
/**
|
||||
* @typedef {Object} Watcher
|
||||
* @property {function(): void} close
|
||||
* @property {function(): void} pause
|
||||
* @property {function(): Map<string, FileSystemInfoEntry>} getFileTimeInfoEntries
|
||||
* @property {function(): Map<string, FileSystemInfoEntry>} getContextTimeInfoEntries
|
||||
*/
|
||||
|
||||
class NodeWatchFileSystem {
|
||||
constructor(inputFileSystem) {
|
||||
this.inputFileSystem = inputFileSystem;
|
||||
|
@ -16,14 +26,24 @@ class NodeWatchFileSystem {
|
|||
this.watcher = new Watchpack(this.watcherOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Iterable<string>} files watched files
|
||||
* @param {Iterable<string>} dirs watched directories
|
||||
* @param {Iterable<string>} missing watched exitance entries
|
||||
* @param {number} startTime timestamp of start time
|
||||
* @param {TODO} options options object
|
||||
* @param {function(Error=, Map<string, FileSystemInfoEntry>, Map<string, FileSystemInfoEntry>, Set<string>, Set<string>): void} callback aggregated callback
|
||||
* @param {function(string, number): void} callbackUndelayed callback when the first change was detected
|
||||
* @returns {Watcher} a watcher
|
||||
*/
|
||||
watch(files, dirs, missing, startTime, options, callback, callbackUndelayed) {
|
||||
if (!Array.isArray(files)) {
|
||||
if (!files || typeof files[Symbol.iterator] !== "function") {
|
||||
throw new Error("Invalid arguments: 'files'");
|
||||
}
|
||||
if (!Array.isArray(dirs)) {
|
||||
if (!dirs || typeof dirs[Symbol.iterator] !== "function") {
|
||||
throw new Error("Invalid arguments: 'dirs'");
|
||||
}
|
||||
if (!Array.isArray(missing)) {
|
||||
if (!missing || typeof missing[Symbol.iterator] !== "function") {
|
||||
throw new Error("Invalid arguments: 'missing'");
|
||||
}
|
||||
if (typeof callback !== "function") {
|
||||
|
@ -44,8 +64,6 @@ class NodeWatchFileSystem {
|
|||
if (callbackUndelayed) {
|
||||
this.watcher.once("change", callbackUndelayed);
|
||||
}
|
||||
const cachedFiles = files;
|
||||
const cachedDirs = dirs;
|
||||
this.watcher.once("aggregated", (changes, removals) => {
|
||||
if (this.inputFileSystem && this.inputFileSystem.purge) {
|
||||
for (const item of changes) {
|
||||
|
@ -56,10 +74,13 @@ class NodeWatchFileSystem {
|
|||
}
|
||||
}
|
||||
const times = this.watcher.getTimeInfoEntries();
|
||||
callback(null, times, times, removals);
|
||||
callback(null, times, times, changes, removals);
|
||||
});
|
||||
|
||||
this.watcher.watch(cachedFiles.concat(missing), cachedDirs, startTime);
|
||||
const filesSet = new Set(files);
|
||||
for (const item of missing) filesSet.add(item);
|
||||
|
||||
this.watcher.watch(filesSet, dirs, startTime);
|
||||
|
||||
if (oldWatcher) {
|
||||
oldWatcher.close();
|
||||
|
|
Loading…
Reference in New Issue