Skip to content

Commit 7fd589a

Browse files
committed
fix: fetch prebuilt binary from latest GitHub release, not package version
Query the GitHub releases API for the latest tag instead of deriving it from package.json. This ensures users always get the newest prebuilt binary regardless of which npm version they installed.
1 parent 7e93003 commit 7fd589a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/download.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { existsSync, copyFileSync, writeFileSync, mkdirSync } from 'node:fs';
88
import { execSync, spawnSync } from 'node:child_process';
99
import { dirname, join } from 'node:path';
1010
import { fileURLToPath } from 'node:url';
11-
import { createRequire } from 'node:module';
1211

1312
const __dirname = dirname(fileURLToPath(import.meta.url));
1413
const nativeDir = join(__dirname, '..', 'native');
@@ -31,10 +30,6 @@ const ARTIFACT_MAP = {
3130
const platformKey = `${process.platform}-${process.arch}`;
3231
const artifactName = ARTIFACT_MAP[platformKey];
3332

34-
// Read package version to find matching GitHub release
35-
const require = createRequire(import.meta.url);
36-
const pkg = require('../package.json');
37-
const version = pkg.version;
3833
const repo = 'imazen/imageflow-node';
3934

4035
async function tryDownloadPrebuilt() {
@@ -43,12 +38,23 @@ async function tryDownloadPrebuilt() {
4338
return false;
4439
}
4540

46-
const tag = `v${version}`;
47-
const url = `https://github.com/${repo}/releases/download/${tag}/${artifactName}`;
41+
try {
42+
// Fetch latest release tag from GitHub API
43+
console.log(`Querying latest release from ${repo}...`);
44+
const apiUrl = `https://api.github.com/repos/${repo}/releases/latest`;
45+
const apiResp = await fetch(apiUrl, {
46+
headers: { 'Accept': 'application/vnd.github.v3+json' },
47+
});
48+
if (!apiResp.ok) {
49+
console.log(`GitHub API returned ${apiResp.status}, will build from source.`);
50+
return false;
51+
}
52+
const release = await apiResp.json();
53+
const tag = release.tag_name;
4854

49-
console.log(`Downloading prebuilt binary for ${platformKey} from ${url}...`);
55+
const url = `https://github.com/${repo}/releases/download/${tag}/${artifactName}`;
56+
console.log(`Downloading prebuilt binary for ${platformKey} from ${tag}...`);
5057

51-
try {
5258
const response = await fetch(url, { redirect: 'follow' });
5359
if (!response.ok) {
5460
console.log(`Download failed (HTTP ${response.status}), will build from source.`);

0 commit comments

Comments
 (0)