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
@@ -43,8 +43,7 @@ export class ProjectPrincipal {
43
43
  backend;
44
44
  findReferences;
45
45
  getImplementationAtPosition;
46
- constructor({ compilerOptions, cwd, compilers, isSkipLibs, isWatch, pkgName, toSourceFilePath, isCache, cacheLocation, isProduction, }) {
47
- this.cwd = cwd;
46
+ constructor(options, { compilerOptions, compilers, pkgName, toSourceFilePath }) {
48
47
  this.compilerOptions = {
49
48
  ...compilerOptions,
50
49
  ...baseCompilerOptions,
@@ -55,12 +54,13 @@ export class ProjectPrincipal {
55
54
  this.extensions = new Set([...DEFAULT_EXTENSIONS, ...getCompilerExtensions(compilers)]);
56
55
  this.syncCompilers = syncCompilers;
57
56
  this.asyncCompilers = asyncCompilers;
58
- this.isSkipLibs = isSkipLibs;
59
- this.isWatch = isWatch;
60
- this.cache = new CacheConsultant({ name: pkgName || ANONYMOUS, isEnabled: isCache, cacheLocation, isProduction });
57
+ this.cwd = options.cwd;
58
+ this.isSkipLibs = options.isSkipLibs;
59
+ this.isWatch = options.isWatch;
60
+ this.cache = new CacheConsultant(pkgName || ANONYMOUS, options);
61
61
  this.toSourceFilePath = toSourceFilePath;
62
62
  this.backend = {
63
- fileManager: new SourceFileManager({ compilers, isSkipLibs }),
63
+ fileManager: new SourceFileManager({ compilers, isSkipLibs: options.isSkipLibs }),
64
64
  };
65
65
  }
66
66
  init() {
@@ -156,7 +156,7 @@ export class ProjectPrincipal {
156
156
  const sourceFiles = this.getProgramSourceFiles();
157
157
  return Array.from(this.projectPaths).filter(filePath => !sourceFiles.has(filePath));
158
158
  }
159
- analyzeSourceFile(filePath, options) {
159
+ analyzeSourceFile(filePath, options, ignoreExportsUsedInFile) {
160
160
  const fd = this.cache.getFileDescriptor(filePath);
161
161
  if (!fd.changed && fd.meta?.data)
162
162
  return fd.meta.data;
@@ -168,7 +168,7 @@ export class ProjectPrincipal {
168
168
  throw new Error(`Unable to find ${filePath}`);
169
169
  const skipExports = this.skipExportsAnalysis.has(filePath);
170
170
  const resolve = (specifier) => this.backend.resolveModuleNames([specifier], sourceFile.fileName)[0];
171
- return _getImportsAndExports(sourceFile, resolve, typeChecker, { ...options, skipExports });
171
+ return _getImportsAndExports(sourceFile, resolve, typeChecker, options, ignoreExportsUsedInFile, skipExports);
172
172
  }
173
173
  invalidateFile(filePath) {
174
174
  this.backend.fileManager.snapshotCache.delete(filePath);
@@ -5,11 +5,11 @@ import type { Configuration, GetReferencedInternalFilePath, GetSourceFile, Works
5
5
  import type { ConfigurationHints } from './types/issues.js';
6
6
  import type { PackageJson } from './types/package-json.js';
7
7
  import type { DependencySet } from './types/workspace.js';
8
+ import type { MainOptions } from './util/create-options.js';
8
9
  import { type Input } from './util/input.js';
9
10
  type WorkspaceManagerOptions = {
10
11
  name: string;
11
12
  dir: string;
12
- cwd: string;
13
13
  config: WorkspaceConfiguration;
14
14
  manifest: PackageJson;
15
15
  dependencies: DependencySet;
@@ -20,11 +20,8 @@ type WorkspaceManagerOptions = {
20
20
  negatedWorkspacePatterns: string[];
21
21
  ignoredWorkspacePatterns: string[];
22
22
  enabledPluginsInAncestors: string[];
23
- isProduction: boolean;
24
- isStrict: boolean;
25
- isCache: boolean;
26
- cacheLocation: string;
27
23
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
24
+ options: MainOptions;
28
25
  };
29
26
  type CacheItem = {
30
27
  resolveConfig?: Input[];
@@ -34,24 +31,22 @@ type CacheItem = {
34
31
  export declare class WorkspaceWorker {
35
32
  name: string;
36
33
  dir: string;
37
- cwd: string;
38
34
  config: WorkspaceConfiguration;
39
35
  manifest: PackageJson;
40
36
  dependencies: DependencySet;
41
37
  getReferencedInternalFilePath: GetReferencedInternalFilePath;
42
38
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
43
39
  getSourceFile: GetSourceFile;
44
- isProduction: boolean;
45
- isStrict: boolean;
46
40
  rootIgnore: Configuration['ignore'];
47
41
  negatedWorkspacePatterns: string[];
48
42
  ignoredWorkspacePatterns: string[];
43
+ options: MainOptions;
49
44
  enabledPluginsMap: Record<PluginName, boolean>;
50
45
  enabledPlugins: PluginName[];
51
46
  enabledPluginsInAncestors: string[];
52
47
  cache: CacheConsultant<CacheItem>;
53
48
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
54
- constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, configFilesMap, }: WorkspaceManagerOptions);
49
+ constructor({ name, dir, config, manifest, dependencies, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, configFilesMap, options, }: WorkspaceManagerOptions);
55
50
  init(): Promise<void>;
56
51
  private determineEnabledPlugins;
57
52
  private getConfigForPlugin;
@@ -19,32 +19,27 @@ const initEnabledPluginsMap = () => Object.keys(Plugins).reduce((enabled, plugin
19
19
  export class WorkspaceWorker {
20
20
  name;
21
21
  dir;
22
- cwd;
23
22
  config;
24
23
  manifest;
25
24
  dependencies;
26
25
  getReferencedInternalFilePath;
27
26
  findWorkspaceByFilePath;
28
27
  getSourceFile;
29
- isProduction;
30
- isStrict;
31
28
  rootIgnore;
32
29
  negatedWorkspacePatterns = [];
33
30
  ignoredWorkspacePatterns = [];
31
+ options;
34
32
  enabledPluginsMap = initEnabledPluginsMap();
35
33
  enabledPlugins = [];
36
34
  enabledPluginsInAncestors;
37
35
  cache;
38
36
  configFilesMap;
39
- constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, configFilesMap, }) {
37
+ constructor({ name, dir, config, manifest, dependencies, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, configFilesMap, options, }) {
40
38
  this.name = name;
41
39
  this.dir = dir;
42
- this.cwd = cwd;
43
40
  this.config = config;
44
41
  this.manifest = manifest;
45
42
  this.dependencies = dependencies;
46
- this.isProduction = isProduction;
47
- this.isStrict = isStrict;
48
43
  this.rootIgnore = rootIgnore;
49
44
  this.negatedWorkspacePatterns = negatedWorkspacePatterns;
50
45
  this.ignoredWorkspacePatterns = ignoredWorkspacePatterns;
@@ -53,7 +48,8 @@ export class WorkspaceWorker {
53
48
  this.getReferencedInternalFilePath = getReferencedInternalFilePath;
54
49
  this.findWorkspaceByFilePath = findWorkspaceByFilePath;
55
50
  this.getSourceFile = getSourceFile;
56
- this.cache = new CacheConsultant({ name: `plugins-${name}`, isEnabled: isCache, cacheLocation, isProduction });
51
+ this.options = options;
52
+ this.cache = new CacheConsultant(`plugins-${name}`, options);
57
53
  this.getConfigurationHints = timerify(this.getConfigurationHints.bind(this), 'worker.getConfigurationHints');
58
54
  }
59
55
  async init() {
@@ -64,7 +60,7 @@ export class WorkspaceWorker {
64
60
  for (const [pluginName, plugin] of PluginEntries) {
65
61
  if (this.config[pluginName] === false)
66
62
  continue;
67
- if (this.cwd !== this.dir && plugin.isRootOnly)
63
+ if (this.options.cwd !== this.dir && plugin.isRootOnly)
68
64
  continue;
69
65
  if (this.config[pluginName]) {
70
66
  this.enabledPluginsMap[pluginName] = true;
@@ -169,10 +165,10 @@ export class WorkspaceWorker {
169
165
  async runPlugins() {
170
166
  const wsName = this.name;
171
167
  const cwd = this.dir;
172
- const rootCwd = this.cwd;
168
+ const rootCwd = this.options.cwd;
173
169
  const manifest = this.manifest;
174
170
  const containingFilePath = join(cwd, 'package.json');
175
- const isProduction = this.isProduction;
171
+ const isProduction = this.options.isProduction;
176
172
  const knownBinsOnly = false;
177
173
  const manifestScriptNames = new Set(Object.keys(manifest.scripts ?? {}));
178
174
  const baseOptions = { manifestScriptNames, cwd, rootCwd, containingFilePath, knownBinsOnly };
@@ -344,7 +340,7 @@ export class WorkspaceWorker {
344
340
  } while (remainingPlugins.size > 0 && configFiles.size > 0);
345
341
  }
346
342
  }
347
- debugLogArray(wsName, 'Plugin dependencies', () => compact(inputs.map(toDebugString)));
343
+ debugLogArray(wsName, 'Plugin dependencies', () => compact(inputs.map(input => toDebugString(input, rootCwd))));
348
344
  return inputs;
349
345
  }
350
346
  getConfigurationHints(type, patterns, filePaths, includedPaths) {
@@ -1,3 +1,4 @@
1
1
  import type { GetInputsFromScriptsOptions } from '../types/config.js';
2
2
  import { type Input } from '../util/input.js';
3
+ export declare const isValidBinary: (str: string) => boolean;
3
4
  export declare const getDependenciesFromScript: (script: string, options: GetInputsFromScriptsOptions) => Input[];
@@ -12,10 +12,13 @@ import { parseNodeArgs } from './util.js';
12
12
  const spawningBinaries = ['cross-env', 'retry-cli'];
13
13
  const isExpansion = (node) => 'expansion' in node;
14
14
  const isAssignment = (node) => 'type' in node && node.type === 'AssignmentWord';
15
+ export const isValidBinary = (str) => !/[*:!()]/.test(str);
15
16
  export const getDependenciesFromScript = (script, options) => {
16
17
  if (!script)
17
18
  return [];
18
19
  const fromArgs = (args, opts) => {
20
+ if (args.length === 0 || !isValidBinary(args[0]))
21
+ return [];
19
22
  return getDependenciesFromScript(args.filter(arg => arg !== '--').join(' '), {
20
23
  ...options,
21
24
  ...opts,
@@ -88,7 +91,7 @@ export const getDependenciesFromScript = (script, options) => {
88
91
  return parsed?.commands ? getDependenciesFromNodes(parsed.commands) : [];
89
92
  }
90
93
  catch (error) {
91
- const msg = `Warning: failed to parse and ignoring script in ${relative(options.containingFilePath)} (${truncate(script, 30)})`;
94
+ const msg = `Warning: failed to parse and ignoring script in ${relative(options.cwd, options.containingFilePath)} (${truncate(script, 30)})`;
92
95
  debugLogObject('*', msg, error);
93
96
  return [];
94
97
  }
@@ -1,13 +1,14 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { compact } from '../util/array.js';
3
3
  import { toBinary, toDeferResolve, toEntry } from '../util/input.js';
4
+ import { isValidBinary } from './bash-parser.js';
4
5
  const spawningBinaries = ['cross-env', 'retry-cli'];
5
- const endOfCommandBinaries = ['dotenvx'];
6
+ const endOfCommandBinaries = ['dotenvx', 'env-cmd'];
6
7
  const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
7
8
  const positionalBinaries = new Set(['concurrently']);
8
9
  export const resolve = (binary, args, { fromArgs }) => {
9
10
  const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
10
- const bin = binary.startsWith('.') ? toEntry(binary) : binary.includes('*') ? undefined : toBinary(binary);
11
+ const bin = binary.startsWith('.') ? toEntry(binary) : isValidBinary(binary) ? toBinary(binary) : undefined;
11
12
  const shiftedArgs = spawningBinaries.includes(binary) ? fromArgs(args) : [];
12
13
  const pos = positionals.has(binary) ? [toDeferResolve(parsed._[0])] : [];
13
14
  const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
@@ -6,6 +6,7 @@ import { resolveX } from './bunx.js';
6
6
  const commands = [
7
7
  'add',
8
8
  'audit',
9
+ 'ci',
9
10
  'create',
10
11
  'init',
11
12
  'install',
@@ -3,9 +3,12 @@ import { toBinary } from '../../util/input.js';
3
3
  import { resolveDlx } from './pnpx.js';
4
4
  const commands = [
5
5
  'add',
6
+ 'approve-builds',
6
7
  'audit',
7
8
  'bin',
8
9
  'cache',
10
+ 'cat-file',
11
+ 'cat-index',
9
12
  'config',
10
13
  'dedupe',
11
14
  'deploy',
@@ -13,7 +16,9 @@ const commands = [
13
16
  'doctor',
14
17
  'env',
15
18
  'fetch',
19
+ 'find-hash',
16
20
  'i',
21
+ 'ignored-builds',
17
22
  'import',
18
23
  'init',
19
24
  'install-test',
@@ -25,7 +30,6 @@ const commands = [
25
30
  'ln',
26
31
  'ls',
27
32
  'outdated',
28
- 'outdated',
29
33
  'pack',
30
34
  'patch-commit',
31
35
  'patch-remove',
@@ -39,6 +43,7 @@ const commands = [
39
43
  'rm',
40
44
  'root',
41
45
  'run',
46
+ 'self-update',
42
47
  'server',
43
48
  'setup',
44
49
  'start',
@@ -48,7 +48,7 @@ export const resolve = (binary, _args, options) => {
48
48
  const resolvedFromArgs = typeof pluginArgs.fromArgs === 'function'
49
49
  ? fromArgs(pluginArgs.fromArgs(parsed, args))
50
50
  : Array.isArray(pluginArgs.fromArgs)
51
- ? fromArgs(pluginArgs.fromArgs.flatMap(mapToParsedKey))
51
+ ? fromArgs(pluginArgs.fromArgs.flatMap(mapToParsedKey).filter(Boolean))
52
52
  : [];
53
53
  const config = pluginArgs.config === true ? ['config'] : pluginArgs.config || [];
54
54
  const mapToConfigPattern = (value) => {
@@ -58,6 +58,7 @@ export const resolve = (binary, _args, options) => {
58
58
  return parsed[id] && pluginName ? [toConfig(pluginName, fn(parsed[id]), inputOpts)] : [];
59
59
  };
60
60
  const configFilePaths = config.flatMap(mapToConfigPattern);
61
+ const inputs = pluginArgs.resolveInputs?.(parsed, args) ?? [];
61
62
  return [
62
63
  toBinary(binary, inputOpts),
63
64
  ...positionals,
@@ -65,5 +66,6 @@ export const resolve = (binary, _args, options) => {
65
66
  ...resolvedImports.map(id => toDeferResolve(id)),
66
67
  ...resolvedFromArgs,
67
68
  ...configFilePaths,
69
+ ...inputs,
68
70
  ];
69
71
  };
package/dist/cli.js CHANGED
@@ -1,103 +1,85 @@
1
1
  import { main } from './index.js';
2
2
  import { perfObserver } from './util/Performance.js';
3
- import parsedArgValues, { helpText } from './util/cli-arguments.js';
3
+ import { helpText } from './util/cli-arguments.js';
4
+ import parseArgs from './util/cli-arguments.js';
5
+ import { createOptions } from './util/create-options.js';
4
6
  import { getKnownError, isConfigurationError, isDisplayReason, isKnownError } from './util/errors.js';
5
7
  import { logError, logWarning } from './util/log.js';
6
- import { cwd, join, toPosix } from './util/path.js';
7
8
  import { runPreprocessors, runReporters } from './util/reporter.js';
8
9
  import { prettyMilliseconds } from './util/string.js';
9
- import { splitTags } from './util/tag.js';
10
- import { isTrace } from './util/trace.js';
11
10
  import { version } from './version.js';
12
- const defaultCacheLocation = join(cwd, 'node_modules', '.cache', 'knip');
13
- const { 'allow-remove-files': isRemoveFiles = false, cache: isCache = false, 'cache-location': cacheLocation = defaultCacheLocation, debug: isDebug = false, dependencies: isDependenciesShorthand = false, exclude: excludedIssueTypes = [], 'experimental-tags': experimentalTags = [], exports: isExportsShorthand = false, files: isFilesShorthand = false, fix: isFix = false, format: isFormat = false, 'fix-type': fixTypes = [], help: isHelp, include: includedIssueTypes = [], 'include-entry-exports': isIncludeEntryExports = false, 'include-libs': isIncludeLibs = false, 'isolate-workspaces': isIsolateWorkspaces = false, 'max-issues': maxIssues = '0', 'memory-realtime': memoryRealtime = false, 'no-config-hints': isNoConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = isDebug || isTrace || memoryRealtime, preprocessor = [], 'preprocessor-options': preprocessorOptions = '', production: isProduction = false, reporter = ['symbols'], 'reporter-options': reporterOptions = '', strict: isStrict = false, tags = [], 'treat-config-hints-as-errors': treatConfigHintsAsErrors = false, tsConfig, version: isVersion, watch: isWatch = false, workspace: rawWorkspaceArg, } = parsedArgValues;
14
- if (isHelp) {
15
- console.log(helpText);
16
- process.exit(0);
11
+ let parsedCLIArgs = {};
12
+ try {
13
+ parsedCLIArgs = parseArgs();
17
14
  }
18
- if (isVersion) {
19
- console.log(version);
20
- process.exit(0);
15
+ catch (error) {
16
+ if (error instanceof Error) {
17
+ console.error(error.message);
18
+ console.log(`\n${helpText}`);
19
+ process.exit(1);
20
+ }
21
+ throw error;
21
22
  }
22
- const isShowProgress = isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
23
- const workspace = rawWorkspaceArg ? toPosix(rawWorkspaceArg).replace(/^\.\//, '').replace(/\/$/, '') : undefined;
24
23
  const run = async () => {
25
24
  try {
26
- const { report, issues, counters, rules, tagHints, configurationHints, isTreatConfigHintsAsErrors, includedWorkspaces, configFilePath, } = await main({
27
- cacheLocation,
28
- cwd,
29
- excludedIssueTypes,
30
- fixTypes: fixTypes.flatMap(type => type.split(',')),
31
- gitignore: !isNoGitIgnore,
32
- includedIssueTypes,
33
- isCache,
34
- isDebug,
35
- isDependenciesShorthand,
36
- isExportsShorthand,
37
- isFilesShorthand,
38
- isFix: isFix || fixTypes.length > 0,
39
- isFormat,
40
- isIncludeEntryExports,
41
- isIncludeLibs,
42
- isIsolateWorkspaces,
43
- isProduction: isStrict || isProduction,
44
- isRemoveFiles,
45
- isShowProgress,
46
- isStrict,
47
- isWatch,
48
- tags: tags.length > 0 ? splitTags(tags) : splitTags(experimentalTags),
49
- tsConfigFile: tsConfig,
50
- workspace,
51
- });
52
- const isDisableConfigHints = isNoConfigHints || isProduction || Boolean(workspace);
53
- if (isWatch || isTrace)
25
+ const options = await createOptions({ parsedCLIArgs });
26
+ if (parsedCLIArgs.help) {
27
+ console.log(helpText);
28
+ process.exit(0);
29
+ }
30
+ if (parsedCLIArgs.version) {
31
+ console.log(version);
32
+ process.exit(0);
33
+ }
34
+ const { issues, counters, tagHints, configurationHints, includedWorkspaceDirs } = await main(options);
35
+ if (options.isWatch || options.isTrace)
54
36
  return;
55
37
  const initialData = {
56
- report,
38
+ report: options.includedIssueTypes,
57
39
  issues,
58
40
  counters,
59
41
  tagHints,
60
42
  configurationHints,
61
- isDisableConfigHints,
62
- isTreatConfigHintsAsErrors: treatConfigHintsAsErrors ?? isTreatConfigHintsAsErrors,
63
- cwd,
64
- isProduction,
65
- isShowProgress,
66
- options: reporterOptions,
67
- preprocessorOptions,
68
- includedWorkspaces,
69
- configFilePath,
43
+ includedWorkspaceDirs,
44
+ cwd: options.cwd,
45
+ configFilePath: options.configFilePath,
46
+ isDisableConfigHints: options.isDisableConfigHints,
47
+ isProduction: options.isProduction,
48
+ isShowProgress: options.isShowProgress,
49
+ isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
50
+ options: parsedCLIArgs['reporter-options'] ?? '',
51
+ preprocessorOptions: parsedCLIArgs['preprocessor-options'] ?? '',
70
52
  };
71
- const finalData = await runPreprocessors(preprocessor, initialData);
72
- await runReporters(reporter, finalData);
53
+ const finalData = await runPreprocessors(parsedCLIArgs.preprocessor ?? [], initialData);
54
+ await runReporters(parsedCLIArgs.reporter ?? ['symbols'], finalData);
73
55
  const totalErrorCount = Object.keys(finalData.report)
74
- .filter(reportGroup => finalData.report[reportGroup] && rules[reportGroup] === 'error')
56
+ .filter(reportGroup => finalData.report[reportGroup] && options.rules[reportGroup] === 'error')
75
57
  .reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
76
58
  if (perfObserver.isEnabled)
77
59
  await perfObserver.finalize();
78
60
  if (perfObserver.isTimerifyFunctions)
79
61
  console.log(`\n${perfObserver.getTimerifiedFunctionsTable()}`);
80
- if (perfObserver.isMemoryUsageEnabled && !memoryRealtime)
62
+ if (perfObserver.isMemoryUsageEnabled && !parsedCLIArgs['memory-realtime'])
81
63
  console.log(`\n${perfObserver.getMemoryUsageTable()}`);
82
64
  if (perfObserver.isEnabled) {
83
65
  const duration = perfObserver.getCurrentDurationInMs();
84
66
  console.log('\nTotal running time:', prettyMilliseconds(duration));
85
67
  perfObserver.reset();
86
68
  }
87
- if (experimentalTags.length > 0) {
69
+ if (parsedCLIArgs['experimental-tags'] && parsedCLIArgs['experimental-tags'].length > 0) {
88
70
  logWarning('DEPRECATION WARNING', '--experimental-tags is deprecated, please start using --tags instead');
89
71
  }
90
- if (isIsolateWorkspaces && report.classMembers) {
72
+ if (options.isIsolateWorkspaces && options.includedIssueTypes.classMembers) {
91
73
  logWarning('WARNING', 'Class members are not tracked when using the --isolate-workspaces flag');
92
74
  }
93
- if ((!noExitCode && totalErrorCount > Number(maxIssues)) ||
94
- ((treatConfigHintsAsErrors || isTreatConfigHintsAsErrors) && configurationHints.size > 0)) {
75
+ if ((!parsedCLIArgs['no-exit-code'] && totalErrorCount > Number(parsedCLIArgs['max-issues'] ?? 0)) ||
76
+ (options.isTreatConfigHintsAsErrors && configurationHints.size > 0)) {
95
77
  process.exit(1);
96
78
  }
97
79
  }
98
80
  catch (error) {
99
81
  process.exitCode = 2;
100
- if (!isDebug && error instanceof Error && isKnownError(error)) {
82
+ if (!parsedCLIArgs.debug && error instanceof Error && isKnownError(error)) {
101
83
  const knownError = getKnownError(error);
102
84
  logError('ERROR', knownError.message);
103
85
  if (isDisplayReason(knownError))
@@ -4,9 +4,6 @@ import type { AsyncCompilerFn, AsyncCompilers, RawSyncCompilers, SyncCompilerFn,
4
4
  export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
5
5
  syncCompilers: Record<string, SyncCompilerFn>;
6
6
  asyncCompilers: Record<string, AsyncCompilerFn>;
7
- exclude?: ("dependencies" | "exports" | "files" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
8
- tags?: string[] | undefined;
9
- include?: ("dependencies" | "exports" | "files" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
10
7
  node?: string | boolean | string[] | {
11
8
  config?: string | string[] | undefined;
12
9
  entry?: string | string[] | undefined;
@@ -39,6 +36,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
39
36
  entry?: string | string[] | undefined;
40
37
  project?: string | string[] | undefined;
41
38
  } | undefined;
39
+ bumpp?: string | boolean | string[] | {
40
+ config?: string | string[] | undefined;
41
+ entry?: string | string[] | undefined;
42
+ project?: string | string[] | undefined;
43
+ } | undefined;
42
44
  bun?: string | boolean | string[] | {
43
45
  config?: string | string[] | undefined;
44
46
  entry?: string | string[] | undefined;
@@ -324,6 +326,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
324
326
  entry?: string | string[] | undefined;
325
327
  project?: string | string[] | undefined;
326
328
  } | undefined;
329
+ pnpm?: string | boolean | string[] | {
330
+ config?: string | string[] | undefined;
331
+ entry?: string | string[] | undefined;
332
+ project?: string | string[] | undefined;
333
+ } | undefined;
327
334
  postcss?: string | boolean | string[] | {
328
335
  config?: string | string[] | undefined;
329
336
  entry?: string | string[] | undefined;
@@ -394,6 +401,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
394
401
  entry?: string | string[] | undefined;
395
402
  project?: string | string[] | undefined;
396
403
  } | undefined;
404
+ rstest?: string | boolean | string[] | {
405
+ config?: string | string[] | undefined;
406
+ entry?: string | string[] | undefined;
407
+ project?: string | string[] | undefined;
408
+ } | undefined;
397
409
  'semantic-release'?: string | boolean | string[] | {
398
410
  config?: string | string[] | undefined;
399
411
  entry?: string | string[] | undefined;
@@ -564,8 +576,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
564
576
  entry?: string | string[] | undefined;
565
577
  project?: string | string[] | undefined;
566
578
  } | undefined;
579
+ exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
567
580
  $schema?: string | undefined;
568
- rules?: Partial<Record<"dependencies" | "exports" | "files" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
581
+ rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
569
582
  paths?: Record<string, string[]> | undefined;
570
583
  ignore?: string | string[] | undefined;
571
584
  ignoreBinaries?: (string | RegExp)[] | undefined;
@@ -576,7 +589,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
576
589
  ignoreWorkspaces?: string[] | undefined;
577
590
  includeEntryExports?: boolean | undefined;
578
591
  compilers?: Record<string, true | ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
592
+ tags?: string[] | undefined;
579
593
  treatConfigHintsAsErrors?: boolean | undefined;
594
+ include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
580
595
  workspaces?: Record<string, {
581
596
  node?: string | boolean | string[] | {
582
597
  config?: string | string[] | undefined;
@@ -610,6 +625,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
610
625
  entry?: string | string[] | undefined;
611
626
  project?: string | string[] | undefined;
612
627
  } | undefined;
628
+ bumpp?: string | boolean | string[] | {
629
+ config?: string | string[] | undefined;
630
+ entry?: string | string[] | undefined;
631
+ project?: string | string[] | undefined;
632
+ } | undefined;
613
633
  bun?: string | boolean | string[] | {
614
634
  config?: string | string[] | undefined;
615
635
  entry?: string | string[] | undefined;
@@ -895,6 +915,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
895
915
  entry?: string | string[] | undefined;
896
916
  project?: string | string[] | undefined;
897
917
  } | undefined;
918
+ pnpm?: string | boolean | string[] | {
919
+ config?: string | string[] | undefined;
920
+ entry?: string | string[] | undefined;
921
+ project?: string | string[] | undefined;
922
+ } | undefined;
898
923
  postcss?: string | boolean | string[] | {
899
924
  config?: string | string[] | undefined;
900
925
  entry?: string | string[] | undefined;
@@ -965,6 +990,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
965
990
  entry?: string | string[] | undefined;
966
991
  project?: string | string[] | undefined;
967
992
  } | undefined;
993
+ rstest?: string | boolean | string[] | {
994
+ config?: string | string[] | undefined;
995
+ entry?: string | string[] | undefined;
996
+ project?: string | string[] | undefined;
997
+ } | undefined;
968
998
  'semantic-release'?: string | boolean | string[] | {
969
999
  config?: string | string[] | undefined;
970
1000
  entry?: string | string[] | undefined;
package/dist/constants.js CHANGED
@@ -106,6 +106,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
106
106
  'tac',
107
107
  'tee',
108
108
  'test',
109
+ 'time',
109
110
  'timeout',
110
111
  'touch',
111
112
  'tr',
@@ -115,6 +116,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
115
116
  'uname',
116
117
  'unexpand',
117
118
  'uniq',
119
+ 'unzip',
118
120
  'wc',
119
121
  'who',
120
122
  'whoami',
@@ -4,9 +4,8 @@ import type { DependencyDeputy } from '../DependencyDeputy.js';
4
4
  import type { IssueCollector } from '../IssueCollector.js';
5
5
  import type { IssueFixer } from '../IssueFixer.js';
6
6
  import type { PrincipalFactory } from '../PrincipalFactory.js';
7
- import type { Tags } from '../types/cli.js';
8
- import type { Report } from '../types/issues.js';
9
7
  import type { ModuleGraph } from '../types/module-graph.js';
8
+ import type { MainOptions } from '../util/create-options.js';
10
9
  interface AnalyzeOptions {
11
10
  analyzedFiles: Set<string>;
12
11
  chief: ConfigurationChief;
@@ -16,13 +15,9 @@ interface AnalyzeOptions {
16
15
  factory: PrincipalFactory;
17
16
  fixer: IssueFixer;
18
17
  graph: ModuleGraph;
19
- isFix: boolean;
20
- isIncludeLibs: boolean;
21
- isProduction: boolean;
22
- report: Report;
23
18
  streamer: ConsoleStreamer;
24
- tags: Tags;
25
19
  unreferencedFiles: Set<string>;
20
+ options: MainOptions;
26
21
  }
27
- export declare const analyze: (options: AnalyzeOptions) => Promise<() => Promise<void>>;
22
+ export declare const analyze: ({ analyzedFiles, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }: AnalyzeOptions) => Promise<() => Promise<void>>;
28
23
  export {};