knip icon indicating copy to clipboard operation
knip copied to clipboard

feat: make knip understand yarn pnp

Open jwoo0122 opened this issue 1 year ago • 3 comments

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.

jwoo0122 avatar Jan 22 '25 16:01 jwoo0122

Open in Stackblitz

npm i https://pkg.pr.new/knip@924

commit: 5e2b43f

pkg-pr-new[bot] avatar Jan 22 '25 16:01 pkg-pr-new[bot]

It turns out that running all test code in series global variable in helpers (isPnPEnabled) is unintentionally flagged as false because other fixtures are not yarn pnp workspace. I'll fix it.

jwoo0122 avatar Jan 22 '25 16:01 jwoo0122

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:

  • The fixture has only "internal" packages and ignores a bunch of stuff, but perhaps we could see a more realistic example?
  • Is there support for monorepos/workspaces (i.e. package.json#workspaces)? Or is that not relevant cq nothing to worry about?
  • Since there are no node_modules anymore, what about:
    • Binaries (node_modules/.bin) e.g. those referenced in package.json#scripts
    • Knip reads package.json#types etc. to see if types are included with the package (so e.g. @​types/eslint is unused if eslint is listed).

webpro avatar Feb 14 '25 07:02 webpro

Closing this due to inactivity and lack of responses. Feel free to reopen, discuss, or upvote as you see fit.

webpro avatar Mar 31 '25 05:03 webpro