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

Issues are not reported in monorepo when workspaces are setup in knip.json #722

Closed vubogovich closed 4 months ago

vubogovich commented 4 months ago

Our monorepo consists of independent packages and does not use npm workspaces yet. As a result, it and requires npm install for each of the package separately. We have setup prettier and eslint in the root package and typescript is configurated independently.

knip is installed on the root package and knip.json has the following content:

{
  "$schema": "https://unpkg.com/knip@5/schema.json",
  "workspaces": {
    "packages/*": {}
  }
}

However, knip reports issues only in the root package. knip --workspace packages/shared suggested in the docs didn't help.

The issues were unused dependency and file unused.ts. Very nice template for reproductions 👍 here is my version.

Thanks a lot for very useful tool! I used it in the normal repo and enjoyed a lot ❤️

webpro commented 4 months ago

If yup is listed in both root and shared package, seems it's unused in root. Expected behavior?

vubogovich commented 4 months ago

If yup is listed in both root and shared package, seems it's unused in root. Expected behavior?

Expected behavior is all issues from all packages are reported.

It does not matter what dependency, now replaced yup with zod in packages/shared in my example. Both of them unused but only root one is reported. When yup is removed from the root, knip says all good so it ignores packages/shared having unused file and dependency.

webpro commented 4 months ago

Sorry, maybe checking that from phone late at night wasn't the best idea.

Non-glob additional workspace names were indeed not added properly (e.g. just "packages/*": {} seems to work fine).

Thanks for the report!

webpro commented 4 months ago

:rocket: This issue has been resolved in v5.25.2. See Release 5.25.2 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

vubogovich commented 4 months ago

Interesting that I had an issue with the glob workspace name in 5.25.1 but the new version 5.25.2 works like a charm 🥇 Thanks a lot for the prompt solution!

webpro commented 4 months ago

Thanks @vubogovich!