Repository navigation
Exclude files behind wildcard null package exports - #2085
jonathanong wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr
β¦#2084) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr
commit: |
|
Thanks for the two reports and both pull requests, Jonathan. The fixtures and tests made the problems easy to confirm, and #2083 is merged. For #2084 I landed a different implementation on
Keeping the key-as-path negation next to the new one also keeps treating keys as file paths. Node resolves them as subpaths: What landed instead:
Your three fixtures and their tests are in that commit (the tests now share one file) and you are credited as co-author. There is also a follow-up to #2083 (7c229f4): flattening a plugin's entry patterns into negations lost the group's own exclusions, so with Thanks again, these were good reports to work from. |
|
π This issue has been resolved in v6.40.0. See Release 6.40.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Closes #2084
Refs #2082
A wildcard
nullsubpath such as"./internal/*": nullhides<pkg>/internal/*in Node.js. Knip negates the key as a path (!./internal/**), not the files that a less specific pattern like"./*": "./src/*.ts"resolves those subpaths to, so those files stay entries.Changes
getEntrySpecifiersFromManifest: for each wildcardnullkey, find the pattern that would match it without thenull(getPackageMapTarget), and negate that target with the key's pattern match substituted. Under"./*": "./src/*.ts","./internal/*": nulladds!./src/internal/**/*.ts. The existing key-as-path negation stays, so"./hidden.js": nullinpackage-entry-points-gitignoredis unchanged.nullprefix that wins under Node.js precedence (e.g."./internal/public") still exports its file. When such a key exists, thatnullkey keeps the current behaviour instead of adding a negation.getToSourcePathsHandler: negated patterns are now source-mapped like positive ones. Without this,!./dist/internal/**/*.jsnever matched thesrcfiles that./dist/**/*.jsis mapped to. Only manifest entry specifiers go through this handler, so the only other negations affected are the existing key-as-path ones, and only when they fall under anoutDir.Scope
nullkeys. An exact key like"./features/private": nullunder"./features/*"is also unexported in Node.js. Handling it the same way would makedeclaration-dependenciesreportdist/features/private.d.tsas an unused file, so I left that out.nullinside condition objects is unchanged.Tests
The first commit adds the fixtures and tests:
package-entry-points-null-subpath:src/internal/orphan.tsandformatLoudare reported.package-entry-points-null-subpath-dist: the same, with"./*": "./dist/*.js"and a tsconfigoutDir.package-entry-points-null-subpath-exported:"./internal/public"below thenullpattern stays an entry.The first two fail on
main, and the third passes. Each part of the change has a test that fails without it:Local results:
node --testandbun test, along with the otherpackage-entry-points*,null-root-exportanddeclaration-dependenciestests.dist/cli.js, which isn't built locally.test/entry,test/dependenciesandtest/clipass.π€ Generated with Claude Code
https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr