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.92k stars 169 forks source link

SvelteKit support #170

Closed didier closed 1 year ago

didier commented 1 year ago

When running knip on a SvelteKit project, knip marks files belonging the framework as unused. This happens for routes, hooks (src/hooks.ts) and possibly more files.

An example of knip ignoring SvelteKit routes can be seen here by running pnpm run knip: https://stackblitz.com/edit/sveltejs-kit-template-default-tbvdgh?file=src%2Froutes%2Flogin%2F%2Bserver.ts

webpro commented 1 year ago

Yes, non-JS/TS files are not included by default. Please see https://github.com/webpro/knip/blob/main/docs/compilers.md

didier commented 1 year ago

Hey, appreciate the swift response. This is however not about non-JS/TS files, the files (routes) in question are +(page.)server.ts files used by SvelteKit. These aren't necessarily 'imported' in the traditional sense, but they are native to the framework and thus always in use.

webpro commented 1 year ago

:rocket: This issue has been resolved in v2.17.1. See Release 2.17.1 for release notes.

webpro commented 1 year ago

Upon closing inspection I noticed the +server.* pattern was not included in the Svelte entry file pattern. Thanks for reporting this, @didier.

didier commented 1 year ago

You’re welcome! Does this also include hooks(.server/.client).ts, app.d.ts and other SK-native files?

https://kit.svelte.dev/docs/hooks

https://kit.svelte.dev/docs/advanced-routing#matching

https://kit.svelte.dev/docs/service-workers

https://kit.svelte.dev/docs/modules#$lib

webpro commented 1 year ago

https://github.com/webpro/knip/tree/main/src/plugins/svelte doesn't complete, no, I'll take another look :)

webpro commented 1 year ago

Feel free to open a PR, btw

didier commented 1 year ago

I’ll have a look later to see how I can contribute as I’m on my phone right now.

Guessing I just add patterns to the entry file in the default config?

webpro commented 1 year ago

No worries if it doesn't work out, just let me know. Here's two relevant links if you're up to it:

Contributions from people that actually use the tool or framework related to the Knip plugin are very welcome, since it can be tested on actual projects (i.e. better than fixtures).