webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
6.52k stars 150 forks source link

🐛 Soft-linked dependencies are considered unused #766

Open robintown opened 3 weeks ago

robintown commented 3 weeks ago

Prerequisites

Reproduction url

https://stackblitz.com/edit/github-jj73er

Reproduction access

Description of the issue

I am seeing false positives for dependencies that are soft-linked into node_modules from somewhere else on the file system. This can happen when using package manager features such as npm link to work on an application and a library simultaneously, for instance.

To reproduce: go to the link above and,

cd test-1
npm run knip

test-2 is flagged as an unused dependency even though it is imported in index.ts. test-1/node_modules/test-2 is a soft link to test-2.

webpro commented 3 weeks ago

Thanks for the report. Yeah, that makes sense. There's quite some string comparisons/refs to /node_modules/. Fixing this would require to actually follow the fs link, etc. Not sure if it's worth fixing this in terms of both code complexity and performance given the use case/situation in which the simplicity fails.