knip 2.33.4 → 2.34.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 +25 -7
- package/dist/ConfigurationChief.d.ts +1 -0
- package/dist/ConfigurationChief.js +13 -1
- package/dist/ConfigurationValidator.d.ts +56 -0
- package/dist/ConfigurationValidator.js +1 -0
- package/dist/WorkspaceWorker.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/plugins/astro/index.d.ts +7 -0
- package/dist/plugins/astro/index.js +10 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/nx/index.js +1 -1
- package/dist/typescript/ast-helpers.d.ts +2 -1
- package/dist/typescript/ast-helpers.js +3 -0
- package/dist/typescript/visitors/exports/exportKeyword.js +5 -2
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +2 -0
- package/dist/util/compilers.d.ts +10 -0
- package/dist/util/modules.js +1 -1
- package/dist/util/path.js +3 -1
- package/dist/util/unwrapFunction.d.ts +1 -0
- package/dist/util/unwrapFunction.js +13 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +4 -0
package/README.md
CHANGED
|
@@ -125,6 +125,19 @@ const config: KnipConfig = {
|
|
|
125
125
|
export default config;
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
+
And if you need, you can also expose an (async) function if you need, like so:
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import type { KnipConfig } from 'knip';
|
|
132
|
+
|
|
133
|
+
const config = async (): Promise<KnipConfig> => ({
|
|
134
|
+
entry: ['src/index.ts'],
|
|
135
|
+
project: ['src/**/*.ts'],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
export default config;
|
|
139
|
+
```
|
|
140
|
+
|
|
128
141
|
Use `--config path/to/knip.config.json` for a different path.
|
|
129
142
|
|
|
130
143
|
### Let's Go!
|
|
@@ -251,6 +264,7 @@ This is especially useful over time when such configuration files change (and th
|
|
|
251
264
|
Knip contains a growing list of plugins:
|
|
252
265
|
|
|
253
266
|
- [Angular][plugin-angular]
|
|
267
|
+
- [Astro][plugin-astro]
|
|
254
268
|
- [Ava][plugin-ava]
|
|
255
269
|
- [Babel][plugin-babel]
|
|
256
270
|
- [Capacitor][plugin-capacitor]
|
|
@@ -304,6 +318,8 @@ themselves and/or `entry` files for Knip to analyze.
|
|
|
304
318
|
|
|
305
319
|
See each plugin's documentation for its default values.
|
|
306
320
|
|
|
321
|
+
In an Astro, Svelte or Vue project? Make sure to see [compilers][46] and add some extra configuration.
|
|
322
|
+
|
|
307
323
|
#### `config`
|
|
308
324
|
|
|
309
325
|
Plugins usually include `config` files. They are handled by the plugin's custom dependency finder, which returns all
|
|
@@ -341,7 +357,7 @@ level by setting it to `false` there, and vice versa.
|
|
|
341
357
|
#### Multi-project repositories
|
|
342
358
|
|
|
343
359
|
Some repositories have a single `package.json`, but consist of multiple projects with configuration files across the
|
|
344
|
-
repository (such as the [Nx "intregrated repo" style][
|
|
360
|
+
repository (such as the [Nx "intregrated repo" style][47]). Let's assume some of these projects are apps and have their
|
|
345
361
|
own Cypress configuration and test files. In that case, we could configure the Cypress plugin like this:
|
|
346
362
|
|
|
347
363
|
```json
|
|
@@ -354,7 +370,7 @@ own Cypress configuration and test files. In that case, we could configure the C
|
|
|
354
370
|
|
|
355
371
|
#### Create a new plugin
|
|
356
372
|
|
|
357
|
-
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][
|
|
373
|
+
Getting false positives because a plugin is missing? Want to help out? Please read more at [writing a plugin][48]. This
|
|
358
374
|
guide also contains more details if you want to learn more about plugins and why they are useful.
|
|
359
375
|
|
|
360
376
|
### Compilers
|
|
@@ -377,7 +393,7 @@ export default {
|
|
|
377
393
|
};
|
|
378
394
|
```
|
|
379
395
|
|
|
380
|
-
Read [Compilers][
|
|
396
|
+
Read [Compilers][46] for more details and examples.
|
|
381
397
|
|
|
382
398
|
### Ignore files, binaries, dependencies and workspaces
|
|
383
399
|
|
|
@@ -385,7 +401,7 @@ There are a few ways to tell Knip to ignore certain files, binaries, dependencie
|
|
|
385
401
|
|
|
386
402
|
```json
|
|
387
403
|
{
|
|
388
|
-
"ignore": ["
|
|
404
|
+
"ignore": ["**/fixtures"],
|
|
389
405
|
"ignoreBinaries": ["zip", "docker-compose"],
|
|
390
406
|
"ignoreDependencies": ["hidden-package"],
|
|
391
407
|
"ignoreWorkspaces": ["packages/ignore", "packages/examples/**"]
|
|
@@ -678,6 +694,7 @@ $ npx knip --help
|
|
|
678
694
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
679
695
|
--ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
|
|
680
696
|
-W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
|
|
697
|
+
--directory [dir] Run process from a different directory (default: cwd)
|
|
681
698
|
--no-gitignore Don't use .gitignore
|
|
682
699
|
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
683
700
|
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
@@ -869,9 +886,9 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
869
886
|
[43]: #why-knip
|
|
870
887
|
[44]: #really-another-unused-filedependencyexport-finder
|
|
871
888
|
[45]: #contributors
|
|
872
|
-
[46]:
|
|
873
|
-
[47]:
|
|
874
|
-
[48]: ./docs/
|
|
889
|
+
[46]: ./docs/compilers.md
|
|
890
|
+
[47]: https://nx.dev/concepts/integrated-vs-package-based
|
|
891
|
+
[48]: ./docs/writing-a-plugin.md
|
|
875
892
|
[49]: ./docs/handling-issues.md
|
|
876
893
|
[50]: ./docs/reporters-and-preprocessors.md
|
|
877
894
|
[51]: ./docs/perf-boost-with-no-gitignore.md
|
|
@@ -898,6 +915,7 @@ Special thanks to the wonderful people who have contributed to this project:
|
|
|
898
915
|
[72]: https://github.com/webpro/knip/graphs/contributors
|
|
899
916
|
[73]: https://contrib.rocks/image?repo=webpro/knip
|
|
900
917
|
[plugin-angular]: ./src/plugins/angular
|
|
918
|
+
[plugin-astro]: ./src/plugins/astro
|
|
901
919
|
[plugin-ava]: ./src/plugins/ava
|
|
902
920
|
[plugin-babel]: ./src/plugins/babel
|
|
903
921
|
[plugin-capacitor]: ./src/plugins/capacitor
|
|
@@ -37,6 +37,7 @@ export declare class ConfigurationChief {
|
|
|
37
37
|
rawConfig?: any;
|
|
38
38
|
constructor({ cwd, isProduction }: ConfigurationManagerOptions);
|
|
39
39
|
init(): Promise<void>;
|
|
40
|
+
private loadResolvedConfigurationFile;
|
|
40
41
|
getCompilers(): [SyncCompilers, AsyncCompilers];
|
|
41
42
|
getRules(): import("./types/issues.js").Rules;
|
|
42
43
|
getFilters(): {
|
|
@@ -18,6 +18,7 @@ import { getKeysByValue } from './util/object.js';
|
|
|
18
18
|
import { join, relative, toPosix } from './util/path.js';
|
|
19
19
|
import { normalizePluginConfig, toCamelCase } from './util/plugin.js';
|
|
20
20
|
import { _require } from './util/require.js';
|
|
21
|
+
import { unwrapFunction } from './util/unwrapFunction.js';
|
|
21
22
|
import { byPathDepth } from './util/workspace.js';
|
|
22
23
|
const { config: rawConfigArg, workspace: rawWorkspaceArg, include = [], exclude = [], dependencies = false, exports = false, } = parsedArgValues;
|
|
23
24
|
const workspaceArg = rawWorkspaceArg ? toPosix(rawWorkspaceArg).replace(/^\.\//, '').replace(/\/$/, '') : undefined;
|
|
@@ -90,11 +91,22 @@ export class ConfigurationChief {
|
|
|
90
91
|
if (rawConfigArg && !this.resolvedConfigFilePath && !manifest.knip) {
|
|
91
92
|
throw new ConfigurationError(`Unable to find ${rawConfigArg} or package.json#knip`);
|
|
92
93
|
}
|
|
93
|
-
this.rawConfig = this.resolvedConfigFilePath
|
|
94
|
+
this.rawConfig = this.resolvedConfigFilePath
|
|
95
|
+
? await this.loadResolvedConfigurationFile(this.resolvedConfigFilePath)
|
|
96
|
+
: manifest.knip;
|
|
94
97
|
const parsedConfig = this.rawConfig ? ConfigurationValidator.parse(partitionCompilers(this.rawConfig)) : {};
|
|
95
98
|
this.config = this.normalize(parsedConfig);
|
|
96
99
|
await this.setWorkspaces();
|
|
97
100
|
}
|
|
101
|
+
async loadResolvedConfigurationFile(configPath) {
|
|
102
|
+
const loadedValue = await _load(configPath);
|
|
103
|
+
try {
|
|
104
|
+
return await unwrapFunction(loadedValue);
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
throw new ConfigurationError(`Error running the function from ${configPath}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
98
110
|
getCompilers() {
|
|
99
111
|
return [this.config.syncCompilers, this.config.asyncCompilers];
|
|
100
112
|
}
|
|
@@ -34,6 +34,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
34
34
|
ignore: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
35
35
|
ignoreBinaries: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
36
36
|
ignoreDependencies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
37
|
+
astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
38
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
39
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
40
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
config?: string | string[] | undefined;
|
|
43
|
+
entry?: string | string[] | undefined;
|
|
44
|
+
project?: string | string[] | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
config?: string | string[] | undefined;
|
|
47
|
+
entry?: string | string[] | undefined;
|
|
48
|
+
project?: string | string[] | undefined;
|
|
49
|
+
}>]>>;
|
|
37
50
|
angular: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
38
51
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
39
52
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -574,6 +587,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
574
587
|
ignore?: string | string[] | undefined;
|
|
575
588
|
ignoreBinaries?: string[] | undefined;
|
|
576
589
|
ignoreDependencies?: string[] | undefined;
|
|
590
|
+
astro?: string | boolean | string[] | {
|
|
591
|
+
config?: string | string[] | undefined;
|
|
592
|
+
entry?: string | string[] | undefined;
|
|
593
|
+
project?: string | string[] | undefined;
|
|
594
|
+
} | undefined;
|
|
577
595
|
angular?: string | boolean | string[] | {
|
|
578
596
|
config?: string | string[] | undefined;
|
|
579
597
|
entry?: string | string[] | undefined;
|
|
@@ -786,6 +804,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
786
804
|
ignore?: string | string[] | undefined;
|
|
787
805
|
ignoreBinaries?: string[] | undefined;
|
|
788
806
|
ignoreDependencies?: string[] | undefined;
|
|
807
|
+
astro?: string | boolean | string[] | {
|
|
808
|
+
config?: string | string[] | undefined;
|
|
809
|
+
entry?: string | string[] | undefined;
|
|
810
|
+
project?: string | string[] | undefined;
|
|
811
|
+
} | undefined;
|
|
789
812
|
angular?: string | boolean | string[] | {
|
|
790
813
|
config?: string | string[] | undefined;
|
|
791
814
|
entry?: string | string[] | undefined;
|
|
@@ -992,6 +1015,19 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
992
1015
|
project?: string | string[] | undefined;
|
|
993
1016
|
} | undefined;
|
|
994
1017
|
}>>>;
|
|
1018
|
+
astro: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
1019
|
+
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1020
|
+
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1021
|
+
project: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
1022
|
+
}, "strip", z.ZodTypeAny, {
|
|
1023
|
+
config?: string | string[] | undefined;
|
|
1024
|
+
entry?: string | string[] | undefined;
|
|
1025
|
+
project?: string | string[] | undefined;
|
|
1026
|
+
}, {
|
|
1027
|
+
config?: string | string[] | undefined;
|
|
1028
|
+
entry?: string | string[] | undefined;
|
|
1029
|
+
project?: string | string[] | undefined;
|
|
1030
|
+
}>]>>;
|
|
995
1031
|
angular: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, z.ZodObject<{
|
|
996
1032
|
config: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
997
1033
|
entry: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
@@ -1547,6 +1583,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1547
1583
|
ignore?: string | string[] | undefined;
|
|
1548
1584
|
ignoreBinaries?: string[] | undefined;
|
|
1549
1585
|
ignoreDependencies?: string[] | undefined;
|
|
1586
|
+
astro?: string | boolean | string[] | {
|
|
1587
|
+
config?: string | string[] | undefined;
|
|
1588
|
+
entry?: string | string[] | undefined;
|
|
1589
|
+
project?: string | string[] | undefined;
|
|
1590
|
+
} | undefined;
|
|
1550
1591
|
angular?: string | boolean | string[] | {
|
|
1551
1592
|
config?: string | string[] | undefined;
|
|
1552
1593
|
entry?: string | string[] | undefined;
|
|
@@ -1753,6 +1794,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1753
1794
|
project?: string | string[] | undefined;
|
|
1754
1795
|
} | undefined;
|
|
1755
1796
|
}> | undefined;
|
|
1797
|
+
astro?: string | boolean | string[] | {
|
|
1798
|
+
config?: string | string[] | undefined;
|
|
1799
|
+
entry?: string | string[] | undefined;
|
|
1800
|
+
project?: string | string[] | undefined;
|
|
1801
|
+
} | undefined;
|
|
1756
1802
|
angular?: string | boolean | string[] | {
|
|
1757
1803
|
config?: string | string[] | undefined;
|
|
1758
1804
|
entry?: string | string[] | undefined;
|
|
@@ -1980,6 +2026,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
1980
2026
|
ignore?: string | string[] | undefined;
|
|
1981
2027
|
ignoreBinaries?: string[] | undefined;
|
|
1982
2028
|
ignoreDependencies?: string[] | undefined;
|
|
2029
|
+
astro?: string | boolean | string[] | {
|
|
2030
|
+
config?: string | string[] | undefined;
|
|
2031
|
+
entry?: string | string[] | undefined;
|
|
2032
|
+
project?: string | string[] | undefined;
|
|
2033
|
+
} | undefined;
|
|
1983
2034
|
angular?: string | boolean | string[] | {
|
|
1984
2035
|
config?: string | string[] | undefined;
|
|
1985
2036
|
entry?: string | string[] | undefined;
|
|
@@ -2186,6 +2237,11 @@ export declare const ConfigurationValidator: z.ZodObject<{
|
|
|
2186
2237
|
project?: string | string[] | undefined;
|
|
2187
2238
|
} | undefined;
|
|
2188
2239
|
}> | undefined;
|
|
2240
|
+
astro?: string | boolean | string[] | {
|
|
2241
|
+
config?: string | string[] | undefined;
|
|
2242
|
+
entry?: string | string[] | undefined;
|
|
2243
|
+
project?: string | string[] | undefined;
|
|
2244
|
+
} | undefined;
|
|
2189
2245
|
angular?: string | boolean | string[] | {
|
|
2190
2246
|
config?: string | string[] | undefined;
|
|
2191
2247
|
entry?: string | string[] | undefined;
|
|
@@ -52,7 +52,7 @@ export declare class WorkspaceWorker {
|
|
|
52
52
|
installedBinaries: InstalledBinaries;
|
|
53
53
|
referencedDependencies: ReferencedDependencies;
|
|
54
54
|
hasTypesIncluded: Set<string>;
|
|
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" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
55
|
+
enabledPlugins: ("astro" | "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" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
|
|
56
56
|
entryFilePatterns: string[];
|
|
57
57
|
productionEntryFilePatterns: string[];
|
|
58
58
|
}>;
|
package/dist/cli.js
CHANGED
|
@@ -44,7 +44,7 @@ const run = async () => {
|
|
|
44
44
|
};
|
|
45
45
|
const finalData = await runPreprocessors(initialData);
|
|
46
46
|
await runReporters(finalData);
|
|
47
|
-
const totalErrorCount = Object.keys(report)
|
|
47
|
+
const totalErrorCount = Object.keys(finalData.report)
|
|
48
48
|
.filter(reportGroup => report[reportGroup] && rules[reportGroup] === 'error')
|
|
49
49
|
.reduce((errorCount, reportGroup) => errorCount + counters[reportGroup], 0);
|
|
50
50
|
if (isObservePerf) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
|
|
2
|
+
export declare const NAME = "Astro";
|
|
3
|
+
export declare const ENABLERS: string[];
|
|
4
|
+
export declare const isEnabled: IsPluginEnabledCallback;
|
|
5
|
+
export declare const ENTRY_FILE_PATTERNS: string[];
|
|
6
|
+
export declare const PRODUCTION_ENTRY_FILE_PATTERNS: string[];
|
|
7
|
+
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { hasDependency } from '../../util/plugin.js';
|
|
2
|
+
import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
|
|
3
|
+
export const NAME = 'Astro';
|
|
4
|
+
export const ENABLERS = ['astro'];
|
|
5
|
+
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
6
|
+
export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content/config.ts'];
|
|
7
|
+
export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx'];
|
|
8
|
+
export const findDependencies = async () => {
|
|
9
|
+
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
|
|
10
|
+
};
|
package/dist/plugins/index.d.ts
CHANGED
package/dist/plugins/index.js
CHANGED
package/dist/plugins/nx/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { compact } from '../../util/array.js';
|
|
|
3
3
|
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
5
5
|
export const NAME = 'Nx';
|
|
6
|
-
export const ENABLERS = ['nx', /^@nrwl\//];
|
|
6
|
+
export const ENABLERS = ['nx', /^@nrwl\//, /^@nx\//];
|
|
7
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
8
8
|
export const CONFIG_FILE_PATTERNS = ['project.json', '{apps,libs}/**/project.json'];
|
|
9
9
|
const findNxDependencies = async (configFilePath, options) => {
|
|
@@ -5,7 +5,8 @@ interface ValidImportTypeNode extends ts.ImportTypeNode {
|
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
export declare function isValidImportTypeNode(node: ts.Node): node is ValidImportTypeNode;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function isGetOrSetAccessorDeclaration(node: ts.Node): node is ts.AccessorDeclaration;
|
|
9
|
+
export declare function isPrivateMember(node: ts.MethodDeclaration | ts.PropertyDeclaration | ts.SetAccessorDeclaration | ts.GetAccessorDeclaration): boolean;
|
|
9
10
|
export declare function isDefaultImport(node: ts.ImportDeclaration | ts.ImportEqualsDeclaration | ts.ExportDeclaration): boolean;
|
|
10
11
|
export declare function isAccessExpression(node: ts.Node): node is ts.PropertyAccessExpression | ts.ElementAccessExpression;
|
|
11
12
|
export declare function isImportCall(node: ts.Node): node is ts.ImportCall;
|
|
@@ -2,6 +2,9 @@ import ts from 'typescript';
|
|
|
2
2
|
export function isValidImportTypeNode(node) {
|
|
3
3
|
return ts.isImportTypeNode(node);
|
|
4
4
|
}
|
|
5
|
+
export function isGetOrSetAccessorDeclaration(node) {
|
|
6
|
+
return node.kind === ts.SyntaxKind.SetAccessor || node.kind === ts.SyntaxKind.GetAccessor;
|
|
7
|
+
}
|
|
5
8
|
export function isPrivateMember(node) {
|
|
6
9
|
return node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword) ?? false;
|
|
7
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { SymbolType } from '../../../types/issues.js';
|
|
3
3
|
import { compact } from '../../../util/array.js';
|
|
4
|
-
import { isPrivateMember, stripQuotes } from '../../ast-helpers.js';
|
|
4
|
+
import { isGetOrSetAccessorDeclaration, isPrivateMember, stripQuotes } from '../../ast-helpers.js';
|
|
5
5
|
import { exportVisitor as visit } from '../index.js';
|
|
6
6
|
export default visit(() => true, node => {
|
|
7
7
|
const modifierKinds = node.modifiers?.map(modifier => modifier.kind) ?? [];
|
|
@@ -47,7 +47,10 @@ export default visit(() => true, node => {
|
|
|
47
47
|
const identifier = modifierKinds.includes(ts.SyntaxKind.DefaultKeyword) ? 'default' : node.name.getText();
|
|
48
48
|
const pos = (node.name ?? node).getStart();
|
|
49
49
|
const members = node.members
|
|
50
|
-
.filter((member) => (ts.isPropertyDeclaration(member) ||
|
|
50
|
+
.filter((member) => (ts.isPropertyDeclaration(member) ||
|
|
51
|
+
ts.isMethodDeclaration(member) ||
|
|
52
|
+
isGetOrSetAccessorDeclaration(member)) &&
|
|
53
|
+
!isPrivateMember(member))
|
|
51
54
|
.map(member => ({
|
|
52
55
|
node: member,
|
|
53
56
|
identifier: member.name.getText(),
|
|
@@ -1,9 +1,10 @@
|
|
|
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 --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\n -W, --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 --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\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";
|
|
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 --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\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 --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\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;
|
|
5
5
|
'debug-file-filter': string | undefined;
|
|
6
6
|
dependencies: boolean | undefined;
|
|
7
|
+
directory: string | undefined;
|
|
7
8
|
exclude: string[] | undefined;
|
|
8
9
|
exports: boolean | undefined;
|
|
9
10
|
help: boolean | undefined;
|
|
@@ -10,6 +10,7 @@ Options:
|
|
|
10
10
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
11
11
|
--ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
|
|
12
12
|
-W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
|
|
13
|
+
--directory [dir] Run process from a different directory (default: cwd)
|
|
13
14
|
--no-gitignore Don't use .gitignore
|
|
14
15
|
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
15
16
|
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
@@ -50,6 +51,7 @@ try {
|
|
|
50
51
|
debug: { type: 'boolean', short: 'd' },
|
|
51
52
|
'debug-file-filter': { type: 'string' },
|
|
52
53
|
dependencies: { type: 'boolean' },
|
|
54
|
+
directory: { type: 'string' },
|
|
53
55
|
exclude: { type: 'string', multiple: true },
|
|
54
56
|
exports: { type: 'boolean' },
|
|
55
57
|
help: { type: 'boolean', short: 'h' },
|
package/dist/util/compilers.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
22
22
|
ignore?: string | string[] | undefined;
|
|
23
23
|
ignoreBinaries?: string[] | undefined;
|
|
24
24
|
ignoreDependencies?: string[] | undefined;
|
|
25
|
+
astro?: string | boolean | string[] | {
|
|
26
|
+
config?: string | string[] | undefined;
|
|
27
|
+
entry?: string | string[] | undefined;
|
|
28
|
+
project?: string | string[] | undefined;
|
|
29
|
+
} | undefined;
|
|
25
30
|
angular?: string | boolean | string[] | {
|
|
26
31
|
config?: string | string[] | undefined;
|
|
27
32
|
entry?: string | string[] | undefined;
|
|
@@ -228,6 +233,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
228
233
|
project?: string | string[] | undefined;
|
|
229
234
|
} | undefined;
|
|
230
235
|
}> | undefined;
|
|
236
|
+
astro?: string | boolean | string[] | {
|
|
237
|
+
config?: string | string[] | undefined;
|
|
238
|
+
entry?: string | string[] | undefined;
|
|
239
|
+
project?: string | string[] | undefined;
|
|
240
|
+
} | undefined;
|
|
231
241
|
angular?: string | boolean | string[] | {
|
|
232
242
|
config?: string | string[] | undefined;
|
|
233
243
|
entry?: string | string[] | undefined;
|
package/dist/util/modules.js
CHANGED
|
@@ -51,4 +51,4 @@ export const getEntryPathFromManifest = (cwd, dir, manifest) => {
|
|
|
51
51
|
}
|
|
52
52
|
return _glob({ cwd, workingDir: dir, patterns: Array.from(entryPaths) });
|
|
53
53
|
};
|
|
54
|
-
export const sanitizeSpecifier = (specifier) => specifier.replace(/^([?!|-]+)?([
|
|
54
|
+
export const sanitizeSpecifier = (specifier) => specifier.replace(/^([?!|-]+)?([^!?:]+).*/, '$2');
|
package/dist/util/path.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import parsedArgValues from './cli-arguments.js';
|
|
3
|
+
const { directory } = parsedArgValues;
|
|
2
4
|
const isAbsolute = path.isAbsolute;
|
|
3
5
|
export const dirname = path.posix.dirname;
|
|
4
6
|
export const extname = path.posix.extname;
|
|
5
7
|
export const join = path.posix.join;
|
|
6
8
|
export const toPosix = (value) => value.split(path.sep).join(path.posix.sep);
|
|
7
|
-
export const cwd = toPosix(process.cwd());
|
|
9
|
+
export const cwd = directory ? path.posix.resolve(directory) : toPosix(process.cwd());
|
|
8
10
|
export const resolve = (...paths) => paths.length === 1 ? path.posix.join(cwd, paths[0]) : path.posix.resolve(...paths);
|
|
9
11
|
export const relative = (from, to) => toPosix(path.relative(to ? from : cwd, to ?? from));
|
|
10
12
|
export const isInNodeModules = (filePath) => filePath.includes('node_modules');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const unwrapFunction: (possibleFunction: unknown) => Promise<any>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { debugLogObject } from './debug.js';
|
|
2
|
+
export const unwrapFunction = async (possibleFunction) => {
|
|
3
|
+
if (typeof possibleFunction === 'function') {
|
|
4
|
+
try {
|
|
5
|
+
return await possibleFunction();
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
debugLogObject('*', 'Error executing function:', error);
|
|
9
|
+
throw error;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return possibleFunction;
|
|
13
|
+
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.34.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.34.0';
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
@@ -224,6 +224,10 @@
|
|
|
224
224
|
"title": "angular plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/angular/README.md)",
|
|
225
225
|
"$ref": "#/definitions/plugin"
|
|
226
226
|
},
|
|
227
|
+
"astro": {
|
|
228
|
+
"title": "astro plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/astro/README.md)",
|
|
229
|
+
"$ref": "#/definitions/plugin"
|
|
230
|
+
},
|
|
227
231
|
"ava": {
|
|
228
232
|
"title": "ava plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/ava/README.md)",
|
|
229
233
|
"$ref": "#/definitions/plugin"
|