




















@@ -489,26 +489,42 @@ function resolveInstalledDirectDependencyNames(
489489return directDependencyNames;
490490}
491491492+function appendDirectoryFingerprint(hash, rootDir, currentDir = rootDir) {
493+const entries = fs
494+.readdirSync(currentDir, { withFileTypes: true })
495+.toSorted((left, right) => left.name.localeCompare(right.name));
496+497+for (const entry of entries) {
498+const fullPath = path.join(currentDir, entry.name);
499+const relativePath = path.relative(rootDir, fullPath).replace(/\\/g, "/");
500+const stats = fs.lstatSync(fullPath);
501+if (stats.isSymbolicLink()) {
502+hash.update(`symlink:${relativePath}->${fs.readlinkSync(fullPath).replace(/\\/g, "/")}\n`);
503+continue;
504+}
505+if (stats.isDirectory()) {
506+hash.update(`dir:${relativePath}\n`);
507+appendDirectoryFingerprint(hash, rootDir, fullPath);
508+continue;
509+}
510+if (!stats.isFile()) {
511+continue;
512+}
513+const stat = fs.statSync(fullPath);
514+hash.update(`file:${relativePath}:${stat.size}\n`);
515+hash.update(fs.readFileSync(fullPath));
516+}
517+}
518+492519function createInstalledRuntimeClosureFingerprint(rootNodeModulesDir, dependencyNames) {
493520const hash = createHash("sha256");
494521for (const depName of [...dependencyNames].toSorted((left, right) => left.localeCompare(right))) {
495522const depRoot = dependencyNodeModulesPath(rootNodeModulesDir, depName);
496523if (depRoot === null || !fs.existsSync(depRoot)) {
497524return null;
498525}
499-const packageJsonPath = path.join(depRoot, "package.json");
500-const installedVersion = readInstalledDependencyVersionFromRoot(depRoot);
501-const realRoot = fs.realpathSync(depRoot);
502-const packageJsonStat = fs.statSync(packageJsonPath);
503-hash.update(
504-JSON.stringify({
505- depName,
506- installedVersion,
507-packageJsonMtimeMs: packageJsonStat.mtimeMs,
508-packageJsonSize: packageJsonStat.size,
509- realRoot,
510-}),
511-);
526+hash.update(`package:${depName}:${fs.realpathSync(depRoot)}\n`);
527+appendDirectoryFingerprint(hash, depRoot);
512528}
513529return hash.digest("hex");
514530}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。