knip 5.63.0 → 5.64.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/CacheConsultant.d.ts +3 -9
- package/dist/CacheConsultant.js +5 -5
- package/dist/ConfigurationChief.d.ts +597 -38
- package/dist/ConfigurationChief.js +33 -122
- package/dist/ConsoleStreamer.d.ts +2 -3
- package/dist/ConsoleStreamer.js +2 -2
- package/dist/DependencyDeputy.d.ts +2 -6
- package/dist/DependencyDeputy.js +3 -2
- package/dist/IssueCollector.d.ts +4 -12
- package/dist/IssueCollector.js +9 -9
- package/dist/IssueFixer.d.ts +3 -14
- package/dist/IssueFixer.js +14 -22
- package/dist/PrincipalFactory.d.ts +3 -2
- package/dist/PrincipalFactory.js +11 -11
- package/dist/ProjectPrincipal.d.ts +4 -3
- package/dist/ProjectPrincipal.js +8 -8
- package/dist/WorkspaceWorker.d.ts +4 -9
- package/dist/WorkspaceWorker.js +8 -12
- package/dist/binaries/bash-parser.d.ts +1 -0
- package/dist/binaries/bash-parser.js +4 -1
- package/dist/binaries/fallback.js +3 -2
- package/dist/binaries/package-manager/bun.js +1 -0
- package/dist/binaries/package-manager/pnpm.js +6 -1
- package/dist/binaries/plugins.js +3 -1
- package/dist/cli.js +43 -61
- package/dist/compilers/index.d.ts +34 -4
- package/dist/constants.js +2 -0
- package/dist/graph/analyze.d.ts +3 -8
- package/dist/graph/analyze.js +31 -31
- package/dist/graph/build.d.ts +3 -17
- package/dist/graph/build.js +49 -46
- package/dist/index.d.ts +3 -7
- package/dist/index.js +22 -62
- package/dist/plugins/angular/index.js +2 -3
- package/dist/plugins/bumpp/index.d.ts +8 -0
- package/dist/plugins/bumpp/index.js +11 -0
- package/dist/plugins/eslint/index.d.ts +7 -0
- package/dist/plugins/eslint/index.js +12 -0
- package/dist/plugins/glob/index.d.ts +0 -1
- package/dist/plugins/glob/index.js +0 -1
- package/dist/plugins/index.d.ts +24 -7
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/karma/helpers.js +1 -1
- package/dist/plugins/node-modules-inspector/index.d.ts +0 -1
- package/dist/plugins/node-modules-inspector/index.js +0 -1
- package/dist/plugins/nuxt/index.js +10 -3
- package/dist/plugins/nuxt/types.d.ts +3 -2
- package/dist/plugins/oxlint/index.d.ts +0 -1
- package/dist/plugins/oxlint/index.js +0 -1
- package/dist/plugins/playwright/index.d.ts +0 -1
- package/dist/plugins/playwright/index.js +0 -1
- package/dist/plugins/playwright-test/index.d.ts +0 -1
- package/dist/plugins/playwright-test/index.js +0 -1
- package/dist/plugins/pnpm/index.d.ts +8 -0
- package/dist/plugins/pnpm/index.js +12 -0
- package/dist/plugins/prisma/index.d.ts +0 -1
- package/dist/plugins/prisma/index.js +0 -1
- package/dist/plugins/rsbuild/index.js +23 -6
- package/dist/plugins/rsbuild/types.d.ts +3 -0
- package/dist/plugins/rslib/index.js +1 -1
- package/dist/plugins/rstest/index.d.ts +10 -0
- package/dist/plugins/rstest/index.js +29 -0
- package/dist/plugins/rstest/types.d.ts +6 -0
- package/dist/plugins/ts-node/index.d.ts +0 -1
- package/dist/plugins/ts-node/index.js +0 -1
- package/dist/plugins.js +3 -2
- package/dist/reporters/codeclimate.d.ts +1 -1
- package/dist/reporters/codeclimate.js +10 -10
- package/dist/reporters/codeowners.d.ts +1 -1
- package/dist/reporters/codeowners.js +5 -5
- package/dist/reporters/compact.d.ts +1 -1
- package/dist/reporters/compact.js +7 -7
- package/dist/reporters/disclosure.d.ts +1 -1
- package/dist/reporters/disclosure.js +2 -2
- package/dist/reporters/githubActions.d.ts +3 -0
- package/dist/reporters/githubActions.js +94 -0
- package/dist/reporters/index.d.ts +7 -6
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +4 -4
- package/dist/reporters/markdown.d.ts +1 -1
- package/dist/reporters/markdown.js +4 -4
- package/dist/reporters/symbols.js +1 -1
- package/dist/reporters/util/configuration-hints.d.ts +14 -2
- package/dist/reporters/util/configuration-hints.js +7 -7
- package/dist/reporters/util/util.d.ts +2 -2
- package/dist/reporters/util/util.js +4 -4
- package/dist/reporters/watch.d.ts +3 -4
- package/dist/reporters/watch.js +5 -5
- package/dist/schema/configuration.d.ts +176 -8
- package/dist/schema/plugins.d.ts +69 -0
- package/dist/schema/plugins.js +3 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +3 -0
- package/dist/types/args.d.ts +2 -0
- package/dist/types/config.d.ts +4 -10
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/imports.d.ts +1 -1
- package/dist/types/issues.d.ts +1 -2
- package/dist/types/module-graph.d.ts +5 -4
- package/dist/types/{cli.d.ts → options.d.ts} +2 -2
- package/dist/types/options.js +1 -0
- package/dist/types/package-json.d.ts +1 -0
- package/dist/types/project.d.ts +1 -7
- package/dist/typescript/SourceFile.d.ts +2 -2
- package/dist/typescript/ast-helpers.d.ts +4 -0
- package/dist/typescript/ast-helpers.js +29 -0
- package/dist/typescript/find-internal-references.js +10 -1
- package/dist/typescript/get-imports-and-exports.d.ts +2 -2
- package/dist/typescript/get-imports-and-exports.js +32 -23
- package/dist/typescript/visitors/dynamic-imports/importCall.js +6 -1
- package/dist/util/Performance.js +16 -6
- package/dist/util/cli-arguments.d.ts +3 -3
- package/dist/util/cli-arguments.js +4 -14
- package/dist/util/create-options.d.ts +1238 -0
- package/dist/util/create-options.js +112 -0
- package/dist/util/debug.js +3 -4
- package/dist/util/errors.d.ts +1 -1
- package/dist/util/file-entry-cache.js +3 -3
- package/dist/util/get-included-issue-types.d.ts +9 -13
- package/dist/util/get-included-issue-types.js +10 -16
- package/dist/util/get-referenced-inputs.js +1 -1
- package/dist/util/input.d.ts +1 -1
- package/dist/util/input.js +1 -1
- package/dist/util/is-identifier-referenced.d.ts +1 -1
- package/dist/util/is-identifier-referenced.js +2 -2
- package/dist/util/load-config.d.ts +2 -0
- package/dist/util/load-config.js +24 -0
- package/dist/util/modules.js +18 -7
- package/dist/util/path.d.ts +4 -4
- package/dist/util/path.js +5 -7
- package/dist/util/require.js +1 -2
- package/dist/util/tag.d.ts +1 -1
- package/dist/util/to-source-path.d.ts +1 -1
- package/dist/util/to-source-path.js +5 -5
- package/dist/util/trace.d.ts +6 -6
- package/dist/util/trace.js +18 -22
- package/dist/util/watch.d.ts +2 -5
- package/dist/util/watch.js +3 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
- package/schema.json +12 -0
- package/dist/util/unwrap-function.d.ts +0 -1
- package/dist/util/unwrap-function.js +0 -13
- /package/dist/{types/cli.js → plugins/rstest/types.js} +0 -0
package/dist/types/exports.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type ts from 'typescript';
|
|
2
2
|
import type { SymbolType } from './issues.js';
|
|
3
3
|
type Identifier = string;
|
|
4
|
-
type ExportPosTuple = [number, number, number];
|
|
4
|
+
export type ExportPosTuple = [number, number, number];
|
|
5
5
|
export type Fix = ExportPosTuple | undefined;
|
|
6
6
|
export type Fixes = Array<ExportPosTuple>;
|
|
7
7
|
export type ExportNode = {
|
package/dist/types/imports.d.ts
CHANGED
package/dist/types/issues.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Workspace } from '../ConfigurationChief.js';
|
|
2
1
|
export declare enum SymbolType {
|
|
3
2
|
VARIABLE = "variable",
|
|
4
3
|
TYPE = "type",
|
|
@@ -68,7 +67,7 @@ export type ReporterOptions = {
|
|
|
68
67
|
isShowProgress: boolean;
|
|
69
68
|
options: string;
|
|
70
69
|
preprocessorOptions: string;
|
|
71
|
-
|
|
70
|
+
includedWorkspaceDirs: string[];
|
|
72
71
|
configFilePath?: string;
|
|
73
72
|
};
|
|
74
73
|
export type Reporter = (options: ReporterOptions) => void;
|
|
@@ -19,7 +19,7 @@ export type ImportDetails = {
|
|
|
19
19
|
reExportedNs: IdToFileMap;
|
|
20
20
|
};
|
|
21
21
|
export type ImportMap = Map<FilePath, ImportDetails>;
|
|
22
|
-
export type
|
|
22
|
+
export type Import = {
|
|
23
23
|
specifier: string;
|
|
24
24
|
pos?: number;
|
|
25
25
|
line?: number;
|
|
@@ -50,13 +50,14 @@ export type ExportMember = {
|
|
|
50
50
|
jsDocTags: Tags;
|
|
51
51
|
};
|
|
52
52
|
export type ExportMap = Map<Identifier, Export>;
|
|
53
|
+
export type Specifiers = Set<[Import, FilePath]>;
|
|
53
54
|
export type FileNode = {
|
|
54
55
|
imports: {
|
|
55
56
|
internal: ImportMap;
|
|
56
|
-
external: Set<
|
|
57
|
-
unresolved: Set<
|
|
57
|
+
external: Set<Import>;
|
|
58
|
+
unresolved: Set<Import>;
|
|
58
59
|
resolved: Set<FilePath>;
|
|
59
|
-
specifiers:
|
|
60
|
+
specifiers: Specifiers;
|
|
60
61
|
};
|
|
61
62
|
exports: ExportMap;
|
|
62
63
|
duplicates: Iterable<Array<IssueSymbol>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface Options {
|
|
2
2
|
cacheLocation: string;
|
|
3
3
|
cwd: string;
|
|
4
4
|
excludedIssueTypes: string[];
|
|
@@ -20,7 +20,7 @@ export interface CommandLineOptions {
|
|
|
20
20
|
isShowProgress: boolean;
|
|
21
21
|
isStrict: boolean;
|
|
22
22
|
isWatch: boolean;
|
|
23
|
-
tags:
|
|
23
|
+
tags: string[];
|
|
24
24
|
tsConfigFile: string | undefined;
|
|
25
25
|
workspace: string | undefined;
|
|
26
26
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/project.d.ts
CHANGED
|
@@ -3,16 +3,10 @@ import type { AsyncCompilers, SyncCompilers } from '../compilers/types.js';
|
|
|
3
3
|
import type { ToSourceFilePath } from '../util/to-source-path.js';
|
|
4
4
|
export type Paths = ts.CompilerOptions['paths'];
|
|
5
5
|
export type PrincipalOptions = {
|
|
6
|
-
|
|
6
|
+
dir: string;
|
|
7
7
|
isFile: boolean;
|
|
8
8
|
compilerOptions: ts.CompilerOptions;
|
|
9
9
|
compilers: [SyncCompilers, AsyncCompilers];
|
|
10
10
|
pkgName: string;
|
|
11
|
-
isIsolateWorkspaces: boolean;
|
|
12
|
-
isSkipLibs: boolean;
|
|
13
|
-
isWatch: boolean;
|
|
14
11
|
toSourceFilePath: ToSourceFilePath;
|
|
15
|
-
isCache: boolean;
|
|
16
|
-
cacheLocation: string;
|
|
17
|
-
isProduction: boolean;
|
|
18
12
|
};
|
|
@@ -49,3 +49,7 @@ export declare const isModuleExportsAccess: (node: ts.PropertyAccessExpression)
|
|
|
49
49
|
export declare const getImportMap: (sourceFile: ts.SourceFile) => Map<string, string>;
|
|
50
50
|
export declare const getDefaultImportName: (importMap: ReturnType<typeof getImportMap>, specifier: string) => string | undefined;
|
|
51
51
|
export declare const getPropertyValues: (node: ts.ObjectLiteralExpression, propertyName: string) => Set<string>;
|
|
52
|
+
export declare const getAccessedIdentifiers: (identifier: string, scope: ts.Node) => {
|
|
53
|
+
identifier: string;
|
|
54
|
+
pos: number;
|
|
55
|
+
}[];
|
|
@@ -265,3 +265,32 @@ export const getPropertyValues = (node, propertyName) => {
|
|
|
265
265
|
}
|
|
266
266
|
return values;
|
|
267
267
|
};
|
|
268
|
+
export const getAccessedIdentifiers = (identifier, scope) => {
|
|
269
|
+
const identifiers = [];
|
|
270
|
+
function visit(node) {
|
|
271
|
+
if (ts.isPropertyAccessExpression(node) && node.expression.getText() === identifier) {
|
|
272
|
+
identifiers.push({ identifier: String(node.name.escapedText), pos: node.name.pos });
|
|
273
|
+
}
|
|
274
|
+
else if (ts.isElementAccessExpression(node) &&
|
|
275
|
+
node.expression.getText() === identifier &&
|
|
276
|
+
ts.isStringLiteral(node.argumentExpression)) {
|
|
277
|
+
identifiers.push({
|
|
278
|
+
identifier: stripQuotes(node.argumentExpression.text),
|
|
279
|
+
pos: node.argumentExpression.pos,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
else if (ts.isVariableDeclaration(node) &&
|
|
283
|
+
node.initializer?.getText() === identifier &&
|
|
284
|
+
ts.isObjectBindingPattern(node.name)) {
|
|
285
|
+
for (const element of node.name.elements) {
|
|
286
|
+
if (ts.isBindingElement(element)) {
|
|
287
|
+
const identifier = (element.propertyName ?? element.name).getText();
|
|
288
|
+
identifiers.push({ identifier, pos: element.pos });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
ts.forEachChild(node, visit);
|
|
293
|
+
}
|
|
294
|
+
visit(scope);
|
|
295
|
+
return identifiers;
|
|
296
|
+
};
|
|
@@ -38,12 +38,21 @@ export const findInternalReferences = (item, sourceFile, typeChecker, referenced
|
|
|
38
38
|
const declaration = symbol.declarations?.[0];
|
|
39
39
|
if (declaration) {
|
|
40
40
|
if (findInFlow(declaration.name?.flowNode, item.symbol)) {
|
|
41
|
-
|
|
41
|
+
refCount++;
|
|
42
|
+
return [refCount, isSymbolInExport];
|
|
42
43
|
}
|
|
43
44
|
if (ts.isImportSpecifier(declaration) && symbols.has(symbol)) {
|
|
44
45
|
return [++refCount, isSymbolInExport];
|
|
45
46
|
}
|
|
46
47
|
}
|
|
48
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Property) {
|
|
49
|
+
const type = typeChecker.getTypeOfSymbol(symbol);
|
|
50
|
+
if (type?.symbol && item.symbol === type.symbol) {
|
|
51
|
+
refCount++;
|
|
52
|
+
if (isBindingElement)
|
|
53
|
+
return [refCount, isSymbolInExport];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
47
56
|
symbols.add(symbol);
|
|
48
57
|
}
|
|
49
58
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
-
import type { GetImportsAndExportsOptions } from '../types/config.js';
|
|
2
|
+
import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile } from '../types/config.js';
|
|
3
3
|
import type { FileNode } from '../types/module-graph.js';
|
|
4
4
|
import type { BoundSourceFile } from './SourceFile.js';
|
|
5
|
-
export declare const _getImportsAndExports: (sourceFile: BoundSourceFile, resolveModule: (specifier: string) => ts.ResolvedModuleFull | undefined, typeChecker: ts.TypeChecker, options: GetImportsAndExportsOptions) => FileNode;
|
|
5
|
+
export declare const _getImportsAndExports: (sourceFile: BoundSourceFile, resolveModule: (specifier: string) => ts.ResolvedModuleFull | undefined, typeChecker: ts.TypeChecker, options: GetImportsAndExportsOptions, ignoreExportsUsedInFile: IgnoreExportsUsedInFile, skipExports: boolean) => FileNode;
|
|
@@ -33,8 +33,7 @@ const createMember = (node, member, pos) => {
|
|
|
33
33
|
jsDocTags: getJSDocTags(member.node),
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) => {
|
|
37
|
-
const { skipTypeOnly, tags, ignoreExportsUsedInFile } = options;
|
|
36
|
+
const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, ignoreExportsUsedInFile, skipExports) => {
|
|
38
37
|
const internal = new Map();
|
|
39
38
|
const external = new Set();
|
|
40
39
|
const unresolved = new Set();
|
|
@@ -79,7 +78,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
79
78
|
const addInternalImport = (options) => {
|
|
80
79
|
const { identifier, symbol, filePath, namespace, alias, specifier, isReExport } = options;
|
|
81
80
|
const isStar = identifier === IMPORT_STAR;
|
|
82
|
-
specifiers.add([specifier, filePath]);
|
|
81
|
+
specifiers.add([{ specifier, pos: options.pos, line: options.line, col: options.col }, filePath]);
|
|
83
82
|
const file = internal.get(filePath);
|
|
84
83
|
const imports = file ?? createImports();
|
|
85
84
|
if (!file)
|
|
@@ -112,50 +111,60 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options) =
|
|
|
112
111
|
importedInternalSymbols.set(symbol, filePath);
|
|
113
112
|
}
|
|
114
113
|
};
|
|
115
|
-
const addImport = (
|
|
116
|
-
|
|
117
|
-
if (isBuiltin(specifier))
|
|
114
|
+
const addImport = (opts, node) => {
|
|
115
|
+
if (isBuiltin(opts.specifier))
|
|
118
116
|
return;
|
|
119
|
-
const module = resolveModule(specifier);
|
|
117
|
+
const module = resolveModule(opts.specifier);
|
|
120
118
|
if (module) {
|
|
121
119
|
const filePath = module.resolvedFileName;
|
|
122
120
|
if (filePath) {
|
|
123
|
-
if (
|
|
121
|
+
if (opts.resolve && !isInNodeModules(filePath)) {
|
|
124
122
|
resolved.add(filePath);
|
|
125
123
|
return;
|
|
126
124
|
}
|
|
127
125
|
if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
|
|
128
|
-
|
|
126
|
+
const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
|
|
127
|
+
addInternalImport({
|
|
128
|
+
...opts,
|
|
129
|
+
identifier: opts.identifier ?? ANONYMOUS,
|
|
130
|
+
filePath,
|
|
131
|
+
isReExport: opts.isReExport ?? false,
|
|
132
|
+
line: line + 1,
|
|
133
|
+
col: character + 1,
|
|
134
|
+
});
|
|
129
135
|
}
|
|
130
136
|
if (module.isExternalLibraryImport) {
|
|
131
|
-
if (skipTypeOnly && isTypeOnly)
|
|
137
|
+
if (options.skipTypeOnly && opts.isTypeOnly)
|
|
132
138
|
return;
|
|
133
|
-
const
|
|
139
|
+
const isInNM = isInNodeModules(opts.specifier);
|
|
140
|
+
const sanitizedSpecifier = sanitizeSpecifier(isInNM || isInNodeModules(filePath) ? getPackageNameFromFilePath(opts.specifier) : opts.specifier);
|
|
134
141
|
if (!isStartsLikePackageName(sanitizedSpecifier)) {
|
|
135
142
|
return;
|
|
136
143
|
}
|
|
137
|
-
|
|
144
|
+
if (isInNM) {
|
|
145
|
+
external.add({ specifier: sanitizedSpecifier });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(opts.pos);
|
|
149
|
+
external.add({ specifier: sanitizedSpecifier, pos: opts.pos, line: line + 1, col: character + 2 });
|
|
150
|
+
}
|
|
138
151
|
}
|
|
139
152
|
}
|
|
140
153
|
}
|
|
141
154
|
else {
|
|
142
|
-
if (skipTypeOnly && isTypeOnly)
|
|
155
|
+
if (options.skipTypeOnly && opts.isTypeOnly)
|
|
143
156
|
return;
|
|
144
|
-
if (shouldIgnore(getJSDocTags(node), tags))
|
|
157
|
+
if (shouldIgnore(getJSDocTags(node), options.tags))
|
|
145
158
|
return;
|
|
146
|
-
if (specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
159
|
+
if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
147
160
|
return;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
unresolved.add({ specifier });
|
|
154
|
-
}
|
|
161
|
+
const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
|
|
162
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
|
|
163
|
+
unresolved.add({ specifier: opts.specifier, pos, line: line + 1, col: character + 2 });
|
|
155
164
|
}
|
|
156
165
|
};
|
|
157
166
|
const addExport = ({ node, symbol, identifier, type, pos, members = [], fix }) => {
|
|
158
|
-
if (
|
|
167
|
+
if (skipExports)
|
|
159
168
|
return;
|
|
160
169
|
if (symbol) {
|
|
161
170
|
const importedSymbolFilePath = importedInternalSymbols.get(symbol);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { ANONYMOUS } from '../../../constants.js';
|
|
3
|
-
import { findAncestor, findDescendants, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
3
|
+
import { findAncestor, findDescendants, getAccessedIdentifiers, isAccessExpression, isImportCall, isTopLevel, stripQuotes, } from '../../ast-helpers.js';
|
|
4
4
|
import { importVisitor as visit } from '../index.js';
|
|
5
5
|
const getSymbol = (node, isTopLevel) => (isTopLevel ? node.symbol : undefined);
|
|
6
6
|
export default visit(() => true, node => {
|
|
@@ -64,6 +64,11 @@ export default visit(() => true, node => {
|
|
|
64
64
|
if (ts.isIdentifier(variableDeclaration.name)) {
|
|
65
65
|
const alias = String(variableDeclaration.name.escapedText);
|
|
66
66
|
const symbol = getSymbol(variableDeclaration, isTLA);
|
|
67
|
+
const scope = findAncestor(variableDeclaration, ts.isFunctionBody) || node.getSourceFile();
|
|
68
|
+
const accessed = getAccessedIdentifiers(alias, scope);
|
|
69
|
+
if (accessed.length > 0) {
|
|
70
|
+
return accessed.map(acc => ({ identifier: acc.identifier, alias, symbol, specifier, pos: acc.pos }));
|
|
71
|
+
}
|
|
67
72
|
return { identifier: 'default', alias, symbol, specifier, pos: node.arguments[0].pos };
|
|
68
73
|
}
|
|
69
74
|
const bindings = findDescendants(variableDeclaration, ts.isBindingElement);
|
package/dist/util/Performance.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import { PerformanceObserver, performance } from 'node:perf_hooks';
|
|
3
3
|
import { memoryUsage } from 'node:process';
|
|
4
|
-
import
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
5
|
import { getStats } from './math.js';
|
|
6
6
|
import { Table } from './table.js';
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const { values } = parseArgs({
|
|
8
|
+
strict: false,
|
|
9
|
+
options: {
|
|
10
|
+
performance: { type: 'boolean' },
|
|
11
|
+
'performance-fn': { type: 'string' },
|
|
12
|
+
memory: { type: 'boolean' },
|
|
13
|
+
'memory-realtime': { type: 'boolean' },
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const timerifyOnlyFnName = values['performance-fn'];
|
|
17
|
+
const isMemoryRealtime = !!values['memory-realtime'];
|
|
18
|
+
const isTimerifyFunctions = !!values.performance || !!timerifyOnlyFnName;
|
|
19
|
+
const isMemoryUsageEnabled = !!values.memory || isMemoryRealtime;
|
|
10
20
|
export const timerify = (fn, name = fn.name) => {
|
|
11
21
|
if (!isTimerifyFunctions)
|
|
12
22
|
return fn;
|
|
@@ -57,7 +67,7 @@ class Performance {
|
|
|
57
67
|
}
|
|
58
68
|
});
|
|
59
69
|
this.memObserver.observe({ type: 'mark' });
|
|
60
|
-
if (
|
|
70
|
+
if (isMemoryRealtime)
|
|
61
71
|
logHead();
|
|
62
72
|
this.addMemoryMark(0);
|
|
63
73
|
}
|
|
@@ -108,7 +118,7 @@ class Performance {
|
|
|
108
118
|
const id = `${this.memId}:${index}`;
|
|
109
119
|
const detail = getMemInfo();
|
|
110
120
|
performance.mark(id, { detail });
|
|
111
|
-
if (
|
|
121
|
+
if (isMemoryRealtime && detail)
|
|
112
122
|
log(detail);
|
|
113
123
|
}
|
|
114
124
|
getMemoryUsageTable() {
|
|
@@ -1,5 +1,6 @@
|
|
|
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 -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|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 test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\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 --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\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,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\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, codeclimate, markdown, disclosure, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any 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 --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\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(2) Fixable issue types: dependencies, exports, types\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 --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
|
-
|
|
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 -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|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 test files, devDependencies)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\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 --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --watch Watch mode\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,binaries,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --files Shortcut for --include files\n --fix Fix issues\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --format Format modified files after --fix using the local formatter\n --allow-remove-files Allow Knip to remove files (with --fix)\n --include-libs Include type definitions from external dependencies (default: false)\n --include-entry-exports Include entry files when reporting unused exports\n --isolate-workspaces Isolate workspaces into separate programs\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, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --tags Include or exclude tagged exports\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any 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 --trace Show trace output\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\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(2) Fixable issue types: dependencies, exports, types\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 --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
|
+
export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
|
|
3
|
+
export default function parseCLIArgs(): {
|
|
3
4
|
cache?: boolean | undefined;
|
|
4
5
|
'cache-location'?: string | undefined;
|
|
5
6
|
config?: string | undefined;
|
|
@@ -45,4 +46,3 @@ declare const _default: {
|
|
|
45
46
|
watch?: boolean | undefined;
|
|
46
47
|
workspace?: string | undefined;
|
|
47
48
|
};
|
|
48
|
-
export default _default;
|
|
@@ -29,7 +29,7 @@ Options:
|
|
|
29
29
|
-n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
|
|
30
30
|
--preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
|
|
31
31
|
--preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)
|
|
32
|
-
--reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, can be repeated (default: symbols)
|
|
32
|
+
--reporter Select reporter: symbols, compact, codeowners, json, codeclimate, markdown, disclosure, github-actions, can be repeated (default: symbols)
|
|
33
33
|
--reporter-options Pass extra options to the reporter (as JSON string, see example)
|
|
34
34
|
--tags Include or exclude tagged exports
|
|
35
35
|
--no-config-hints Suppress configuration hints
|
|
@@ -60,9 +60,8 @@ $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
|
60
60
|
$ knip --tags=-lintignore
|
|
61
61
|
|
|
62
62
|
Website: https://knip.dev`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
parsedArgs = parseArgs({
|
|
63
|
+
export default function parseCLIArgs() {
|
|
64
|
+
return parseArgs({
|
|
66
65
|
options: {
|
|
67
66
|
cache: { type: 'boolean' },
|
|
68
67
|
'cache-location': { type: 'string' },
|
|
@@ -109,14 +108,5 @@ try {
|
|
|
109
108
|
watch: { type: 'boolean' },
|
|
110
109
|
workspace: { type: 'string', short: 'W' },
|
|
111
110
|
},
|
|
112
|
-
});
|
|
111
|
+
}).values;
|
|
113
112
|
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
if (error instanceof Error) {
|
|
116
|
-
console.error(error.message);
|
|
117
|
-
console.log(`\n${helpText}`);
|
|
118
|
-
process.exit(1);
|
|
119
|
-
}
|
|
120
|
-
throw error;
|
|
121
|
-
}
|
|
122
|
-
export default parsedArgs.values;
|