Repository navigation
test(config): check the package files list with publint over npm's real pack list - #568
Merged
Merged
Conversation
The package.json test asserted that every export target, declaration file, and bin was covered by the `files` list with a hand-rolled isPacked: each entry read as a literal file or directory, with or without a trailing slash, matched by equality or prefix. That loop is deleted. manifestMessages builds a scratch package through withTempDir holding the manifest and an empty stub at every file it points a consumer at (a bin stub carries the shebang publint requires), and runs publint's API with pack: "npm", so `npm pack --json --dry-run --ignore-scripts` computes the list npm would publish, at level warning with strict on, as lint:package runs it in the package-smoke job. The real manifest must produce no messages, and a negative control adds an export outside `files` and pins publint's FILE_NOT_PUBLISHED message for it. publint was already a direct devDependency, so nothing is added; manifestTargets now takes the manifest it reads and manifestDeclarations gathers the `types` paths the test collected inline. Differential, the old loop against publint over npm's pack list, on 14 manifests: the real one and a plain hand-made one accept both ways; an export or a types target outside `files`, a glob that misses the declarations, and an empty `files` refuse both ways; `files` without the trailing slash, as the parent directory, or negating the bin accept both ways. Five differ, and in each npm's behavior is the answer: a bin outside `files` (the old loop refused it; npm always packs the files `bin` names), `files` as globs (refused; npm expands them), `./`-prefixed entries (refused; npm accepts them), an entry naming a file by its basename (refused; npm matches it at any depth), and a negated `!lib/pkg/index.js` beside `lib/pkg/` (the old loop accepted it through the directory prefix; npm excludes it, so it is now refused). The real manifest uses none of those shapes. Dropping `lib/pkg/` from `files` fails the new test with four FILE_NOT_PUBLISHED lines, the two export targets and their declarations; the bins stay absent because npm packs them regardless. publint has nothing else to say about the real manifest at any level; on an unbuilt tree it reports only FILE_DOES_NOT_EXIST for the six lib/pkg targets, which is what the stubs stand in for. The test pins npm as the packer because npm publishes the package, where lint:package's auto-detection picks bun from bun.lock.
Contributor
File size check0 over a hard cap (fails), 6 warning(s).
Split the file, wrap the line, shorten or exempt the comment, or list the path in 5 managed file(s) skipped; repo-platform owns them. |
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only changes preserve existing checks and verify an unpublished export, with no blocking defects identified.
No open issues 🎉
What changed in this PR
This PR checks package file inclusion using publint with npm's actual pack list, replacing literal path matching in the manifest tests.
Changes:
- Creates a temporary package with stubbed export, declaration, and bin targets.
- Runs publint with npm packing and strict warning checks.
- Adds checks for the real manifest and an unpublished export while preserving existing manifest assertions.
| File | Description |
|---|---|
test/config/package-json.test.ts |
Replaces the path-prefix packing check with publint and adds positive and negative packaging tests. |
Review effort: Balanced
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.
What this changes
How
filessays, so a bin outsidefilesnow passes where the old loop refused; a!lib/pkg/index.jsbesidelib/pkg/is now refused where the prefix match let it through. The real manifest uses none of these.lint:packagein CI auto-detects bun from the lockfile.publint0.3.25, already a direct devDependency;withTempDirfrom the test helpers.Proof
filespins theFILE_NOT_PUBLISHEDline); droppinglib/pkg/fromfilesfails with four such lines.Technical details
FILE_DOES_NOT_EXISTfor the sixlib/pkgtargets, which is why the test stubs them.npm pack --dry-runruns; npm comes from the runner image, as package-smoke already assumes.test/config/package-json.test.ts.