Skip to content

fix(verify-package): accept npm 12 object-shaped pack output - #207

Closed
stysus wants to merge 1 commit into
kenryu42:mainfrom
stysus:fix/verify-package-npm-pack-json
Closed

stysus wants to merge 1 commit into
kenryu42:mainfrom
stysus:fix/verify-package-npm-pack-json

Conversation

@stysus

@stysus stysus commented Oct 4, 2026 •

Copy link
Copy Markdown

Summary

buildPackageTarball now reads the packed artifact from either shape of npm pack --json, so bun run verify:package and bun run check no longer fail on npm >= 12.

Fixes #206.

Root cause

npm 12.0.0 changed npm pack --json from an array of entries to an object keyed by package name (npm/cli#9247):

// npm < 12
[{ "filename": "cc-safety-net-2.5.2.tgz", ... }]

// npm >= 12
{ "cc-safety-net": { "filename": "cc-safety-net-2.5.2.tgz", ... } }

scripts/verify-package.ts cast the parsed output to PackResult[] and read packed[0]. For the object shape that index is undefined, so it threw npm pack did not report an artifact before the tarball was ever inspected.

Fix

-    ) as PackResult[];
-    const result = packed[0];
+    ) as PackResult[] | Record<string, PackResult>;
+    const result = Array.isArray(packed) ? packed[0] : Object.values(packed)[0];

CI stays green today only because the runners' bundled npm is 11.x (array shape) and publish.yml pins npm@11.5.1. Once those runners ship npm 12, both release verification and every contributor's bun run check break on an unrelated change.

Tests

Added reads the artifact from npm 12 object-shaped pack output to tests/scripts/package-git-head.test.ts. It drives buildPackageTarball with a fake npm that emits the object shape, so the regression is covered even on a runner whose npm still emits an array. The shared readPackedManifest helper was extracted to avoid duplicating the tarball extraction.

Red (before the fix):

(fail) release package identity > reads the artifact from npm 12 object-shaped pack output
error: npm pack did not report an artifact
      at buildPackageTarball (scripts/verify-package.ts:718:28)

Green (after): 2 pass, 0 fail.

bun run check: 3509 pass, 4 skip, 0 fail, coverage verified.

Notes

Per CONTRIBUTING.md, small bug fixes with an obvious solution normally go straight to a PR. This one also affects release tooling, so it is tracked in #206 for traceability.

Summary by CodeRabbit

  • Bug Fixes
    • Package verification now recognizes artifact details reported in either array or object format by npm, helping valid package tarballs pass verification.
    • Verified package tarballs retain their Git revision information and exclude the prepare script.

npm 12 changed `npm pack --json` from an array of entries to an object keyed by package name (npm/cli#9247). buildPackageTarball read `packed[0]`, so any run with npm >= 12 threw "npm pack did not report an artifact", failing the release check and `bun run check`.

Read the first entry from either shape, and pin the object shape with a fake npm so the regression is covered even where the installed npm still emits an array.
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: kenryu42/cc-safety-net/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3889e955-a98c-43a0-9aa8-d2abe9d2fe09
📥 Commits

Reviewing files that changed from the base of the PR and between 3db0a46 and e861f5e.

📒 Files selected for processing (2)
  • scripts/verify-package.ts
  • tests/scripts/package-git-head.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

buildPackageTarball now accepts array- or record-shaped npm pack --json output. Tests cover object-shaped output and verify the packed manifest’s gitHead.

Changes

Package verification

Layer / File(s) Summary
Artifact selection and validation
scripts/verify-package.ts, tests/scripts/package-git-head.test.ts
buildPackageTarball selects the first artifact from an array or record. Tests use object-shaped pack output and check the packed manifest’s gitHead; the existing test also checks that scripts.prepare is absent.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: kenryu42

Merge Risk: ⚪ Minimal · up to e861f

This change addresses npm 12’s object-shaped pack output. The malformed-output concern does not establish a production failure, so no merge-blocking issue remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: accepting npm 12 object-shaped pack output in verify-package.
Linked Issues check ✅ Passed Issue #206 requires buildPackageTarball to accept npm 12 object-shaped npm pack --json output and prevent npm pack did not report an artifact. scripts/verify-package.ts now selects the first v…
Out of Scope Changes check ✅ Passed The changes are limited to package verification and its regression test. The helper extraction supports the test assertions. No unrelated changes appear in the reviewed diff.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • buildPackageTarball accepts both npm pack --json shapes — widens the cast to PackResult[] | Record<string, PackResult> and normalizes via Array.isArray(packed) ? packed[0] : Object.values(packed)[0], matching the npm 12 object-keyed-by-package-name change (npm/cli#9247).
  • Regression test for the object shape — a fake npm emitting { "cc-safety-net": { filename, size, files } } drives the real buildPackageTarball and asserts the packed gitHead, so the npm 12 path is covered on a runner whose bundled npm still emits an array. readPackedManifest was extracted to share tarball extraction.

The npm 12 claim checks out against npm/cli#9247 (latest emits { [tar.name]: tarball }; array is npm <= 11). Before the fix packed[0] is undefined on the object, so the test genuinely fails without the change. This is the only pack-json parse site, and publish.yml consumes the tarball through this script rather than re-parsing the JSON, so no other caller is left array-shaped. Focused suite passes (2 pass, 0 fail).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Updates package build script to handle npm 12 output format.

The PR appears safe to merge.

Summary

The PR accepts both array- and object-shaped npm pack --json results and adds a regression test using object-shaped output.

  • The array path and existing package-identity check remain intact.
  • No actionable issue was identified.

Reviews (1) · Last reviewed commit: "fix(verify-package): accept npm 12 objec..."

@kenryu42

kenryu42 commented Oct 5, 2026

Copy link
Copy Markdown
Owner

Thanks for the report.

I'm closing this in favor of #218. It test re-keys real npm output instead of building a tarball by hand, which leaves the existing test unchanged.

@kenryu42 kenryu42 closed this Oct 5, 2026
invidtiv pushed a commit to invidtiv/claude-code-safety-net that referenced this pull request Oct 6, 2026
Why:
- npm 12 prints `npm pack --json` as an object keyed by package name
  instead of an array, so `packed[0]` was undefined and verify:package
  and `bun run check` failed with "npm pack did not report an
  artifact" (kenryu42#206). CI and the publish job still run npm 11, but
  `npm install -g npm` now installs 12.

What:
- Take the first value of the report with Object.values, which reads
  an npm 11 array and an npm 12 object alike.
- The new test runs the real npm and re-keys its report by package
  name, as npm 12 does, so the tarball, file list and modes stay real
  on an npm 11 runner.

Validation:
- Red first: the new test failed on main with "npm pack did not report
  an artifact" and passes with the fix.
- buildPackageTarball run through `npx npm@12` (12.2.0) produced
  cc-safety-net-2.5.2.tgz with 23 files.
- bun run check passed (3753 pass, 4 skip, 0 fail; lines 98.81%).

LOC:
  src/     +0 / -0 = net +0
  tests/  +15 / -0 = net +15
  *.md     +0 / -0 = net +0
  Total   +17 / -2 = net +15

Fixes kenryu42#206.
Supersedes kenryu42#207.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: verify-package rejects npm 12 because npm pack --json now returns an object

2 participants