Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion scripts/size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PackSummary>;

interface ConsumerBundlePaths {
entryPath: string;
outDir: string;
Expand Down Expand Up @@ -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.");
Expand Down
Loading