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.
Files changed (146) hide show
  1. package/dist/CacheConsultant.d.ts +3 -9
  2. package/dist/CacheConsultant.js +5 -5
  3. package/dist/ConfigurationChief.d.ts +597 -38
  4. package/dist/ConfigurationChief.js +33 -122
  5. package/dist/ConsoleStreamer.d.ts +2 -3
  6. package/dist/ConsoleStreamer.js +2 -2
  7. package/dist/DependencyDeputy.d.ts +2 -6
  8. package/dist/DependencyDeputy.js +3 -2
  9. package/dist/IssueCollector.d.ts +4 -12
  10. package/dist/IssueCollector.js +9 -9
  11. package/dist/IssueFixer.d.ts +3 -14
  12. package/dist/IssueFixer.js +14 -22
  13. package/dist/PrincipalFactory.d.ts +3 -2
  14. package/dist/PrincipalFactory.js +11 -11
  15. package/dist/ProjectPrincipal.d.ts +4 -3
  16. package/dist/ProjectPrincipal.js +8 -8
  17. package/dist/WorkspaceWorker.d.ts +4 -9
  18. package/dist/WorkspaceWorker.js +8 -12
  19. package/dist/binaries/bash-parser.d.ts +1 -0
  20. package/dist/binaries/bash-parser.js +4 -1
  21. package/dist/binaries/fallback.js +3 -2
  22. package/dist/binaries/package-manager/bun.js +1 -0
  23. package/dist/binaries/package-manager/pnpm.js +6 -1
  24. package/dist/binaries/plugins.js +3 -1
  25. package/dist/cli.js +43 -61
  26. package/dist/compilers/index.d.ts +34 -4
  27. package/dist/constants.js +2 -0
  28. package/dist/graph/analyze.d.ts +3 -8
  29. package/dist/graph/analyze.js +31 -31
  30. package/dist/graph/build.d.ts +3 -17
  31. package/dist/graph/build.js +49 -46
  32. package/dist/index.d.ts +3 -7
  33. package/dist/index.js +22 -62
  34. package/dist/plugins/angular/index.js +2 -3
  35. package/dist/plugins/bumpp/index.d.ts +8 -0
  36. package/dist/plugins/bumpp/index.js +11 -0
  37. package/dist/plugins/eslint/index.d.ts +7 -0
  38. package/dist/plugins/eslint/index.js +12 -0
  39. package/dist/plugins/glob/index.d.ts +0 -1
  40. package/dist/plugins/glob/index.js +0 -1
  41. package/dist/plugins/index.d.ts +24 -7
  42. package/dist/plugins/index.js +6 -0
  43. package/dist/plugins/karma/helpers.js +1 -1
  44. package/dist/plugins/node-modules-inspector/index.d.ts +0 -1
  45. package/dist/plugins/node-modules-inspector/index.js +0 -1
  46. package/dist/plugins/nuxt/index.js +10 -3
  47. package/dist/plugins/nuxt/types.d.ts +3 -2
  48. package/dist/plugins/oxlint/index.d.ts +0 -1
  49. package/dist/plugins/oxlint/index.js +0 -1
  50. package/dist/plugins/playwright/index.d.ts +0 -1
  51. package/dist/plugins/playwright/index.js +0 -1
  52. package/dist/plugins/playwright-test/index.d.ts +0 -1
  53. package/dist/plugins/playwright-test/index.js +0 -1
  54. package/dist/plugins/pnpm/index.d.ts +8 -0
  55. package/dist/plugins/pnpm/index.js +12 -0
  56. package/dist/plugins/prisma/index.d.ts +0 -1
  57. package/dist/plugins/prisma/index.js +0 -1
  58. package/dist/plugins/rsbuild/index.js +23 -6
  59. package/dist/plugins/rsbuild/types.d.ts +3 -0
  60. package/dist/plugins/rslib/index.js +1 -1
  61. package/dist/plugins/rstest/index.d.ts +10 -0
  62. package/dist/plugins/rstest/index.js +29 -0
  63. package/dist/plugins/rstest/types.d.ts +6 -0
  64. package/dist/plugins/ts-node/index.d.ts +0 -1
  65. package/dist/plugins/ts-node/index.js +0 -1
  66. package/dist/plugins.js +3 -2
  67. package/dist/reporters/codeclimate.d.ts +1 -1
  68. package/dist/reporters/codeclimate.js +10 -10
  69. package/dist/reporters/codeowners.d.ts +1 -1
  70. package/dist/reporters/codeowners.js +5 -5
  71. package/dist/reporters/compact.d.ts +1 -1
  72. package/dist/reporters/compact.js +7 -7
  73. package/dist/reporters/disclosure.d.ts +1 -1
  74. package/dist/reporters/disclosure.js +2 -2
  75. package/dist/reporters/githubActions.d.ts +3 -0
  76. package/dist/reporters/githubActions.js +94 -0
  77. package/dist/reporters/index.d.ts +7 -6
  78. package/dist/reporters/index.js +2 -0
  79. package/dist/reporters/json.d.ts +1 -1
  80. package/dist/reporters/json.js +4 -4
  81. package/dist/reporters/markdown.d.ts +1 -1
  82. package/dist/reporters/markdown.js +4 -4
  83. package/dist/reporters/symbols.js +1 -1
  84. package/dist/reporters/util/configuration-hints.d.ts +14 -2
  85. package/dist/reporters/util/configuration-hints.js +7 -7
  86. package/dist/reporters/util/util.d.ts +2 -2
  87. package/dist/reporters/util/util.js +4 -4
  88. package/dist/reporters/watch.d.ts +3 -4
  89. package/dist/reporters/watch.js +5 -5
  90. package/dist/schema/configuration.d.ts +176 -8
  91. package/dist/schema/plugins.d.ts +69 -0
  92. package/dist/schema/plugins.js +3 -0
  93. package/dist/types/PluginNames.d.ts +2 -2
  94. package/dist/types/PluginNames.js +3 -0
  95. package/dist/types/args.d.ts +2 -0
  96. package/dist/types/config.d.ts +4 -10
  97. package/dist/types/exports.d.ts +1 -1
  98. package/dist/types/imports.d.ts +1 -1
  99. package/dist/types/issues.d.ts +1 -2
  100. package/dist/types/module-graph.d.ts +5 -4
  101. package/dist/types/{cli.d.ts → options.d.ts} +2 -2
  102. package/dist/types/options.js +1 -0
  103. package/dist/types/package-json.d.ts +1 -0
  104. package/dist/types/project.d.ts +1 -7
  105. package/dist/typescript/SourceFile.d.ts +2 -2
  106. package/dist/typescript/ast-helpers.d.ts +4 -0
  107. package/dist/typescript/ast-helpers.js +29 -0
  108. package/dist/typescript/find-internal-references.js +10 -1
  109. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  110. package/dist/typescript/get-imports-and-exports.js +32 -23
  111. package/dist/typescript/visitors/dynamic-imports/importCall.js +6 -1
  112. package/dist/util/Performance.js +16 -6
  113. package/dist/util/cli-arguments.d.ts +3 -3
  114. package/dist/util/cli-arguments.js +4 -14
  115. package/dist/util/create-options.d.ts +1238 -0
  116. package/dist/util/create-options.js +112 -0
  117. package/dist/util/debug.js +3 -4
  118. package/dist/util/errors.d.ts +1 -1
  119. package/dist/util/file-entry-cache.js +3 -3
  120. package/dist/util/get-included-issue-types.d.ts +9 -13
  121. package/dist/util/get-included-issue-types.js +10 -16
  122. package/dist/util/get-referenced-inputs.js +1 -1
  123. package/dist/util/input.d.ts +1 -1
  124. package/dist/util/input.js +1 -1
  125. package/dist/util/is-identifier-referenced.d.ts +1 -1
  126. package/dist/util/is-identifier-referenced.js +2 -2
  127. package/dist/util/load-config.d.ts +2 -0
  128. package/dist/util/load-config.js +24 -0
  129. package/dist/util/modules.js +18 -7
  130. package/dist/util/path.d.ts +4 -4
  131. package/dist/util/path.js +5 -7
  132. package/dist/util/require.js +1 -2
  133. package/dist/util/tag.d.ts +1 -1
  134. package/dist/util/to-source-path.d.ts +1 -1
  135. package/dist/util/to-source-path.js +5 -5
  136. package/dist/util/trace.d.ts +6 -6
  137. package/dist/util/trace.js +18 -22
  138. package/dist/util/watch.d.ts +2 -5
  139. package/dist/util/watch.js +3 -3
  140. package/dist/version.d.ts +1 -1
  141. package/dist/version.js +1 -1
  142. package/package.json +4 -4
  143. package/schema.json +12 -0
  144. package/dist/util/unwrap-function.d.ts +0 -1
  145. package/dist/util/unwrap-function.js +0 -13
  146. /package/dist/{types/cli.js → plugins/rstest/types.js} +0 -0
