MCPcopy
hub / github.com/webpack/webpack / _readContextHash

Method _readContextHash

lib/FileSystemInfo.js:4058–4124  ·  view source on GitHub ↗

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

(path, callback)

Source from the content-addressed store, hash-verified

4056 * @type {Processor<string, ContextHash>}
4057 */
4058 _readContextHash(path, callback) {
4059 this._readContext(
4060 {
4061 path,
4062 fromImmutablePath: () => /** @type {ContextHash | ""} */ (""),
4063 fromManagedItem: (info) => info || "",
4064 fromSymlink: (file, target, callback) => {
4065 callback(
4066 null,
4067 /** @type {ContextHash} */
4068 ({
4069 hash: target,
4070 symlinks: new Set([target])
4071 })
4072 );
4073 },
4074 fromFile: (file, stat, callback) =>
4075 this.getFileHash(file, (err, hash) => {
4076 callback(err, hash || "");
4077 }),
4078 fromDirectory: (directory, stat, callback) => {
4079 this.contextHashQueue.increaseParallelism();
4080 this._getUnresolvedContextHash(directory, (err, hash) => {
4081 this.contextHashQueue.decreaseParallelism();
4082 callback(err, hash || "");
4083 });
4084 },
4085 /**
4086 * Returns reduced hash.
4087 * @param {string[]} files files
4088 * @param {(string | ContextHash)[]} fileHashes hashes
4089 * @returns {ContextHash} reduced hash
4090 */
4091 reduce: (files, fileHashes) => {
4092 /** @type {undefined | Symlinks} */
4093 let symlinks;
4094 const hash = createHash(this._hashFunction);
4095
4096 for (const file of files) hash.update(file);
4097 for (const entry of fileHashes) {
4098 if (typeof entry === "string") {
4099 hash.update(entry);
4100 } else {
4101 hash.update(entry.hash);
4102 if (entry.symlinks) {
4103 if (symlinks === undefined) symlinks = new Set();
4104 addAll(entry.symlinks, symlinks);
4105 }
4106 }
4107 }
4108
4109 /** @type {ContextHash} */
4110 const result = {
4111 hash: hash.digest("hex")
4112 };
4113 if (symlinks) result.symlinks = symlinks;
4114 return result;
4115 }

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected