knip: 🐛 Knip does not resolve package.json exports quite correctly

Prerequisites

Reproduction url

https://github.com/maastrich/repro/pull/2

Reproduction access

  • I’ve made sure the reproduction is publicly accessible

Description of the issue

First, thanks for the amazing tool, it’s really impressive how quick and effective knip is 👏

When setting up exports using glob syntax in the package.json, typescript can resolve * to be either a path part or multiple path part:

"./*": "./src/public/*/index.ts" // can resolve to
   -> "./src/public/foo/bar/index.ts"
   -> "./src/public/baz/index.ts"

but knip doesn’t

For the moment I’ve found a workaround where I add this in my package.json so knip can resolve le path (leaving both as typescript resolve the first one and knip the second)

"./*": "./src/public/*/index.ts",
+ "./**": "./src/public/**/index.ts",

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Understood, but this is a good example of static analysis versus runtime behavior and there are tradeoffs to be considered.

I’ll have to try it, but I think that next major i there is one should handle exports as specified in node.js docs