@@ -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 = {
@@ -4,7 +4,7 @@ export interface ImportNode {
4
4
  identifier: string | undefined;
5
5
  alias?: string | undefined;
6
6
  namespace?: string | undefined;
7
- pos: number | undefined;
7
+ pos: number;
8
8
  symbol?: ts.Symbol;
9
9
  isTypeOnly?: boolean;
10
10
  isReExport?: boolean;
@@ -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
- includedWorkspaces: Workspace[];
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 UnresolvedImport = {
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<string>;
57
- unresolved: Set<UnresolvedImport>;
57
+ external: Set<Import>;
58
+ unresolved: Set<Import>;
58
59
  resolved: Set<FilePath>;
59
- specifiers: Set<[string, FilePath]>;
60
+ specifiers: Specifiers;
60
61
  };
61
62
  exports: ExportMap;
62
63
  duplicates: Iterable<Array<IssueSymbol>>;
@@ -1,4 +1,4 @@
1
- export interface CommandLineOptions {
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: Tags;
23
+ tags: string[];
24
24
  tsConfigFile: string | undefined;
25
25
  workspace: string | undefined;
26
26
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -45,6 +45,7 @@ export type PackageJson = {
45
45
  browser?: string;
46
46
  types?: string;
47
47
  typings?: string;
48
+ packageManager?: string;
48
49
  } & Plugins;
49
50
  export type WorkspacePackage = {
50
51
  dir: string;
@@ -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
- cwd: string;
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
  };
@@ -14,8 +14,8 @@ type PragmaMap = {
14
14
  pos?: number;
15
15
  };
16
16
  types?: {
17
- value?: string;
18
- pos?: number;
17
+ value: string;
18
+ pos: number;
19
19
  };
20
20
  };
21
21
  range?: {
@@ -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
- return [++refCount, isSymbolInExport];
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 = (options, node) => {
116
- const { specifier, isTypeOnly, pos, identifier = ANONYMOUS, isReExport = false } = options;
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 (options.resolve && !isInNodeModules(filePath)) {
121
+ if (opts.resolve && !isInNodeModules(filePath)) {
124
122
  resolved.add(filePath);
125
123
  return;
126
124
  }
127
125
  if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
128
- addInternalImport({ ...options, identifier, filePath, isReExport });
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 sanitizedSpecifier = sanitizeSpecifier(isInNodeModules(specifier) || isInNodeModules(filePath) ? getPackageNameFromFilePath(specifier) : specifier);
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
- external.add(sanitizedSpecifier);
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
- if (typeof pos === 'number') {
149
- const { line, character } = sourceFile.getLineAndCharacterOfPosition(pos);
150
- unresolved.add({ specifier, pos, line: line + 1, col: character + 1 });
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 (options.skipExports)
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);
@@ -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 parsedArgValues from './cli-arguments.js';
4
+ import { parseArgs } from 'node:util';
5
5
  import { getStats } from './math.js';
6
6
  import { Table } from './table.js';
7
- const { performance: enableTimerify = false, 'performance-fn': timerifyOnlyFnName, memory: enableMemoryUsage = false, 'memory-realtime': memoryRealtime = false, } = parsedArgValues;
8
- const isTimerifyFunctions = enableTimerify || !!timerifyOnlyFnName;
9
- const isMemoryUsageEnabled = enableMemoryUsage || memoryRealtime;
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 (memoryRealtime)
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 (memoryRealtime && detail)
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
- declare const _default: {
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
- let parsedArgs;
64
- try {
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;