knip 5.63.0 → 5.63.1

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 (103) hide show
  1. package/dist/CacheConsultant.d.ts +3 -9
  2. package/dist/CacheConsultant.js +5 -5
  3. package/dist/ConfigurationChief.d.ts +585 -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/IssueCollector.d.ts +4 -12
  9. package/dist/IssueCollector.js +9 -9
  10. package/dist/IssueFixer.d.ts +3 -14
  11. package/dist/IssueFixer.js +11 -21
  12. package/dist/PrincipalFactory.d.ts +3 -2
  13. package/dist/PrincipalFactory.js +11 -11
  14. package/dist/ProjectPrincipal.d.ts +4 -3
  15. package/dist/ProjectPrincipal.js +8 -8
  16. package/dist/WorkspaceWorker.d.ts +4 -9
  17. package/dist/WorkspaceWorker.js +8 -12
  18. package/dist/binaries/bash-parser.js +1 -1
  19. package/dist/binaries/fallback.js +1 -1
  20. package/dist/binaries/package-manager/pnpm.js +6 -1
  21. package/dist/cli.js +43 -61
  22. package/dist/compilers/index.d.ts +14 -4
  23. package/dist/graph/analyze.d.ts +3 -8
  24. package/dist/graph/analyze.js +24 -27
  25. package/dist/graph/build.d.ts +3 -17
  26. package/dist/graph/build.js +42 -39
  27. package/dist/index.d.ts +3 -7
  28. package/dist/index.js +22 -62
  29. package/dist/plugins/index.d.ts +5 -0
  30. package/dist/plugins/index.js +2 -0
  31. package/dist/plugins/nuxt/index.js +4 -3
  32. package/dist/plugins/nuxt/types.d.ts +3 -2
  33. package/dist/plugins/pnpm/index.d.ts +7 -0
  34. package/dist/plugins/pnpm/index.js +8 -0
  35. package/dist/plugins/rsbuild/index.js +23 -6
  36. package/dist/plugins/rsbuild/types.d.ts +3 -0
  37. package/dist/plugins.js +3 -2
  38. package/dist/reporters/codeclimate.d.ts +1 -1
  39. package/dist/reporters/codeclimate.js +10 -10
  40. package/dist/reporters/codeowners.d.ts +1 -1
  41. package/dist/reporters/codeowners.js +5 -5
  42. package/dist/reporters/compact.d.ts +1 -1
  43. package/dist/reporters/compact.js +7 -7
  44. package/dist/reporters/disclosure.d.ts +1 -1
  45. package/dist/reporters/disclosure.js +2 -2
  46. package/dist/reporters/index.d.ts +6 -6
  47. package/dist/reporters/json.d.ts +1 -1
  48. package/dist/reporters/json.js +3 -3
  49. package/dist/reporters/markdown.d.ts +1 -1
  50. package/dist/reporters/markdown.js +4 -4
  51. package/dist/reporters/symbols.js +1 -1
  52. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  53. package/dist/reporters/util/configuration-hints.js +6 -7
  54. package/dist/reporters/util/util.d.ts +2 -2
  55. package/dist/reporters/util/util.js +4 -4
  56. package/dist/reporters/watch.d.ts +3 -4
  57. package/dist/reporters/watch.js +5 -5
  58. package/dist/schema/configuration.d.ts +64 -8
  59. package/dist/schema/plugins.d.ts +23 -0
  60. package/dist/schema/plugins.js +1 -0
  61. package/dist/types/PluginNames.d.ts +2 -2
  62. package/dist/types/PluginNames.js +1 -0
  63. package/dist/types/config.d.ts +4 -10
  64. package/dist/types/issues.d.ts +1 -2
  65. package/dist/types/{cli.d.ts → options.d.ts} +2 -2
  66. package/dist/types/package-json.d.ts +1 -0
  67. package/dist/types/project.d.ts +1 -7
  68. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  69. package/dist/typescript/get-imports-and-exports.js +9 -10
  70. package/dist/util/Performance.js +16 -6
  71. package/dist/util/cli-arguments.d.ts +1 -2
  72. package/dist/util/cli-arguments.js +3 -13
  73. package/dist/util/create-options.d.ts +1219 -0
  74. package/dist/util/create-options.js +112 -0
  75. package/dist/util/debug.js +3 -4
  76. package/dist/util/errors.d.ts +1 -1
  77. package/dist/util/file-entry-cache.js +3 -3
  78. package/dist/util/get-included-issue-types.d.ts +9 -13
  79. package/dist/util/get-included-issue-types.js +10 -16
  80. package/dist/util/get-referenced-inputs.js +1 -1
  81. package/dist/util/input.d.ts +1 -1
  82. package/dist/util/input.js +1 -1
  83. package/dist/util/is-identifier-referenced.d.ts +1 -1
  84. package/dist/util/is-identifier-referenced.js +2 -2
  85. package/dist/util/load-config.d.ts +1 -0
  86. package/dist/util/load-config.js +24 -0
  87. package/dist/util/path.d.ts +4 -4
  88. package/dist/util/path.js +5 -7
  89. package/dist/util/require.js +1 -2
  90. package/dist/util/tag.d.ts +1 -1
  91. package/dist/util/to-source-path.d.ts +1 -1
  92. package/dist/util/to-source-path.js +5 -5
  93. package/dist/util/trace.d.ts +6 -6
  94. package/dist/util/trace.js +18 -22
  95. package/dist/util/watch.d.ts +2 -5
  96. package/dist/util/watch.js +3 -3
  97. package/dist/version.d.ts +1 -1
  98. package/dist/version.js +1 -1
  99. package/package.json +2 -2
  100. package/schema.json +4 -0
  101. package/dist/util/unwrap-function.d.ts +0 -1
  102. package/dist/util/unwrap-function.js +0 -13
  103. /package/dist/types/{cli.js → options.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) {
@@ -88,7 +88,7 @@ export const getDependenciesFromScript = (script, options) => {
88
88
  return parsed?.commands ? getDependenciesFromNodes(parsed.commands) : [];
89
89
  }
90
90
  catch (error) {
91
- const msg = `Warning: failed to parse and ignoring script in ${relative(options.containingFilePath)} (${truncate(script, 30)})`;
91
+ const msg = `Warning: failed to parse and ignoring script in ${relative(options.cwd, options.containingFilePath)} (${truncate(script, 30)})`;
92
92
  debugLogObject('*', msg, error);
93
93
  return [];
94
94
  }
@@ -7,7 +7,7 @@ const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode',
7
7
  const positionalBinaries = new Set(['concurrently']);
8
8
  export const resolve = (binary, args, { fromArgs }) => {
9
9
  const parsed = parseArgs(args, { boolean: ['quiet', 'verbose'], '--': endOfCommandBinaries.includes(binary) });
10
- const bin = binary.startsWith('.') ? toEntry(binary) : binary.includes('*') ? undefined : toBinary(binary);
10
+ const bin = binary.startsWith('.') ? toEntry(binary) : /[*:]/.test(binary) ? undefined : toBinary(binary);
11
11
  const shiftedArgs = spawningBinaries.includes(binary) ? fromArgs(args) : [];
12
12
  const pos = positionals.has(binary) ? [toDeferResolve(parsed._[0])] : [];
13
13
  const newCommand = parsed['--'] && parsed['--'].length > 0 ? fromArgs(parsed['--']) : [];
@@ -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',
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;
@@ -324,6 +321,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
324
321
  entry?: string | string[] | undefined;
325
322
  project?: string | string[] | undefined;
326
323
  } | undefined;
324
+ pnpm?: string | boolean | string[] | {
325
+ config?: string | string[] | undefined;
326
+ entry?: string | string[] | undefined;
327
+ project?: string | string[] | undefined;
328
+ } | undefined;
327
329
  postcss?: string | boolean | string[] | {
328
330
  config?: string | string[] | undefined;
329
331
  entry?: string | string[] | undefined;
@@ -564,8 +566,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
564
566
  entry?: string | string[] | undefined;
565
567
  project?: string | string[] | undefined;
566
568
  } | undefined;
569
+ exclude?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
567
570
  $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;
571
+ rules?: Partial<Record<"files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers", "error" | "warn" | "off">> | undefined;
569
572
  paths?: Record<string, string[]> | undefined;
570
573
  ignore?: string | string[] | undefined;
571
574
  ignoreBinaries?: (string | RegExp)[] | undefined;
@@ -576,7 +579,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
576
579
  ignoreWorkspaces?: string[] | undefined;
577
580
  includeEntryExports?: boolean | undefined;
578
581
  compilers?: Record<string, true | ((args_0: string, args_1: string, ...args: unknown[]) => string) | ((args_0: string, args_1: string, ...args: unknown[]) => Promise<string>)> | undefined;
582
+ tags?: string[] | undefined;
579
583
  treatConfigHintsAsErrors?: boolean | undefined;
584
+ include?: ("files" | "dependencies" | "devDependencies" | "optionalPeerDependencies" | "unlisted" | "binaries" | "unresolved" | "exports" | "types" | "nsExports" | "nsTypes" | "duplicates" | "enumMembers" | "classMembers")[] | undefined;
580
585
  workspaces?: Record<string, {
581
586
  node?: string | boolean | string[] | {
582
587
  config?: string | string[] | undefined;
@@ -895,6 +900,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
895
900
  entry?: string | string[] | undefined;
896
901
  project?: string | string[] | undefined;
897
902
  } | undefined;
903
+ pnpm?: string | boolean | string[] | {
904
+ config?: string | string[] | undefined;
905
+ entry?: string | string[] | undefined;
906
+ project?: string | string[] | undefined;
907
+ } | undefined;
898
908
  postcss?: string | boolean | string[] | {
899
909
  config?: string | string[] | undefined;
900
910
  entry?: string | string[] | undefined;
@@ -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 {};
@@ -4,16 +4,10 @@ import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
4
4
  import { findMatch } from '../util/regex.js';
5
5
  import { getShouldIgnoreHandler, getShouldIgnoreTagHandler } from '../util/tag.js';
6
6
  import { createAndPrintTrace, printTrace } from '../util/trace.js';
7
- export const analyze = async (options) => {
8
- const { analyzedFiles, chief, collector, deputy, entryPaths, factory, fixer, graph, isFix, isIncludeLibs, isProduction, report, streamer, tags, unreferencedFiles, } = options;
9
- const isReportDependencies = report.dependencies || report.unlisted || report.unresolved || report.binaries;
10
- const isReportValues = report.exports || report.nsExports || report.classMembers;
11
- const isReportTypes = report.types || report.nsTypes || report.enumMembers;
12
- const isReportClassMembers = report.classMembers;
13
- const isSkipLibs = !(isIncludeLibs || isReportClassMembers);
14
- const shouldIgnore = getShouldIgnoreHandler(isProduction);
15
- const shouldIgnoreTags = getShouldIgnoreTagHandler(tags);
16
- const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths);
7
+ export const analyze = async ({ analyzedFiles, chief, collector, deputy, entryPaths, factory, fixer, graph, streamer, unreferencedFiles, options, }) => {
8
+ const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
9
+ const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
10
+ const isIdentifierReferenced = getIsIdentifierReferencedHandler(graph, entryPaths, options.isTrace);
17
11
  const ignoreExportsUsedInFile = chief.config.ignoreExportsUsedInFile;
18
12
  const isExportedItemReferenced = (exportedItem) => exportedItem.refs[1] ||
19
13
  (exportedItem.refs[0] > 0 &&
@@ -21,7 +15,7 @@ export const analyze = async (options) => {
21
15
  ? exportedItem.type !== 'unknown' && !!ignoreExportsUsedInFile[exportedItem.type]
22
16
  : ignoreExportsUsedInFile));
23
17
  const analyzeGraph = async () => {
24
- if (isReportValues || isReportTypes) {
18
+ if (options.isReportValues || options.isReportTypes) {
25
19
  streamer.cast('Connecting the dots');
26
20
  for (const [filePath, file] of graph.entries()) {
27
21
  const exportItems = file.exports;
@@ -33,7 +27,7 @@ export const analyze = async (options) => {
33
27
  const principal = factory.getPrincipalByPackageName(workspace.pkgName);
34
28
  const isEntry = entryPaths.has(filePath);
35
29
  if (!isIncludeEntryExports && isEntry) {
36
- createAndPrintTrace(filePath, { isEntry });
30
+ createAndPrintTrace(filePath, options, { isEntry });
37
31
  continue;
38
32
  }
39
33
  const importsForExport = file.imported;
@@ -45,7 +39,7 @@ export const analyze = async (options) => {
45
39
  const { isReferenced, reExportingEntryFile, traceNode } = isIdentifierReferenced(filePath, identifier, isIncludeEntryExports);
46
40
  if ((isReferenced || exportedItem.refs[1]) && isIgnored) {
47
41
  for (const tagName of exportedItem.jsDocTags) {
48
- if (tags[1].includes(tagName.replace(/^@/, ''))) {
42
+ if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
49
43
  collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
50
44
  }
51
45
  }
@@ -54,7 +48,7 @@ export const analyze = async (options) => {
54
48
  continue;
55
49
  if (reExportingEntryFile) {
56
50
  if (!isIncludeEntryExports) {
57
- createAndPrintTrace(filePath, { identifier, isEntry, hasRef: isReferenced });
51
+ createAndPrintTrace(filePath, options, { identifier, isEntry, hasRef: isReferenced });
58
52
  continue;
59
53
  }
60
54
  const reExportedItem = graph.get(reExportingEntryFile)?.exports.get(identifier);
@@ -62,10 +56,10 @@ export const analyze = async (options) => {
62
56
  continue;
63
57
  }
64
58
  if (traceNode)
65
- printTrace(traceNode, filePath, identifier);
59
+ printTrace(traceNode, filePath, options, identifier);
66
60
  if (isReferenced) {
67
- if (report.enumMembers && exportedItem.type === 'enum') {
68
- if (!report.nsTypes && importsForExport.refs.has(identifier))
61
+ if (options.includedIssueTypes.enumMembers && exportedItem.type === 'enum') {
62
+ if (!options.includedIssueTypes.nsTypes && importsForExport.refs.has(identifier))
69
63
  continue;
70
64
  if (hasStrictlyEnumReferences(importsForExport, identifier))
71
65
  continue;
@@ -91,12 +85,12 @@ export const analyze = async (options) => {
91
85
  line: member.line,
92
86
  col: member.col,
93
87
  });
94
- if (isFix && isIssueAdded && member.fix)
88
+ if (options.isFix && isIssueAdded && member.fix)
95
89
  fixer.addUnusedTypeNode(filePath, [member.fix]);
96
90
  }
97
91
  else if (isIgnored) {
98
92
  for (const tagName of exportedItem.jsDocTags) {
99
- if (tags[1].includes(tagName.replace(/^@/, ''))) {
93
+ if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
100
94
  collector.addTagHint({ type: 'tag', filePath, identifier: id, tagName });
101
95
  }
102
96
  }
@@ -104,13 +98,13 @@ export const analyze = async (options) => {
104
98
  }
105
99
  }
106
100
  }
107
- if (principal && isReportClassMembers && exportedItem.type === 'class') {
101
+ if (principal && options.isReportClassMembers && exportedItem.type === 'class') {
108
102
  const members = exportedItem.members.filter(member => !(findMatch(workspace.ignoreMembers, member.identifier) || shouldIgnore(member.jsDocTags)));
109
103
  for (const member of principal.findUnusedMembers(filePath, members)) {
110
104
  if (shouldIgnoreTags(member.jsDocTags)) {
111
105
  const identifier = `${exportedItem.identifier}.${member.identifier}`;
112
106
  for (const tagName of exportedItem.jsDocTags) {
113
- if (tags[1].includes(tagName.replace(/^@/, ''))) {
107
+ if (options.tags[1].includes(tagName.replace(/^@/, ''))) {
114
108
  collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
115
109
  }
116
110
  }
@@ -126,7 +120,7 @@ export const analyze = async (options) => {
126
120
  line: member.line,
127
121
  col: member.col,
128
122
  });
129
- if (isFix && isIssueAdded && member.fix)
123
+ if (options.isFix && isIssueAdded && member.fix)
130
124
  fixer.addUnusedTypeNode(filePath, [member.fix]);
131
125
  }
132
126
  }
@@ -135,12 +129,13 @@ export const analyze = async (options) => {
135
129
  }
136
130
  const [hasStrictlyNsRefs, namespace] = hasStrictlyNsReferences(graph, importsForExport, identifier);
137
131
  const isType = ['enum', 'type', 'interface'].includes(exportedItem.type);
138
- if (hasStrictlyNsRefs && ((!report.nsTypes && isType) || !(report.nsExports || isType)))
132
+ if (hasStrictlyNsRefs &&
133
+ ((!options.includedIssueTypes.nsTypes && isType) || !(options.includedIssueTypes.nsExports || isType)))
139
134
  continue;
140
135
  if (!isExportedItemReferenced(exportedItem)) {
141
136
  if (isIgnored)
142
137
  continue;
143
- if (!isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
138
+ if (!options.isSkipLibs && principal?.hasExternalReferences(filePath, exportedItem))
144
139
  continue;
145
140
  const type = getType(hasStrictlyNsRefs, isType);
146
141
  const isIssueAdded = collector.addIssue({
@@ -154,7 +149,7 @@ export const analyze = async (options) => {
154
149
  line: exportedItem.line,
155
150
  col: exportedItem.col,
156
151
  });
157
- if (isFix && isIssueAdded) {
152
+ if (options.isFix && isIssueAdded) {
158
153
  if (isType)
159
154
  fixer.addUnusedTypeNode(filePath, exportedItem.fixes);
160
155
  else
@@ -201,11 +196,11 @@ export const analyze = async (options) => {
201
196
  const unusedFiles = [...unreferencedFiles].filter(filePath => !analyzedFiles.has(filePath));
202
197
  collector.addFilesIssues(unusedFiles);
203
198
  collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
204
- if (isReportDependencies) {
199
+ if (options.isReportDependencies) {
205
200
  const { dependencyIssues, devDependencyIssues, optionalPeerDependencyIssues } = deputy.settleDependencyIssues();
206
201
  for (const issue of dependencyIssues)
207
202
  collector.addIssue(issue);
208
- if (!isProduction)
203
+ if (!options.isProduction)
209
204
  for (const issue of devDependencyIssues)
210
205
  collector.addIssue(issue);
211
206
  for (const issue of optionalPeerDependencyIssues)
@@ -219,6 +214,8 @@ export const analyze = async (options) => {
219
214
  for (const identifier of unusedIgnoredWorkspaces) {
220
215
  collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier });
221
216
  }
217
+ for (const hint of chief.getConfigurationHints())
218
+ collector.addConfigurationHint(hint);
222
219
  };
223
220
  await analyzeGraph();
224
221
  return analyzeGraph;