-
-
Notifications
You must be signed in to change notification settings - Fork 336
Support Yarn PnP #1361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support Yarn PnP #1361
Conversation
|
For test consistency, I've added the Yarn PnP cache files. This is equivalent to committing the |
|
|
||
| if (pnpApi != null) { | ||
| const packageJsonPath = join(packageName, 'package.json'); | ||
| const resolvedPath = pnpApi.resolveToUnqualified(packageJsonPath, dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used resolveToUnqualified to bypass exports map restrictions. This is necessary for reading metadata (bin, peerDependencies, types, ...) even when:
- Workspace packages don't have
./package.jsonentry in exports map - Packages have no JavaScript entry point (e.g.,
@types/*packages)
Actual resolution (oxc-resolver) still respects exports map, so invalid imports will be correctly detected.
f4844ad to
0faa3b8
Compare
This PR continues the work from #924. Thanks @jwoo0122 :)
When a project uses Yarn PnP, this PR makes knip look for manifest files in the PnP file instead of searching in the
node_modulesdirectory. Previously, knip incorrectly reported peer dependencies required by packages as unused dependencies in Yarn PnP projects.Below is an example where knip reports react and react-dom as unused dependencies in a project using styled-components. (styled-components requires react and react-dom as peer dependencies.)
With Yarn PnP support in this PR, knip correctly reports no unused dependencies as shown below.