knip 2.29.0 → 2.30.1
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 +34 -16
- package/dist/DependencyDeputy.d.ts +3 -0
- package/dist/DependencyDeputy.js +11 -0
- package/dist/WorkspaceWorker.d.ts +2 -0
- package/dist/WorkspaceWorker.js +4 -1
- package/dist/constants.js +1 -0
- package/dist/index.js +2 -1
- package/dist/manifest/index.d.ts +1 -0
- package/dist/manifest/index.js +5 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -80,7 +80,9 @@ For updates or questions, come hang out in [The Knip Barn (Discord)][10], or fol
|
|
|
80
80
|
|
|
81
81
|
### Installation
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
```
|
|
84
|
+
npm install -D knip
|
|
85
|
+
```
|
|
84
86
|
|
|
85
87
|
Knip supports LTS versions of Node.js, and currently requires at least Node.js v16.17 or v18.6.
|
|
86
88
|
|
|
@@ -445,7 +447,9 @@ In a more fine-grained manner, you can also ignore only specific issue types:
|
|
|
445
447
|
|
|
446
448
|
When a repository is self-contained or private, you may want to include entry files when reporting unused exports:
|
|
447
449
|
|
|
448
|
-
|
|
450
|
+
```
|
|
451
|
+
knip --include-entry-exports
|
|
452
|
+
```
|
|
449
453
|
|
|
450
454
|
Knip will also report unused exports in entry source files and scripts (such as those referenced in `package.json`). But
|
|
451
455
|
not in entry and configuration files from plugins, such as `next.config.js` or `src/routes/+page.svelte`.
|
|
@@ -587,12 +591,16 @@ Alternatively, they can be added to the configuration (e.g. `"exclude": ["depend
|
|
|
587
591
|
|
|
588
592
|
Use `--include` to report only specific issue types (the following example commands do the same):
|
|
589
593
|
|
|
590
|
-
|
|
591
|
-
|
|
594
|
+
```
|
|
595
|
+
knip --include files --include dependencies
|
|
596
|
+
knip --include files,dependencies
|
|
597
|
+
```
|
|
592
598
|
|
|
593
599
|
Use `--exclude` to ignore reports you're not interested in:
|
|
594
600
|
|
|
595
|
-
|
|
601
|
+
```
|
|
602
|
+
knip --include files --exclude classMembers,enumMembers
|
|
603
|
+
```
|
|
596
604
|
|
|
597
605
|
Use `--dependencies` or `--exports` as shortcuts to combine groups of related types.
|
|
598
606
|
|
|
@@ -660,7 +668,8 @@ Knip takes the following JSDoc/TSDoc tags into account:
|
|
|
660
668
|
|
|
661
669
|
## Command Line Options
|
|
662
670
|
|
|
663
|
-
|
|
671
|
+
```
|
|
672
|
+
$ npx knip --help
|
|
664
673
|
✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects
|
|
665
674
|
|
|
666
675
|
Usage: knip [options]
|
|
@@ -704,6 +713,7 @@ Knip takes the following JSDoc/TSDoc tags into account:
|
|
|
704
713
|
$ knip --debug --debug-file-filter '(specific|particular)-module'
|
|
705
714
|
|
|
706
715
|
More documentation and bug reports: https://github.com/webpro/knip
|
|
716
|
+
```
|
|
707
717
|
|
|
708
718
|
## Potential boost with `--no-gitignore`
|
|
709
719
|
|
|
@@ -739,15 +749,19 @@ Below some similar commands to get another idea of what Knip does in comparison:
|
|
|
739
749
|
|
|
740
750
|
The following commands are similar:
|
|
741
751
|
|
|
742
|
-
|
|
743
|
-
|
|
752
|
+
```
|
|
753
|
+
depcheck
|
|
754
|
+
knip --dependencies
|
|
755
|
+
```
|
|
744
756
|
|
|
745
757
|
### unimported
|
|
746
758
|
|
|
747
759
|
The following commands are similar:
|
|
748
760
|
|
|
749
|
-
|
|
750
|
-
|
|
761
|
+
```
|
|
762
|
+
unimported
|
|
763
|
+
knip --production --dependencies --include files
|
|
764
|
+
```
|
|
751
765
|
|
|
752
766
|
Also see [production mode][25].
|
|
753
767
|
|
|
@@ -755,17 +769,21 @@ Also see [production mode][25].
|
|
|
755
769
|
|
|
756
770
|
The following commands are similar:
|
|
757
771
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
772
|
+
```
|
|
773
|
+
ts-unused-exports
|
|
774
|
+
knip --include exports,types,nsExports,nsTypes
|
|
775
|
+
knip --exports # Adds unused enum and class members
|
|
776
|
+
```
|
|
761
777
|
|
|
762
778
|
### ts-prune
|
|
763
779
|
|
|
764
780
|
The following commands are similar:
|
|
765
781
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
782
|
+
```
|
|
783
|
+
ts-prune
|
|
784
|
+
knip --include exports,types
|
|
785
|
+
knip --exports # Adds unused exports/types in namespaces and unused enum/class members
|
|
786
|
+
```
|
|
769
787
|
|
|
770
788
|
## Projects using Knip
|
|
771
789
|
|
|
@@ -13,6 +13,7 @@ export declare class DependencyDeputy {
|
|
|
13
13
|
referencedBinaries: Map<string, Set<string>>;
|
|
14
14
|
hostDependencies: Map<string, HostDependencies>;
|
|
15
15
|
installedBinaries: Map<string, InstalledBinaries>;
|
|
16
|
+
hasTypesIncluded: Map<string, Set<string>>;
|
|
16
17
|
ignoreBinaries: string[];
|
|
17
18
|
ignoreDependencies: string[];
|
|
18
19
|
constructor({ isStrict }: Options);
|
|
@@ -42,6 +43,8 @@ export declare class DependencyDeputy {
|
|
|
42
43
|
getDevDependencies(workspaceName: string): string[];
|
|
43
44
|
setInstalledBinaries(workspaceName: string, installedBinaries: Map<string, Set<string>>): void;
|
|
44
45
|
getInstalledBinaries(workspaceName: string): InstalledBinaries | undefined;
|
|
46
|
+
setHasTypesIncluded(workspaceName: string, hasTypesIncluded: Set<string>): void;
|
|
47
|
+
getHasTypesIncluded(workspaceName: string): InstalledBinaries | undefined;
|
|
45
48
|
addReferencedDependency(workspaceName: string, packageName: string): void;
|
|
46
49
|
addReferencedBinary(workspaceName: string, binaryName: string): void;
|
|
47
50
|
addHostDependencies(workspaceName: string, hostDependencies: HostDependencies): void;
|
package/dist/DependencyDeputy.js
CHANGED
|
@@ -8,6 +8,7 @@ export class DependencyDeputy {
|
|
|
8
8
|
referencedBinaries;
|
|
9
9
|
hostDependencies;
|
|
10
10
|
installedBinaries;
|
|
11
|
+
hasTypesIncluded;
|
|
11
12
|
ignoreBinaries = [];
|
|
12
13
|
ignoreDependencies = [];
|
|
13
14
|
constructor({ isStrict }) {
|
|
@@ -16,6 +17,7 @@ export class DependencyDeputy {
|
|
|
16
17
|
this.referencedBinaries = new Map();
|
|
17
18
|
this.hostDependencies = new Map();
|
|
18
19
|
this.installedBinaries = new Map();
|
|
20
|
+
this.hasTypesIncluded = new Map();
|
|
19
21
|
}
|
|
20
22
|
addWorkspace({ name, dir, manifestPath, manifest, ignoreDependencies, ignoreBinaries, }) {
|
|
21
23
|
const scripts = Object.values(manifest.scripts ?? {});
|
|
@@ -67,6 +69,12 @@ export class DependencyDeputy {
|
|
|
67
69
|
getInstalledBinaries(workspaceName) {
|
|
68
70
|
return this.installedBinaries.get(workspaceName);
|
|
69
71
|
}
|
|
72
|
+
setHasTypesIncluded(workspaceName, hasTypesIncluded) {
|
|
73
|
+
this.hasTypesIncluded.set(workspaceName, hasTypesIncluded);
|
|
74
|
+
}
|
|
75
|
+
getHasTypesIncluded(workspaceName) {
|
|
76
|
+
return this.installedBinaries.get(workspaceName);
|
|
77
|
+
}
|
|
70
78
|
addReferencedDependency(workspaceName, packageName) {
|
|
71
79
|
if (!this.referencedDependencies.has(workspaceName)) {
|
|
72
80
|
this.referencedDependencies.set(workspaceName, new Set());
|
|
@@ -155,6 +163,7 @@ export class DependencyDeputy {
|
|
|
155
163
|
for (const [workspaceName, { manifestPath, ignoreDependencies, ignoreBinaries }] of this._manifests.entries()) {
|
|
156
164
|
const referencedDependencies = this.referencedDependencies.get(workspaceName);
|
|
157
165
|
const installedBinaries = this.getInstalledBinaries(workspaceName);
|
|
166
|
+
const hasTypesIncluded = this.getHasTypesIncluded(workspaceName);
|
|
158
167
|
const ignoreBins = [...IGNORED_GLOBAL_BINARIES, ...this.ignoreBinaries, ...ignoreBinaries];
|
|
159
168
|
const ignoreDeps = [...IGNORED_DEPENDENCIES, ...this.ignoreDependencies, ...ignoreDependencies];
|
|
160
169
|
const isNotIgnoredDependency = (packageName) => !ignoreDeps.includes(packageName);
|
|
@@ -176,6 +185,8 @@ export class DependencyDeputy {
|
|
|
176
185
|
return false;
|
|
177
186
|
const [scope, typedDependency] = dependency.split('/');
|
|
178
187
|
if (scope === '@types') {
|
|
188
|
+
if (hasTypesIncluded?.has(typedDependency))
|
|
189
|
+
return false;
|
|
179
190
|
const typedPackageName = getPackageFromDefinitelyTyped(typedDependency);
|
|
180
191
|
if (IGNORE_DEFINITELY_TYPED.includes(typedPackageName))
|
|
181
192
|
return true;
|
|
@@ -30,6 +30,7 @@ export declare class WorkspaceWorker {
|
|
|
30
30
|
referencedDependencies: ReferencedDependencies;
|
|
31
31
|
hostDependencies: HostDependencies;
|
|
32
32
|
installedBinaries: InstalledBinaries;
|
|
33
|
+
hasTypesIncluded: Set<string>;
|
|
33
34
|
constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
|
|
34
35
|
init(): Promise<void>;
|
|
35
36
|
private setEnabledPlugins;
|
|
@@ -50,6 +51,7 @@ export declare class WorkspaceWorker {
|
|
|
50
51
|
hostDependencies: HostDependencies;
|
|
51
52
|
installedBinaries: InstalledBinaries;
|
|
52
53
|
referencedDependencies: ReferencedDependencies;
|
|
54
|
+
hasTypesIncluded: Set<string>;
|
|
53
55
|
enabledPlugins: ("angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "drizzle" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
54
56
|
}>;
|
|
55
57
|
}
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -22,6 +22,7 @@ export class WorkspaceWorker {
|
|
|
22
22
|
referencedDependencies = new Set();
|
|
23
23
|
hostDependencies = new Map();
|
|
24
24
|
installedBinaries = new Map();
|
|
25
|
+
hasTypesIncluded = new Set();
|
|
25
26
|
constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
|
|
26
27
|
this.name = name;
|
|
27
28
|
this.dir = dir;
|
|
@@ -59,7 +60,7 @@ export class WorkspaceWorker {
|
|
|
59
60
|
debugLogObject(`Enabled plugins (${this.name})`, enabledPluginNames);
|
|
60
61
|
}
|
|
61
62
|
async initReferencedDependencies() {
|
|
62
|
-
const { dependencies, hostDependencies, installedBinaries } = await npm.findDependencies({
|
|
63
|
+
const { dependencies, hostDependencies, installedBinaries, hasTypesIncluded } = await npm.findDependencies({
|
|
63
64
|
manifest: this.manifest,
|
|
64
65
|
isProduction: this.isProduction,
|
|
65
66
|
isStrict: this.isStrict,
|
|
@@ -70,6 +71,7 @@ export class WorkspaceWorker {
|
|
|
70
71
|
dependencies.forEach(dependency => this.referencedDependencies.add([filePath, dependency]));
|
|
71
72
|
this.hostDependencies = hostDependencies;
|
|
72
73
|
this.installedBinaries = installedBinaries;
|
|
74
|
+
this.hasTypesIncluded = hasTypesIncluded;
|
|
73
75
|
}
|
|
74
76
|
getConfigForPlugin(pluginName) {
|
|
75
77
|
return this.config[pluginName] ?? { config: null, entry: null, project: null };
|
|
@@ -238,6 +240,7 @@ export class WorkspaceWorker {
|
|
|
238
240
|
hostDependencies: this.hostDependencies,
|
|
239
241
|
installedBinaries: this.installedBinaries,
|
|
240
242
|
referencedDependencies: this.referencedDependencies,
|
|
243
|
+
hasTypesIncluded: this.hasTypesIncluded,
|
|
241
244
|
enabledPlugins: this.enabledPlugins,
|
|
242
245
|
};
|
|
243
246
|
}
|
package/dist/constants.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -168,9 +168,10 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
168
168
|
if (chief.resolvedConfigFilePath)
|
|
169
169
|
principal.addEntryPath(chief.resolvedConfigFilePath, { skipExportsAnalysis: true });
|
|
170
170
|
const dependencies = await worker.findAllDependencies();
|
|
171
|
-
const { referencedDependencies, hostDependencies, installedBinaries, enabledPlugins } = dependencies;
|
|
171
|
+
const { referencedDependencies, hostDependencies, installedBinaries, enabledPlugins, hasTypesIncluded } = dependencies;
|
|
172
172
|
deputy.addHostDependencies(name, hostDependencies);
|
|
173
173
|
deputy.setInstalledBinaries(name, installedBinaries);
|
|
174
|
+
deputy.setHasTypesIncluded(name, hasTypesIncluded);
|
|
174
175
|
enabledPluginsStore.set(name, enabledPlugins);
|
|
175
176
|
referencedDependencies.forEach(([containingFilePath, specifier]) => {
|
|
176
177
|
handleReferencedDependency({ specifier, containingFilePath, principal, workspace });
|
package/dist/manifest/index.d.ts
CHANGED
package/dist/manifest/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _getDependenciesFromScripts } from '../binaries/index.js';
|
|
2
|
+
import { isDefinitelyTyped } from '../util/modules.js';
|
|
2
3
|
import { timerify } from '../util/Performance.js';
|
|
3
4
|
import { getPackageManifest } from './helpers.js';
|
|
4
5
|
const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir, cwd }) => {
|
|
@@ -12,6 +13,7 @@ const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir,
|
|
|
12
13
|
}, []);
|
|
13
14
|
const dependencies = _getDependenciesFromScripts(scripts, { cwd: dir, manifest });
|
|
14
15
|
const installedBinaries = new Map();
|
|
16
|
+
const hasTypesIncluded = new Set();
|
|
15
17
|
const packageNames = [
|
|
16
18
|
...Object.keys(manifest.dependencies ?? {}),
|
|
17
19
|
...(isStrict ? Object.keys(manifest.peerDependencies ?? {}) : []),
|
|
@@ -45,12 +47,15 @@ const findManifestDependencies = async ({ manifest, isProduction, isStrict, dir,
|
|
|
45
47
|
hostDependencies.set(packagePeerDependency, new Set([packageName]));
|
|
46
48
|
}
|
|
47
49
|
});
|
|
50
|
+
if (!isDefinitelyTyped(packageName) && (manifest.types || manifest.typings))
|
|
51
|
+
hasTypesIncluded.add(packageName);
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
return {
|
|
51
55
|
dependencies,
|
|
52
56
|
hostDependencies,
|
|
53
57
|
installedBinaries,
|
|
58
|
+
hasTypesIncluded,
|
|
54
59
|
};
|
|
55
60
|
};
|
|
56
61
|
export const findDependencies = timerify(findManifestDependencies);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.30.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.30.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.30.1",
|
|
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",
|
|
@@ -65,27 +65,27 @@
|
|
|
65
65
|
"@npmcli/package-json": "5.0.0",
|
|
66
66
|
"@release-it/bumper": "5.1.0",
|
|
67
67
|
"@swc/cli": "0.1.62",
|
|
68
|
-
"@swc/core": "1.3.
|
|
68
|
+
"@swc/core": "1.3.91",
|
|
69
69
|
"@types/eslint": "8.44.3",
|
|
70
70
|
"@types/js-yaml": "4.0.6",
|
|
71
|
-
"@types/micromatch": "4.0.
|
|
72
|
-
"@types/minimist": "1.2.
|
|
73
|
-
"@types/node": "20.
|
|
71
|
+
"@types/micromatch": "4.0.3",
|
|
72
|
+
"@types/minimist": "1.2.3",
|
|
73
|
+
"@types/node": "20.8.2",
|
|
74
74
|
"@types/npmcli__map-workspaces": "3.0.2",
|
|
75
75
|
"@types/webpack": "5.28.3",
|
|
76
|
-
"@typescript-eslint/eslint-plugin": "6.7.
|
|
77
|
-
"@typescript-eslint/parser": "6.7.
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "6.7.4",
|
|
77
|
+
"@typescript-eslint/parser": "6.7.4",
|
|
78
78
|
"c8": "8.0.1",
|
|
79
79
|
"eslint": "8.50.0",
|
|
80
80
|
"eslint-import-resolver-typescript": "3.6.1",
|
|
81
81
|
"eslint-plugin-import": "2.28.1",
|
|
82
82
|
"eslint-plugin-n": "16.1.0",
|
|
83
83
|
"prettier": "3.0.3",
|
|
84
|
-
"release-it": "16.2.
|
|
85
|
-
"remark-cli": "
|
|
86
|
-
"remark-preset-webpro": "0.0
|
|
84
|
+
"release-it": "16.2.1",
|
|
85
|
+
"remark-cli": "12.0.0",
|
|
86
|
+
"remark-preset-webpro": "1.0.0",
|
|
87
87
|
"tsx": "3.13.0",
|
|
88
|
-
"type-fest": "4.3.
|
|
88
|
+
"type-fest": "4.3.3"
|
|
89
89
|
},
|
|
90
90
|
"engines": {
|
|
91
91
|
"node": ">=16.17.0 <17 || >=18.6.0"
|