diff --git a/lib/FileSystemInfo.js b/lib/FileSystemInfo.js index 82b04d456ab..07a6461958f 100644 --- a/lib/FileSystemInfo.js +++ b/lib/FileSystemInfo.js @@ -206,17 +206,17 @@ class Snapshot { this._flags = 0; /** @type {number | undefined} */ this.startTime = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.fileTimestamps = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.fileHashes = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.fileTshs = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.contextTimestamps = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.contextHashes = undefined; - /** @type {Map | undefined} */ + /** @type {Map | undefined} */ this.contextTshs = undefined; /** @type {Map | undefined} */ this.missingExistence = undefined; @@ -823,11 +823,10 @@ const getManagedItem = (managedPath, path) => { /** * @template {ContextFileSystemInfoEntry | ContextTimestampAndHash} T - * @param {T | "ignore"} entry entry + * @param {T} entry entry * @returns {T["resolved"] | undefined} the resolved entry */ const getResolvedTimestamp = entry => { - if (entry === "ignore") return undefined; if (entry === null) return null; if (entry.resolved !== undefined) return entry.resolved; return entry.symlinks === undefined ? entry : undefined; @@ -1191,6 +1190,7 @@ class FileSystemInfo { getContextTimestamp(path, callback) { const cache = this._contextTimestamps.get(path); if (cache !== undefined) { + if (cache === "ignore") return callback(null, "ignore"); const resolved = getResolvedTimestamp(cache); if (resolved !== undefined) return callback(null, resolved); return this._resolveContextTimestamp(cache, callback); @@ -1876,17 +1876,17 @@ class FileSystemInfo { * @returns {void} */ createSnapshot(startTime, files, directories, missing, options, callback) { - /** @type {Map} */ + /** @type {Map} */ const fileTimestamps = new Map(); - /** @type {Map} */ + /** @type {Map} */ const fileHashes = new Map(); - /** @type {Map} */ + /** @type {Map} */ const fileTshs = new Map(); - /** @type {Map} */ + /** @type {Map} */ const contextTimestamps = new Map(); - /** @type {Map} */ + /** @type {Map} */ const contextHashes = new Map(); - /** @type {Map} */ + /** @type {Map} */ const contextTshs = new Map(); /** @type {Map} */ const missingExistence = new Map(); @@ -2080,6 +2080,7 @@ class FileSystemInfo { this._contextTshsOptimization.optimize(snapshot, capturedDirectories); for (const path of capturedDirectories) { const cache = this._contextTshs.get(path); + /** @type {ResolvedContextTimestampAndHash} */ let resolved; if ( cache !== undefined && @@ -2088,6 +2089,11 @@ class FileSystemInfo { contextTshs.set(path, resolved); } else { jobs++; + /** + * @param {Error=} err error + * @param {ResolvedContextTimestampAndHash=} entry entry + * @returns {void} + */ const callback = (err, entry) => { if (err) { if (this.logger) { @@ -2152,14 +2158,20 @@ class FileSystemInfo { ); for (const path of capturedDirectories) { const cache = this._contextTimestamps.get(path); + if (cache === "ignore") continue; let resolved; if ( cache !== undefined && (resolved = getResolvedTimestamp(cache)) !== undefined ) { contextTimestamps.set(path, resolved); - } else if (cache !== "ignore") { + } else { jobs++; + /** + * @param {Error=} err error + * @param {ResolvedContextFileSystemInfoEntry=} entry entry + * @returns {void} + */ const callback = (err, entry) => { if (err) { if (this.logger) { @@ -2572,14 +2584,14 @@ class FileSystemInfo { const cache = this._fileTimestamps.get(path); if (cache !== undefined) { if (cache === "ignore" || !checkFile(path, cache, tsh, false)) { - processFileHashSnapshot(path, tsh.hash); + processFileHashSnapshot(path, tsh && tsh.hash); } } else { jobs++; this.fileTimestampQueue.add(path, (err, entry) => { if (err) return invalidWithError(path, err); if (!checkFile(path, entry, tsh, false)) { - processFileHashSnapshot(path, tsh.hash); + processFileHashSnapshot(path, tsh && tsh.hash); } jobDone(); }); @@ -2592,6 +2604,7 @@ class FileSystemInfo { this._statTestedEntries += contextTimestamps.size; for (const [path, ts] of contextTimestamps) { const cache = this._contextTimestamps.get(path); + if (cache === "ignore") continue; let resolved; if ( cache !== undefined && @@ -2601,8 +2614,13 @@ class FileSystemInfo { invalid(); return; } - } else if (cache !== "ignore") { + } else { jobs++; + /** + * @param {Error=} err error + * @param {ResolvedContextFileSystemInfoEntry=} entry entry + * @returns {void} + */ const callback = (err, entry) => { if (err) return invalidWithError(path, err); if (!checkContext(path, entry, ts)) { @@ -2662,27 +2680,33 @@ class FileSystemInfo { processContextHashSnapshot(path, tsh); } else { const cache = this._contextTimestamps.get(path); + if (cache === "ignore") continue; let resolved; if ( cache !== undefined && (resolved = getResolvedTimestamp(cache)) !== undefined ) { if (!checkContext(path, resolved, tsh, false)) { - processContextHashSnapshot(path, tsh.hash); + processContextHashSnapshot(path, tsh && tsh.hash); } - } else if (cache !== "ignore") { + } else { jobs++; + /** + * @param {Error=} err error + * @param {ResolvedContextFileSystemInfoEntry=} entry entry + * @returns {void} + */ const callback = (err, entry) => { if (err) return invalidWithError(path, err); if (!checkContext(path, entry, tsh, false)) { - processContextHashSnapshot(path, tsh.hash); + processContextHashSnapshot(path, tsh && tsh.hash); } jobDone(); }; if (cache !== undefined) { - this._resolveContextTsh(cache, callback); + this._resolveContextTimestamp(cache, callback); } else { - this.getContextTsh(path, callback); + this.getContextTimestamp(path, callback); } } } @@ -3032,6 +3056,11 @@ class FileSystemInfo { ); } + /** + * @param {ContextFileSystemInfoEntry} entry entry + * @param {function(Error=, ResolvedContextFileSystemInfoEntry=): void} callback callback + * @returns {void} + */ _resolveContextTimestamp(entry, callback) { const hashes = []; let safeTime = 0; @@ -3135,6 +3164,11 @@ class FileSystemInfo { ); } + /** + * @param {ContextHash} entry context hash + * @param {function(Error=, string=): void} callback callback + * @returns {void} + */ _resolveContextHash(entry, callback) { const hashes = []; processAsyncTree( @@ -3286,6 +3320,11 @@ class FileSystemInfo { } } + /** + * @param {ContextTimestampAndHash} entry entry + * @param {function(Error=, ResolvedContextTimestampAndHash=): void} callback callback + * @returns {void} + */ _resolveContextTsh(entry, callback) { const hashes = []; const tsHashes = []; diff --git a/types.d.ts b/types.d.ts index 1eac9201e8a..7d1bfd9621c 100644 --- a/types.d.ts +++ b/types.d.ts @@ -10448,12 +10448,12 @@ declare class SizeOnlySource extends Source { } declare abstract class Snapshot { startTime?: number; - fileTimestamps?: Map; - fileHashes?: Map; - fileTshs?: Map; - contextTimestamps?: Map; - contextHashes?: Map; - contextTshs?: Map; + fileTimestamps?: Map; + fileHashes?: Map; + fileTshs?: Map; + contextTimestamps?: Map; + contextHashes?: Map; + contextTshs?: Map; missingExistence?: Map; managedItemInfo?: Map; managedFiles?: Set;