fix: reuse shared npm binary marker path

This commit is contained in:
lixia
2026-05-10 11:55:55 +08:00
parent e61a40f39d
commit 904298216c
2 changed files with 4 additions and 3 deletions
+3 -3
View File
@@ -1001,7 +1001,7 @@ function existingBinaryCandidates(targetPath, assetName) {
return candidates;
}
async function adoptExistingBinaryIfValid(targetPath, assetName, version, getChecksums) {
async function adoptExistingBinaryIfValid(targetPath, assetName, version, getChecksums, marker) {
const candidates = [];
for (const candidate of existingBinaryCandidates(targetPath, assetName)) {
if (await fileExists(candidate)) {
@@ -1024,7 +1024,7 @@ async function adoptExistingBinaryIfValid(targetPath, assetName, version, getChe
if (process.platform !== "win32") {
await chmod(targetPath, 0o755);
}
await writeFile(`${targetPath}.version`, String(version), "utf8");
await writeFile(marker, String(version), "utf8");
return true;
}
return false;
@@ -1042,7 +1042,7 @@ async function ensureBinary(targetPath, assetName, version, repo, getChecksums,
return targetPath;
}
}
if (await adoptExistingBinaryIfValid(targetPath, assetName, version, getChecksums)) {
if (await adoptExistingBinaryIfValid(targetPath, assetName, version, getChecksums, marker)) {
return targetPath;
}
}
+1
View File
@@ -171,6 +171,7 @@ test("manual binaries with mismatched checksums are not adopted", async (t) => {
assetName,
"0.8.25",
async () => new Map([[assetName, sha256(Buffer.from("different bytes"))]]),
`${target}.version`,
);
assert.equal(adopted, false);