knip: 🐛 Knip does not resolve package.json exports quite correctly
Prerequisites
- I’m using the latest version
- I’ve read the relevant documentation
- I’ve searched for existing issues
- I’ve checked the list of known issues
- I’ve read the issue reproduction guide
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
- Support the stars of package entry points (resolves #853) — committed to webpro-nl/knip by webpro 2 years ago
- Support the stars of package entry points (resolves #853) — committed to webpro-nl/knip by webpro 2 years ago
- Wrap up source mapping (close #853) — committed to webpro-nl/knip by webpro 2 years ago
- Improve support for package.json#exports (closes #853) — committed to cylewaitforit/knip by webpro 2 years ago
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
exportsas specified in node.js docs