Skip to content

Commit 35ede57

Browse files
committed
fix: hard link to binary on windows
1 parent ef27a97 commit 35ede57

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

scripts/preinstall.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ async function parsePackageJson() {
7373
url = url.replace(/{{version}}/g, version);
7474
url = url.replace(/{{bin_name}}/g, binName);
7575

76-
// Binary name on Windows has .exe suffix
77-
if (process.platform === "win32") {
78-
binName += ".exe";
79-
}
80-
8176
return { binName, binPath, url, version };
8277
}
8378

@@ -93,10 +88,11 @@ async function main() {
9388
const opts = await parsePackageJson();
9489
await fs.promises.mkdir(opts.binPath, { recursive: true });
9590

96-
// First we will Un-GZip, then we will untar. So once untar is completed,
97-
// binary is downloaded into `downloadPath`. Verify the binary and call it good
91+
// First we will Un-GZip, then we will untar.
9892
const ungz = zlib.createGunzip();
99-
const untar = tar.x({ cwd: opts.binPath }, [opts.binName]);
93+
// Binary name on Windows has .exe suffix
94+
const ext = process.platform === "win32" ? ".exe" : "";
95+
const untar = tar.x({ cwd: opts.binPath }, [opts.binName + ext]);
10096

10197
console.info("Downloading", opts.url);
10298
const resp = await fetch(opts.url);
@@ -106,6 +102,12 @@ async function main() {
106102
untar.on("end", () => resolve());
107103
});
108104

105+
// Creates a hardlink for npm to find the binary on Windows
106+
if (ext) {
107+
const bin = path.join(opts.binPath, opts.binName);
108+
await fs.promises.link(bin + ext, bin);
109+
}
110+
109111
// TODO: verify checksums
110112
console.info("Installed Supabase CLI successfully");
111113
}

0 commit comments

Comments
 (0)