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 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.");