knip 6.32.3 → 6.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/dist/DependencyDeputy.d.ts +1 -2
- package/dist/DependencyDeputy.js +1 -2
- package/dist/ProjectPrincipal.d.ts +6 -3
- package/dist/ProjectPrincipal.js +29 -6
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/graph/analyze.js +4 -4
- package/dist/graph/build.js +1 -2
- package/dist/graph-explorer/explorer.d.ts +1 -0
- package/dist/graph-explorer/explorer.js +2 -0
- package/dist/graph-explorer/operations/is-enumerated.d.ts +2 -0
- package/dist/graph-explorer/operations/is-enumerated.js +33 -0
- package/dist/manifest/helpers.d.ts +2 -3
- package/dist/manifest/helpers.js +6 -42
- package/dist/manifest/index.d.ts +1 -2
- package/dist/manifest/index.js +2 -2
- package/dist/plugins/dotenv/index.js +1 -8
- package/dist/plugins/eslint/helpers.d.ts +2 -1
- package/dist/plugins/eslint/helpers.js +1 -0
- package/dist/plugins/eslint/resolveFromAST.d.ts +1 -0
- package/dist/plugins/eslint/resolveFromAST.js +5 -2
- package/dist/plugins/eslint/types.d.ts +1 -1
- package/dist/plugins/moonrepo/index.js +3 -3
- package/dist/plugins/node/index.js +5 -0
- package/dist/plugins/node/visitors/fsPromisesGlob.d.ts +2 -0
- package/dist/plugins/node/visitors/fsPromisesGlob.js +89 -0
- package/dist/plugins/nuxt/index.js +38 -13
- package/dist/plugins/nuxt/types.d.ts +5 -1
- package/dist/plugins/oxlint/index.js +6 -2
- package/dist/plugins/oxlint/types.d.ts +2 -0
- package/dist/plugins/typescript/index.js +22 -5
- package/dist/plugins/vitest/index.js +18 -11
- package/dist/plugins/vitest/types.d.ts +1 -1
- package/dist/plugins/vitest/visitors/mock.d.ts +2 -0
- package/dist/plugins/vitest/visitors/mock.js +50 -0
- package/dist/plugins/webpack/index.js +15 -14
- package/dist/run.js +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/module-graph.d.ts +2 -0
- package/dist/types/tsconfig-json.d.ts +6 -0
- package/dist/typescript/get-imports-and-exports.js +7 -1
- package/dist/typescript/glob-imports.js +8 -3
- package/dist/typescript/visitors/calls.js +2 -2
- package/dist/typescript/visitors/members.js +56 -8
- package/dist/typescript/visitors/walk.d.ts +4 -1
- package/dist/typescript/visitors/walk.js +78 -14
- package/dist/util/cli-arguments.d.ts +1 -0
- package/dist/util/cli-arguments.js +9 -0
- package/dist/util/create-options.d.ts +2 -1
- package/dist/util/create-options.js +3 -1
- package/dist/util/load-config.js +6 -1
- package/dist/util/resolve.d.ts +1 -0
- package/dist/util/resolve.js +11 -0
- package/dist/util/scripts.d.ts +1 -0
- package/dist/util/scripts.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +16 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Visitor, type Class, type Function as FunctionNode, type Program, type Span, type VariableDeclarator } from 'oxc-parser';
|
|
1
|
+
import { Visitor, type Class, type Function as FunctionNode, type Program, type Span, type TSInterfaceDeclaration, type VariableDeclarator } from 'oxc-parser';
|
|
2
2
|
import type { PluginVisitorObject } from '../../types/config.ts';
|
|
3
3
|
import type { GetImportsAndExportsOptions } from '../../types/config.ts';
|
|
4
4
|
import type { Fix } from '../../types/exports.ts';
|
|
@@ -43,6 +43,7 @@ interface WalkContext {
|
|
|
43
43
|
resolveModule: ResolveModule;
|
|
44
44
|
programFiles: Set<string>;
|
|
45
45
|
entryFiles: Set<string>;
|
|
46
|
+
handledImportExpressions: Set<number>;
|
|
46
47
|
visitor: Visitor;
|
|
47
48
|
getJSDocTags: (nodeStart: number) => Set<string>;
|
|
48
49
|
}
|
|
@@ -66,10 +67,12 @@ export interface WalkState extends WalkContext {
|
|
|
66
67
|
scopeEnds: number[];
|
|
67
68
|
shadowScopes: Map<string, [number, number][]>;
|
|
68
69
|
localDeclarations: Map<string, FunctionNode | Class | VariableDeclarator>;
|
|
70
|
+
localInterfaces: Map<string, TSInterfaceDeclaration | null>;
|
|
69
71
|
pendingCallRefs: Array<{
|
|
70
72
|
name: string;
|
|
71
73
|
exportName: string;
|
|
72
74
|
seen: Set<string>;
|
|
75
|
+
kind: 'callee' | 'argument';
|
|
73
76
|
}>;
|
|
74
77
|
pendingMemberCallRefs: Array<{
|
|
75
78
|
objectName: string;
|
|
@@ -49,7 +49,7 @@ const _addExport = (identifier, type, pos, members, fix, isReExport, jsDocTags)
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), inBody = false) => {
|
|
52
|
+
const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), inBody = false, thisType) => {
|
|
53
53
|
if (!node)
|
|
54
54
|
return;
|
|
55
55
|
const type = node.type;
|
|
@@ -64,10 +64,14 @@ const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), i
|
|
|
64
64
|
if (node.typeName?.type === 'Identifier')
|
|
65
65
|
_addRefInExport(node.typeName.name, exportName);
|
|
66
66
|
break;
|
|
67
|
+
case 'TSThisType':
|
|
68
|
+
if (thisType)
|
|
69
|
+
_addRefInExport(thisType, exportName);
|
|
70
|
+
return;
|
|
67
71
|
case 'CallExpression': {
|
|
68
72
|
const callee = node.callee;
|
|
69
73
|
if (callee?.type === 'Identifier') {
|
|
70
|
-
state.pendingCallRefs.push({ name: callee.name, exportName, seen });
|
|
74
|
+
state.pendingCallRefs.push({ name: callee.name, exportName, seen, kind: 'callee' });
|
|
71
75
|
}
|
|
72
76
|
else if (callee?.type === 'MemberExpression' &&
|
|
73
77
|
!callee.computed &&
|
|
@@ -84,8 +88,9 @@ const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), i
|
|
|
84
88
|
const args = node.arguments;
|
|
85
89
|
if (args) {
|
|
86
90
|
for (const arg of args) {
|
|
87
|
-
if (arg?.type === 'Identifier')
|
|
88
|
-
state.pendingCallRefs.push({ name: arg.name, exportName, seen });
|
|
91
|
+
if (arg?.type === 'Identifier') {
|
|
92
|
+
state.pendingCallRefs.push({ name: arg.name, exportName, seen, kind: 'argument' });
|
|
93
|
+
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
}
|
|
@@ -101,14 +106,14 @@ const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), i
|
|
|
101
106
|
case 'TSSatisfiesExpression':
|
|
102
107
|
if (inBody) {
|
|
103
108
|
if (node.expression)
|
|
104
|
-
_collectRefsInType(node.expression, exportName, signatureOnly, seen, inBody);
|
|
109
|
+
_collectRefsInType(node.expression, exportName, signatureOnly, seen, inBody, thisType);
|
|
105
110
|
return;
|
|
106
111
|
}
|
|
107
112
|
break;
|
|
108
113
|
case 'VariableDeclarator':
|
|
109
114
|
if (inBody) {
|
|
110
115
|
if (node.init)
|
|
111
|
-
_collectRefsInType(node.init, exportName, signatureOnly, seen, inBody);
|
|
116
|
+
_collectRefsInType(node.init, exportName, signatureOnly, seen, inBody, thisType);
|
|
112
117
|
return;
|
|
113
118
|
}
|
|
114
119
|
break;
|
|
@@ -124,14 +129,63 @@ const _collectRefsInType = (node, exportName, signatureOnly, seen = new Set(), i
|
|
|
124
129
|
if (Array.isArray(val)) {
|
|
125
130
|
for (const item of val) {
|
|
126
131
|
if (item)
|
|
127
|
-
_collectRefsInType(item, exportName, signatureOnly, seen, childInBody);
|
|
132
|
+
_collectRefsInType(item, exportName, signatureOnly, seen, childInBody, thisType);
|
|
128
133
|
}
|
|
129
134
|
}
|
|
130
135
|
else {
|
|
131
|
-
_collectRefsInType(val, exportName, signatureOnly, seen, childInBody);
|
|
136
|
+
_collectRefsInType(val, exportName, signatureOnly, seen, childInBody, thisType);
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
};
|
|
140
|
+
const _collectRefsInDirectMemberResult = (fn, exportName, seen) => {
|
|
141
|
+
const body = fn.body;
|
|
142
|
+
if (body?.type !== 'MemberExpression' ||
|
|
143
|
+
body.computed ||
|
|
144
|
+
body.object?.type !== 'Identifier' ||
|
|
145
|
+
body.property?.type !== 'Identifier') {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
const params = Array.isArray(fn.params) ? fn.params : (fn.params?.items ?? []);
|
|
149
|
+
const param = params.find((param) => param.type === 'Identifier' && param.name === body.object.name);
|
|
150
|
+
const paramType = param?.typeAnnotation?.typeAnnotation;
|
|
151
|
+
if (paramType?.type !== 'TSTypeReference' || paramType.typeName?.type !== 'Identifier' || paramType.typeArguments) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
const declaration = state.localInterfaces.get(paramType.typeName.name);
|
|
155
|
+
if (!declaration || declaration.typeParameters)
|
|
156
|
+
return false;
|
|
157
|
+
const members = declaration.body.body.filter((member) => member.type === 'TSPropertySignature' &&
|
|
158
|
+
!member.computed &&
|
|
159
|
+
member.key?.type === 'Identifier' &&
|
|
160
|
+
member.key.name === body.property.name &&
|
|
161
|
+
Boolean(member.typeAnnotation));
|
|
162
|
+
if (members.length !== 1)
|
|
163
|
+
return false;
|
|
164
|
+
_collectRefsInType(members[0].typeAnnotation, exportName, true, seen, false, paramType.typeName.name);
|
|
165
|
+
return true;
|
|
166
|
+
};
|
|
167
|
+
const _collectRefsInCallResult = (node, exportName, seen) => {
|
|
168
|
+
const annotatedType = node.type === 'VariableDeclarator' ? node.id.typeAnnotation?.typeAnnotation : undefined;
|
|
169
|
+
if (annotatedType?.type === 'TSFunctionType') {
|
|
170
|
+
_collectRefsInType(annotatedType.typeParameters, exportName, true, seen);
|
|
171
|
+
return _collectRefsInType(annotatedType.returnType, exportName, true, seen);
|
|
172
|
+
}
|
|
173
|
+
if (annotatedType)
|
|
174
|
+
return _collectRefsInType(annotatedType, exportName, true, seen);
|
|
175
|
+
const fn = node.type === 'VariableDeclarator' ? node.init : node;
|
|
176
|
+
if (fn?.type !== 'ArrowFunctionExpression' &&
|
|
177
|
+
fn?.type !== 'FunctionDeclaration' &&
|
|
178
|
+
fn?.type !== 'FunctionExpression') {
|
|
179
|
+
return _collectRefsInType(node, exportName, true, seen);
|
|
180
|
+
}
|
|
181
|
+
if (fn.returnType) {
|
|
182
|
+
_collectRefsInType(fn.typeParameters, exportName, true, seen);
|
|
183
|
+
return _collectRefsInType(fn.returnType, exportName, true, seen);
|
|
184
|
+
}
|
|
185
|
+
if (_collectRefsInDirectMemberResult(fn, exportName, seen))
|
|
186
|
+
return;
|
|
187
|
+
_collectRefsInType(fn, exportName, true, seen);
|
|
188
|
+
};
|
|
135
189
|
const _addRefInExport = (name, exportName) => {
|
|
136
190
|
const refs = state.referencedInExport.get(name);
|
|
137
191
|
if (refs)
|
|
@@ -221,6 +275,12 @@ const coreVisitorObject = {
|
|
|
221
275
|
state.addImport(specifier, name, undefined, undefined, node.id.start, IMPORT_FLAGS.TYPE_ONLY | IMPORT_FLAGS.AUGMENT);
|
|
222
276
|
}
|
|
223
277
|
},
|
|
278
|
+
TSInterfaceDeclaration(node) {
|
|
279
|
+
if (state.scopeDepth > 0 || state.isInNamespace(node))
|
|
280
|
+
return;
|
|
281
|
+
const name = node.id.name;
|
|
282
|
+
state.localInterfaces.set(name, state.localInterfaces.has(name) ? null : node);
|
|
283
|
+
},
|
|
224
284
|
ClassDeclaration(node) {
|
|
225
285
|
state.classNameStack.push(node.id?.name ?? '');
|
|
226
286
|
if (node.id?.name) {
|
|
@@ -726,7 +786,6 @@ function walkAST(program, sourceText, filePath, hasModuleSyntax, ctx) {
|
|
|
726
786
|
sourceText,
|
|
727
787
|
isJS,
|
|
728
788
|
isModuleFile: isExternalModule(program, hasModuleSyntax),
|
|
729
|
-
handledImportExpressions: new Set(),
|
|
730
789
|
bareExprRefs: new Set(),
|
|
731
790
|
accessedAliases: new Set(),
|
|
732
791
|
nsContainers: new Map(),
|
|
@@ -741,6 +800,7 @@ function walkAST(program, sourceText, filePath, hasModuleSyntax, ctx) {
|
|
|
741
800
|
scopeEnds: [],
|
|
742
801
|
shadowScopes: new Map(),
|
|
743
802
|
localDeclarations: new Map(),
|
|
803
|
+
localInterfaces: new Map(),
|
|
744
804
|
pendingCallRefs: [],
|
|
745
805
|
pendingMemberCallRefs: [],
|
|
746
806
|
localToExports: new Map(),
|
|
@@ -757,14 +817,18 @@ function walkAST(program, sourceText, filePath, hasModuleSyntax, ctx) {
|
|
|
757
817
|
ctx.visitor.visit(program);
|
|
758
818
|
while (state.pendingCallRefs.length > 0 || state.pendingMemberCallRefs.length > 0) {
|
|
759
819
|
while (state.pendingCallRefs.length > 0) {
|
|
760
|
-
const { name, exportName, seen } = state.pendingCallRefs.pop();
|
|
761
|
-
|
|
820
|
+
const { name, exportName, seen, kind } = state.pendingCallRefs.pop();
|
|
821
|
+
const key = `${kind}:${name}`;
|
|
822
|
+
if (seen.has(key))
|
|
762
823
|
continue;
|
|
763
824
|
const decl = state.localDeclarations.get(name);
|
|
764
825
|
if (!decl)
|
|
765
826
|
continue;
|
|
766
|
-
seen.add(
|
|
767
|
-
|
|
827
|
+
seen.add(key);
|
|
828
|
+
if (kind === 'callee')
|
|
829
|
+
_collectRefsInCallResult(decl, exportName, seen);
|
|
830
|
+
else
|
|
831
|
+
_collectRefsInType(decl, exportName, true, seen);
|
|
768
832
|
}
|
|
769
833
|
while (state.pendingMemberCallRefs.length > 0) {
|
|
770
834
|
const { objectName, propertyName, exportName, seen } = state.pendingMemberCallRefs.pop();
|
|
@@ -781,7 +845,7 @@ function walkAST(program, sourceText, filePath, hasModuleSyntax, ctx) {
|
|
|
781
845
|
if (fn.type !== 'ArrowFunctionExpression' && fn.type !== 'FunctionExpression')
|
|
782
846
|
continue;
|
|
783
847
|
seen.add(key);
|
|
784
|
-
|
|
848
|
+
_collectRefsInCallResult(fn, exportName, seen);
|
|
785
849
|
}
|
|
786
850
|
}
|
|
787
851
|
for (let i = 0; i < state.memberRefsInFile.length; i += 2) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include Include 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,binaries,unresolved,catalog,catalogReferences\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --cycles Shortcut for --include cycles (circular dependencies)\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\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 (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-tag-hints Suppress tag hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog, catalogReferences, cycles\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, cycles, json, codeclimate, markdown, disclosure, github-actions, sarif\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
2
|
export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
|
|
3
|
+
export declare const parseNumericOption: (value: string | undefined, option: string) => number | undefined;
|
|
3
4
|
export default function parseCLIArgs(): {
|
|
4
5
|
cache?: boolean | undefined;
|
|
5
6
|
'cache-location'?: string | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
+
import { ConfigurationError } from './errors.js';
|
|
2
3
|
export const helpText = `✂️ Find unused dependencies, exports and files in your JavaScript and TypeScript projects
|
|
3
4
|
|
|
4
5
|
Usage: knip [options]
|
|
@@ -79,6 +80,14 @@ $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
|
79
80
|
$ knip --tags=-lintignore
|
|
80
81
|
|
|
81
82
|
Website: https://knip.dev`;
|
|
83
|
+
export const parseNumericOption = (value, option) => {
|
|
84
|
+
if (value === undefined)
|
|
85
|
+
return undefined;
|
|
86
|
+
if (!/^\d+$/.test(value)) {
|
|
87
|
+
throw new ConfigurationError(`Option --${option} expects a non-negative integer, got: ${value}`);
|
|
88
|
+
}
|
|
89
|
+
return Number(value);
|
|
90
|
+
};
|
|
82
91
|
export default function parseCLIArgs() {
|
|
83
92
|
return parseArgs({
|
|
84
93
|
options: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Options } from '../types/options.ts';
|
|
2
|
-
import type
|
|
2
|
+
import { type ParsedCLIArgs } from './cli-arguments.ts';
|
|
3
3
|
interface CreateOptions extends Partial<Options> {
|
|
4
4
|
args?: ParsedCLIArgs;
|
|
5
5
|
}
|
|
@@ -43,6 +43,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
43
43
|
isTreatTagHintsAsErrors: boolean;
|
|
44
44
|
isUseTscFiles: boolean | undefined;
|
|
45
45
|
isWatch: boolean;
|
|
46
|
+
maxIssues: number;
|
|
46
47
|
maxShowIssues: number | undefined;
|
|
47
48
|
parsedConfig: {
|
|
48
49
|
angular?: string | boolean | string[] | {
|
|
@@ -2,6 +2,7 @@ import { partitionCompilers } from '../compilers/index.js';
|
|
|
2
2
|
import { ISSUE_TYPES, KNIP_CONFIG_LOCATIONS } from '../constants.js';
|
|
3
3
|
import { knipConfigurationSchema } from '../schema/configuration.js';
|
|
4
4
|
import { getCatalogContainer } from './catalog.js';
|
|
5
|
+
import { parseNumericOption } from './cli-arguments.js';
|
|
5
6
|
import { ConfigurationError } from './errors.js';
|
|
6
7
|
import { findFile, loadJSON } from './fs.js';
|
|
7
8
|
import { getIncludedIssueTypes, shorthandCycles, shorthandDeps, shorthandExports, shorthandFiles, } from './get-included-issue-types.js';
|
|
@@ -150,7 +151,8 @@ export const createOptions = async (options) => {
|
|
|
150
151
|
isTreatTagHintsAsErrors: args['treat-tag-hints-as-errors'] ?? parsedConfig.treatTagHintsAsErrors ?? false,
|
|
151
152
|
isUseTscFiles: options.isUseTscFiles ?? args['use-tsconfig-files'] ?? (options.isSession && !configFilePath),
|
|
152
153
|
isWatch: args.watch ?? options.isWatch ?? false,
|
|
153
|
-
|
|
154
|
+
maxIssues: parseNumericOption(args['max-issues'], 'max-issues') ?? 0,
|
|
155
|
+
maxShowIssues: parseNumericOption(args['max-show-issues'], 'max-show-issues'),
|
|
154
156
|
parsedConfig,
|
|
155
157
|
rules,
|
|
156
158
|
tags,
|
package/dist/util/load-config.js
CHANGED
|
@@ -13,12 +13,17 @@ const unwrapFunction = async (maybeFunction, options) => {
|
|
|
13
13
|
}
|
|
14
14
|
return maybeFunction;
|
|
15
15
|
};
|
|
16
|
+
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
17
|
export async function loadResolvedConfigFile(configPath, options) {
|
|
17
18
|
const loadedValue = await _load(configPath);
|
|
19
|
+
let config;
|
|
18
20
|
try {
|
|
19
|
-
|
|
21
|
+
config = await unwrapFunction(loadedValue, options);
|
|
20
22
|
}
|
|
21
23
|
catch (_error) {
|
|
22
24
|
throw new ConfigurationError(`Error running the function from ${configPath}`);
|
|
23
25
|
}
|
|
26
|
+
if (!isObject(config))
|
|
27
|
+
throw new ConfigurationError(`Expected an object as configuration from ${configPath}`);
|
|
28
|
+
return config;
|
|
24
29
|
}
|
package/dist/util/resolve.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const extensionAlias: Record<string, string[]>;
|
|
2
|
+
export declare const resolvePackageManifestPath: (packageName: string, baseDir: string) => string | undefined;
|
|
2
3
|
export declare const _resolveModuleSync: (specifier: string, basePath: string) => string | undefined;
|
|
3
4
|
declare const resolveDeclarationSync: (specifier: string, containingFile: string) => {
|
|
4
5
|
path: string;
|
package/dist/util/resolve.js
CHANGED
|
@@ -23,6 +23,17 @@ const declarationResolver = new ResolverFactory({
|
|
|
23
23
|
nodePath: false,
|
|
24
24
|
});
|
|
25
25
|
resolverInstances.push(declarationResolver);
|
|
26
|
+
const packageManifestResolver = new ResolverFactory({
|
|
27
|
+
extensions: ['.json'],
|
|
28
|
+
exportsFields: [],
|
|
29
|
+
nodePath: false,
|
|
30
|
+
});
|
|
31
|
+
resolverInstances.push(packageManifestResolver);
|
|
32
|
+
export const resolvePackageManifestPath = (packageName, baseDir) => {
|
|
33
|
+
const resolved = packageManifestResolver.sync(baseDir, `${packageName}/package.json`);
|
|
34
|
+
if (resolved.path)
|
|
35
|
+
return toPosix(resolved.path);
|
|
36
|
+
};
|
|
26
37
|
const createSyncModuleResolver = (extensions, tsConfigFile) => {
|
|
27
38
|
const baseOptions = {
|
|
28
39
|
extensions,
|
package/dist/util/scripts.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export interface ScriptCommand {
|
|
|
3
3
|
binary: string;
|
|
4
4
|
args: string[];
|
|
5
5
|
}
|
|
6
|
+
export declare const toShellCommand: (argv: string[]) => string;
|
|
6
7
|
export declare function walkCommands(node: Node): Generator<Command>;
|
|
7
8
|
export declare const getScriptCommands: (script: string) => ScriptCommand[];
|
package/dist/util/scripts.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parse } from 'unbash';
|
|
2
2
|
import { extractBinary } from './modules.js';
|
|
3
3
|
const spawningBinaries = new Set(['c8', 'cross-env', 'retry-cli']);
|
|
4
|
+
export const toShellCommand = (argv) => argv.map(arg => `'${arg.replaceAll("'", `'\\''`)}'`).join(' ');
|
|
4
5
|
export function* walkCommands(node) {
|
|
5
6
|
switch (node.type) {
|
|
6
7
|
case 'Command':
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "6.
|
|
1
|
+
export declare const version = "6.34.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '6.
|
|
1
|
+
export const version = '6.34.0';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.34.0",
|
|
4
4
|
"description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analysis",
|
|
@@ -71,6 +71,10 @@
|
|
|
71
71
|
"types": "./dist/types.d.ts",
|
|
72
72
|
"default": "./dist/index.js"
|
|
73
73
|
},
|
|
74
|
+
"./config": {
|
|
75
|
+
"types": "./dist/config.d.ts",
|
|
76
|
+
"default": "./dist/config.js"
|
|
77
|
+
},
|
|
74
78
|
"./session": {
|
|
75
79
|
"types": "./dist/session/index.d.ts",
|
|
76
80
|
"default": "./dist/session/index.js"
|
|
@@ -78,28 +82,28 @@
|
|
|
78
82
|
},
|
|
79
83
|
"dependencies": {
|
|
80
84
|
"fdir": "^6.5.0",
|
|
81
|
-
"formatly": "^0.
|
|
82
|
-
"get-tsconfig": "4.14.
|
|
85
|
+
"formatly": "^0.7.0",
|
|
86
|
+
"get-tsconfig": "4.14.3",
|
|
83
87
|
"jiti": "^2.7.0",
|
|
84
|
-
"oxc-parser": "^0.
|
|
88
|
+
"oxc-parser": "^0.147.0",
|
|
85
89
|
"oxc-resolver": "11.24.2",
|
|
86
|
-
"picomatch": "^4.0.
|
|
87
|
-
"smol-toml": "^1.
|
|
90
|
+
"picomatch": "^4.0.7",
|
|
91
|
+
"smol-toml": "^1.8.0",
|
|
88
92
|
"strip-json-comments": "5.0.3",
|
|
89
93
|
"tinyglobby": "^0.2.17",
|
|
90
|
-
"unbash": "^4.0.
|
|
94
|
+
"unbash": "^4.0.10",
|
|
91
95
|
"yaml": "^2.9.0",
|
|
92
96
|
"zod": "^4.4.3"
|
|
93
97
|
},
|
|
94
98
|
"devDependencies": {
|
|
95
|
-
"@jest/types": "^30.
|
|
96
|
-
"@types/bun": "^1.
|
|
99
|
+
"@jest/types": "^30.5.0",
|
|
100
|
+
"@types/bun": "^1.4.0",
|
|
97
101
|
"@types/picomatch": "^4.0.3",
|
|
98
|
-
"@types/webpack": "^5.28.5",
|
|
99
102
|
"codeclimate-types": "^0.3.1",
|
|
100
103
|
"prettier": "^3.9.6",
|
|
101
|
-
"tsx": "^4.23.
|
|
102
|
-
"typescript": "7.0.2"
|
|
104
|
+
"tsx": "^4.23.12",
|
|
105
|
+
"typescript": "7.0.2",
|
|
106
|
+
"webpack": "^5.110.1"
|
|
103
107
|
},
|
|
104
108
|
"engines": {
|
|
105
109
|
"node": "^20.19.0 || >=22.12.0"
|