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

💡 Configurable workspace config defaults #805

Closed sparten11740 closed 1 month ago

sparten11740 commented 1 month ago

Suggest an idea for this project

A workspace's configuration currently defaults to a static pattern of files if no explicit workspace configuration is provided:

https://github.com/webpro-nl/knip/blob/617a06a173e5cdcbd2798e442d97344e48523f42/packages/knip/src/ConfigurationChief.ts#L38-L39

In a monorepo it is a likely scenario to have different entry patterns than above, which currently have to be specified as a separate configuration for each workspace following that pattern, which is quite tedious.

I have a concrete case where I need redux/index.[jt]s as an additional entry point. Specifying it in package.json's exports of each package is currently not an option for us as it constitutes a breaking change (unless everything else contained in the package is also explicitly exported, which we also don't want)

Inheriting the root config's entry as default and only if that's not defined use the current static default (arguably breaking) or a different way of explicitly specifying a default entry for workspaces (and potentially other options) would be great.

webpro commented 1 month ago

How about using a dynamic config: https://knip.dev/reference/dynamic-configuration?

sparten11740 commented 1 month ago

thanks for pointing that out. I went with dynamically populating the workspaces object with the defaults I need based on the available workspaces. Feel free to close this issue if you don't think it would be a useful addition

webpro commented 1 month ago

Great!

The dynamic option is meant for such use cases and to keep Knip itself simpler (the behavior might also even surprise users in some cases), so I'm going to close this one.