knip 0.7.2 → 0.7.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/README.md +178 -180
- package/dist/help.js +3 -3
- package/dist/util/debug.js +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
# ✂️ Knip
|
|
2
2
|
|
|
3
|
-
Knip
|
|
4
|
-
|
|
3
|
+
Knip finds **unused files, dependencies and exports** in your JavaScript and TypeScript projects. Less code leads to
|
|
4
|
+
improved performance, less maintenance and easier refactorings.
|
|
5
5
|
|
|
6
6
|
```ts
|
|
7
7
|
export const myVar = true;
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
ESLint handles files in isolation, so the `export` keyword "blocks" further analysis. Unused files and dependencies will
|
|
11
|
-
also not be detected. You could think of Knip as going (far!) beyond the
|
|
12
|
-
|
|
11
|
+
also not be detected. You could think of Knip as going (far!) beyond the `no-unused-vars` rule of ESLint. Knip lints the
|
|
12
|
+
project as a whole (or parts of it).
|
|
13
13
|
|
|
14
|
-
It's only human to forget
|
|
15
|
-
|
|
16
|
-
start finding things that can be removed during maintenance and refactorings? Especially in larger projects all of this
|
|
17
|
-
can be tedious. This is where Knip comes in.
|
|
14
|
+
It's only human to forget removing things that you no longer use. But how do you find out? Where to even start finding
|
|
15
|
+
things that can be removed?
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
The dots don't connect themselves. This is where Knip comes in:
|
|
20
18
|
|
|
21
19
|
- [x] Finds **unused files, dependencies and exports**.
|
|
22
20
|
- [x] Finds dependencies not listed in `package.json`.
|
|
@@ -24,24 +22,21 @@ Boring stuff should be automated! Just let Knip have a crack at it:
|
|
|
24
22
|
- [x] Supports JavaScript inside TypeScript projects (`"allowJs": true`).
|
|
25
23
|
- [x] Finds duplicate exports of the same symbol.
|
|
26
24
|
- [x] Supports JavaScript ES Module-based projects without a `tsconfig.json`.
|
|
27
|
-
- [x] Features multiple [reporters]
|
|
25
|
+
- [x] Features multiple [reporters][1] and supports [custom reporters][2].
|
|
28
26
|
|
|
29
27
|
Knip really shines in larger projects. A little bit of configuration will pay off, I promise. A comparison with similar
|
|
30
|
-
tools answers the question
|
|
31
|
-
[why another unused file/dependency/export finder?](#why-yet-another-unused-filedependencyexport-finder)
|
|
28
|
+
tools answers the question [why another unused file/dependency/export finder?][3]
|
|
32
29
|
|
|
33
30
|
Knip is a fresh take on keeping your projects clean & tidy!
|
|
34
31
|
|
|
35
|
-
[![An orange cow with scissors, Van Gogh style]
|
|
36
|
-
|
|
32
|
+
[![An orange cow with scissors, Van Gogh style][5]][4] <sup>_“An orange cow with scissors, Van Gogh style” - generated
|
|
33
|
+
with OpenAI_</sup>
|
|
37
34
|
|
|
38
35
|
## Installation
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
npm install -D knip
|
|
42
|
-
```
|
|
37
|
+
npm install -D knip
|
|
43
38
|
|
|
44
|
-
Knip requires least Node.js v16.17 or v18
|
|
39
|
+
Knip requires at least Node.js v16.17 or v18. Knip is _cutting edge!_
|
|
45
40
|
|
|
46
41
|
## Usage
|
|
47
42
|
|
|
@@ -59,67 +54,67 @@ all files it should match them against, including potentially unused files.
|
|
|
59
54
|
|
|
60
55
|
Then run the checks:
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
npx knip
|
|
64
|
-
```
|
|
57
|
+
npx knip
|
|
65
58
|
|
|
66
59
|
This will analyze the project and output unused files, exports, types and duplicate exports.
|
|
67
60
|
|
|
68
|
-
Use `--include files` when configuring knip the first time for faster initial results.
|
|
69
|
-
|
|
70
61
|
## How It Works
|
|
71
62
|
|
|
72
63
|
Knip works by creating two sets of files:
|
|
73
64
|
|
|
74
|
-
1.
|
|
75
|
-
2.
|
|
76
|
-
3.
|
|
77
|
-
4.
|
|
65
|
+
1. Production code is the set of files resolved from the `entryFiles`.
|
|
66
|
+
2. They are matched against the set of `projectFiles`.
|
|
67
|
+
3. The subset of project files that is not production code will be reported as unused files (in red).
|
|
68
|
+
4. Then the production code (in blue) will be analyzed for unused exports.
|
|
78
69
|
|
|
79
|
-
![How it works]
|
|
70
|
+
![How it works][6]
|
|
80
71
|
|
|
81
72
|
## Options
|
|
82
73
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
$ knip
|
|
109
|
-
$ knip --
|
|
110
|
-
$ knip
|
|
111
|
-
$ knip --
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
More info: https://github.com/webpro/knip
|
|
115
|
-
```
|
|
74
|
+
❯ npx knip
|
|
75
|
+
knip [options]
|
|
76
|
+
|
|
77
|
+
Options:
|
|
78
|
+
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
|
|
79
|
+
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
|
|
80
|
+
--dir Working directory (default: current working directory)
|
|
81
|
+
--include Report only listed issue type(s) (see below)
|
|
82
|
+
--exclude Exclude issue type(s) from report (see below)
|
|
83
|
+
--ignore Ignore files matching this glob pattern (can be set multiple times)
|
|
84
|
+
--no-gitignore Don't use .gitignore
|
|
85
|
+
--dev Include `devDependencies` in report(s)
|
|
86
|
+
--no-progress Don't show dynamic progress updates
|
|
87
|
+
--max-issues Maximum number of issues before non-zero exit code (default: 0)
|
|
88
|
+
--reporter Select reporter: symbols, compact, codeowners (default: symbols)
|
|
89
|
+
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
90
|
+
--jsdoc Enable JSDoc parsing, with options: public
|
|
91
|
+
--debug Show debug output
|
|
92
|
+
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
93
|
+
|
|
94
|
+
Issue types: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
95
|
+
|
|
96
|
+
Examples:
|
|
97
|
+
|
|
98
|
+
$ knip
|
|
99
|
+
$ knip --dir packages/client --include files
|
|
100
|
+
$ knip -c ./knip.js --reporter compact --jsdoc public
|
|
101
|
+
$ knip --ignore 'lib/**/*.ts' --ignore build
|
|
102
|
+
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
103
|
+
|
|
104
|
+
More info: https://github.com/webpro/knip
|
|
116
105
|
|
|
117
|
-
|
|
106
|
+
## Performance
|
|
107
|
+
|
|
108
|
+
🚀 Knip is considerably faster when only the `files` and/or `duplicates` types are included. Finding unused exports
|
|
109
|
+
requires deeper analysis (`exports`, `nsExports`, `types`, `nsTypes`). The following example commands do the same:
|
|
110
|
+
|
|
111
|
+
knip --include files --include duplicates
|
|
112
|
+
knip --include files,duplicates
|
|
118
113
|
|
|
119
114
|
## Reading the report
|
|
120
115
|
|
|
121
116
|
After analyzing all the files resolved from the `entryFiles` against the `projectFiles`, the report contains the
|
|
122
|
-
following
|
|
117
|
+
following types of issues:
|
|
123
118
|
|
|
124
119
|
- `files` - Unused files: did not find references to this file
|
|
125
120
|
- `dependencies` - Unused dependencies: did not find references to this dependency
|
|
@@ -130,25 +125,26 @@ following groups of issues:
|
|
|
130
125
|
- `nsTypes` - Unused types in namespaces: did not find direct references to this exported variable (2)
|
|
131
126
|
- `duplicates` - Duplicate exports: the same thing is exported more than once with different names from the same file
|
|
132
127
|
|
|
133
|
-
|
|
128
|
+
1. This may also include dependencies that could not be resolved properly (such as non-relative `local/dir/file.ts` not
|
|
129
|
+
and `local` not being in `node_modules`).
|
|
130
|
+
2. The variable or type is not referenced directly, and has become a member of a namespace. That's why Knip is not sure
|
|
131
|
+
whether this export can be removed, so please look into it:
|
|
134
132
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
2. The variable or type is not referenced directly, and has become a member of a namespace. That's why Knip is not sure
|
|
138
|
-
whether this export can be removed, so please look into it:
|
|
133
|
+
You can `--include` or `--exclude` any of the types to slice & dice the report to your needs. Alternatively, they can be
|
|
134
|
+
added to the configuration (e.g. `"exclude": ["dependencies"]`).
|
|
139
135
|
|
|
140
136
|
## Now what?
|
|
141
137
|
|
|
142
138
|
As always, make sure to backup files or use Git before deleting files or making changes. Run tests to verify results.
|
|
143
139
|
|
|
144
|
-
- Unused files can be
|
|
140
|
+
- Unused files can be removed.
|
|
145
141
|
- Unused dependencies can be removed from `package.json`.
|
|
146
142
|
- Unlisted dependencies should be added to `package.json`.
|
|
147
143
|
- Unused exports and types: remove the `export` keyword in front of unused exports. Then you (or tools such as the
|
|
148
144
|
TypeScript language server in VS Code and/or ESLint) can see whether the variable or type is used within the same
|
|
149
145
|
file. If this is not the case, it can be removed.
|
|
150
146
|
|
|
151
|
-
🔁 Repeat the process to reveal new unused files and exports. Sometimes it's so liberating to
|
|
147
|
+
🔁 Repeat the process to reveal new unused files and exports. Sometimes it's so liberating to remove things!
|
|
152
148
|
|
|
153
149
|
## Production versus non-production code
|
|
154
150
|
|
|
@@ -157,12 +153,12 @@ Feels like you're getting too many false positives? Let's talk about `entryFiles
|
|
|
157
153
|
### Production code
|
|
158
154
|
|
|
159
155
|
The default configuration for Knip is very strict and targets production code. Non-production files such as tests should
|
|
160
|
-
not be part of the `entryFiles`. Here's why: test and other non-production files often import
|
|
161
|
-
will prevent the production files from being reported as unused. For best results:
|
|
156
|
+
not be part of the `entryFiles` and `projectFiles`. Here's why: test and other non-production files often import
|
|
157
|
+
production files, which will prevent the production files from being reported as unused. For best results:
|
|
162
158
|
|
|
163
159
|
- Include only production entry files to the `entryFiles`.
|
|
164
160
|
- Include only and all production files to the `projectFiles`.
|
|
165
|
-
- If necessary, exclude non-production files from the `projectFiles` (using negation
|
|
161
|
+
- If necessary, add globs to exclude non-production files from the `projectFiles` (using negation pattern).
|
|
166
162
|
|
|
167
163
|
This will ensure Knip understands what production code can be removed.
|
|
168
164
|
|
|
@@ -175,8 +171,8 @@ To analyze the project as a whole:
|
|
|
175
171
|
|
|
176
172
|
- Include both production entry files and test files to the `entryFiles`.
|
|
177
173
|
- Include all production files to the `projectFiles`.
|
|
178
|
-
-
|
|
179
|
-
-
|
|
174
|
+
- If necessary, add globs for non-production files to the `projectFiles`.
|
|
175
|
+
- Set `dev: true` in the configuration or add `--dev` as a command line flag (to add `devDependencies`).
|
|
180
176
|
|
|
181
177
|
Here's an example:
|
|
182
178
|
|
|
@@ -233,18 +229,18 @@ packages can be configured using globs:
|
|
|
233
229
|
|
|
234
230
|
Packages can also be explicitly configured per package directory.
|
|
235
231
|
|
|
236
|
-
To
|
|
232
|
+
To analyze the packages separately, using the matching pattern from the configuration file:
|
|
237
233
|
|
|
238
|
-
|
|
239
|
-
knip --dir packages/
|
|
240
|
-
knip --dir packages/services
|
|
241
|
-
```
|
|
234
|
+
knip --dir packages/client
|
|
235
|
+
knip --dir packages/services
|
|
242
236
|
|
|
243
237
|
#### Connected projects
|
|
244
238
|
|
|
245
|
-
A good example of a large project setup is a monorepo
|
|
246
|
-
|
|
247
|
-
|
|
239
|
+
A good example of a large project setup is a monorepo. Let's take an example (Nx) project configuration using Next.js,
|
|
240
|
+
Jest and Storybook, which has multiple apps and libs. They are not published separately and don't have their own
|
|
241
|
+
`package.json`.
|
|
242
|
+
|
|
243
|
+
This configuration file can also be a JavaScript file, which allows to add logic and/or comments (e.g. `knip.js`):
|
|
248
244
|
|
|
249
245
|
```js
|
|
250
246
|
const entryFiles = ['apps/**/pages/**/*.{js,ts,tsx}'];
|
|
@@ -266,8 +262,8 @@ const projectFiles = [
|
|
|
266
262
|
module.exports = { entryFiles, projectFiles };
|
|
267
263
|
```
|
|
268
264
|
|
|
269
|
-
This should give good results about unused files and exports for the monorepo. After the first run, the
|
|
270
|
-
can be tweaked further to the project structure.
|
|
265
|
+
This should give good results about unused files, dependencies and exports for the monorepo. After the first run, the
|
|
266
|
+
configuration can be tweaked further to the project structure.
|
|
271
267
|
|
|
272
268
|
## Reporters
|
|
273
269
|
|
|
@@ -302,84 +298,78 @@ The data can then be used to write issues to `stdout`, a JSON or CSV file, or se
|
|
|
302
298
|
|
|
303
299
|
The default reporter shows the sorted symbols first:
|
|
304
300
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
src/
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
type
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
ProductsList, default src/components/Products.tsx
|
|
328
|
-
```
|
|
301
|
+
$ knip
|
|
302
|
+
--- UNUSED FILES (2)
|
|
303
|
+
src/chat/helpers.ts
|
|
304
|
+
src/components/SideBar.tsx
|
|
305
|
+
--- UNUSED DEPENDENCIES (1)
|
|
306
|
+
moment
|
|
307
|
+
--- UNLISTED DEPENDENCIES (1)
|
|
308
|
+
react
|
|
309
|
+
--- UNUSED EXPORTS (5)
|
|
310
|
+
lowercaseFirstLetter src/common/src/string/index.ts
|
|
311
|
+
RegistrationBox src/components/Registration.tsx
|
|
312
|
+
clamp src/css.ts
|
|
313
|
+
restoreSession src/services/authentication.ts
|
|
314
|
+
PREFIX src/services/authentication.ts
|
|
315
|
+
--- UNUSED TYPES (4)
|
|
316
|
+
enum RegistrationServices src/components/Registration/registrationMachine.ts
|
|
317
|
+
type RegistrationAction src/components/Registration/registrationMachine.ts
|
|
318
|
+
type ComponentProps src/components/Registration.tsx
|
|
319
|
+
interface ProductDetail src/types/Product.ts
|
|
320
|
+
--- DUPLICATE EXPORTS (2)
|
|
321
|
+
Registration, default src/components/Registration.tsx
|
|
322
|
+
ProductsList, default src/components/Products.tsx
|
|
329
323
|
|
|
330
324
|
#### Compact
|
|
331
325
|
|
|
332
326
|
The compact reporter shows the sorted files first, and then a list of symbols:
|
|
333
327
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
src/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
src/
|
|
345
|
-
src/
|
|
346
|
-
src/
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
src/components/Registration
|
|
350
|
-
src/
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
src/components/
|
|
354
|
-
src/components/Products.tsx: ProductsList, default
|
|
355
|
-
```
|
|
328
|
+
$ knip --reporter compact
|
|
329
|
+
--- UNUSED FILES (2)
|
|
330
|
+
src/chat/helpers.ts
|
|
331
|
+
src/components/SideBar.tsx
|
|
332
|
+
--- UNUSED DEPENDENCIES (1)
|
|
333
|
+
moment
|
|
334
|
+
--- UNLISTED DEPENDENCIES (1)
|
|
335
|
+
react
|
|
336
|
+
--- UNUSED EXPORTS (4)
|
|
337
|
+
src/common/src/string/index.ts: lowercaseFirstLetter
|
|
338
|
+
src/components/Registration.tsx: RegistrationBox
|
|
339
|
+
src/css.ts: clamp
|
|
340
|
+
src/services/authentication.ts: restoreSession, PREFIX
|
|
341
|
+
--- UNUSED TYPES (3)
|
|
342
|
+
src/components/Registration/registrationMachine.ts: RegistrationServices, RegistrationAction
|
|
343
|
+
src/components/Registration.tsx: ComponentProps
|
|
344
|
+
src/types/Product.ts: ProductDetail
|
|
345
|
+
--- DUPLICATE EXPORTS (2)
|
|
346
|
+
src/components/Registration.tsx: Registration, default
|
|
347
|
+
src/components/Products.tsx: ProductsList, default
|
|
356
348
|
|
|
357
349
|
#### Code Owners
|
|
358
350
|
|
|
359
351
|
The `codeowners` reporter is like `compact`, but shows the sorted code owners (according to `.github/CODEOWNERS`) first:
|
|
360
352
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
@org/
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
@org/
|
|
372
|
-
@org/owner src/
|
|
373
|
-
@org/owner src/
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
@org/owner src/components/Registration
|
|
377
|
-
@org/owner src/
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
@org/owner src/components/
|
|
381
|
-
@org/owner src/components/Products.tsx: ProductsList, default
|
|
382
|
-
```
|
|
353
|
+
$ knip --reporter codeowners
|
|
354
|
+
--- UNUSED FILES (2)
|
|
355
|
+
@org/team src/chat/helpers.ts
|
|
356
|
+
@org/owner src/components/SideBar.tsx
|
|
357
|
+
--- UNUSED DEPENDENCIES (1)
|
|
358
|
+
@org/admin moment
|
|
359
|
+
--- UNLISTED DEPENDENCIES (1)
|
|
360
|
+
@org/owner src/components/Registration.tsx react
|
|
361
|
+
--- UNUSED EXPORTS (4)
|
|
362
|
+
@org/team src/common/src/string/index.ts: lowercaseFirstLetter
|
|
363
|
+
@org/owner src/components/Registration.tsx: RegistrationBox
|
|
364
|
+
@org/owner src/css.ts: clamp
|
|
365
|
+
@org/owner src/services/authentication.ts: restoreSession, PREFIX
|
|
366
|
+
--- UNUSED TYPES (3)
|
|
367
|
+
@org/owner src/components/Registration/registrationMachine.ts: RegistrationServices, RegistrationAction
|
|
368
|
+
@org/owner src/components/Registration.tsx: ComponentProps
|
|
369
|
+
@org/owner src/types/Product.ts: ProductDetail
|
|
370
|
+
--- DUPLICATE EXPORTS (2)
|
|
371
|
+
@org/owner src/components/Registration.tsx: Registration, default
|
|
372
|
+
@org/owner src/components/Products.tsx: ProductsList, default
|
|
383
373
|
|
|
384
374
|
The owner of `package.json` is considered the owner of unused (dev) dependencies.
|
|
385
375
|
|
|
@@ -397,26 +387,26 @@ collect the various issues in one go?
|
|
|
397
387
|
|
|
398
388
|
This table is a work in progress, but here's a first impression. Based on their docs (please report any mistakes):
|
|
399
389
|
|
|
400
|
-
| Feature
|
|
401
|
-
|
|
|
402
|
-
| Unused files
|
|
403
|
-
| Unused dependencies
|
|
404
|
-
| Unlisted dependencies
|
|
405
|
-
| [Custom dependency resolvers][
|
|
406
|
-
| Unused exports
|
|
407
|
-
| Duplicate exports
|
|
408
|
-
| Search namespaces
|
|
409
|
-
| Custom reporters
|
|
410
|
-
| Pure JavaScript/ESM
|
|
411
|
-
| Configure entry files
|
|
412
|
-
| [Support monorepos][
|
|
413
|
-
| ESLint plugin available
|
|
390
|
+
| Feature | **knip** | [depcheck][7] | [unimported][8] | [ts-unused-exports][9] | [ts-prune][10] | [find-unused-exports][11] |
|
|
391
|
+
| --------------------------------- | :------: | :-----------: | :-------------: | :--------------------: | :------------: | :-----------------------: |
|
|
392
|
+
| Unused files | ✅ | - | ✅ | - | - | - |
|
|
393
|
+
| Unused dependencies | ✅ | ✅ | ✅ | - | - | - |
|
|
394
|
+
| Unlisted dependencies | ✅ | ✅ | ✅ | - | - | - |
|
|
395
|
+
| [Custom dependency resolvers][12] | ❌ | ✅ | ❌ | - | - | - |
|
|
396
|
+
| Unused exports | ✅ | - | - | ✅ | ✅ | ✅ |
|
|
397
|
+
| Duplicate exports | ✅ | - | - | ❌ | ❌ | ❌ |
|
|
398
|
+
| Search namespaces | ✅ | - | - | ✅ | ❌ | ❌ |
|
|
399
|
+
| Custom reporters | ✅ | - | - | - | - | - |
|
|
400
|
+
| Pure JavaScript/ESM | ✅ | ✅ | ✅ | - | - | ✅ |
|
|
401
|
+
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ |
|
|
402
|
+
| [Support monorepos][13] | 🟠 | - | - | - | - | - |
|
|
403
|
+
| ESLint plugin available | - | - | - | ✅ | - | - |
|
|
414
404
|
|
|
415
405
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
416
406
|
|
|
417
407
|
## Monorepos
|
|
418
408
|
|
|
419
|
-
Knip wants to [support monorepos]
|
|
409
|
+
Knip wants to [support monorepos][14] properly, the first steps in this direction are implemented.
|
|
420
410
|
|
|
421
411
|
## Custom dependency resolvers
|
|
422
412
|
|
|
@@ -425,8 +415,7 @@ directory of a monorepo is nice for DX. But Knip will need some help to find it
|
|
|
425
415
|
`eslint-plugin-cypress` _dependency_. Or see it is not listed in `package.json`. Or that the dependency is still listed,
|
|
426
416
|
but no longer in use. Many popular projects reference plugins in similar ways, such as Babel, Webpack and Storybook.
|
|
427
417
|
|
|
428
|
-
Big compliments to [depcheck]
|
|
429
|
-
"specials". [Knip has this ambition][6], too.
|
|
418
|
+
Big compliments to [depcheck][15] which already does this! They call this "specials". [Knip has this ambition][16], too.
|
|
430
419
|
|
|
431
420
|
unimported is strict in this regard and works based on production files and `dependencies`, so does not have custom
|
|
432
421
|
dependency resolvers which are usually only needed for `devDependencies`.
|
|
@@ -434,19 +423,28 @@ dependency resolvers which are usually only needed for `devDependencies`.
|
|
|
434
423
|
## TypeScript language services
|
|
435
424
|
|
|
436
425
|
TypeScript language services could play a major role in most of the "unused" areas, as they have an overview of the
|
|
437
|
-
project as a whole.
|
|
438
|
-
exports" or "custom dependency resolvers" are
|
|
426
|
+
project as a whole. This powers things in VS Code like "Find references" or the "Module "./some" declares 'Thing'
|
|
427
|
+
locally, but it is not exported" message. I think features like "duplicate exports" or "custom dependency resolvers" are
|
|
428
|
+
userland territory, much like code linters.
|
|
439
429
|
|
|
440
430
|
## Knip?!
|
|
441
431
|
|
|
442
432
|
Knip is Dutch for a "cut". A Dutch expression is "to be ge**knip**t for something", which means to be perfectly suited
|
|
443
433
|
for the job. I'm motivated to make knip perfectly suited for the job of cutting projects to perfection! ✂️
|
|
444
434
|
|
|
445
|
-
[1]:
|
|
446
|
-
[2]:
|
|
447
|
-
[3]:
|
|
448
|
-
[4]: https://
|
|
449
|
-
[5]:
|
|
450
|
-
[6]:
|
|
451
|
-
[7]:
|
|
452
|
-
[8]:
|
|
435
|
+
[1]: #reporters
|
|
436
|
+
[2]: #custom-reporters
|
|
437
|
+
[3]: #why-yet-another-unused-filedependencyexport-finder
|
|
438
|
+
[4]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
439
|
+
[5]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
440
|
+
[6]: ./assets/how-it-works.drawio.svg
|
|
441
|
+
[7]: https://github.com/depcheck/depcheck
|
|
442
|
+
[8]: https://github.com/smeijer/unimported
|
|
443
|
+
[9]: https://github.com/pzavolinsky/ts-unused-exports
|
|
444
|
+
[10]: https://github.com/nadeesha/ts-prune
|
|
445
|
+
[11]: https://github.com/jaydenseric/find-unused-exports
|
|
446
|
+
[12]: #custom-dependency-resolvers
|
|
447
|
+
[13]: #monorepos-1
|
|
448
|
+
[14]: #monorepos
|
|
449
|
+
[15]: https://github.com/depcheck/depcheck#special
|
|
450
|
+
[16]: https://github.com/webpro/knip/issues/7
|
package/dist/help.js
CHANGED
|
@@ -8,8 +8,8 @@ Options:
|
|
|
8
8
|
-c/--config [file] Configuration file path (default: ./knip.json or package.json#knip)
|
|
9
9
|
-t/--tsConfig [file] TypeScript configuration path (default: ./tsconfig.json)
|
|
10
10
|
--dir Working directory (default: current working directory)
|
|
11
|
-
--include Report only listed issue
|
|
12
|
-
--exclude Exclude issue
|
|
11
|
+
--include Report only listed issue type(s) (see below)
|
|
12
|
+
--exclude Exclude issue type(s) from report (see below)
|
|
13
13
|
--ignore Ignore files matching this glob pattern (can be set multiple times)
|
|
14
14
|
--no-gitignore Don't use .gitignore
|
|
15
15
|
--dev Include \`devDependencies\` in report(s)
|
|
@@ -21,7 +21,7 @@ Options:
|
|
|
21
21
|
--debug Show debug output
|
|
22
22
|
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
23
23
|
|
|
24
|
-
Issue
|
|
24
|
+
Issue types: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
25
25
|
|
|
26
26
|
Examples:
|
|
27
27
|
|
package/dist/util/debug.js
CHANGED
|
@@ -9,7 +9,7 @@ const logArray = (collection) => console.log(node_util_1.default.inspect(collect
|
|
|
9
9
|
const debugLogObject = (config, minimumLevel, name, obj) => {
|
|
10
10
|
if (minimumLevel > config.debug.level)
|
|
11
11
|
return;
|
|
12
|
-
console.log(`[
|
|
12
|
+
console.log(`[knip] ${name}:`);
|
|
13
13
|
console.log(node_util_1.default.inspect(obj, { depth: null, colors: true }));
|
|
14
14
|
};
|
|
15
15
|
exports.debugLogObject = debugLogObject;
|
|
@@ -18,11 +18,11 @@ const debugLogFiles = (config, minimumLevel, name, filePaths) => {
|
|
|
18
18
|
return;
|
|
19
19
|
const { debug } = config;
|
|
20
20
|
if (debug.level > 1) {
|
|
21
|
-
console.debug(`[
|
|
21
|
+
console.debug(`[knip] ${name} (${filePaths.length}):`);
|
|
22
22
|
logArray(filePaths);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
console.debug(`[
|
|
25
|
+
console.debug(`[knip] ${name} (${filePaths.length})`);
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
exports.debugLogFiles = debugLogFiles;
|
|
@@ -31,11 +31,11 @@ const debugLogSourceFiles = (config, minimumLevel, name, sourceFiles) => {
|
|
|
31
31
|
return;
|
|
32
32
|
const { debug } = config;
|
|
33
33
|
if (debug.level > 1) {
|
|
34
|
-
console.debug(`[
|
|
34
|
+
console.debug(`[knip] ${name} (${sourceFiles.length}):`);
|
|
35
35
|
logArray(sourceFiles.map(sourceFile => sourceFile.getFilePath()));
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
console.debug(`[
|
|
38
|
+
console.debug(`[knip] ${name} (${sourceFiles.length})`);
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
exports.debugLogSourceFiles = debugLogSourceFiles;
|
|
@@ -44,11 +44,11 @@ const debugLogDiff = (config, minimumLevel, name, arrA, arrB) => {
|
|
|
44
44
|
return;
|
|
45
45
|
const onlyInA = arrA.filter(itemA => !arrB.includes(itemA)).sort();
|
|
46
46
|
const onlyInB = arrB.filter(itemB => !arrA.includes(itemB)).sort();
|
|
47
|
-
console.log(`[
|
|
48
|
-
console.log(`[
|
|
47
|
+
console.log(`[knip] ${name}`);
|
|
48
|
+
console.log(`[knip] Only in left:`);
|
|
49
49
|
logArray(onlyInA);
|
|
50
50
|
console.log();
|
|
51
|
-
console.log(`[
|
|
51
|
+
console.log(`[knip] Only in right:`);
|
|
52
52
|
logArray(onlyInB);
|
|
53
53
|
};
|
|
54
54
|
exports.debugLogDiff = debugLogDiff;
|