Skip to content

Commit dcc9947

Browse files
committed
chore: updated postinstall script
1 parent c920f14 commit dcc9947

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

npm/postinstall.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,35 @@ async function main() {
121121

122122
const version = pkg.version;
123123
const tag = `v${version}`;
124-
const assetName = `thanks-stars-${tag}-${target.triple}.${target.ext}`;
125-
const url = `https://github.com/Kenzo-Wada/thanks-stars/releases/download/${tag}/${assetName}`;
124+
const assetNameCandidates = [
125+
`thanks-stars-${tag}-${target.triple}.${target.ext}`,
126+
`thanks-stars-${target.triple}.${target.ext}`
127+
];
126128

127-
const tempFile = path.join(os.tmpdir(), `${assetName}`);
129+
const tempFile = path.join(os.tmpdir(), `thanks-stars-${target.triple}.${target.ext}`);
128130
try {
129-
console.log(`Downloading ${url}`);
130-
await download(url, tempFile);
131+
let downloadedAsset = null;
132+
let lastError = null;
133+
for (const assetName of assetNameCandidates) {
134+
const url = `https://github.com/Kenzo-Wada/thanks-stars/releases/download/${tag}/${assetName}`;
135+
console.log(`Downloading ${url}`);
136+
try {
137+
await download(url, tempFile);
138+
downloadedAsset = assetName;
139+
break;
140+
} catch (error) {
141+
lastError = error;
142+
if (error?.message?.includes('(status: 404)')) {
143+
console.warn(`Asset not found: ${assetName}. Trying next candidate if available.`);
144+
continue;
145+
}
146+
throw error;
147+
}
148+
}
149+
150+
if (!downloadedAsset) {
151+
throw lastError ?? new Error('Failed to download any release asset.');
152+
}
131153

132154
const binDir = path.join(__dirname, 'bin');
133155
await extractArchive(tempFile, binDir, target.ext);

0 commit comments

Comments
 (0)