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
7.06k stars 177 forks source link

🐛 Soft-linked dependencies are considered unused #766

Closed robintown closed 2 months ago

robintown commented 3 months 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 months 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.

webpro commented 2 months ago

Decided to close this as "wontfix", due to reasons described.