knip 6.14.2 → 6.16.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 (111) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +32 -0
  4. package/dist/ConfigurationChief.js +9 -11
  5. package/dist/DependencyDeputy.d.ts +0 -4
  6. package/dist/DependencyDeputy.js +4 -16
  7. package/dist/IssueCollector.d.ts +1 -0
  8. package/dist/IssueCollector.js +10 -20
  9. package/dist/IssueFixer.js +10 -15
  10. package/dist/ProjectPrincipal.d.ts +2 -3
  11. package/dist/ProjectPrincipal.js +13 -21
  12. package/dist/WorkspaceWorker.js +6 -1
  13. package/dist/binaries/fallback.js +1 -1
  14. package/dist/binaries/plugins.js +1 -1
  15. package/dist/binaries/resolvers/bun.js +1 -1
  16. package/dist/binaries/resolvers/bunx.js +1 -1
  17. package/dist/binaries/resolvers/npm.js +1 -1
  18. package/dist/binaries/resolvers/npx.js +1 -1
  19. package/dist/binaries/resolvers/pnpm.js +1 -1
  20. package/dist/binaries/resolvers/pnpx.js +1 -1
  21. package/dist/binaries/resolvers/yarn.js +1 -1
  22. package/dist/binaries/util.d.ts +1 -2
  23. package/dist/binaries/util.js +1 -1
  24. package/dist/cli.js +3 -1
  25. package/dist/compilers/compilers.d.ts +3 -0
  26. package/dist/compilers/compilers.js +9 -13
  27. package/dist/compilers/index.d.ts +52 -0
  28. package/dist/compilers/scss.js +9 -3
  29. package/dist/graph/analyze.js +15 -8
  30. package/dist/graph/build.js +3 -5
  31. package/dist/manifest/index.js +11 -14
  32. package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
  33. package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
  34. package/dist/plugins/bun/index.js +1 -1
  35. package/dist/plugins/catalyst/index.d.ts +3 -0
  36. package/dist/plugins/catalyst/index.js +16 -0
  37. package/dist/plugins/execa/visitors/execa.js +4 -17
  38. package/dist/plugins/fast/index.d.ts +3 -0
  39. package/dist/plugins/fast/index.js +16 -0
  40. package/dist/plugins/index.d.ts +5 -0
  41. package/dist/plugins/index.js +10 -0
  42. package/dist/plugins/lit/index.d.ts +3 -0
  43. package/dist/plugins/lit/index.js +25 -0
  44. package/dist/plugins/nano-spawn/index.d.ts +3 -0
  45. package/dist/plugins/nano-spawn/index.js +15 -0
  46. package/dist/plugins/nano-spawn/visitors/nano-spawn.d.ts +2 -0
  47. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +12 -0
  48. package/dist/plugins/orval/index.d.ts +3 -0
  49. package/dist/plugins/orval/index.js +16 -0
  50. package/dist/plugins/orval/resolveFromAST.d.ts +2 -0
  51. package/dist/plugins/orval/resolveFromAST.js +11 -0
  52. package/dist/plugins/orval/types.d.ts +9 -0
  53. package/dist/plugins/orval/types.js +1 -0
  54. package/dist/plugins/relay/index.js +1 -1
  55. package/dist/plugins/stencil/index.js +17 -1
  56. package/dist/plugins/sveltejs-package/helpers.js +1 -1
  57. package/dist/plugins/vite/helpers.js +23 -6
  58. package/dist/plugins/webdriver-io/index.js +3 -3
  59. package/dist/plugins/webdriver-io/types.d.ts +5 -1
  60. package/dist/reporters/github-actions.d.ts +1 -1
  61. package/dist/reporters/github-actions.js +19 -1
  62. package/dist/reporters/index.d.ts +1 -1
  63. package/dist/reporters/symbols.js +2 -1
  64. package/dist/reporters/trace.d.ts +3 -1
  65. package/dist/reporters/trace.js +48 -16
  66. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  67. package/dist/reporters/util/configuration-hints.js +3 -2
  68. package/dist/schema/configuration.d.ts +83 -1
  69. package/dist/schema/configuration.js +2 -0
  70. package/dist/schema/plugins.d.ts +25 -0
  71. package/dist/schema/plugins.js +5 -0
  72. package/dist/types/PluginNames.d.ts +2 -2
  73. package/dist/types/PluginNames.js +5 -0
  74. package/dist/types/args.d.ts +1 -1
  75. package/dist/types/config.d.ts +2 -0
  76. package/dist/types/issues.d.ts +1 -0
  77. package/dist/types/module-graph.d.ts +1 -0
  78. package/dist/types/project.d.ts +0 -1
  79. package/dist/typescript/ast-helpers.js +21 -20
  80. package/dist/typescript/ast-nodes.d.ts +1 -0
  81. package/dist/typescript/ast-nodes.js +19 -0
  82. package/dist/typescript/get-imports-and-exports.js +18 -2
  83. package/dist/typescript/resolve-module-names.d.ts +6 -2
  84. package/dist/typescript/resolve-module-names.js +20 -29
  85. package/dist/typescript/visitors/calls.d.ts +3 -2
  86. package/dist/typescript/visitors/calls.js +88 -16
  87. package/dist/typescript/visitors/exports.js +12 -0
  88. package/dist/typescript/visitors/walk.d.ts +7 -0
  89. package/dist/typescript/visitors/walk.js +43 -1
  90. package/dist/util/Performance.d.ts +13 -28
  91. package/dist/util/Performance.js +41 -72
  92. package/dist/util/cli-arguments.d.ts +3 -1
  93. package/dist/util/cli-arguments.js +4 -0
  94. package/dist/util/create-options.d.ts +53 -0
  95. package/dist/util/create-options.js +2 -1
  96. package/dist/util/disk-cache.d.ts +1 -0
  97. package/dist/util/disk-cache.js +8 -0
  98. package/dist/util/gitignore-cache.js +5 -11
  99. package/dist/util/glob-cache.js +2 -8
  100. package/dist/util/glob-core.js +4 -7
  101. package/dist/util/jiti.js +1 -0
  102. package/dist/util/load-tsconfig.js +0 -3
  103. package/dist/util/parse-args.d.ts +14 -0
  104. package/dist/util/parse-args.js +112 -0
  105. package/dist/util/trace.js +1 -1
  106. package/dist/version.d.ts +1 -1
  107. package/dist/version.js +1 -1
  108. package/package.json +3 -6
  109. package/schema.json +73 -43
  110. package/dist/util/math.d.ts +0 -6
  111. package/dist/util/math.js +0 -11
