Skip to content

Commit dc1a8ad

Browse files
committed
fix(build): add missing import and error handling for hole-punch in build
- Add missing 'import { processBinary }' in build.ts (would have caused ReferenceError at runtime). - Wrap parseIcuToc/holePunch in try-catch inside processBinary so an unexpected ICU layout skips hole-punch gracefully instead of crashing the build.
1 parent f100ff0 commit dc1a8ad

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

script/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { promisify } from "node:util";
2424
import { gzip } from "node:zlib";
2525
import { $ } from "bun";
2626
import pkg from "../package.json";
27+
import { processBinary } from "./hole-punch.js";
2728

2829
const gzipAsync = promisify(gzip);
2930

@@ -100,7 +101,6 @@ async function buildTarget(target: BuildTarget): Promise<boolean> {
100101

101102
// Hole-punch: zero unused ICU data entries so they compress to nearly nothing.
102103
// Must run before gzip so the compressed output benefits from zeroed regions.
103-
// biome-ignore lint/correctness/noUndeclaredVariables: resolved at runtime via ./hole-punch.ts
104104
const hpStats = processBinary(outfile);
105105
if (hpStats && hpStats.removedEntries > 0) {
106106
console.log(

script/hole-punch.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ function holePunch(buf: Buffer, scan: IcuScanResult): HolePunchStats {
370370
/**
371371
* Process a single binary file: find ICU data, zero unused entries, write back.
372372
*
373-
* @returns Hole-punch statistics, or null if no ICU data was found
373+
* Returns null (rather than throwing) when the binary has no ICU data or
374+
* when the ICU blob has an unexpected layout, so callers like the build
375+
* script can skip hole-punch gracefully instead of crashing.
376+
*
377+
* @returns Hole-punch statistics, or null if no ICU data was found/parseable
374378
*/
375379
function processBinary(filePath: string): HolePunchStats | null {
376380
const buf = readFileSync(filePath);
@@ -380,11 +384,17 @@ function processBinary(filePath: string): HolePunchStats | null {
380384
return null;
381385
}
382386

383-
const scan = parseIcuToc(buf, blobOffset);
384-
const stats = holePunch(buf, scan);
387+
try {
388+
const scan = parseIcuToc(buf, blobOffset);
389+
const stats = holePunch(buf, scan);
385390

386-
writeFileSync(filePath, buf);
387-
return stats;
391+
writeFileSync(filePath, buf);
392+
return stats;
393+
} catch {
394+
// ICU blob matched the magic bytes but has an unexpected layout
395+
// (e.g., entry count out of range). Skip instead of crashing.
396+
return null;
397+
}
388398
}
389399

390400
/** Format bytes as a human-readable string */

0 commit comments

Comments
 (0)