Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically pick up knip.mjs and knip.cjs #478

Closed
fregante opened this issue Jan 26, 2024 · 9 comments
Closed

Automatically pick up knip.mjs and knip.cjs #478

fregante opened this issue Jan 26, 2024 · 9 comments
Labels
feature request Feature request

Comments

@fregante
Copy link

fregante commented Jan 26, 2024

https://knip.dev/overview/configuration#location

Could you add these two extensions to the list of files knip automatically looks for? So I don't have to add --config knip.mjs

Reasoning

My app doesn't use type=module, but my webpack config does (.mjs), which means that knip also has to be loaded as a module.

https://github.com/pixiebrix/pixiebrix-extension/blob/951da774d2ecb296f381b3b6cda128be790fac3f/knip.mjs#L1

@fregante fregante added the feature request Feature request label Jan 26, 2024
@webpro
Copy link
Member

webpro commented Jan 29, 2024

Sorry, I'd rather make that list smaller than bigger. Hopefully the ecosystem can agree on some conventions and we'll move on from CJS to ESM too.

I could even imagine supporting only JSON, since compilers might become a solved problem.

Let's see where this goes. I'm not against the idea per se, but not at this time.

@webpro webpro closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2024
@fregante
Copy link
Author

Hopefully the ecosystem can agree on some conventions and we'll move on from CJS to ESM too.

What convention? Those two extensions are here to stay and will never not be used. There are a lot of people who are unable/unwilling to switch to ESM, or are in these partial states because of other tools that don't support ESM.

since compilers might become a solved problem.

A solved problem in knip or in development? Because webpack is not going anywhere anytime soon either.

@webpro
Copy link
Member

webpro commented Jan 30, 2024

A solved problem in Knip, as compilers are basically the only reason Knip has dynamic config files in the first place. Going back to JSON(C) only and we wouldn't even have this conversation :)

@fregante
Copy link
Author

How will knip read the entry points from webpack's config without importing webpack's config? Would I have to repeat them and hope they will not get out of sync?

@webpro
Copy link
Member

webpro commented Jan 30, 2024

OK I think I see we're the confusion stems from. Let's break it down:

  • The initial request is about the Knip configuration file (e.g. knip.json or knip.ts).
  • The Webpack configuration file (e.g. webpack.config.ts) is handled by Knip's Webpack plugin, which should automatically result in those config.entry files being added as entry files to Knip.

Sorry, I didn't dive into the links you've sent and explain immediately. You shouldn't need to do any of this: https://github.com/pixiebrix/pixiebrix-extension/blob/951da774d2ecb296f381b3b6cda128be790fac3f/knip.mjs#L1-L14

Knowing this, if anything isn't working as expected, please file an issue :)

@fregante
Copy link
Author

I tried it but it wasn't picked up automatically. Could it be because of the mjs extension of the webpack config?

@webpro
Copy link
Member

webpro commented Jan 30, 2024

@fregante
Copy link
Author

fregante commented Jan 31, 2024

The file is executed, I see the console.logs within it, but its entries don't appear in Knip's debug output. Does knip support config factories?

https://webpack.js.org/configuration/configuration-types/#exporting-a-function

With the current setup, I get 0 unused exports, but if I remove the explicit webpack import I get 64 unused exports and 87 unused files

@webpro
Copy link
Member

webpro commented Jan 31, 2024

Yes, it does, there's quite a few scenarios Knip supports (including tests/coverage/fixtures), but there can always be something missing or bugs. Please file a separate issue with a repro so I can look into it 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

2 participants