knip 2.19.4 → 2.20.0-preprocess.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 +125 -116
- package/dist/ProjectPrincipal.js +12 -6
- package/dist/cli.js +14 -5
- package/dist/index.d.ts +1 -1
- package/dist/types/issues.d.ts +1 -1
- package/dist/util/cli-arguments.d.ts +3 -2
- package/dist/util/cli-arguments.js +4 -2
- 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
|
|
@@ -635,7 +637,8 @@ for false positives, and how to handle them.
|
|
|
635
637
|
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
636
638
|
--include-entry-exports Include entry files when reporting unused exports
|
|
637
639
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
638
|
-
--
|
|
640
|
+
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
641
|
+
--reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
|
|
639
642
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
640
643
|
--no-config-hints Suppress configuration hints
|
|
641
644
|
--no-exit-code Always exit with code zero (0)
|
|
@@ -661,13 +664,13 @@ for false positives, and how to handle them.
|
|
|
661
664
|
|
|
662
665
|
## Potential boost with `--no-gitignore`
|
|
663
666
|
|
|
664
|
-
To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][
|
|
667
|
+
To increase performance in a large monorepo, check out [Potential boost with `--no-gitignore`][47].
|
|
665
668
|
|
|
666
669
|
## Comparison & Migration
|
|
667
670
|
|
|
668
671
|
This table is an ongoing comparison. Based on their docs (please report any mistakes):
|
|
669
672
|
|
|
670
|
-
| Feature | **knip** | [depcheck][
|
|
673
|
+
| Feature | **knip** | [depcheck][48] | [unimported][49] | [ts-unused-exports][50] | [ts-prune][51] |
|
|
671
674
|
| :---------------------- | :------: | :------------: | :--------------: | :---------------------: | :------------: |
|
|
672
675
|
| Unused files | ✅ | - | ✅ | - | - |
|
|
673
676
|
| Unused dependencies | ✅ | ✅ | ✅ | - | - |
|
|
@@ -703,7 +706,7 @@ The following commands are similar:
|
|
|
703
706
|
unimported
|
|
704
707
|
knip --production --dependencies --include files
|
|
705
708
|
|
|
706
|
-
Also see [production mode][
|
|
709
|
+
Also see [production mode][21].
|
|
707
710
|
|
|
708
711
|
### ts-unused-exports
|
|
709
712
|
|
|
@@ -725,21 +728,23 @@ The following commands are similar:
|
|
|
725
728
|
|
|
726
729
|
Many thanks to some of the early adopters of Knip:
|
|
727
730
|
|
|
728
|
-
- [Block Protocol][
|
|
729
|
-
- [DeepmergeTS][
|
|
730
|
-
- [eslint-plugin-functional][
|
|
731
|
-
- [freeCodeCamp.org][
|
|
732
|
-
- [is-immutable-type][
|
|
733
|
-
- [IsaacScript][
|
|
734
|
-
- [
|
|
735
|
-
- [
|
|
736
|
-
- [
|
|
731
|
+
- [Block Protocol][52]
|
|
732
|
+
- [DeepmergeTS][53]
|
|
733
|
+
- [eslint-plugin-functional][54]
|
|
734
|
+
- [freeCodeCamp.org][55]
|
|
735
|
+
- [is-immutable-type][56]
|
|
736
|
+
- [IsaacScript][57]
|
|
737
|
+
- [Nuxt][58]
|
|
738
|
+
- [Owncast][59]
|
|
739
|
+
- [release-it][60]
|
|
740
|
+
- [Template TypeScript Node Package][61]
|
|
741
|
+
- [Tipi][62]
|
|
737
742
|
|
|
738
743
|
## Articles, etc.
|
|
739
744
|
|
|
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][
|
|
745
|
+
- Ask your questions in the [Knip knowledge base][63] (powered by OpenAI and [7-docs][64], experimental!)
|
|
746
|
+
- Smashing Magazine: [Knip: An Automated Tool For Finding Unused Files, Exports, And Dependencies][65]
|
|
747
|
+
- Effective TypeScript: [Recommendation Update: ✂️ Use knip to detect dead code and types][66]
|
|
743
748
|
|
|
744
749
|
## Why "Knip"?
|
|
745
750
|
|
|
@@ -757,7 +762,7 @@ each file, and traversing all of this, why not collect the various issues in one
|
|
|
757
762
|
|
|
758
763
|
Special thanks to the wonderful people who have contributed to this project:
|
|
759
764
|
|
|
760
|
-
[![Contributors][
|
|
765
|
+
[![Contributors][68]][67]
|
|
761
766
|
|
|
762
767
|
[1]: #workspaces
|
|
763
768
|
[2]: #plugins
|
|
@@ -766,63 +771,67 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
766
771
|
[5]: #custom-reporters
|
|
767
772
|
[6]: https://labs.openai.com/s/xZQACaLepaKya0PRUPtIN5dC
|
|
768
773
|
[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://
|
|
774
|
+
[8]: https://twitter.com/webprolific
|
|
775
|
+
[9]: https://fosstodon.org/@webpro
|
|
776
|
+
[10]: #getting-started
|
|
777
|
+
[11]: #installation
|
|
778
|
+
[12]: #default-configuration
|
|
779
|
+
[13]: #lets-go
|
|
780
|
+
[14]: #configuration
|
|
781
|
+
[15]: #entry-files
|
|
782
|
+
[16]: #ignore-files-binaries-dependencies-and-workspaces
|
|
783
|
+
[17]: #public-exports
|
|
784
|
+
[18]: #ignore-exports-used-in-file
|
|
785
|
+
[19]: #include-exports-in-entry-files
|
|
786
|
+
[20]: #paths
|
|
787
|
+
[21]: #production-mode
|
|
788
|
+
[22]: #strict
|
|
789
|
+
[23]: #plugins-1
|
|
790
|
+
[24]: #output
|
|
791
|
+
[25]: #screenshots
|
|
792
|
+
[26]: #reading-the-report
|
|
793
|
+
[27]: #rules--filters
|
|
794
|
+
[28]: #fixing-issues
|
|
795
|
+
[29]: #command-line-options
|
|
796
|
+
[30]: #potential-boost-with---no-gitignore
|
|
797
|
+
[31]: #comparison--migration
|
|
798
|
+
[32]: #depcheck
|
|
799
|
+
[33]: #unimported
|
|
800
|
+
[34]: #ts-unused-exports
|
|
801
|
+
[35]: #ts-prune
|
|
802
|
+
[36]: #projects-using-knip
|
|
803
|
+
[37]: #articles-etc
|
|
804
|
+
[38]: #why-knip
|
|
805
|
+
[39]: #really-another-unused-filedependencyexport-finder
|
|
806
|
+
[40]: #contributors
|
|
807
|
+
[41]: https://nx.dev/concepts/integrated-vs-package-based
|
|
808
|
+
[42]: ./docs/writing-a-plugin.md
|
|
809
|
+
[43]: ./docs/compilers.md
|
|
810
|
+
[44]: #handling-issues
|
|
811
|
+
[45]: ./docs/custom-reporters.md
|
|
812
|
+
[46]: ./docs/handling-issues.md
|
|
813
|
+
[47]: ./docs/perf-boost-with-no-gitignore.md
|
|
814
|
+
[48]: https://github.com/depcheck/depcheck
|
|
815
|
+
[49]: https://github.com/smeijer/unimported
|
|
816
|
+
[50]: https://github.com/pzavolinsky/ts-unused-exports
|
|
817
|
+
[51]: https://github.com/nadeesha/ts-prune
|
|
818
|
+
[52]: https://github.com/blockprotocol/blockprotocol
|
|
819
|
+
[53]: https://github.com/RebeccaStevens/deepmerge-ts
|
|
820
|
+
[54]: https://github.com/eslint-functional/eslint-plugin-functional
|
|
821
|
+
[55]: https://github.com/freeCodeCamp/freeCodeCamp
|
|
822
|
+
[56]: https://github.com/RebeccaStevens/is-immutable-type
|
|
823
|
+
[57]: https://github.com/IsaacScript/isaacscript
|
|
824
|
+
[58]: https://github.com/nuxt/nuxt
|
|
825
|
+
[59]: https://github.com/owncast/owncast
|
|
826
|
+
[60]: https://github.com/release-it/release-it
|
|
827
|
+
[61]: https://github.com/JoshuaKGoldberg/template-typescript-node-package
|
|
828
|
+
[62]: https://github.com/meienberger/runtipi
|
|
829
|
+
[63]: https://knip.deno.dev
|
|
830
|
+
[64]: https://github.com/7-docs/7-docs
|
|
831
|
+
[65]: https://www.smashingmagazine.com/2023/08/knip-automated-tool-find-unused-files-exports-dependencies/
|
|
832
|
+
[66]: https://effectivetypescript.com/2023/07/29/knip/
|
|
833
|
+
[67]: https://github.com/webpro/knip/graphs/contributors
|
|
834
|
+
[68]: https://contrib.rocks/image?repo=webpro/knip
|
|
826
835
|
[plugin-ava]: ./src/plugins/ava
|
|
827
836
|
[plugin-babel]: ./src/plugins/babel
|
|
828
837
|
[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/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import './util/register.js';
|
|
3
3
|
import prettyMilliseconds from 'pretty-ms';
|
|
4
|
-
import
|
|
4
|
+
import internalReporters from './reporters/index.js';
|
|
5
5
|
import parsedArgValues, { helpText } from './util/cli-arguments.js';
|
|
6
6
|
import { isKnownError, getKnownError, isConfigurationError, hasCause } from './util/errors.js';
|
|
7
7
|
import { _load } from './util/loader.js';
|
|
@@ -9,7 +9,7 @@ import { cwd, resolve } from './util/path.js';
|
|
|
9
9
|
import { Performance } from './util/Performance.js';
|
|
10
10
|
import { version } from './version.js';
|
|
11
11
|
import { main } from './index.js';
|
|
12
|
-
const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'include-entry-exports': isIncludeEntryExports = false, performance: isObservePerf = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
|
|
12
|
+
const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'include-entry-exports': isIncludeEntryExports = false, performance: isObservePerf = false, production: isProduction = false, preprocessor = [], reporter = ['symbols'], 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
|
|
13
13
|
if (isHelp) {
|
|
14
14
|
console.log(helpText);
|
|
15
15
|
process.exit(0);
|
|
@@ -19,7 +19,13 @@ if (isVersion) {
|
|
|
19
19
|
process.exit(0);
|
|
20
20
|
}
|
|
21
21
|
const isShowProgress = !isDebug && isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
|
|
22
|
-
const
|
|
22
|
+
const preprocessors = await Promise.all(preprocessor.map(processor => _load(resolve(processor))));
|
|
23
|
+
const processAsync = (data, processors) => processors.length === 0 ? Promise.resolve(data) : processAsync(processors[0](data), processors.slice(1));
|
|
24
|
+
const reporters = await Promise.all(reporter.map(async (reporter) => {
|
|
25
|
+
return reporter in internalReporters
|
|
26
|
+
? internalReporters[reporter]
|
|
27
|
+
: await _load(resolve(reporter));
|
|
28
|
+
}));
|
|
23
29
|
const run = async () => {
|
|
24
30
|
try {
|
|
25
31
|
const perfObserver = new Performance(isObservePerf);
|
|
@@ -32,7 +38,7 @@ const run = async () => {
|
|
|
32
38
|
isShowProgress,
|
|
33
39
|
isIncludeEntryExports,
|
|
34
40
|
});
|
|
35
|
-
|
|
41
|
+
const initialData = {
|
|
36
42
|
report,
|
|
37
43
|
issues,
|
|
38
44
|
configurationHints,
|
|
@@ -41,7 +47,10 @@ const run = async () => {
|
|
|
41
47
|
isProduction,
|
|
42
48
|
isShowProgress,
|
|
43
49
|
options: reporterOptions,
|
|
44
|
-
}
|
|
50
|
+
};
|
|
51
|
+
const finalData = await processAsync(initialData, preprocessors);
|
|
52
|
+
for (const reporter of reporters)
|
|
53
|
+
await reporter(finalData);
|
|
45
54
|
const totalErrorCount = Object.keys(report)
|
|
46
55
|
.filter(reportGroup => report[reportGroup] && rules[reportGroup] === 'error')
|
|
47
56
|
.reduce((errorCount, reportGroup) => errorCount + counters[reportGroup], 0);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommandLineOptions } from './types/cli.js';
|
|
2
2
|
export type { RawConfiguration as KnipConfig } from './types/config.js';
|
|
3
|
-
export type { Reporter, ReporterOptions } from './types/issues.js';
|
|
3
|
+
export type { Preprocessor, Reporter, ReporterOptions } from './types/issues.js';
|
|
4
4
|
export declare const main: (unresolvedConfiguration: CommandLineOptions) => Promise<{
|
|
5
5
|
report: import("./types/issues.js").Report;
|
|
6
6
|
issues: import("./types/issues.js").Issues;
|
package/dist/types/issues.d.ts
CHANGED
|
@@ -45,12 +45,12 @@ export type ReporterOptions = {
|
|
|
45
45
|
configurationHints: ConfigurationHints;
|
|
46
46
|
noConfigHints: boolean;
|
|
47
47
|
cwd: string;
|
|
48
|
-
workingDir: string;
|
|
49
48
|
isProduction: boolean;
|
|
50
49
|
isShowProgress: boolean;
|
|
51
50
|
options: string;
|
|
52
51
|
};
|
|
53
52
|
export type Reporter = (options: ReporterOptions) => void;
|
|
53
|
+
export type Preprocessor = (options: ReporterOptions) => ReporterOptions;
|
|
54
54
|
export type IssueSeverity = 'error' | 'warn' | 'off';
|
|
55
55
|
export type Rules = Record<IssueType, IssueSeverity>;
|
|
56
56
|
export type ConfigurationHints = Set<ConfigurationHint>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
1
|
+
export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
config: string | undefined;
|
|
4
4
|
debug: boolean | undefined;
|
|
@@ -16,7 +16,8 @@ declare const _default: {
|
|
|
16
16
|
'no-progress': boolean | undefined;
|
|
17
17
|
performance: boolean | undefined;
|
|
18
18
|
production: boolean | undefined;
|
|
19
|
-
|
|
19
|
+
preprocessor: string[] | undefined;
|
|
20
|
+
reporter: string[] | undefined;
|
|
20
21
|
'reporter-options': string | undefined;
|
|
21
22
|
strict: boolean | undefined;
|
|
22
23
|
tsConfig: string | undefined;
|
|
@@ -16,7 +16,8 @@ Options:
|
|
|
16
16
|
--exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
|
|
17
17
|
--include-entry-exports Include entry files when reporting unused exports
|
|
18
18
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
19
|
-
--
|
|
19
|
+
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
20
|
+
--reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
|
|
20
21
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
21
22
|
--no-config-hints Suppress configuration hints
|
|
22
23
|
--no-exit-code Always exit with code zero (0)
|
|
@@ -59,7 +60,8 @@ try {
|
|
|
59
60
|
'no-progress': { type: 'boolean', short: 'n' },
|
|
60
61
|
performance: { type: 'boolean' },
|
|
61
62
|
production: { type: 'boolean' },
|
|
62
|
-
|
|
63
|
+
preprocessor: { type: 'string', multiple: true },
|
|
64
|
+
reporter: { type: 'string', multiple: true },
|
|
63
65
|
'reporter-options': { type: 'string' },
|
|
64
66
|
strict: { type: 'boolean' },
|
|
65
67
|
tsConfig: { type: 'string', short: 't' },
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.20.0-preprocess.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.20.0-preprocess.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.0-preprocess.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",
|