@@ -1,7 +1,6 @@
1
- import { PerformanceObserver, performance } from 'node:perf_hooks';
1
+ import { PerformanceObserver, createHistogram, performance, } from 'node:perf_hooks';
2
2
  import { memoryUsage } from 'node:process';
3
3
  import { parseArgs } from 'node:util';
4
- import { getStats } from './math.js';
5
4
  import { Table } from './table.js';
6
5
  const { values } = parseArgs({
7
6
  strict: false,
@@ -18,13 +17,6 @@ const isMemoryRealtime = !!values['memory-realtime'];
18
17
  const isTimerifyFunctions = !!values.performance || !!timerifyOnlyFnName;
19
18
  const isMemoryUsageEnabled = !!values.memory || isMemoryRealtime;
20
19
  const isDurationEnabled = !!values.duration;
21
- export const timerify = (fn, name = fn.name) => {
22
- if (!isTimerifyFunctions)
23
- return fn;
24
- if (timerifyOnlyFnName && !timerifyOnlyFnName.includes(name))
25
- return fn;
26
- return performance.timerify(Object.defineProperty(fn, 'name', { get: () => name }));
27
- };
28
20
  const getMemInfo = (label) => {
29
21
  const usage = memoryUsage();
30
22
  return { label, heapUsed: usage.heapUsed, heapTotal: usage.heapTotal, rss: usage.rss };
@@ -39,36 +31,20 @@ class Performance {
39
31
  isTimerifyFunctions;
40
32
  isMemoryUsageEnabled;
41
33
  isDurationEnabled;
42
- startTime = 0;
43
- endTime = 0;
44
- perfEntries = [];
34
+ startTime = performance.now();
35
+ memId = `mem-${Math.floor(performance.now() * 100)}`;
36
+ histograms = new Map();
45
37
  memEntries = [];
46
- perfId;
47
- memId;
48
- fnObserver;
49
38
  memObserver;
50
39
  constructor({ isTimerifyFunctions = false, isMemoryUsageEnabled = false, isDurationEnabled = false }) {
51
40
  this.isEnabled = isTimerifyFunctions || isMemoryUsageEnabled;
52
41
  this.isTimerifyFunctions = isTimerifyFunctions;
53
42
  this.isMemoryUsageEnabled = isMemoryUsageEnabled;
54
43
  this.isDurationEnabled = isDurationEnabled;
55
- this.startTime = performance.now();
56
- const instanceId = Math.floor(performance.now() * 100);
57
- this.perfId = `perf-${instanceId}`;
58
- this.memId = `mem-${instanceId}`;
59
- if (isTimerifyFunctions) {
60
- this.fnObserver = new PerformanceObserver(items => {
61
- for (const entry of items.getEntries()) {
62
- this.perfEntries.push(entry);
63
- }
64
- });
65
- this.fnObserver.observe({ type: 'function' });
66
- }
67
44
  if (isMemoryUsageEnabled) {
68
45
  this.memObserver = new PerformanceObserver(items => {
69
- for (const entry of items.getEntries()) {
46
+ for (const entry of items.getEntries())
70
47
  this.memEntries.push(entry);
71
- }
72
48
  });
73
49
  this.memObserver.observe({ type: 'mark' });
74
50
  if (isMemoryRealtime)
@@ -76,57 +52,42 @@ class Performance {
76
52
  this.addMemoryMark('start');
77
53
  }
78
54
  }
79
- setMark(name) {
80
- const id = `${this.perfId}:${name}`;
81
- performance.mark(`${id}:start`);
82
- }
83
- clearMark(name) {
84
- const id = `${this.perfId}:${name}`;
85
- performance.mark(`${id}:end`);
86
- performance.measure(id, `${id}:start`, `${id}:end`);
87
- performance.clearMarks(`${id}:start`);
88
- performance.clearMarks(`${id}:end`);
89
- }
90
- async flush() {
91
- this.setMark('_flush');
92
- await new Promise(resolve => setTimeout(resolve, 1));
93
- this.clearMark('_flush');
55
+ registerHistogram(name) {
56
+ let histogram = this.histograms.get(name);
57
+ if (!histogram) {
58
+ histogram = createHistogram();
59
+ this.histograms.set(name, histogram);
60
+ }
61
+ return histogram;
94
62
  }
95
- getPerfEntriesByName() {
96
- return this.perfEntries.reduce((entries, entry) => {
97
- const name = entry.name.replace(`${this.perfId}:`, '');
98
- entries[name] = entries[name] ?? [];
99
- entries[name].push(entry.duration);
100
- return entries;
101
- }, {});
63
+ addMemoryMark(label) {
64
+ if (!this.isMemoryUsageEnabled)
65
+ return;
66
+ const detail = getMemInfo(label);
67
+ performance.mark(`${this.memId}:${label}`, { detail });
68
+ if (isMemoryRealtime)
69
+ log(detail);
102
70
  }
103
71
  getTimerifiedFunctionsTable() {
104
- const entriesByName = this.getPerfEntriesByName();
105
72
  const totalDuration = this.getCurrentDurationInMs();
106
73
  const table = new Table({ header: true });
107
- for (const [name, values] of Object.entries(entriesByName)) {
108
- const stats = getStats(values);
74
+ for (const [name, h] of this.histograms) {
75
+ if (h.count === 0)
76
+ continue;
77
+ const meanMs = h.mean / 1e6;
78
+ const sumMs = meanMs * h.count;
109
79
  table.row();
110
80
  table.cell('Name', name);
111
- table.cell('size', values.length);
112
- table.cell('min', stats.min, twoFixed);
113
- table.cell('max', stats.max, twoFixed);
114
- table.cell('median', stats.median, twoFixed);
115
- table.cell('sum', stats.sum, twoFixed);
116
- table.cell('%', (stats.sum / totalDuration) * 100, v => (typeof v === 'number' ? `${v.toFixed(0)}%` : ''));
81
+ table.cell('size', h.count);
82
+ table.cell('min', h.min / 1e6, twoFixed);
83
+ table.cell('max', h.max / 1e6, twoFixed);
84
+ table.cell('median', h.percentile(50) / 1e6, twoFixed);
85
+ table.cell('sum', sumMs, twoFixed);
86
+ table.cell('%', (sumMs / totalDuration) * 100, v => (typeof v === 'number' ? `${v.toFixed(0)}%` : ''));
117
87
  }
118
88
  table.sort('sum', 'desc');
119
89
  return table.toString();
120
90
  }
121
- addMemoryMark(label) {
122
- if (!this.isMemoryUsageEnabled)
123
- return;
124
- const id = `${this.memId}:${label}`;
125
- const detail = getMemInfo(label);
126
- performance.mark(id, { detail });
127
- if (isMemoryRealtime)
128
- log(detail);
129
- }
130
91
  getMemoryUsageTable() {
131
92
  const table = new Table({ header: true });
132
93
  let prevHeapUsed = 0;
@@ -168,12 +129,20 @@ class Performance {
168
129
  if (!this.isEnabled)
169
130
  return;
170
131
  this.addMemoryMark('end');
171
- await this.flush();
132
+ await new Promise(resolve => setTimeout(resolve, 1));
172
133
  }
173
134
  reset() {
174
- this.perfEntries = [];
175
- this.fnObserver?.disconnect();
135
+ this.histograms.clear();
136
+ this.memEntries.length = 0;
176
137
  this.memObserver?.disconnect();
177
138
  }
178
139
  }
179
140
  export const perfObserver = new Performance({ isTimerifyFunctions, isMemoryUsageEnabled, isDurationEnabled });
141
+ export const timerify = (fn, name = fn.name) => {
142
+ if (!isTimerifyFunctions)
143
+ return fn;
144
+ if (timerifyOnlyFnName && !timerifyOnlyFnName.includes(name))
145
+ return fn;
146
+ const histogram = perfObserver.registerHistogram(name);
147
+ return performance.timerify(Object.defineProperty(fn, 'name', { value: name }), { histogram });
148
+ };
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include 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,catalog\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, json, codeclimate, markdown, disclosure, github-actions\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
1
+ export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include 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,catalog\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-tag-hints Suppress tag hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, json, codeclimate, markdown, disclosure, github-actions\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
2
2
  export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
3
3
  export default function parseCLIArgs(): {
4
4
  cache?: boolean | undefined;
@@ -26,6 +26,7 @@ export default function parseCLIArgs(): {
26
26
  'no-exit-code'?: boolean | undefined;
27
27
  'no-gitignore'?: boolean | undefined;
28
28
  'no-progress'?: boolean | undefined;
29
+ 'no-tag-hints'?: boolean | undefined;
29
30
  performance?: boolean | undefined;
30
31
  'performance-fn'?: string | undefined;
31
32
  production?: boolean | undefined;
@@ -40,6 +41,7 @@ export default function parseCLIArgs(): {
40
41
  'trace-export'?: string | undefined;
41
42
  'trace-file'?: string | undefined;
42
43
  'treat-config-hints-as-errors'?: boolean | undefined;
44
+ 'treat-tag-hints-as-errors'?: boolean | undefined;
43
45
  tsConfig?: string | undefined;
44
46
  'use-tsconfig-files'?: boolean | undefined;
45
47
  version?: boolean | undefined;
@@ -43,7 +43,9 @@ Output
43
43
  --reporter Select reporter (default: symbols), can be repeated (3)
44
44
  --reporter-options Pass extra options to the reporter (as JSON string, see example)
45
45
  --no-config-hints Suppress configuration hints
46
+ --no-tag-hints Suppress tag hints
46
47
  --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints
48
+ --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints
47
49
  --max-issues Maximum number of total issues before non-zero exit code (default: 0)
48
50
  --max-show-issues Maximum number of issues to display per type
49
51
  --no-exit-code Always exit with code zero (0)
@@ -104,6 +106,7 @@ export default function parseCLIArgs() {
104
106
  'no-exit-code': { type: 'boolean' },
105
107
  'no-gitignore': { type: 'boolean' },
106
108
  'no-progress': { type: 'boolean', short: 'n' },
109
+ 'no-tag-hints': { type: 'boolean' },
107
110
  performance: { type: 'boolean' },
108
111
  'performance-fn': { type: 'string' },
109
112
  production: { type: 'boolean', short: 'p' },
@@ -118,6 +121,7 @@ export default function parseCLIArgs() {
118
121
  'trace-export': { type: 'string' },
119
122
  'trace-file': { type: 'string' },
120
123
  'treat-config-hints-as-errors': { type: 'boolean' },
124
+ 'treat-tag-hints-as-errors': { type: 'boolean' },
121
125
  tsConfig: { type: 'string', short: 't' },
122
126
  'use-tsconfig-files': { type: 'boolean' },
123
127
  version: { type: 'boolean', short: 'V' },
@@ -38,6 +38,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
38
38
  isStrict: boolean;
39
39
  isTrace: boolean;
40
40
  isTreatConfigHintsAsErrors: boolean;
41
+ isTreatTagHintsAsErrors: boolean;
41
42
  isUseTscFiles: boolean | undefined;
42
43
  isWatch: boolean;
43
44
  maxShowIssues: number | undefined;
@@ -97,6 +98,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
97
98
  entry?: string | string[] | undefined;
98
99
  project?: string | string[] | undefined;
99
100
  } | undefined;
101
+ catalyst?: string | boolean | string[] | {
102
+ config?: string | string[] | undefined;
103
+ entry?: string | string[] | undefined;
104
+ project?: string | string[] | undefined;
105
+ } | undefined;
100
106
  changelogen?: string | boolean | string[] | {
101
107
  config?: string | string[] | undefined;
102
108
  entry?: string | string[] | undefined;
@@ -197,6 +203,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
197
203
  entry?: string | string[] | undefined;
198
204
  project?: string | string[] | undefined;
199
205
  } | undefined;
206
+ fast?: string | boolean | string[] | {
207
+ config?: string | string[] | undefined;
208
+ entry?: string | string[] | undefined;
209
+ project?: string | string[] | undefined;
210
+ } | undefined;
200
211
  gatsby?: string | boolean | string[] | {
201
212
  config?: string | string[] | undefined;
202
213
  entry?: string | string[] | undefined;
@@ -272,6 +283,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
272
283
  entry?: string | string[] | undefined;
273
284
  project?: string | string[] | undefined;
274
285
  } | undefined;
286
+ lit?: string | boolean | string[] | {
287
+ config?: string | string[] | undefined;
288
+ entry?: string | string[] | undefined;
289
+ project?: string | string[] | undefined;
290
+ } | undefined;
275
291
  'lockfile-lint'?: string | boolean | string[] | {
276
292
  config?: string | string[] | undefined;
277
293
  entry?: string | string[] | undefined;
@@ -317,6 +333,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
317
333
  entry?: string | string[] | undefined;
318
334
  project?: string | string[] | undefined;
319
335
  } | undefined;
336
+ 'nano-spawn'?: string | boolean | string[] | {
337
+ config?: string | string[] | undefined;
338
+ entry?: string | string[] | undefined;
339
+ project?: string | string[] | undefined;
340
+ } | undefined;
320
341
  'nano-staged'?: string | boolean | string[] | {
321
342
  config?: string | string[] | undefined;
322
343
  entry?: string | string[] | undefined;
@@ -397,6 +418,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
397
418
  entry?: string | string[] | undefined;
398
419
  project?: string | string[] | undefined;
399
420
  } | undefined;
421
+ orval?: string | boolean | string[] | {
422
+ config?: string | string[] | undefined;
423
+ entry?: string | string[] | undefined;
424
+ project?: string | string[] | undefined;
425
+ } | undefined;
400
426
  oxfmt?: string | boolean | string[] | {
401
427
  config?: string | string[] | undefined;
402
428
  entry?: string | string[] | undefined;
@@ -812,6 +838,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
812
838
  asyncCompilers?: Record<string, import("../compilers/types.ts").CompilerAsync> | undefined;
813
839
  tags?: string[] | undefined;
814
840
  treatConfigHintsAsErrors?: boolean | undefined;
841
+ treatTagHintsAsErrors?: boolean | undefined;
815
842
  include?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
816
843
  exclude?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
817
844
  workspaces?: Record<string, {
@@ -870,6 +897,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
870
897
  entry?: string | string[] | undefined;
871
898
  project?: string | string[] | undefined;
872
899
  } | undefined;
900
+ catalyst?: string | boolean | string[] | {
901
+ config?: string | string[] | undefined;
902
+ entry?: string | string[] | undefined;
903
+ project?: string | string[] | undefined;
904
+ } | undefined;
873
905
  changelogen?: string | boolean | string[] | {
874
906
  config?: string | string[] | undefined;
875
907
  entry?: string | string[] | undefined;
@@ -970,6 +1002,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
970
1002
  entry?: string | string[] | undefined;
971
1003
  project?: string | string[] | undefined;
972
1004
  } | undefined;
1005
+ fast?: string | boolean | string[] | {
1006
+ config?: string | string[] | undefined;
1007
+ entry?: string | string[] | undefined;
1008
+ project?: string | string[] | undefined;
1009
+ } | undefined;
973
1010
  gatsby?: string | boolean | string[] | {
974
1011
  config?: string | string[] | undefined;
975
1012
  entry?: string | string[] | undefined;
@@ -1045,6 +1082,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1045
1082
  entry?: string | string[] | undefined;
1046
1083
  project?: string | string[] | undefined;
1047
1084
  } | undefined;
1085
+ lit?: string | boolean | string[] | {
1086
+ config?: string | string[] | undefined;
1087
+ entry?: string | string[] | undefined;
1088
+ project?: string | string[] | undefined;
1089
+ } | undefined;
1048
1090
  'lockfile-lint'?: string | boolean | string[] | {
1049
1091
  config?: string | string[] | undefined;
1050
1092
  entry?: string | string[] | undefined;
@@ -1090,6 +1132,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1090
1132
  entry?: string | string[] | undefined;
1091
1133
  project?: string | string[] | undefined;
1092
1134
  } | undefined;
1135
+ 'nano-spawn'?: string | boolean | string[] | {
1136
+ config?: string | string[] | undefined;
1137
+ entry?: string | string[] | undefined;
1138
+ project?: string | string[] | undefined;
1139
+ } | undefined;
1093
1140
  'nano-staged'?: string | boolean | string[] | {
1094
1141
  config?: string | string[] | undefined;
1095
1142
  entry?: string | string[] | undefined;
@@ -1170,6 +1217,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1170
1217
  entry?: string | string[] | undefined;
1171
1218
  project?: string | string[] | undefined;
1172
1219
  } | undefined;
1220
+ orval?: string | boolean | string[] | {
1221
+ config?: string | string[] | undefined;
1222
+ entry?: string | string[] | undefined;
1223
+ project?: string | string[] | undefined;
1224
+ } | undefined;
1173
1225
  oxfmt?: string | boolean | string[] | {
1174
1226
  config?: string | string[] | undefined;
1175
1227
  entry?: string | string[] | undefined;
@@ -1574,6 +1626,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1574
1626
  ignoreDependencies?: (string | RegExp)[] | undefined;
1575
1627
  ignoreMembers?: (string | RegExp)[] | undefined;
1576
1628
  ignoreUnresolved?: (string | RegExp)[] | undefined;
1629
+ ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
1577
1630
  includeEntryExports?: boolean | undefined;
1578
1631
  }> | undefined;
1579
1632
  };
@@ -107,7 +107,7 @@ export const createOptions = async (options) => {
107
107
  isCache: args.cache ?? false,
108
108
  isDebug,
109
109
  isDisableConfigHints: args['no-config-hints'] || isProduction || Boolean(workspace),
110
- isDisableTagHints: Boolean(args['no-config-hints']),
110
+ isDisableTagHints: Boolean(args['no-tag-hints']),
111
111
  isFix: args.fix ?? options.isFix ?? isFixFiles ?? fixTypes.length > 0,
112
112
  isFixCatalog: fixTypes.length === 0 || fixTypes.includes('catalog'),
113
113
  isFixDependencies: fixTypes.length === 0 || fixTypes.includes('dependencies'),
@@ -144,6 +144,7 @@ export const createOptions = async (options) => {
144
144
  isStrict,
145
145
  isTrace,
146
146
  isTreatConfigHintsAsErrors: args['treat-config-hints-as-errors'] ?? parsedConfig.treatConfigHintsAsErrors ?? false,
147
+ isTreatTagHintsAsErrors: args['treat-tag-hints-as-errors'] ?? parsedConfig.treatTagHintsAsErrors ?? false,
147
148
  isUseTscFiles: options.isUseTscFiles ?? args['use-tsconfig-files'] ?? (options.isSession && !configFilePath),
148
149
  isWatch: args.watch ?? options.isWatch ?? false,
149
150
  maxShowIssues: args['max-show-issues'] ? Number(args['max-show-issues']) : undefined,
@@ -1,3 +1,4 @@
1
+ export declare const mtimeMatches: (filePath: string, mtimeMs: number) => boolean;
1
2
  export interface DiskCache<V> {
2
3
  init: (cacheLocation: string) => void;
3
4
  isEnabled: () => boolean;
@@ -5,6 +5,14 @@ import { version } from '../version.js';
5
5
  import { debugLog } from './debug.js';
6
6
  import { isDirectory, isFile } from './fs.js';
7
7
  import { dirname } from './path.js';
8
+ export const mtimeMatches = (filePath, mtimeMs) => {
9
+ try {
10
+ return fs.statSync(filePath).mtimeMs === mtimeMs;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ };
8
16
  export const createDiskCache = (name) => {
9
17
  const filename = `${name}-${version}.cache`;
10
18
  let cacheFilePath;
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { createDiskCache } from './disk-cache.js';
3
+ import { createDiskCache, mtimeMatches } from './disk-cache.js';
4
4
  const store = createDiskCache('gitignore');
5
5
  export const initGitignoreCache = store.init;
6
6
  export const isGitignoreCacheEnabled = store.isEnabled;
@@ -13,17 +13,11 @@ const workspaceDirsKey = (workspaceDirs) => {
13
13
  const validateEntry = (entry, wsKey, cwd) => {
14
14
  if (entry.workspaceDirsKey !== wsKey)
15
15
  return false;
16
- const files = entry.gitignoreFiles;
17
- const mtimes = entry.mtimes;
18
- for (let i = 0; i < files.length; i++) {
19
- const abs = path.isAbsolute(files[i]) ? files[i] : path.resolve(cwd, files[i]);
20
- try {
21
- if (fs.statSync(abs).mtimeMs !== mtimes[i])
22
- return false;
23
- }
24
- catch {
16
+ const { gitignoreFiles, mtimes } = entry;
17
+ for (let i = 0; i < gitignoreFiles.length; i++) {
18
+ const abs = path.isAbsolute(gitignoreFiles[i]) ? gitignoreFiles[i] : path.resolve(cwd, gitignoreFiles[i]);
19
+ if (!mtimeMatches(abs, mtimes[i]))
25
20
  return false;
26
- }
27
21
  }
28
22
  return true;
29
23
  };
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import fs from 'node:fs';
3
- import { createDiskCache } from './disk-cache.js';
3
+ import { createDiskCache, mtimeMatches } from './disk-cache.js';
4
4
  import { dirname } from './path.js';
5
5
  const store = createDiskCache('glob');
6
6
  export const initGlobCache = store.init;
@@ -23,14 +23,8 @@ export const computeGlobCacheKey = (input) => {
23
23
  };
24
24
  const validateEntry = (entry) => {
25
25
  for (const dir in entry.dirMtimes) {
26
- try {
27
- const stat = fs.statSync(dir);
28
- if (stat.mtimeMs !== entry.dirMtimes[dir])
29
- return false;
30
- }
31
- catch {
26
+ if (!mtimeMatches(dir, entry.dirMtimes[dir]))
32
27
  return false;
33
- }
34
28
  }
35
29
  return true;
36
30
  };
@@ -216,12 +216,10 @@ const _parseFindGitignores = timerify(findAndParseGitignores);
216
216
  export async function glob(_patterns, options) {
217
217
  if (Array.isArray(_patterns) && _patterns.length === 0)
218
218
  return [];
219
- const hasCache = cachedGlobIgnores.has(options.dir);
220
- const willCache = !hasCache && options.gitignore && options.label;
221
219
  const cachedIgnores = options.gitignore ? cachedGlobIgnores.get(options.dir) : undefined;
222
220
  const _ignore = [...GLOBAL_IGNORE_PATTERNS];
223
221
  const [negatedPatterns, patterns] = partition(_patterns, pattern => pattern.startsWith('!'));
224
- if (options.gitignore && willCache) {
222
+ if (!cachedIgnores && options.gitignore && options.label) {
225
223
  let dir = options.dir;
226
224
  let prev;
227
225
  while (dir) {
@@ -232,16 +230,15 @@ export async function glob(_patterns, options) {
232
230
  if (prev === dir || dir === '.')
233
231
  break;
234
232
  }
235
- }
236
- if (willCache)
237
233
  cachedGlobIgnores.set(options.dir, compact(_ignore));
238
- const ignorePatterns = (cachedIgnores || _ignore).concat(negatedPatterns.map(pattern => pattern.slice(1)));
234
+ }
235
+ const ignorePatterns = (cachedIgnores ?? _ignore).concat(negatedPatterns.map(pattern => pattern.slice(1)));
239
236
  const { dir, label, ...fgOptions } = { ...options, ignore: ignorePatterns, expandDirectories: false };
240
237
  const paths = await tinyGlob(patterns, fgOptions);
241
238
  debugLogObject(relative(options.cwd, dir), label ? `Finding ${label}` : 'Finding paths', () => ({
242
239
  patterns,
243
240
  ...fgOptions,
244
- ignore: hasCache && ignorePatterns.length === (cachedIgnores || _ignore).length
241
+ ignore: cachedIgnores && negatedPatterns.length === 0
245
242
  ? `// using cache from previous glob cwd: ${fgOptions.cwd}`
246
243
  : ignorePatterns,
247
244
  paths,
package/dist/util/jiti.js CHANGED
@@ -7,6 +7,7 @@ const options = {
7
7
  '@rushstack/eslint-config/patch/modern-module-resolution': empty,
8
8
  '@rushstack/eslint-patch/modern-module-resolution': empty,
9
9
  },
10
+ tsconfigPaths: true,
10
11
  };
11
12
  const createLoader = (options) => createJiti(process.cwd(), options);
12
13
  export const jiti = createLoader(options);
@@ -97,9 +97,6 @@ export const loadTSConfig = async (tsConfigFilePath) => {
97
97
  if (compilerOptions.paths) {
98
98
  compilerOptions.pathsBasePath ??= dir;
99
99
  }
100
- if (compilerOptions.rootDirs) {
101
- compilerOptions.rootDirs = compilerOptions.rootDirs.map((d) => (isAbsolute(d) ? d : join(dir, d)));
102
- }
103
100
  const sourceMapPairs = [];
104
101
  if (config.references?.length) {
105
102
  walkReferences(compilerOptions, config.references, dir, new Set([tsConfigFilePath]), sourceMapPairs);
@@ -0,0 +1,14 @@
1
+ type ParsedValue = any;
2
+ export interface ParsedArgs {
3
+ _: string[];
4
+ '--'?: string[];
5
+ [key: string]: ParsedValue;
6
+ }
7
+ interface Opts {
8
+ string?: string[];
9
+ boolean?: string[];
10
+ alias?: Record<string, string | string[]>;
11
+ '--'?: boolean;
12
+ }
13
+ declare const parseArgs: (argv: string[], opts?: Opts) => ParsedArgs;
14
+ export default parseArgs;
@@ -0,0 +1,112 @@
1
+ import { parseArgs as nodeParseArgs } from 'node:util';
2
+ const isHex = /^0x[0-9a-f]+$/i;
3
+ const isDecimal = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/;
4
+ const coerce = (value) => (isHex.test(value) || isDecimal.test(value) ? Number(value) : value);
5
+ const setNested = (target, key, value) => {
6
+ if (!key.includes('.')) {
7
+ target[key] = value;
8
+ return;
9
+ }
10
+ const parts = key.split('.');
11
+ let obj = target;
12
+ for (let i = 0; i < parts.length - 1; i++) {
13
+ const part = parts[i];
14
+ if (typeof obj[part] !== 'object' || obj[part] === null)
15
+ obj[part] = {};
16
+ obj = obj[part];
17
+ }
18
+ obj[parts[parts.length - 1]] = value;
19
+ };
20
+ const parseArgs = (argv, opts = {}) => {
21
+ const strings = new Set(opts.string ?? []);
22
+ const booleans = new Set(opts.boolean ?? []);
23
+ const groups = new Map();
24
+ const canonicalOf = new Map();
25
+ if (opts.alias) {
26
+ for (const key in opts.alias) {
27
+ const names = [key, ...[opts.alias[key]].flat()];
28
+ const isString = names.some(name => strings.has(name));
29
+ const isBoolean = names.some(name => booleans.has(name));
30
+ groups.set(key, names);
31
+ for (const name of names) {
32
+ canonicalOf.set(name, key);
33
+ if (isString)
34
+ strings.add(name);
35
+ if (isBoolean)
36
+ booleans.add(name);
37
+ }
38
+ }
39
+ }
40
+ const canonical = (name) => canonicalOf.get(name) ?? name;
41
+ const args = [];
42
+ for (const arg of argv) {
43
+ if (typeof arg === 'string')
44
+ args.push(/^-[A-Za-z]=/.test(arg) ? `-${arg}` : arg);
45
+ }
46
+ const { tokens } = nodeParseArgs({ args, strict: false, allowPositionals: true, tokens: true });
47
+ const positionals = [];
48
+ const dd = [];
49
+ const store = new Map();
50
+ const consumed = new Set();
51
+ let terminated = false;
52
+ const set = (name, value) => {
53
+ const key = canonical(name);
54
+ const prev = store.get(key);
55
+ if (prev === undefined)
56
+ store.set(key, value);
57
+ else if (prev === true && value === true)
58
+ return;
59
+ else if (Array.isArray(prev))
60
+ prev.push(value);
61
+ else
62
+ store.set(key, [prev, value]);
63
+ };
64
+ for (let i = 0; i < tokens.length; i++) {
65
+ const token = tokens[i];
66
+ if (token.kind === 'option-terminator') {
67
+ terminated = true;
68
+ }
69
+ else if (token.kind === 'positional') {
70
+ if (terminated && opts['--'])
71
+ dd.push(token.value);
72
+ else if (!consumed.has(i))
73
+ positionals.push(coerce(token.value));
74
+ }
75
+ else if (token.value === undefined && token.rawName.startsWith('--no-')) {
76
+ set(token.name.slice(3), false);
77
+ }
78
+ else {
79
+ const name = token.name;
80
+ if (booleans.has(name)) {
81
+ set(name, token.value !== 'false');
82
+ }
83
+ else if (token.value !== undefined) {
84
+ set(name, strings.has(name) ? token.value : coerce(token.value));
85
+ }
86
+ else {
87
+ const next = tokens[i + 1];
88
+ if (next?.kind === 'positional' && !consumed.has(i + 1)) {
89
+ consumed.add(i + 1);
90
+ set(name, strings.has(name) ? next.value : coerce(next.value));
91
+ }
92
+ else {
93
+ set(name, strings.has(name) ? '' : true);
94
+ }
95
+ }
96
+ }
97
+ }
98
+ for (const name of booleans) {
99
+ const key = canonical(name);
100
+ if (!store.has(key))
101
+ store.set(key, false);
102
+ }
103
+ const result = { _: positionals };
104
+ for (const [key, value] of store) {
105
+ for (const name of groups.get(key) ?? [key])
106
+ setNested(result, name, value);
107
+ }
108
+ if (opts['--'])
109
+ result['--'] = dd;
110
+ return result;
111
+ };
112
+ export default parseArgs;