MCPcopy
hub / github.com/webpack/webpack / _readContextTimestampAndHash

Method _readContextTimestampAndHash

lib/FileSystemInfo.js:4175–4301  ·  lib/FileSystemInfo.js::FileSystemInfo._readContextTimestampAndHash

* @private * @type {Processor<string, ContextTimestampAndHash>}

(path, callback)

Source from the content-addressed store, hash-verified

4173 * @type {Processor<string, ContextTimestampAndHash>}
4174 */
4175 _readContextTimestampAndHash(path, callback) {
4176 /**
4177 * Processes the provided timestamp.
4178 * @param {ContextTimestamp} timestamp timestamp
4179 * @param {ContextHash} hash hash
4180 */
4181 const finalize = (timestamp, hash) => {
4182 const result =
4183 /** @type {ContextTimestampAndHash} */
4184 (timestamp === class="st">"ignore" ? hash : { ...timestamp, ...hash });
4185 this._contextTshs.set(path, result);
4186 callback(null, result);
4187 };
4188 const cachedHash = this._contextHashes.get(path);
4189 const cachedTimestamp = this._contextTimestamps.get(path);
4190 if (cachedHash !== undefined) {
4191 if (cachedTimestamp !== undefined) {
4192 finalize(cachedTimestamp, cachedHash);
4193 } else {
4194 this.contextTimestampQueue.add(path, (err, entry) => {
4195 if (err) return callback(err);
4196 finalize(
4197 /** @type {ContextFileSystemInfoEntry} */
4198 (entry),
4199 cachedHash
4200 );
4201 });
4202 }
4203 } else if (cachedTimestamp !== undefined) {
4204 this.contextHashQueue.add(path, (err, entry) => {
4205 if (err) return callback(err);
4206 finalize(cachedTimestamp, /** @type {ContextHash} */ (entry));
4207 });
4208 } else {
4209 this._readContext(
4210 {
4211 path,
4212 fromImmutablePath: () =>
4213 /** @type {ContextTimestampAndHash | Omit<ContextTimestampAndHash, class="st">"safeTime"> | string | null} */ (
4214 null
4215 ),
4216 fromManagedItem: (info) => ({
4217 safeTime: 0,
4218 timestampHash: info,
4219 hash: info || class="st">""
4220 }),
4221 fromSymlink: (file, target, callback) => {
4222 callback(null, {
4223 timestampHash: target,
4224 hash: target,
4225 symlinks: new Set([target])
4226 });
4227 },
4228 fromFile: (file, stat, callback) => {
4229 this._getFileTimestampAndHash(file, callback);
4230 },
4231 fromDirectory: (directory, stat, callback) => {
4232 this.contextTshQueue.increaseParallelism();

Callers

nothing calls this directly

Calls 12

_readContextMethod · 0.95
createHashFunction · 0.85
addAllFunction · 0.85
increaseParallelismMethod · 0.80
decreaseParallelismMethod · 0.80
callbackFunction · 0.50
getMethod · 0.45
addMethod · 0.45
updateMethod · 0.45
digestMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected