Skip to content

Commit 22b4e31

Browse files
OttoAllmendingerllm-git
andcommitted
fix(scripts): update babylon vendor script and btc-staking-ts version
Update the vendor-github-repo.ts script to better handle edge cases: 1. Check if existing archive file is non-empty before skipping 2. Add proper error handling for HTTP fetch failures 3. Make handler function async to properly wait for vendoring Also update babylonlabs-io/btc-staking-ts from v0.4.0-rc.2 to v1.0.3. Issue: BTC-2032 Co-authored-by: llm-git <[email protected]>
1 parent 76f765e commit 22b4e31

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

scripts/vendor-github-repo.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,18 @@ function getArchivePath(lib: GithubSource): string {
4444

4545
async function fetchArchive(lib: GithubSource, outfile: string): Promise<void> {
4646
try {
47-
await fs.stat(outfile);
48-
console.log(`Archive already exists: ${outfile}`);
49-
return;
47+
const result = await fs.stat(outfile);
48+
if (result.size > 0) {
49+
console.log(`Archive already exists: ${outfile}`);
50+
return;
51+
}
5052
} catch (e) {}
51-
const buffer = await fetch(getUrl(lib)).then((res) => res.arrayBuffer());
52-
await fs.writeFile(outfile, Buffer.from(buffer));
53+
const url = getUrl(lib);
54+
const result = await fetch(url);
55+
if (!result.ok) {
56+
throw new Error(`Failed to fetch ${url}: ${result.status} ${result.statusText}`);
57+
}
58+
await fs.writeFile(outfile, Buffer.from(await result.arrayBuffer()));
5359
}
5460

5561
async function extractArchive(archivePath: string, targetDir: string): Promise<void> {
@@ -79,7 +85,7 @@ const vendorConfigs: VendorConfig[] = [
7985
{
8086
org: 'babylonlabs-io',
8187
repo: 'btc-staking-ts',
82-
tag: 'v0.4.0-rc.2',
88+
tag: 'v1.0.3',
8389
targetDir: 'modules/babylonlabs-io-btc-staking-ts',
8490
},
8591
];
@@ -90,15 +96,15 @@ yargs
9096
builder(a) {
9197
return a.options({ name: { type: 'string' } });
9298
},
93-
handler(a) {
99+
async handler(a) {
94100
const matches = vendorConfigs.filter((cfg) => a.name === cfg.repo);
95101
if (matches.length === 0) {
96102
throw new Error(`no such vendor config ${a.name}`);
97103
}
98104
if (matches.length > 1) {
99105
throw new Error(`ambiguous vendor config ${a.name}`);
100106
}
101-
main(matches);
107+
await main(matches);
102108
},
103109
})
104110
.help()

0 commit comments

Comments
 (0)