src/generate.ts: Undo Nix shebang patching

Fixes generation of a broken yarn-project.nix when running a Nix-built
Yarn.
This commit is contained in:
the-sun-will-rise-tomorrow
2024-11-06 12:30:17 +00:00
parent 06b4193023
commit 1186a8a9f1
+7 -3
View File
@@ -59,9 +59,13 @@ export default async (
let yarnBinExpr: string;
if (yarnPathAbs === null) {
// Assume the current running script is the correct Yarn.
const sha512 = await hashUtils.checksumFile(
process.argv[1] as PortablePath,
);
let text = (await xfs.readFilePromise(process.argv[1] as PortablePath)).toString();
// If yarn was installed via Nix, revert shebang patching to get correct checksum
if (text.startsWith("#!/nix/store/")) {
const code = text.substring(text.indexOf("\n") + 1);
text = `#!/usr/bin/env node\n${code}`;
}
const sha512 = hashUtils.makeHash(Buffer.from(text));
yarnBinExpr = [
"fetchurl {",
` url = "https://repo.yarnpkg.com/${YarnVersion!}/packages/yarnpkg-cli/bin/yarn.js";`,