@knip/mcp 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/blog/for-editors-and-agents.md +50 -35
- package/docs/docs/blog/brief-history.md +30 -0
- package/docs/docs/blog/for-editors-and-agents.md +124 -0
- package/docs/docs/blog/knip-v3.mdx +88 -0
- package/docs/docs/blog/knip-v4.mdx +149 -0
- package/docs/docs/blog/knip-v5.mdx +190 -0
- package/docs/docs/blog/migration-to-v1.md +65 -0
- package/docs/docs/blog/release-notes-v2.md +46 -0
- package/docs/docs/blog/slim-down-to-speed-up.md +269 -0
- package/docs/docs/blog/state-of-knip.md +191 -0
- package/docs/docs/blog/two-years.mdx +107 -0
- package/docs/docs/explanations/comparison-and-migration.md +129 -0
- package/docs/docs/explanations/entry-files.md +70 -0
- package/docs/docs/explanations/plugins.md +318 -0
- package/docs/docs/explanations/why-use-knip.md +128 -0
- package/docs/docs/features/auto-fix.mdx +333 -0
- package/docs/docs/features/compilers.md +172 -0
- package/docs/docs/features/integrated-monorepos.md +52 -0
- package/docs/docs/features/monorepos-and-workspaces.md +134 -0
- package/docs/docs/features/production-mode.md +95 -0
- package/docs/docs/features/reporters.md +302 -0
- package/docs/docs/features/rules-and-filters.md +102 -0
- package/docs/docs/features/script-parser.md +156 -0
- package/docs/docs/features/source-mapping.md +100 -0
- package/docs/docs/guides/configuring-project-files.md +205 -0
- package/docs/docs/guides/contributing.md +24 -0
- package/docs/docs/guides/handling-issues.mdx +646 -0
- package/docs/docs/guides/issue-reproduction.md +94 -0
- package/docs/docs/guides/namespace-imports.md +125 -0
- package/docs/docs/guides/performance.md +97 -0
- package/docs/docs/guides/troubleshooting.md +127 -0
- package/docs/docs/guides/using-knip-in-ci.md +54 -0
- package/docs/docs/guides/working-with-commonjs.md +72 -0
- package/docs/docs/index.mdx +160 -0
- package/docs/docs/overview/configuration.md +104 -0
- package/docs/docs/overview/features.md +66 -0
- package/docs/docs/overview/getting-started.mdx +195 -0
- package/docs/docs/overview/screenshots-videos.md +42 -0
- package/docs/docs/playground.mdx +38 -0
- package/docs/docs/reference/cli.md +481 -0
- package/docs/docs/reference/configuration.md +413 -0
- package/docs/docs/reference/dynamic-configuration.mdx +72 -0
- package/docs/docs/reference/faq.md +441 -0
- package/docs/docs/reference/issue-types.md +43 -0
- package/docs/docs/reference/jsdoc-tsdoc-tags.md +122 -0
- package/docs/docs/reference/known-issues.md +64 -0
- package/docs/docs/reference/plugins/.gitkeep +0 -0
- package/docs/docs/reference/plugins.md +238 -0
- package/docs/docs/reference/related-tooling.md +46 -0
- package/docs/docs/sponsors.mdx +65 -0
- package/docs/docs/typescript/unused-dependencies.md +86 -0
- package/docs/docs/typescript/unused-exports.md +87 -0
- package/docs/docs/writing-a-plugin/argument-parsing.md +202 -0
- package/docs/docs/writing-a-plugin/index.md +376 -0
- package/docs/docs/writing-a-plugin/inputs.md +162 -0
- package/package.json +8 -6
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: The State of Knip
|
|
3
|
+
date: 2025-02-28
|
|
4
|
+
sidebar:
|
|
5
|
+
order: 2
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
_Published: 2025-02-28_
|
|
9
|
+
|
|
10
|
+
Honestly, Knip was a bit of a "cursed" project from the get-go. Getting anywhere
|
|
11
|
+
near a level of being broadly-ish valuable requires a good amount of
|
|
12
|
+
~~foolishness~~ determination, and it has always been clear it would stay far
|
|
13
|
+
from perfect. It's telling that most of [similar projects][1] have been
|
|
14
|
+
abandoned.
|
|
15
|
+
|
|
16
|
+
And even though Knip is in its infancy, this update is meant as a sign we feel
|
|
17
|
+
we're still on to something. External indicators include increased usage looking
|
|
18
|
+
at numbers such as dependent repositories on GitHub and weekly downloads on npm,
|
|
19
|
+
and bug reports about increasingly less rudimentary issues.
|
|
20
|
+
|
|
21
|
+
## Two Cases
|
|
22
|
+
|
|
23
|
+
For those interested, let's take a look at two cases that hopefully give an
|
|
24
|
+
impression of how Knip works under the hood and the level of issues we're
|
|
25
|
+
currently dealing with. It's assumed you already have a basic understanding of
|
|
26
|
+
Knip (otherwise please consider to read at least [entry files][2] and
|
|
27
|
+
[plugins][3] first).
|
|
28
|
+
|
|
29
|
+
### Case 1: Next.js
|
|
30
|
+
|
|
31
|
+
Let's say this default configuration represents, greatly simplified, [the
|
|
32
|
+
default `entry` patterns][4] for projects using Next.js:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"next": {
|
|
37
|
+
"entry": ["next.config.ts", "src/pages/**/*.tsx"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Those files will be searched for and then statically analyzed to collect
|
|
43
|
+
`import` statements and find other local files and external dependencies. This
|
|
44
|
+
is the generic way Knip handles all source files.
|
|
45
|
+
|
|
46
|
+
However, the game changes if the project uses the following Next.js
|
|
47
|
+
configuration:
|
|
48
|
+
|
|
49
|
+
```ts title="next.config.ts"
|
|
50
|
+
const nextConfig = {
|
|
51
|
+
pageExtensions: ['page.tsx'],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default nextConfig;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Next.js will now look for files matching `src/pages/**/*.page.tsx` instead (note
|
|
58
|
+
the subtle change of the glob pattern). Knip should respect this to find used
|
|
59
|
+
and unused files properly.
|
|
60
|
+
|
|
61
|
+
Moving the burden to users for them to either not notice at all and get
|
|
62
|
+
incorrect results, or having to override the `next.entry` patterns and include
|
|
63
|
+
`src/pages/**/*.page.tsx` isn't good DX. Knip should take care of it.
|
|
64
|
+
|
|
65
|
+
To get the configuration object and the value of `pageExtensions`, Knip has to
|
|
66
|
+
actually load and execute `next.config.ts` ¹... and trouble is right around the
|
|
67
|
+
corner:
|
|
68
|
+
|
|
69
|
+
```ts title="next.config.ts"
|
|
70
|
+
const nextConfig = {
|
|
71
|
+
pageExtensions: ['page.tsx'],
|
|
72
|
+
env: {
|
|
73
|
+
BASE_URL: process.env.BASE_URL.toLowerCase(),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default nextConfig;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```shell
|
|
81
|
+
$ knip
|
|
82
|
+
💥 LoaderError: Error loading next.config.ts
|
|
83
|
+
💥 Reason: Cannot read properties of undefined (reading 'toLowerCase')
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Obviously a contrived example, but the gist is that lots of tooling
|
|
87
|
+
configuration expects environment variables to be defined. But when running Knip
|
|
88
|
+
there might not be a mechanism to set those. Clearly a breaking change when Knip
|
|
89
|
+
starts doing this, only for Next.js projects with a configuration file that
|
|
90
|
+
doesn't read environment variables safely (or has other contextual
|
|
91
|
+
dependencies).
|
|
92
|
+
|
|
93
|
+
By the way, [the ESLint v9 plugin][5] has a similar issue.
|
|
94
|
+
|
|
95
|
+
¹ Another approach could be to statically analyze the `next.config.ts`
|
|
96
|
+
configuration file. That would require some additional efforts and get us only
|
|
97
|
+
so far, but is definitely useful in some cases and on the radar.
|
|
98
|
+
|
|
99
|
+
**EDIT:** This has been solved in the Next.js plugin in v5.48.0.
|
|
100
|
+
|
|
101
|
+
### Case 2: Knip does that?!
|
|
102
|
+
|
|
103
|
+
To further bring down user configuration and the number of false positives, the
|
|
104
|
+
system required more components. New components have been introduced to keep
|
|
105
|
+
improving and nail it for an increasing number of projects. This case is an
|
|
106
|
+
illustration of some of those components.
|
|
107
|
+
|
|
108
|
+
Let's just dive into this example and find out what's happening:
|
|
109
|
+
|
|
110
|
+
```json title="package.json"
|
|
111
|
+
{
|
|
112
|
+
"scripts": {
|
|
113
|
+
"test": "yarn --cwd packages/frontend vitest -c vitest.components.config.ts"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Orchestration is necessary between various components within Knip, such as:
|
|
119
|
+
|
|
120
|
+
- Plugins, the Vitest plugin parses `vitest.components.config.ts`
|
|
121
|
+
- Custom CLI argument parsing for executables, e.g. `yarn --cwd [dir]` and
|
|
122
|
+
`vitest --config [file]`
|
|
123
|
+
- The workspace graph, to see `packages/frontend` is a descendant workspace of
|
|
124
|
+
the root workspace
|
|
125
|
+
|
|
126
|
+
Patterns like in the script above do not occur only in `package.json` files, but
|
|
127
|
+
could be anywhere. Here's a similar example in a GitHub Actions workflow:
|
|
128
|
+
|
|
129
|
+
```yaml title=".github/workflows/test.yml"
|
|
130
|
+
jobs:
|
|
131
|
+
integration:
|
|
132
|
+
runs-on: ubuntu-latest
|
|
133
|
+
steps:
|
|
134
|
+
- run: playwright test -c playwright.e2e.config.ts
|
|
135
|
+
working-directory: e2e
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The pattern is very similar, because Knip needs to assign a configuration file
|
|
139
|
+
to a specific workspace (assuming there's one in `./e2e`) and apply the Vitest
|
|
140
|
+
configuration to that particular workspace with its own set of directory and
|
|
141
|
+
entry file patterns.
|
|
142
|
+
|
|
143
|
+
An essential part of Knip is to build up the module graph for source files. With
|
|
144
|
+
the configuration files still in mind, this is the pattern Knip follows towards
|
|
145
|
+
this goal:
|
|
146
|
+
|
|
147
|
+
- Find configuration files at default and custom locations
|
|
148
|
+
- Assign them to the right workspace
|
|
149
|
+
- Run plugins in their own workspace to take entry file patterns from the
|
|
150
|
+
configuration objects
|
|
151
|
+
- Load and parse configuration files to get referenced dependencies
|
|
152
|
+
|
|
153
|
+
The referenced dependencies are stored in the `DependencyDeputy` class to
|
|
154
|
+
eventually determine what dependencies are unused or missing in `package.json`
|
|
155
|
+
in each workspace.
|
|
156
|
+
|
|
157
|
+
Both the configuration and entry files are then used to start building up the
|
|
158
|
+
module graph.
|
|
159
|
+
|
|
160
|
+
## Comprehensive
|
|
161
|
+
|
|
162
|
+
Discussing the two cases briefly covers only part of the whole process. This
|
|
163
|
+
might give a sense of the reason why Knip is pretty comprehensive. After all,
|
|
164
|
+
building the module graph for internal source files to find unused files and
|
|
165
|
+
exports requires the list of external dependencies including internal
|
|
166
|
+
workspaces. And on the other hand, a complete module graph is required to find
|
|
167
|
+
unused or missing external dependencies.
|
|
168
|
+
|
|
169
|
+
The comprehensiveness also requires a range of components in the system, such as
|
|
170
|
+
the aforementioned ones, [compilers for popular frameworks][6] and a [script
|
|
171
|
+
parser][7], and other affordances such as [auto-fix][8].
|
|
172
|
+
|
|
173
|
+
That said, code organization could be improved to make it more accessible for
|
|
174
|
+
contributions and, for instance, expose programmatic APIs to use the generated
|
|
175
|
+
module graph outside of Knip. Additionally, existing plugins can better take
|
|
176
|
+
advantage of existing components in the system, and new plugins can be developed
|
|
177
|
+
to further reduce user configuration and false positives.
|
|
178
|
+
|
|
179
|
+
## The End
|
|
180
|
+
|
|
181
|
+
That's all for today, thanks for reading! Have a great one, and don't forget:
|
|
182
|
+
Knip it before you ship it! ✂️
|
|
183
|
+
|
|
184
|
+
[1]: ../explanations/comparison-and-migration.md
|
|
185
|
+
[2]: ../explanations/entry-files.md
|
|
186
|
+
[3]: ../explanations/plugins.md
|
|
187
|
+
[4]: ../reference/plugins/next.md#default-configuration
|
|
188
|
+
[5]: ../reference/plugins/eslint.md#eslint-v9
|
|
189
|
+
[6]: ../features/compilers.md
|
|
190
|
+
[7]: ../features/script-parser.md
|
|
191
|
+
[8]: ../features/auto-fix.mdx
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Two Years
|
|
3
|
+
date: 2024-10-04
|
|
4
|
+
sidebar:
|
|
5
|
+
order: 3
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
_Published: 2024-10-04_
|
|
9
|
+
|
|
10
|
+
import EmojiBlastButton from '../../../components/EmojiBlastButton.astro';
|
|
11
|
+
import Projects from '../../../components/Projects.astro';
|
|
12
|
+
import Sponsors from '../../../components/Sponsors.astro';
|
|
13
|
+
|
|
14
|
+
Exactly two years ago the first commit was pushed to GitHub and the first
|
|
15
|
+
version of Knip was published to the npm registry. The name was initially
|
|
16
|
+
[Exportman][1]! We've come a loooong way... The JavaScript ecosystem is highly
|
|
17
|
+
dynamic and I've been crazy enough to even start, try and keep up with it! But
|
|
18
|
+
here we are.
|
|
19
|
+
|
|
20
|
+
October 4th is World Animal Day, so there was really no choice but bring in the
|
|
21
|
+
crazy mascot that early adopters may remember:
|
|
22
|
+
|
|
23
|
+
![Crazy cow with orange scissors in Van Gogh style][2]
|
|
24
|
+
|
|
25
|
+
Today we celebrate an unknown but CRAZY amount of clutter removed from so many
|
|
26
|
+
codebases with Knip's help. Every single day I see many of those little red
|
|
27
|
+
blocks for thousands of lines of deleted code and dependencies. Call me crazy,
|
|
28
|
+
but to me this is pure joy and never gets old! 🟩 🟥 🟥 🟥 🟥
|
|
29
|
+
|
|
30
|
+
<EmojiBlastButton />
|
|
31
|
+
|
|
32
|
+
## Smiling faces
|
|
33
|
+
|
|
34
|
+
The actual amount of code and dependencies removed and the number of smiling
|
|
35
|
+
faces this brings is what matters most, but also remain a good mystery. Clearly
|
|
36
|
+
more and more projects add Knip to their projects and CI workflows to keep
|
|
37
|
+
ever-growing codebases tidy. It's wonderful to see if Knip plays its part in
|
|
38
|
+
today's ecosystem to help with that. Thanks for bearing with me, here's to a lot
|
|
39
|
+
more little red blocks in your PRs! 🟩 🟥 🟥 🟥 🟥
|
|
40
|
+
|
|
41
|
+
## Updates
|
|
42
|
+
|
|
43
|
+
Why not throw in some freshly cooked updates in [v5.31.0][3] for you while we're
|
|
44
|
+
at it:
|
|
45
|
+
|
|
46
|
+
- [The auto-fix feature][4] has been completely revamped, it's much better and a
|
|
47
|
+
lot more comprehensive! You have to see it to believe it.
|
|
48
|
+
- Knip has upgraded to [Jiti v2][5], resolving a bunch of known issues when
|
|
49
|
+
loading configuration files authored in TypeScript and ESM, such as:
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Cannot use 'import.meta' outside a module
|
|
53
|
+
await is only valid in async functions and the top level bodies of modules
|
|
54
|
+
Unexpected identifier 'Promise'
|
|
55
|
+
Reflect.metadata is not a function
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
And that pesky "CJS build of Vite's Node API is deprecated" warning is finally
|
|
59
|
+
gone!
|
|
60
|
+
|
|
61
|
+
Thanks to everyone involved in making this happen, it's truly much appreciated.
|
|
62
|
+
|
|
63
|
+
## Stable
|
|
64
|
+
|
|
65
|
+
If you haven't tried Knip recently, it's worth taking another look! Version 5
|
|
66
|
+
was released 8 months ago, and even though there were no breaking changes, it
|
|
67
|
+
includes many enhancements. In fact, Knip has been largely stable since version
|
|
68
|
+
3, which came out a year ago. Many releases have a compound effect, as Knip has
|
|
69
|
+
kept the pace for two years now.
|
|
70
|
+
|
|
71
|
+
## Projects using Knip
|
|
72
|
+
|
|
73
|
+
This list of projects using Knip to keep their codebases tidy is something I
|
|
74
|
+
couldn't be more proud of:
|
|
75
|
+
|
|
76
|
+
:::section{.columns.min200}
|
|
77
|
+
|
|
78
|
+
<Projects />
|
|
79
|
+
|
|
80
|
+
:::
|
|
81
|
+
|
|
82
|
+
And so many more on and off the radar. Very, very cool!
|
|
83
|
+
|
|
84
|
+
## Sponsors
|
|
85
|
+
|
|
86
|
+
Last but not least, eternal gratitude for all the sponsors that have been
|
|
87
|
+
supporting me along the way. THANK YOU, THANK YOU, THANK YOU!
|
|
88
|
+
|
|
89
|
+
And eh.. gotta take my chances: how about [joining this awesome club][6]?
|
|
90
|
+
|
|
91
|
+
:::section{.columns.min300.mt}
|
|
92
|
+
|
|
93
|
+
<Sponsors />
|
|
94
|
+
|
|
95
|
+
:::
|
|
96
|
+
|
|
97
|
+
## Acknowledgements
|
|
98
|
+
|
|
99
|
+
Thanks to Joshua Goldberg for [emoji-blast][7]! 🎉
|
|
100
|
+
|
|
101
|
+
[1]: https://www.npmjs.com/package/exportman/v/0.0.1
|
|
102
|
+
[2]: /cow-with-orange-scissors-van-gogh-style.webp
|
|
103
|
+
[3]: https://github.com/webpro-nl/knip/releases/tag/5.31.0
|
|
104
|
+
[4]: ../features/auto-fix.md
|
|
105
|
+
[5]: https://github.com/unjs/jiti
|
|
106
|
+
[6]: /sponsors
|
|
107
|
+
[7]: https://www.emojiblast.dev
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Comparison & Migration
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
First of all, Knip owes a lot to the projects on this page and they've all been
|
|
6
|
+
inspirational in their own way. For best results, Knip has [a vision embracing
|
|
7
|
+
comprehensiveness][1] which is larger in scope than any of the alternatives. So
|
|
8
|
+
if any of those tools has the right scope for your requirements, then by all
|
|
9
|
+
means, use what suits you best. Note that most projects are no longer
|
|
10
|
+
maintained.
|
|
11
|
+
|
|
12
|
+
All tools have in common that they have less features and don't support the
|
|
13
|
+
concept of [monorepos/workspaces][2]. Feel free to send in projects that Knip
|
|
14
|
+
does not handle better, Knip loves to be challenged!
|
|
15
|
+
|
|
16
|
+
## Migration
|
|
17
|
+
|
|
18
|
+
A migration consists of deleting the dependency and its configuration file and
|
|
19
|
+
[getting started with Knip][3]. You should end up with less configuration.
|
|
20
|
+
|
|
21
|
+
## Comparison
|
|
22
|
+
|
|
23
|
+
### depcheck
|
|
24
|
+
|
|
25
|
+
> [Depcheck][4] is a tool for analyzing the dependencies in a project to see:
|
|
26
|
+
> how each dependency is used, which dependencies are useless, and which
|
|
27
|
+
> dependencies are missing from package.json.
|
|
28
|
+
|
|
29
|
+
The project has plugins (specials), yet not as many as Knip has and they're not
|
|
30
|
+
as advanced. It also supports compilers (parsers) for non-standard files.
|
|
31
|
+
|
|
32
|
+
The following commands are similar:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
depcheck
|
|
36
|
+
knip --dependencies
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### unimported
|
|
40
|
+
|
|
41
|
+
> Find and fix dangling files and unused dependencies in your JavaScript
|
|
42
|
+
> projects.
|
|
43
|
+
|
|
44
|
+
[unimported][5] is fast and works well. It works in what Knip calls "production
|
|
45
|
+
mode" exclusively. If you're fine with a little bit of configuration and don't
|
|
46
|
+
want or need to deal with non-production items (such as `devDependencies` and
|
|
47
|
+
test files), then this might work well for you.
|
|
48
|
+
|
|
49
|
+
The following commands are similar:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
unimported
|
|
53
|
+
knip --production --dependencies --files
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Project status**: The project is archived and recommends Knip.
|
|
57
|
+
|
|
58
|
+
### ts-prune
|
|
59
|
+
|
|
60
|
+
> Find unused exports in a typescript project. 🛀
|
|
61
|
+
|
|
62
|
+
[ts-prune][6] aims to find potentially unused exports in your TypeScript project
|
|
63
|
+
with zero configuration.
|
|
64
|
+
|
|
65
|
+
The following commands are similar:
|
|
66
|
+
|
|
67
|
+
```sh
|
|
68
|
+
ts-prune
|
|
69
|
+
knip --include exports,types,nsExports,nsTypes
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Use `knip --exports` to also include class and enum members.
|
|
73
|
+
|
|
74
|
+
**Project status**: The project is archived and recommends Knip.
|
|
75
|
+
|
|
76
|
+
### ts-unused-exports
|
|
77
|
+
|
|
78
|
+
> [ts-unused-exports][7] finds unused exported symbols in your Typescript
|
|
79
|
+
> project
|
|
80
|
+
|
|
81
|
+
The following commands are similar:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
ts-unused-exports
|
|
85
|
+
knip --include exports,types,nsExports,nsTypes
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Use `knip --exports` to also include class and enum members.
|
|
89
|
+
|
|
90
|
+
### tsr
|
|
91
|
+
|
|
92
|
+
> Remove unused code from your TypeScript Project
|
|
93
|
+
|
|
94
|
+
[tsr][8] (previously `ts-remove-unused`) removes unused exports, and works based
|
|
95
|
+
on a single `tsconfig.json` file (`includes` and `excludes`) and requires no
|
|
96
|
+
configuration. It removes the `export` keyword or the whole export declaration.
|
|
97
|
+
|
|
98
|
+
## Related projects
|
|
99
|
+
|
|
100
|
+
Additional alternative and related projects include:
|
|
101
|
+
|
|
102
|
+
- [deadfile][9]
|
|
103
|
+
- [DepClean][10]
|
|
104
|
+
- [dependency-check][11]
|
|
105
|
+
- [find-unused-exports][12]
|
|
106
|
+
- [next-unused][13]
|
|
107
|
+
- [npm-check][14]
|
|
108
|
+
- [renoma][15]
|
|
109
|
+
|
|
110
|
+
In general, the [e18e.dev][16] website and in particular the [Cleanup][17]
|
|
111
|
+
section is a great resource when dealing with technical debt.
|
|
112
|
+
|
|
113
|
+
[1]: ./why-use-knip.md#comprehensive
|
|
114
|
+
[2]: ../features/monorepos-and-workspaces.md
|
|
115
|
+
[3]: ../overview/getting-started.mdx
|
|
116
|
+
[4]: https://github.com/depcheck/depcheck
|
|
117
|
+
[5]: https://github.com/smeijer/unimported
|
|
118
|
+
[6]: https://github.com/nadeesha/ts-prune
|
|
119
|
+
[7]: https://github.com/pzavolinsky/ts-unused-exports
|
|
120
|
+
[8]: https://github.com/line/tsr
|
|
121
|
+
[9]: https://github.com/M-Izadmehr/deadfile
|
|
122
|
+
[10]: https://github.com/mysteryven/depclean
|
|
123
|
+
[11]: https://github.com/dependency-check-team/dependency-check
|
|
124
|
+
[12]: https://github.com/jaydenseric/find-unused-exports
|
|
125
|
+
[13]: https://github.com/pacocoursey/next-unused
|
|
126
|
+
[14]: https://github.com/dylang/npm-check
|
|
127
|
+
[15]: https://github.com/bluwy/renoma
|
|
128
|
+
[16]: https://e18e.dev
|
|
129
|
+
[17]: https://e18e.dev/guide/cleanup.html
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Entry Files
|
|
3
|
+
sidebar:
|
|
4
|
+
order: 1
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Entry files are the starting point for Knip to determine what files are used in
|
|
8
|
+
the codebase. More entry files lead to increased coverage of the codebase. This
|
|
9
|
+
also leads to more dependencies to be discovered. This page explains how Knip
|
|
10
|
+
and its plugins try to find entry files so you don't need to configure them
|
|
11
|
+
yourself.
|
|
12
|
+
|
|
13
|
+
## Default entry file patterns
|
|
14
|
+
|
|
15
|
+
For brevity, the [default configuration][1] on the previous page mentions only
|
|
16
|
+
`index.js` and `index.ts`, but the default set of file names and extensions is
|
|
17
|
+
actually a bit larger:
|
|
18
|
+
|
|
19
|
+
- `index`, `main` and `cli`
|
|
20
|
+
- `js`, `mjs`, `cjs`, `jsx`, `ts`, `mts`, `cts` and `tsx`
|
|
21
|
+
|
|
22
|
+
This means files like `main.cjs` and `src/cli.ts` are automatically added as
|
|
23
|
+
entry files. Here's the default configuration in full:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"entry": [
|
|
28
|
+
"{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}",
|
|
29
|
+
"src/{index,cli,main}.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"
|
|
30
|
+
],
|
|
31
|
+
"project": ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}!"]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Next to the default locations, Knip looks for `entry` files in other places. In
|
|
36
|
+
a monorepo, this is done for each workspace separately.
|
|
37
|
+
|
|
38
|
+
The values you set override the default values, they are not merged.
|
|
39
|
+
|
|
40
|
+
Also see [FAQ: Where does Knip look for entry files?][2]
|
|
41
|
+
|
|
42
|
+
## Plugins
|
|
43
|
+
|
|
44
|
+
Plugins often add entry files. For instance, if the Remix, Storybook and Vitest
|
|
45
|
+
plugins are enabled in your project, they'll add additional entry files. See
|
|
46
|
+
[the next page about plugins][3] for more details about this.
|
|
47
|
+
|
|
48
|
+
## Scripts in package.json
|
|
49
|
+
|
|
50
|
+
The `package.json` is scanned for entry files. The `main`, `bin`, and `exports`
|
|
51
|
+
fields may contain entry files. The `scripts` are also parsed to find entry
|
|
52
|
+
files and dependencies. See [Script Parser][4] for more details.
|
|
53
|
+
|
|
54
|
+
## Ignored files
|
|
55
|
+
|
|
56
|
+
Knip respects `.gitignore` files. By default, ignored files are not added as
|
|
57
|
+
entry files. This behavior can be disabled by using the [`--no-gitignore`][5]
|
|
58
|
+
flag on the CLI.
|
|
59
|
+
|
|
60
|
+
## Configuring project files
|
|
61
|
+
|
|
62
|
+
See [configuring project files][6] for guidance on tuning `entry` and `project`
|
|
63
|
+
and when to use `ignore`.
|
|
64
|
+
|
|
65
|
+
[1]: ../overview/configuration.md#defaults
|
|
66
|
+
[2]: ../reference/faq.md#where-does-knip-look-for-entry-files
|
|
67
|
+
[3]: ./plugins.md
|
|
68
|
+
[4]: ../features/script-parser.md
|
|
69
|
+
[5]: ../reference/cli.md#--no-gitignore
|
|
70
|
+
[6]: ../guides/configuring-project-files.md
|