From 17683ea7e09ed3e2b1c1f853b4482692a4167671 Mon Sep 17 00:00:00 2001 From: Kaylee <65376239+KayleeWilliams@users.noreply.github.com> Date: Tue, 11 Aug 2026 13:25:21 +0100 Subject: [PATCH 1/2] Support npm 12 pack --json output shape in size report npm 12 changed `npm pack --dry-run --json` from returning an array of package summaries to an object keyed by package name, so destructuring the parsed output threw `TypeError: {} is not iterable` and failed `bun run perf` (which CI runs on every pull request). Accept both shapes so the report works regardless of the npm version bundled with the active Node/CI runner. --- scripts/size.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/size.ts b/scripts/size.ts index fff2f3a..c30466b 100644 --- a/scripts/size.ts +++ b/scripts/size.ts @@ -31,6 +31,13 @@ interface PackSummary { unpackedSize: number; } +/** + * `npm pack --json` returns an array of summaries on npm < 12 and an object + * keyed by package name on npm >= 12. Both shapes are accepted so the report + * works regardless of the npm bundled with the active Node/CI runner. + */ +type PackOutput = PackSummary[] | Record; + interface ConsumerBundlePaths { entryPath: string; outDir: string; @@ -83,7 +90,8 @@ const getPackSummary = (): PackSummary => { }, stdio: ["ignore", "pipe", "inherit"], }); - const [summary] = JSON.parse(output) as PackSummary[]; + const parsed = JSON.parse(output) as PackOutput; + const [summary] = Array.isArray(parsed) ? parsed : Object.values(parsed); if (!summary) { throw new Error("npm pack did not return package metadata."); From e6b62460efa8fd0bf7534e9afa4b0b7de6514150 Mon Sep 17 00:00:00 2001 From: Kaylee <65376239+KayleeWilliams@users.noreply.github.com> Date: Tue, 11 Aug 2026 13:55:29 +0100 Subject: [PATCH 2/2] Pin npm 12 in CI so the size report is tested against it Runner images still bundle npm 10, which returns the old array shape from `npm pack --json`, so CI would not have exercised the npm 12 object shape this commit handles. Installing npm 12 makes the perf step cover the shape published releases actually run against, and printing the version records which shape was tested. --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d8e665..2ae56dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,15 @@ jobs: - name: Setup Bun uses: oven-sh/setup-bun@v2 + # The size report shells out to `npm pack --json`, whose output shape + # changed in npm 12. Runner images still bundle npm 10, so pin npm 12 + # to exercise the shape published releases actually run against, and + # print the version so the log records which shape was tested. + - name: Setup npm 12 + run: | + npm install -g npm@12 + npm --version + - name: Install dependencies run: bun install