-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat: make knip understand yarn pnp #924
base: main
Are you sure you want to change the base?
Conversation
commit: |
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 made a real yarn workspace to test real pnp api, but it'll be good to see any ideas for this fixture.
This comment was marked as resolved.
This comment was marked as resolved.
const findNearestPnPFile = (startDir: string) => { | ||
// Find the nearest .pnp.cjs file by traversing up | ||
let currentDir = startDir; | ||
while (currentDir !== '/') { | ||
const pnpPath = join(currentDir, '.pnp.cjs'); | ||
if (isFile(pnpPath)) { | ||
const pnpApi = _require(pnpPath); | ||
pnpApi.setup(); | ||
pnpStatus.dir = startDir; | ||
pnpStatus.pnpPath = pnpPath; | ||
pnpStatus.enabled = true; | ||
return; | ||
} | ||
// Move up one directory | ||
const parentDir = dirname(currentDir); | ||
if (parentDir === currentDir) { | ||
break; // Reached root | ||
} | ||
currentDir = parentDir; | ||
} | ||
pnpStatus.dir = startDir; | ||
pnpStatus.pnpPath = ''; | ||
pnpStatus.enabled = false; | ||
}; |
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 made this by assuming that knip needs to be able to understand yarn pnp, even if it isn't under yarn pnp environment, e.g yarn dlx knip
. If it's not, we can just simply import pnpapi directly, instead of manually finding it.
Thanks for the PR, @jwoo0122. Without knowing exactly how PnP works, please let my try to understand what support for PnP means to Knip, and what features (i.e. issue types) are still (un)available/relevant. Some initial questions that pop up in my mind:
|
Make knip understand yarn pnp. It can now look into manifest files inside yarn cache, and correctly check peer dependency or bin field.
Maybe we can make this feature to be enabled with yarn plugin made from #864 but I couldn't find how to patch manifest helpers with plugin.
You should see
manifest/helpers.ts
.