knip 2.19.4 → 2.19.5
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 +123 -115
- package/dist/ProjectPrincipal.js +12 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,43 +32,45 @@ Knip shines in both small and large projects. It's a fresh take on keeping your
|
|
|
32
32
|
[![An orange cow with scissors, Van Gogh style][7]][6] <sup>_“An orange cow with scissors, Van Gogh style” - generated
|
|
33
33
|
with OpenAI_</sup>
|
|
34
34
|
|
|
35
|
+
📡 For updates, watch this repository or follow [@webprolific (Twitter)][8] or [@webpro (fosstodon.org)][9].
|
|
36
|
+
|
|
35
37
|
## Contents
|
|
36
38
|
|
|
37
|
-
- [Getting Started][
|
|
38
|
-
- [Installation][
|
|
39
|
-
- [Default Configuration][
|
|
40
|
-
- [Let's Go!][
|
|
41
|
-
- [Configuration][
|
|
42
|
-
- [Entry Files][
|
|
39
|
+
- [Getting Started][10]
|
|
40
|
+
- [Installation][11]
|
|
41
|
+
- [Default Configuration][12]
|
|
42
|
+
- [Let's Go!][13]
|
|
43
|
+
- [Configuration][14]
|
|
44
|
+
- [Entry Files][15]
|
|
43
45
|
- [Workspaces][1]
|
|
44
46
|
- [Plugins][2]
|
|
45
47
|
- [Compilers][3]
|
|
46
|
-
- [Ignore files, binaries, dependencies and workspaces][
|
|
47
|
-
- [Public exports][
|
|
48
|
-
- [Ignore exports used in file][
|
|
49
|
-
- [Include exports in entry files][
|
|
50
|
-
- [Paths][
|
|
51
|
-
- [Production Mode][
|
|
52
|
-
- [Strict][
|
|
53
|
-
- [Plugins][
|
|
54
|
-
- [Output][
|
|
55
|
-
- [Screenshots][
|
|
56
|
-
- [Reading the report][
|
|
57
|
-
- [Rules & Filters][
|
|
48
|
+
- [Ignore files, binaries, dependencies and workspaces][16]
|
|
49
|
+
- [Public exports][17]
|
|
50
|
+
- [Ignore exports used in file][18]
|
|
51
|
+
- [Include exports in entry files][19]
|
|
52
|
+
- [Paths][20]
|
|
53
|
+
- [Production Mode][21]
|
|
54
|
+
- [Strict][22]
|
|
55
|
+
- [Plugins][23]
|
|
56
|
+
- [Output][24]
|
|
57
|
+
- [Screenshots][25]
|
|
58
|
+
- [Reading the report][26]
|
|
59
|
+
- [Rules & Filters][27]
|
|
58
60
|
- [Reporters][4]
|
|
59
|
-
- [Fixing Issues][
|
|
60
|
-
- [Command Line Options][
|
|
61
|
-
- [Potential boost with `--no-gitignore`][
|
|
62
|
-
- [Comparison & Migration][
|
|
63
|
-
- [depcheck][
|
|
64
|
-
- [unimported][
|
|
65
|
-
- [ts-unused-exports][
|
|
66
|
-
- [ts-prune][
|
|
67
|
-
- [Projects using Knip][
|
|
68
|
-
- [Articles, etc.][
|
|
69
|
-
- [Why "Knip"?][
|
|
70
|
-
- [Really, another unused file/dependency/export finder?][
|
|
71
|
-
- [Contributors][
|
|
61
|
+
- [Fixing Issues][28]
|
|
62
|
+
- [Command Line Options][29]
|
|
63
|
+
- [Potential boost with `--no-gitignore`][30]
|
|
64
|
+
- [Comparison & Migration][31]
|
|
65
|
+
- [depcheck][32]
|
|
66
|
+
- [unimported][33]
|
|
67
|
+
- [ts-unused-exports][34]
|
|
68
|
+
- [ts-prune][35]
|
|
69
|
+
- [Projects using Knip][36]
|
|
70
|
+
- [Articles, etc.][37]
|
|
71
|
+
- [Why "Knip"?][38]
|
|
72
|
+
- [Really, another unused file/dependency/export finder?][39]
|
|
73
|
+
- [Contributors][40]
|
|
72
74
|
|
|
73
75
|
## Getting Started
|
|
74
76
|
|
|
@@ -89,7 +91,7 @@ Knip has good defaults and you can run it without any configuration. The (simpli
|
|
|
89
91
|
}
|
|
90
92
|
```
|
|
91
93
|
|
|
92
|
-
There's more, jump to [Entry Files][
|
|
94
|
+
There's more, jump to [Entry Files][15] for details.
|
|
93
95
|
|
|
94
96
|
Places where Knip looks for configuration (ordered by priority):
|
|
95
97
|
|
|
@@ -131,7 +133,7 @@ Run the checks with `npx knip`. Or first add this script to `package.json`:
|
|
|
131
133
|
Then use `npm run knip` to analyze the project and output unused files, dependencies and exports. Knip works just fine
|
|
132
134
|
with `yarn` or `pnpm` as well.
|
|
133
135
|
|
|
134
|
-
See [Command Line Options][
|
|
136
|
+
See [Command Line Options][29] for an overview of available CLI options.
|
|
135
137
|
|
|
136
138
|
## Configuration
|
|
137
139
|
|
|
@@ -194,7 +196,7 @@ Here's an example `knip.json` configuration with some custom `entry` and `projec
|
|
|
194
196
|
```
|
|
195
197
|
|
|
196
198
|
It might be useful to run Knip first with no or little configuration to see where it needs custom `entry` and/or
|
|
197
|
-
`project` files. Each workspace has the same [default configuration][
|
|
199
|
+
`project` files. Each workspace has the same [default configuration][14].
|
|
198
200
|
|
|
199
201
|
The root workspace is named `"."` under `workspaces` (like in the example).
|
|
200
202
|
|
|
@@ -317,7 +319,7 @@ has them at `e2e-tests/*.spec.ts`. Here's how to configure this:
|
|
|
317
319
|
#### Multi-project repositories
|
|
318
320
|
|
|
319
321
|
Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
|
|
320
|
-
repository (such as the [Nx "intregrated repo" style][
|
|
322
|
+
repository (such as the [Nx "intregrated repo" style][41]). Let's assume some of these projects are apps and have their
|
|
321
323
|
own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
|
|
322
324
|
|
|
323
325
|
```json
|
|
@@ -334,7 +336,7 @@ In case a plugin causes issues, it can be disabled by using `false` as its value
|
|
|
334
336
|
|
|
335
337
|
#### Create a new plugin
|
|
336
338
|
|
|
337
|
-
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][
|
|
339
|
+
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][42]. This
|
|
338
340
|
guide also contains more details if you want to learn more about plugins and why they are useful.
|
|
339
341
|
|
|
340
342
|
### Compilers
|
|
@@ -357,7 +359,7 @@ export default {
|
|
|
357
359
|
};
|
|
358
360
|
```
|
|
359
361
|
|
|
360
|
-
Read [Compilers][
|
|
362
|
+
Read [Compilers][43] for more details and examples.
|
|
361
363
|
|
|
362
364
|
### Ignore files, binaries, dependencies and workspaces
|
|
363
365
|
|
|
@@ -519,7 +521,7 @@ The report contains the following types of issues:
|
|
|
519
521
|
|
|
520
522
|
When an issue type has zero issues, it is not shown.
|
|
521
523
|
|
|
522
|
-
Getting too many reported issues and false positives? Read more about [handling issues][
|
|
524
|
+
Getting too many reported issues and false positives? Read more about [handling issues][44].
|
|
523
525
|
|
|
524
526
|
### Rules & Filters
|
|
525
527
|
|
|
@@ -546,7 +548,7 @@ Example:
|
|
|
546
548
|
}
|
|
547
549
|
```
|
|
548
550
|
|
|
549
|
-
See [reading the report][
|
|
551
|
+
See [reading the report][26] for the list of issue types.
|
|
550
552
|
|
|
551
553
|
The rules are modeled after the ESLint `rules` configuration, and could be extended in the future. For instance, to
|
|
552
554
|
apply filters or configurations only to a specific issue type.
|
|
@@ -567,7 +569,7 @@ Use `--exclude` to ignore reports you're not interested in:
|
|
|
567
569
|
|
|
568
570
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
569
571
|
|
|
570
|
-
See [reading the report][
|
|
572
|
+
See [reading the report][26] for the list of issue types.
|
|
571
573
|
|
|
572
574
|
#### When to use rules or filters
|
|
573
575
|
|
|
@@ -594,7 +596,7 @@ When the provided built-in reporters are not sufficient, a custom reporter can b
|
|
|
594
596
|
Pass something like `--reporter ./my-reporter` from the command line. The results are passed to the function from its
|
|
595
597
|
default export and can be used to write issues to `stdout`, a JSON or CSV file, or sent to a service.
|
|
596
598
|
|
|
597
|
-
Find more details and ideas in [custom reporters][
|
|
599
|
+
Find more details and ideas in [custom reporters][45].
|
|
598
600
|
|
|
599
601
|
## Fixing Issues
|
|
600
602
|
|
|
@@ -612,7 +614,7 @@ Tip: back up files or use an VCS like Git before deleting files or making change
|
|
|
612
614
|
|
|
613
615
|
Repeat the process to reveal new unused files and exports. It's so liberating to remove unused things!
|
|
614
616
|
|
|
615
|
-
Getting too many reported issues and false positives? Read more about [handling issues][
|
|
617
|
+
Getting too many reported issues and false positives? Read more about [handling issues][46] describing potential causes
|
|
616
618
|
for false positives, and how to handle them.
|
|
617
619
|
|
|
618
620
|
## Command Line Options
|
|
@@ -661,13 +663,13 @@ for false positives, and how to handle them.
|
|
|
661
663
|
|
|
662
664
|
## Potential boost with `--no-gitignore`
|
|
663
665
|
|
|
664
|
-
To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][
|
|
666
|
+
To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][47].
|
|
665
667
|
|
|
666
668
|
## Comparison & Migration
|
|
667
669
|
|
|
668
670
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
669
671
|
|
|
670
|
-
| Feature | **knip** | [depcheck][
|
|
672
|
+
| Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
|
|
671
673
|
| :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
672
674
|
| Unused files | ✅ | - | ✅ | - | - |
|
|
673
675
|
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
@@ -703,7 +705,7 @@ The following commands are similar:
|
|
|
703
705
|
unimported
|
|
704
706
|
knip --production --dependencies --include files
|
|
705
707
|
|
|
706
|
-
Also see [production mode][
|
|
708
|
+
Also see [production mode][21].
|
|
707
709
|
|
|
708
710
|
### ts-unused-exports
|
|
709
711
|
|
|
@@ -725,21 +727,23 @@ The following commands are similar:
|
|
|
725
727
|
|
|
726
728
|
Many thanks to some of the early adopters of Knip:
|
|
727
729
|
|
|
728
|
-
- [Block Protocol][
|
|
729
|
-
- [DeepmergeTS][
|
|
730
|
-
- [eslint-plugin-functional][
|
|
731
|
-
- [freeCodeCamp.org][
|
|
732
|
-
- [is-immutable-type][
|
|
733
|
-
- [IsaacScript][
|
|
734
|
-
- [
|
|
735
|
-
- [
|
|
736
|
-
- [
|
|
730
|
+
- [Block Protocol][52]
|
|
731
|
+
- [DeepmergeTS][53]
|
|
732
|
+
- [eslint-plugin-functional][54]
|
|
733
|
+
- [freeCodeCamp.org][55]
|
|
734
|
+
- [is-immutable-type][56]
|
|
735
|
+
- [IsaacScript][57]
|
|
736
|
+
- [Nuxt][58]
|
|
737
|
+
- [Owncast][59]
|
|
738
|
+
- [release-it][60]
|
|
739
|
+
- [Template TypeScript Node Package][61]
|
|
740
|
+
- [Tipi][62]
|
|
737
741
|
|
|
738
742
|
## Articles, etc.
|
|
739
743
|
|
|
740
|
-
- Ask your questions in the [Knip knowledge base][
|
|
741
|
-
- Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][
|
|
742
|
-
- Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][
|
|
744
|
+
- Ask your questions in the [Knip knowledge base][63] (powered by OpenAI and [7-docs][64], experimental!)
|
|
745
|
+
- Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][65]
|
|
746
|
+
- Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][66]
|
|
743
747
|
|
|
744
748
|
## Why "Knip"?
|
|
745
749
|
|
|
@@ -757,7 +761,7 @@ each file, and traversing all of this, why not collect the various issues in one
|
|
|
757
761
|
|
|
758
762
|
Special thanks to the wonderful people who have contributed to this project:
|
|
759
763
|
|
|
760
|
-
[![Contributors][
|
|
764
|
+
[![Contributors][68]][67]
|
|
761
765
|
|
|
762
766
|
[1]: #workspaces
|
|
763
767
|
[2]: #plugins
|
|
@@ -766,63 +770,67 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
766
770
|
[5]: #custom-reporters
|
|
767
771
|
[6]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
768
772
|
[7]: ./assets/cow-with-orange-scissors-van-gogh-style.webp
|
|
769
|
-
[8]:
|
|
770
|
-
[9]:
|
|
771
|
-
[10]: #
|
|
772
|
-
[11]: #
|
|
773
|
-
[12]: #configuration
|
|
774
|
-
[13]: #
|
|
775
|
-
[14]: #
|
|
776
|
-
[15]: #
|
|
777
|
-
[16]: #ignore-
|
|
778
|
-
[17]: #
|
|
779
|
-
[18]: #
|
|
780
|
-
[19]: #
|
|
781
|
-
[20]: #
|
|
782
|
-
[21]: #
|
|
783
|
-
[22]: #
|
|
784
|
-
[23]: #
|
|
785
|
-
[24]: #
|
|
786
|
-
[25]: #
|
|
787
|
-
[26]: #
|
|
788
|
-
[27]: #
|
|
789
|
-
[28]: #
|
|
790
|
-
[29]: #
|
|
791
|
-
[30]: #
|
|
792
|
-
[31]: #
|
|
793
|
-
[32]: #
|
|
794
|
-
[33]: #
|
|
795
|
-
[34]: #
|
|
796
|
-
[35]: #
|
|
797
|
-
[36]: #
|
|
798
|
-
[37]: #
|
|
799
|
-
[38]: #
|
|
800
|
-
[39]:
|
|
801
|
-
[40]:
|
|
802
|
-
[41]:
|
|
803
|
-
[42]:
|
|
804
|
-
[43]: ./docs/
|
|
805
|
-
[44]:
|
|
806
|
-
[45]: ./docs/
|
|
807
|
-
[46]:
|
|
808
|
-
[47]:
|
|
809
|
-
[48]: https://github.com/
|
|
810
|
-
[49]: https://github.com/
|
|
811
|
-
[50]: https://github.com/
|
|
812
|
-
[51]: https://github.com/
|
|
813
|
-
[52]: https://github.com/
|
|
814
|
-
[53]: https://github.com/
|
|
815
|
-
[54]: https://github.com/
|
|
816
|
-
[55]: https://github.com/
|
|
817
|
-
[56]: https://github.com/
|
|
818
|
-
[57]: https://github.com/
|
|
819
|
-
[58]: https://github.com/
|
|
820
|
-
[59]: https://
|
|
821
|
-
[60]: https://github.com/
|
|
822
|
-
[61]: https://
|
|
823
|
-
[62]: https://
|
|
824
|
-
[63]: https://
|
|
825
|
-
[64]: https://
|
|
773
|
+
[8]: https://twitter.com/webprolific
|
|
774
|
+
[9]: https://fosstodon.org/@webpro
|
|
775
|
+
[10]: #getting-started
|
|
776
|
+
[11]: #installation
|
|
777
|
+
[12]: #default-configuration
|
|
778
|
+
[13]: #lets-go
|
|
779
|
+
[14]: #configuration
|
|
780
|
+
[15]: #entry-files
|
|
781
|
+
[16]: #ignore-files-binaries-dependencies-and-workspaces
|
|
782
|
+
[17]: #public-exports
|
|
783
|
+
[18]: #ignore-exports-used-in-file
|
|
784
|
+
[19]: #include-exports-in-entry-files
|
|
785
|
+
[20]: #paths
|
|
786
|
+
[21]: #production-mode
|
|
787
|
+
[22]: #strict
|
|
788
|
+
[23]: #plugins-1
|
|
789
|
+
[24]: #output
|
|
790
|
+
[25]: #screenshots
|
|
791
|
+
[26]: #reading-the-report
|
|
792
|
+
[27]: #rules--filters
|
|
793
|
+
[28]: #fixing-issues
|
|
794
|
+
[29]: #command-line-options
|
|
795
|
+
[30]: #potential-boost-with---no-gitignore
|
|
796
|
+
[31]: #comparison--migration
|
|
797
|
+
[32]: #depcheck
|
|
798
|
+
[33]: #unimported
|
|
799
|
+
[34]: #ts-unused-exports
|
|
800
|
+
[35]: #ts-prune
|
|
801
|
+
[36]: #projects-using-knip
|
|
802
|
+
[37]: #articles-etc
|
|
803
|
+
[38]: #why-knip
|
|
804
|
+
[39]: #really-another-unused-filedependencyexport-finder
|
|
805
|
+
[40]: #contributors
|
|
806
|
+
[41]: https://nx.dev/concepts/integrated-vs-package-based
|
|
807
|
+
[42]: ./docs/writing-a-plugin.md
|
|
808
|
+
[43]: ./docs/compilers.md
|
|
809
|
+
[44]: #handling-issues
|
|
810
|
+
[45]: ./docs/custom-reporters.md
|
|
811
|
+
[46]: ./docs/handling-issues.md
|
|
812
|
+
[47]: ./docs/perf-boost-with-no-gitignore.md
|
|
813
|
+
[48]: https://github.com/depcheck/depcheck
|
|
814
|
+
[49]: https://github.com/smeijer/unimported
|
|
815
|
+
[50]: https://github.com/pzavolinsky/ts-unused-exports
|
|
816
|
+
[51]: https://github.com/nadeesha/ts-prune
|
|
817
|
+
[52]: https://github.com/blockprotocol/blockprotocol
|
|
818
|
+
[53]: https://github.com/RebeccaStevens/deepmerge-ts
|
|
819
|
+
[54]: https://github.com/eslint-functional/eslint-plugin-functional
|
|
820
|
+
[55]: https://github.com/freeCodeCamp/freeCodeCamp
|
|
821
|
+
[56]: https://github.com/RebeccaStevens/is-immutable-type
|
|
822
|
+
[57]: https://github.com/IsaacScript/isaacscript
|
|
823
|
+
[58]: https://github.com/nuxt/nuxt
|
|
824
|
+
[59]: https://github.com/owncast/owncast
|
|
825
|
+
[60]: https://github.com/release-it/release-it
|
|
826
|
+
[61]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
|
|
827
|
+
[62]: https://github.com/meienberger/runtipi
|
|
828
|
+
[63]: https://knip.deno.dev
|
|
829
|
+
[64]: https://github.com/7-docs/7-docs
|
|
830
|
+
[65]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
|
|
831
|
+
[66]: https://effectivetypescript.com/2023/07/29/knip/
|
|
832
|
+
[67]: https://github.com/webpro/knip/graphs/contributors
|
|
833
|
+
[68]: https://contrib.rocks/image?repo=webpro/knip
|
|
826
834
|
[plugin-ava]: ./src/plugins/ava
|
|
827
835
|
[plugin-babel]: ./src/plugins/babel
|
|
828
836
|
[plugin-capacitor]: ./src/plugins/capacitor
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isGitIgnoredSync } from 'globby';
|
|
1
2
|
import ts from 'typescript';
|
|
2
3
|
import { DEFAULT_EXTENSIONS } from './constants.js';
|
|
3
4
|
import { IGNORED_FILE_EXTENSIONS } from './constants.js';
|
|
@@ -6,7 +7,7 @@ import { createHosts } from './typescript/createHosts.js';
|
|
|
6
7
|
import { getImportsAndExports } from './typescript/getImportsAndExports.js';
|
|
7
8
|
import { SourceFileManager } from './typescript/SourceFileManager.js';
|
|
8
9
|
import { isMaybePackageName } from './util/modules.js';
|
|
9
|
-
import { extname, isInNodeModules } from './util/path.js';
|
|
10
|
+
import { extname, isInNodeModules, join } from './util/path.js';
|
|
10
11
|
import { timerify } from './util/Performance.js';
|
|
11
12
|
const baseCompilerOptions = {
|
|
12
13
|
allowJs: true,
|
|
@@ -22,6 +23,7 @@ const baseCompilerOptions = {
|
|
|
22
23
|
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
23
24
|
};
|
|
24
25
|
const tsCreateProgram = timerify(ts.createProgram);
|
|
26
|
+
const isGitIgnored = isGitIgnoredSync();
|
|
25
27
|
export class ProjectPrincipal {
|
|
26
28
|
entryPaths = new Set();
|
|
27
29
|
projectPaths = new Set();
|
|
@@ -125,13 +127,17 @@ export class ProjectPrincipal {
|
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
129
|
else {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
const sanitizedSpecifier = specifier.replace(/^([?!|-]+)?([^!?]+).*/, '$2');
|
|
131
|
+
if (isMaybePackageName(sanitizedSpecifier)) {
|
|
132
|
+
external.add(sanitizedSpecifier);
|
|
130
133
|
}
|
|
131
134
|
else {
|
|
132
|
-
const
|
|
133
|
-
if (!
|
|
134
|
-
|
|
135
|
+
const isIgnored = isGitIgnored(join(filePath, sanitizedSpecifier));
|
|
136
|
+
if (!isIgnored) {
|
|
137
|
+
const ext = extname(sanitizedSpecifier);
|
|
138
|
+
if (!ext || (ext !== '.json' && !IGNORED_FILE_EXTENSIONS.includes(ext))) {
|
|
139
|
+
unresolvedImports.add(specifier);
|
|
140
|
+
}
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.19.
|
|
1
|
+
export declare const version = "2.19.5";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.19.
|
|
1
|
+
export const version = '2.19.5';
|
package/package.json
CHANGED