test(package): consume the tarball the way npm does - #9
Merged
Conversation
The suite imported `../dist/index.js` by relative path, which walks past the two things a consumer actually depends on: the `exports` map and the `files` allowlist. Both can break while every other test stays green, and the first witness would be whoever runs `npm install` — a bad way to learn it on a first publish. This packs the real tarball, unpacks it as `node_modules/ai-forms`, and imports it by bare specifier from a temp workspace outside the repo. It also covers `ai-forms/react`, which had no test at all: React is an optional peer, so the subpath is resolved and read rather than executed. Verified red before green against three breakages — a dropped subpath, a `types` path pointing at nothing, and a `files` list that forgets `dist`. Each probe records failure as a value instead of throwing, so a broken entry point names itself rather than failing all five assertions at once. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every existing test imports
../dist/index.jsby relative path. That walks straight past the two things a consumer actually depends on — theexportsmap and thefilesallowlist — so either can break while the suite stays green. On a package about to be published for the first time, the first witness to a brokenexportsmap would be whoever runsnpm install.ai-forms/reacthad no test at all.What
Packs the real tarball, unpacks it as
node_modules/ai-forms, and imports it by bare specifier from a temp workspace outside the repo — so resolution goes through the published manifest, not the repo layout.Five assertions: every declared entry point resolves; the runtime entry points expose their whole public API; the react entry point ships its exports; every entry point's
typesfile is actually in the tarball; README and LICENSE ship.React is an optional peer, so
./reactis resolved and read rather than executed — that still proves the exports map and the file exist without dragging the temp workspace's dependencies into the assertion.Verified red before green
Confirmed the gate fails, with a precise message, against three real breakages:
./reactremoved fromexports./servertypes→ a nonexistent file"./server" advertises types at ./dist/nope.d.ts, which is not in the tarballfiles: ["README.md"](dropsdist)Each probe records failure as a value rather than throwing. An earlier draft let a broken exports map crash the setup hook, which failed all five assertions at once and buried the cause; that is fixed and re-verified.
npm run verify: 19/19 pass. No script change needed — the existingtest/*.test.jsglob picks it up.🤖 Generated with Claude Code