knip 1.6.1 → 1.7.0
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 +98 -84
- package/dist/constants.js +17 -1
- package/dist/plugins/nx/index.js +14 -4
- package/dist/plugins/nx/types.d.ts +11 -0
- package/dist/plugins/nx/types.js +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -171,7 +171,20 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
171
171
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
172
172
|
|
|
173
173
|
Still not happy with the results? Getting too much output/false positives? The [FAQ][9] may be useful. Feel free to open
|
|
174
|
-
an issue and I'm happy to look into it.
|
|
174
|
+
an issue and I'm happy to look into it. Also see the next section on how to [ignore][10] certain false positives:
|
|
175
|
+
|
|
176
|
+
## Ignore
|
|
177
|
+
|
|
178
|
+
There are a few ways to tell Knip to ignore certain packages, binaries, dependencies and workspaces. Some examples:
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"ignore": ["**/*.d.ts", "**/fixtures"],
|
|
183
|
+
"ignoreBinaries": ["zip", "docker-compose"],
|
|
184
|
+
"ignoreDependencies": ["hidden-package"],
|
|
185
|
+
"ignoreWorkspaces": ["packages/deno-lib"]
|
|
186
|
+
}
|
|
187
|
+
```
|
|
175
188
|
|
|
176
189
|
## Now what?
|
|
177
190
|
|
|
@@ -223,35 +236,35 @@ Here's some example output when running Knip in a workspace:
|
|
|
223
236
|
Knip contains a growing list of plugins:
|
|
224
237
|
|
|
225
238
|
- [Babel][9]
|
|
226
|
-
- [Capacitor][
|
|
227
|
-
- [Changesets][
|
|
228
|
-
- [commitlint][
|
|
229
|
-
- [Cypress][
|
|
230
|
-
- [ESLint][
|
|
231
|
-
- [Gatsby][
|
|
232
|
-
- [GitHub Actions][
|
|
233
|
-
- [husky][
|
|
234
|
-
- [Jest][
|
|
235
|
-
- [lint-staged][
|
|
236
|
-
- [markdownlint][
|
|
237
|
-
- [Mocha][
|
|
238
|
-
- [Next.js][
|
|
239
|
-
- [npm-package-json-lint][
|
|
240
|
-
- [Nx][
|
|
241
|
-
- [nyc][
|
|
242
|
-
- [Playwright][
|
|
243
|
-
- [PostCSS][
|
|
244
|
-
- [Prettier][
|
|
245
|
-
- [Release It][
|
|
246
|
-
- [Remark][
|
|
247
|
-
- [Remix][
|
|
248
|
-
- [Rollup][
|
|
249
|
-
- [Sentry][
|
|
250
|
-
- [Storybook][
|
|
251
|
-
- [Stryker][
|
|
252
|
-
- [TypeScript][
|
|
253
|
-
- [Vitest][
|
|
254
|
-
- [Webpack][
|
|
239
|
+
- [Capacitor][11]
|
|
240
|
+
- [Changesets][12]
|
|
241
|
+
- [commitlint][13]
|
|
242
|
+
- [Cypress][14]
|
|
243
|
+
- [ESLint][15]
|
|
244
|
+
- [Gatsby][16]
|
|
245
|
+
- [GitHub Actions][17]
|
|
246
|
+
- [husky][18]
|
|
247
|
+
- [Jest][19]
|
|
248
|
+
- [lint-staged][20]
|
|
249
|
+
- [markdownlint][21]
|
|
250
|
+
- [Mocha][22]
|
|
251
|
+
- [Next.js][23]
|
|
252
|
+
- [npm-package-json-lint][24]
|
|
253
|
+
- [Nx][25]
|
|
254
|
+
- [nyc][26]
|
|
255
|
+
- [Playwright][27]
|
|
256
|
+
- [PostCSS][28]
|
|
257
|
+
- [Prettier][29]
|
|
258
|
+
- [Release It][30]
|
|
259
|
+
- [Remark][31]
|
|
260
|
+
- [Remix][32]
|
|
261
|
+
- [Rollup][33]
|
|
262
|
+
- [Sentry][34]
|
|
263
|
+
- [Storybook][35]
|
|
264
|
+
- [Stryker][36]
|
|
265
|
+
- [TypeScript][37]
|
|
266
|
+
- [Vitest][38]
|
|
267
|
+
- [Webpack][39]
|
|
255
268
|
|
|
256
269
|
Plugins are automatically activated. Each plugin is automatically enabled based on simple heuristics. Most of them check
|
|
257
270
|
whether one or one of a few (dev) dependencies are listed in `package.json`. Once enabled, they add a set of
|
|
@@ -259,7 +272,7 @@ configuration and/or entry files for Knip to analyze. These defaults can be over
|
|
|
259
272
|
|
|
260
273
|
Most plugins use one or both of the following file types:
|
|
261
274
|
|
|
262
|
-
- `config` - custom dependency resolvers are applied to the [config files][
|
|
275
|
+
- `config` - custom dependency resolvers are applied to the [config files][40]
|
|
263
276
|
- `entry` - files to include with the analysis of the rest of the source code
|
|
264
277
|
|
|
265
278
|
See each plugin's documentation for its default values.
|
|
@@ -360,10 +373,10 @@ Each workspace can also have its own `paths` configured. Note that Knip `paths`
|
|
|
360
373
|
|
|
361
374
|
Knip provides the following built-in reporters:
|
|
362
375
|
|
|
363
|
-
- [`codeowners`][
|
|
364
|
-
- [`compact`][
|
|
365
|
-
- [`json`][
|
|
366
|
-
- [`symbol`][
|
|
376
|
+
- [`codeowners`][41]
|
|
377
|
+
- [`compact`][42]
|
|
378
|
+
- [`json`][43]
|
|
379
|
+
- [`symbol`][44] (default)
|
|
367
380
|
|
|
368
381
|
The `compact` reporter shows the sorted files first, and then a list of symbols:
|
|
369
382
|
|
|
@@ -390,7 +403,7 @@ type ReporterOptions = {
|
|
|
390
403
|
|
|
391
404
|
The data can then be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
392
405
|
|
|
393
|
-
Find more details and ideas in [custom reporters][
|
|
406
|
+
Find more details and ideas in [custom reporters][45].
|
|
394
407
|
|
|
395
408
|
## Libraries and "unused" exports
|
|
396
409
|
|
|
@@ -448,7 +461,7 @@ When unused dependencies are related to dependencies having a Knip [plugin][1],
|
|
|
448
461
|
for that dependency are at custom locations. The default values are at the plugin's documentation, and can be overridden
|
|
449
462
|
to match the custom location(s).
|
|
450
463
|
|
|
451
|
-
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][
|
|
464
|
+
When the dependencies don't have a Knip plugin yet, please file an issue or [create a new plugin][46].
|
|
452
465
|
|
|
453
466
|
#### Too many unused exports
|
|
454
467
|
|
|
@@ -456,7 +469,7 @@ When the project is a library and the exports are meant to be used by consumers
|
|
|
456
469
|
|
|
457
470
|
1. By default, unused exports of `entry` files are not reported. You could re-export from an existing entry file, or
|
|
458
471
|
add the containing file to the `entry` array in the configuration.
|
|
459
|
-
2. The exported values or types can be marked [using the JSDoc `@public` tag][
|
|
472
|
+
2. The exported values or types can be marked [using the JSDoc `@public` tag][47].
|
|
460
473
|
|
|
461
474
|
### How to start using Knip in CI while having too many issues to sort out?
|
|
462
475
|
|
|
@@ -476,7 +489,7 @@ All of this is hiding problems, so please make sure to plan for fixing them and/
|
|
|
476
489
|
|
|
477
490
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
478
491
|
|
|
479
|
-
| Feature | **knip** | [depcheck][
|
|
492
|
+
| Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
|
|
480
493
|
| :--------------------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
481
494
|
| Unused files | ✅ | - | ✅ | - | - |
|
|
482
495
|
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
@@ -490,7 +503,7 @@ This table is an ongoing comparison. Based on their docs (please report any mist
|
|
|
490
503
|
| Custom reporters | ✅ | - | - | - | - |
|
|
491
504
|
| JavaScript support | ✅ | ✅ | ✅ | - | - |
|
|
492
505
|
| Configure entry files | ✅ | ❌ | ✅ | ❌ | ❌ |
|
|
493
|
-
| [Support workspaces/monorepos][
|
|
506
|
+
| [Support workspaces/monorepos][52] | ✅ | ❌ | ❌ | - | - |
|
|
494
507
|
| ESLint plugin available | - | - | - | ✅ | - |
|
|
495
508
|
|
|
496
509
|
✅ = Supported, ❌ = Not supported, - = Out of scope
|
|
@@ -511,7 +524,7 @@ The following commands are similar:
|
|
|
511
524
|
unimported
|
|
512
525
|
knip --production --dependencies --include files
|
|
513
526
|
|
|
514
|
-
Also see [production mode][
|
|
527
|
+
Also see [production mode][53].
|
|
515
528
|
|
|
516
529
|
### ts-unused-exports
|
|
517
530
|
|
|
@@ -550,46 +563,47 @@ for the job. I'm motivated to make knip perfectly suited for the job of cutting
|
|
|
550
563
|
[7]: https://github.com/webpro/knip/issues
|
|
551
564
|
[8]: #faq
|
|
552
565
|
[9]: ./src/plugins/babel
|
|
553
|
-
[10]:
|
|
554
|
-
[11]: ./src/plugins/
|
|
555
|
-
[12]: ./src/plugins/
|
|
556
|
-
[13]: ./src/plugins/
|
|
557
|
-
[14]: ./src/plugins/
|
|
558
|
-
[15]: ./src/plugins/
|
|
559
|
-
[16]: ./src/plugins/
|
|
560
|
-
[17]: ./src/plugins/
|
|
561
|
-
[18]: ./src/plugins/
|
|
562
|
-
[19]: ./src/plugins/
|
|
563
|
-
[20]: ./src/plugins/
|
|
564
|
-
[21]: ./src/plugins/
|
|
565
|
-
[22]: ./src/plugins/
|
|
566
|
-
[23]: ./src/plugins/
|
|
567
|
-
[24]: ./src/plugins/
|
|
568
|
-
[25]: ./src/plugins/
|
|
569
|
-
[26]: ./src/plugins/
|
|
570
|
-
[27]: ./src/plugins/
|
|
571
|
-
[28]: ./src/plugins/
|
|
572
|
-
[29]: ./src/plugins/
|
|
573
|
-
[30]: ./src/plugins/
|
|
574
|
-
[31]: ./src/plugins/
|
|
575
|
-
[32]: ./src/plugins/
|
|
576
|
-
[33]: ./src/plugins/
|
|
577
|
-
[34]: ./src/plugins/
|
|
578
|
-
[35]: ./src/plugins/
|
|
579
|
-
[36]: ./src/plugins/
|
|
580
|
-
[37]: ./src/plugins/
|
|
581
|
-
[38]: ./src/plugins/
|
|
582
|
-
[39]:
|
|
583
|
-
[40]: #
|
|
584
|
-
[41]: #
|
|
585
|
-
[42]: #
|
|
586
|
-
[43]: #
|
|
587
|
-
[44]:
|
|
588
|
-
[45]:
|
|
589
|
-
[46]: #
|
|
590
|
-
[47]:
|
|
591
|
-
[48]: https://github.com/
|
|
592
|
-
[49]: https://github.com/
|
|
593
|
-
[50]: https://github.com/
|
|
594
|
-
[51]:
|
|
595
|
-
[52]: #
|
|
566
|
+
[10]: #ignore
|
|
567
|
+
[11]: ./src/plugins/capacitor
|
|
568
|
+
[12]: ./src/plugins/changesets
|
|
569
|
+
[13]: ./src/plugins/commitlint
|
|
570
|
+
[14]: ./src/plugins/cypress
|
|
571
|
+
[15]: ./src/plugins/eslint
|
|
572
|
+
[16]: ./src/plugins/gatsby
|
|
573
|
+
[17]: ./src/plugins/github-actions
|
|
574
|
+
[18]: ./src/plugins/husky
|
|
575
|
+
[19]: ./src/plugins/jest
|
|
576
|
+
[20]: ./src/plugins/lint-staged
|
|
577
|
+
[21]: ./src/plugins/markdownlint
|
|
578
|
+
[22]: ./src/plugins/mocha
|
|
579
|
+
[23]: ./src/plugins/next
|
|
580
|
+
[24]: ./src/plugins/npm-package-json-lint
|
|
581
|
+
[25]: ./src/plugins/nx
|
|
582
|
+
[26]: ./src/plugins/nyc
|
|
583
|
+
[27]: ./src/plugins/playwright
|
|
584
|
+
[28]: ./src/plugins/postcss
|
|
585
|
+
[29]: ./src/plugins/prettier
|
|
586
|
+
[30]: ./src/plugins/release-it
|
|
587
|
+
[31]: ./src/plugins/remark
|
|
588
|
+
[32]: ./src/plugins/remix
|
|
589
|
+
[33]: ./src/plugins/rollup
|
|
590
|
+
[34]: ./src/plugins/sentry
|
|
591
|
+
[35]: ./src/plugins/storybook
|
|
592
|
+
[36]: ./src/plugins/stryker
|
|
593
|
+
[37]: ./src/plugins/typescript
|
|
594
|
+
[38]: ./src/plugins/vitest
|
|
595
|
+
[39]: ./src/plugins/webpack
|
|
596
|
+
[40]: #config
|
|
597
|
+
[41]: #code-owners
|
|
598
|
+
[42]: #compact
|
|
599
|
+
[43]: #json
|
|
600
|
+
[44]: #symbol-default
|
|
601
|
+
[45]: ./docs/custom-reporters.md
|
|
602
|
+
[46]: #create-a-new-plugin
|
|
603
|
+
[47]: #libraries-and-unused-exports
|
|
604
|
+
[48]: https://github.com/depcheck/depcheck
|
|
605
|
+
[49]: https://github.com/smeijer/unimported
|
|
606
|
+
[50]: https://github.com/pzavolinsky/ts-unused-exports
|
|
607
|
+
[51]: https://github.com/nadeesha/ts-prune
|
|
608
|
+
[52]: #workspaces--monorepos
|
|
609
|
+
[53]: #production-mode
|
package/dist/constants.js
CHANGED
|
@@ -7,7 +7,23 @@ export const DEFAULT_WORKSPACE_CONFIG = {
|
|
|
7
7
|
ignore: [],
|
|
8
8
|
};
|
|
9
9
|
export const TEST_FILE_PATTERNS = ['**/*.{test,spec}.{js,jsx,ts,tsx}', '**/__tests__/**/*.{js,jsx,ts,tsx}'];
|
|
10
|
-
export const IGNORED_GLOBAL_BINARIES = [
|
|
10
|
+
export const IGNORED_GLOBAL_BINARIES = [
|
|
11
|
+
'deno',
|
|
12
|
+
'git',
|
|
13
|
+
'node',
|
|
14
|
+
'npm',
|
|
15
|
+
'npx',
|
|
16
|
+
'pnpm',
|
|
17
|
+
'yarn',
|
|
18
|
+
'cd',
|
|
19
|
+
'cp',
|
|
20
|
+
'echo',
|
|
21
|
+
'exit',
|
|
22
|
+
'mkdir',
|
|
23
|
+
'mv',
|
|
24
|
+
'rm',
|
|
25
|
+
'sudo',
|
|
26
|
+
];
|
|
11
27
|
export const IGNORE_DEFINITELY_TYPED = ['node'];
|
|
12
28
|
export const ISSUE_TYPES = [
|
|
13
29
|
'files',
|
package/dist/plugins/nx/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
+
import { getBinariesFromScripts } from '../../util/binaries/index.js';
|
|
2
3
|
import { _load } from '../../util/loader.js';
|
|
3
4
|
import { timerify } from '../../util/performance.js';
|
|
4
5
|
import { hasDependency } from '../../util/plugin.js';
|
|
@@ -6,10 +7,19 @@ export const NAME = 'Nx';
|
|
|
6
7
|
export const ENABLERS = [/^@nrwl\//];
|
|
7
8
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
9
|
export const CONFIG_FILE_PATTERNS = ['{apps,libs}/**/project.json'];
|
|
9
|
-
const findNxDependencies = async (configFilePath) => {
|
|
10
|
+
const findNxDependencies = async (configFilePath, { manifest }) => {
|
|
10
11
|
const config = await _load(configFilePath);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
if (!config)
|
|
13
|
+
return [];
|
|
14
|
+
const targets = config.targets ? Object.values(config.targets) : [];
|
|
15
|
+
const executors = compact(targets
|
|
16
|
+
.map(target => target?.executor)
|
|
17
|
+
.filter(executor => executor && !executor.startsWith('.'))
|
|
18
|
+
.map(executor => executor?.split(':')[0]));
|
|
19
|
+
const scripts = compact(targets
|
|
20
|
+
.filter(target => target.executor === 'nx:run-commands')
|
|
21
|
+
.flatMap(target => (target.options?.commands ?? target.options?.command ? [target.options.command] : [])));
|
|
22
|
+
const binaries = getBinariesFromScripts(scripts, { manifest, knownGlobalsOnly: true });
|
|
23
|
+
return [...executors, ...binaries];
|
|
14
24
|
};
|
|
15
25
|
export const findDependencies = timerify(findNxDependencies);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://github.com/webpro/knip",
|
|
6
6
|
"repository": "github:webpro/knip",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@snyk/github-codeowners": "^1.1.0",
|
|
44
44
|
"chalk": "^5.2.0",
|
|
45
45
|
"easy-table": "^1.2.0",
|
|
46
|
-
"esbuild": "^0.17.
|
|
46
|
+
"esbuild": "^0.17.3",
|
|
47
47
|
"esbuild-register": "3.4.2",
|
|
48
48
|
"eslint": "^8.32.0",
|
|
49
49
|
"fast-glob": "^3.2.12",
|