Skip to content

fix: exclude test files matched by wildcard package exports in production mode - #2083

Merged
webpro merged 2 commits into
webpro-nl:mainfrom
jonathanong:production-wildcard-exports-test-files
Oct 1, 2026
Merged

webpro merged 2 commits into
webpro-nl:mainfrom
jonathanong:production-wildcard-exports-test-files

Conversation

@jonathanong

Copy link
Copy Markdown
Contributor

Closes #2082

In production mode, getEntrySpecifiersFromManifest expands exports into concrete files early and globs them as production entries. That glob doesn't get the non-production entry negations. A wildcard like "./*": "./src/*.ts" therefore makes src/math.test.ts a production entry, and exports imported only by tests go unreported.

This change adds negatedEntryPatterns to the production glob for plugin and manifest entries. Production mode already applies these negations to user entry patterns (getProductionEntryFilePatterns) and to project files. Outside production the list is empty, so default mode is unchanged.

Tests

package-entry-points-test-files covers both modes:

  • Default mode: the test file is still an entry.
  • Production mode: subtract, imported only by src/math.test.ts, is now reported.

Local results:

  • The new tests pass with node --test and bun test.
  • Every test that sets isProduction or isStrict passes, along with the tsup, tsdown, rslib and preconstruct plugin tests.
  • node scripts/run-test.js --smoke passes except for the watch test, which also fails on main.

Behaviour changes

  • Bundler entries: production entries from bundler plugins (e.g. tsup or tsdown entry globs) go through the same glob. In production, a bundler entry glob that matches test files no longer includes them. This is the same class of issue.
  • Overlapping patterns: a file matched by both a non-production entry pattern and a production entry pattern is no longer an entry in production.
    • None of the plugins that define both entry and production declare overlapping patterns.
    • A package whose main is the file a node --watch dev script runs gives the same output as before.

πŸ€– Generated with Claude Code

https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr

jonathanong and others added 2 commits September 30, 2026 22:07
…in production mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr
…ction mode

Apply the negated non-production entry patterns to the production glob
for plugin and manifest entries, as production mode already does for
user entry patterns and project files.

Remove the null package entry point fixture. Its test passed only
because of the vitest negation, not because of the null key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RocMt6KQsTi6y25xAphdsr
@pkg-pr-new

pkg-pr-new Bot commented Oct 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@2083
npm i https://pkg.pr.new/@knip/language-server@2083
npm i https://pkg.pr.new/@knip/mcp@2083

commit: eda7d49

@webpro
webpro merged commit b86f45f into webpro-nl:main Oct 1, 2026
32 checks passed
@webpro

webpro commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks for the fix and reproduction! CI is green, and this resolves the production-mode report in #2082.

@webpro

webpro commented Oct 6, 2026

Copy link
Copy Markdown
Member

πŸš€ This pull request is included in v6.40.0. See Release 6.40.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

πŸ› Production mode treats test files matched by wildcard exports as entries

2 participants