knip 6.14.2 → 6.15.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 (74) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +12 -0
  4. package/dist/ConfigurationChief.js +7 -10
  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 +0 -2
  11. package/dist/ProjectPrincipal.js +1 -9
  12. package/dist/WorkspaceWorker.js +6 -1
  13. package/dist/cli.js +3 -1
  14. package/dist/compilers/compilers.d.ts +3 -0
  15. package/dist/compilers/compilers.js +9 -13
  16. package/dist/compilers/index.d.ts +21 -0
  17. package/dist/compilers/scss.js +9 -3
  18. package/dist/graph/analyze.js +7 -1
  19. package/dist/graph/build.js +0 -2
  20. package/dist/manifest/index.js +11 -14
  21. package/dist/plugins/index.d.ts +2 -0
  22. package/dist/plugins/index.js +4 -0
  23. package/dist/plugins/nano-spawn/index.d.ts +3 -0
  24. package/dist/plugins/nano-spawn/index.js +15 -0
  25. package/dist/plugins/nano-spawn/visitors/nano-spawn.d.ts +2 -0
  26. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +25 -0
  27. package/dist/plugins/orval/index.d.ts +3 -0
  28. package/dist/plugins/orval/index.js +16 -0
  29. package/dist/plugins/orval/resolveFromAST.d.ts +2 -0
  30. package/dist/plugins/orval/resolveFromAST.js +11 -0
  31. package/dist/plugins/orval/types.d.ts +9 -0
  32. package/dist/plugins/orval/types.js +1 -0
  33. package/dist/plugins/vite/helpers.js +23 -6
  34. package/dist/plugins/webdriver-io/index.js +3 -3
  35. package/dist/plugins/webdriver-io/types.d.ts +5 -1
  36. package/dist/reporters/github-actions.d.ts +1 -1
  37. package/dist/reporters/github-actions.js +19 -1
  38. package/dist/reporters/index.d.ts +1 -1
  39. package/dist/reporters/symbols.js +2 -1
  40. package/dist/reporters/trace.d.ts +3 -1
  41. package/dist/reporters/trace.js +48 -16
  42. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  43. package/dist/reporters/util/configuration-hints.js +3 -2
  44. package/dist/schema/configuration.d.ts +32 -1
  45. package/dist/schema/configuration.js +1 -0
  46. package/dist/schema/plugins.d.ts +10 -0
  47. package/dist/schema/plugins.js +2 -0
  48. package/dist/types/PluginNames.d.ts +2 -2
  49. package/dist/types/PluginNames.js +2 -0
  50. package/dist/types/issues.d.ts +1 -0
  51. package/dist/types/project.d.ts +0 -1
  52. package/dist/typescript/resolve-module-names.d.ts +0 -1
  53. package/dist/typescript/resolve-module-names.js +0 -17
  54. package/dist/typescript/visitors/walk.js +7 -0
  55. package/dist/util/Performance.d.ts +13 -28
  56. package/dist/util/Performance.js +41 -72
  57. package/dist/util/cli-arguments.d.ts +3 -1
  58. package/dist/util/cli-arguments.js +4 -0
  59. package/dist/util/create-options.d.ts +22 -0
  60. package/dist/util/create-options.js +2 -1
  61. package/dist/util/disk-cache.d.ts +1 -0
  62. package/dist/util/disk-cache.js +8 -0
  63. package/dist/util/gitignore-cache.js +5 -11
  64. package/dist/util/glob-cache.js +2 -8
  65. package/dist/util/glob-core.js +4 -7
  66. package/dist/util/jiti.js +1 -0
  67. package/dist/util/load-tsconfig.js +0 -3
  68. package/dist/util/trace.js +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +3 -4
  72. package/schema.json +12 -0
  73. package/dist/util/math.d.ts +0 -6
  74. package/dist/util/math.js +0 -11
@@ -1,38 +1,22 @@
1
- import { type PerformanceEntry, PerformanceObserver } from 'node:perf_hooks';
2
- export declare const timerify: <T extends (...params: any[]) => any>(fn: T, name?: string) => T;
3
- type MemInfo = {
4
- label: string;
5
- heapUsed: number;
6
- heapTotal: number;
7
- rss: number;
8
- };
9
- interface MemoryEntry extends PerformanceEntry {
10
- detail: MemInfo;
11
- }
1
+ import { type RecordableHistogram } from 'node:perf_hooks';
12
2
  declare class Performance {
13
- isEnabled: boolean;
14
- isTimerifyFunctions: boolean;
15
- isMemoryUsageEnabled: boolean;
16
- isDurationEnabled: boolean;
17
- startTime: number;
18
- endTime: number;
19
- perfEntries: PerformanceEntry[];
20
- memEntries: MemoryEntry[];
21
- perfId?: string;
22
- memId?: string;
23
- fnObserver?: PerformanceObserver;
24
- memObserver?: PerformanceObserver;
3
+ readonly isEnabled: boolean;
4
+ readonly isTimerifyFunctions: boolean;
5
+ readonly isMemoryUsageEnabled: boolean;
6
+ readonly isDurationEnabled: boolean;
7
+ private readonly startTime;
8
+ private readonly memId;
9
+ private readonly histograms;
10
+ private readonly memEntries;
11
+ private readonly memObserver?;
25
12
  constructor({ isTimerifyFunctions, isMemoryUsageEnabled, isDurationEnabled }: {
26
13
  isDurationEnabled?: boolean | undefined;
27
14
  isMemoryUsageEnabled?: boolean | undefined;
28
15
  isTimerifyFunctions?: boolean | undefined;
29
16
  });
30
- private setMark;
31
- private clearMark;
32
- private flush;
33
- private getPerfEntriesByName;
34
- getTimerifiedFunctionsTable(): string;
17
+ registerHistogram(name: string): RecordableHistogram;
35
18
  addMemoryMark(label: string): void;
19
+ getTimerifiedFunctionsTable(): string;
36
20
  getMemoryUsageTable(): string;
37
21
  getCurrentDurationInMs(): number;
38
22
  getMemHeapUsage(): number;
@@ -41,4 +25,5 @@ declare class Performance {
41
25
  reset(): void;
42
26
  }
43
27
  export declare const perfObserver: Performance;
28
+ export declare const timerify: <T extends (...params: any[]) => any>(fn: T, name?: string) => T;
44
29
  export {};
@@ -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;
@@ -317,6 +318,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
317
318
  entry?: string | string[] | undefined;
318
319
  project?: string | string[] | undefined;
319
320
  } | undefined;
321
+ 'nano-spawn'?: string | boolean | string[] | {
322
+ config?: string | string[] | undefined;
323
+ entry?: string | string[] | undefined;
324
+ project?: string | string[] | undefined;
325
+ } | undefined;
320
326
  'nano-staged'?: string | boolean | string[] | {
321
327
  config?: string | string[] | undefined;
322
328
  entry?: string | string[] | undefined;
@@ -397,6 +403,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
397
403
  entry?: string | string[] | undefined;
398
404
  project?: string | string[] | undefined;
399
405
  } | undefined;
406
+ orval?: string | boolean | string[] | {
407
+ config?: string | string[] | undefined;
408
+ entry?: string | string[] | undefined;
409
+ project?: string | string[] | undefined;
410
+ } | undefined;
400
411
  oxfmt?: string | boolean | string[] | {
401
412
  config?: string | string[] | undefined;
402
413
  entry?: string | string[] | undefined;
@@ -812,6 +823,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
812
823
  asyncCompilers?: Record<string, import("../compilers/types.ts").CompilerAsync> | undefined;
813
824
  tags?: string[] | undefined;
814
825
  treatConfigHintsAsErrors?: boolean | undefined;
826
+ treatTagHintsAsErrors?: boolean | undefined;
815
827
  include?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
816
828
  exclude?: ("binaries" | "catalog" | "dependencies" | "devDependencies" | "duplicates" | "enumMembers" | "exports" | "files" | "namespaceMembers" | "nsExports" | "nsTypes" | "optionalPeerDependencies" | "types" | "unlisted" | "unresolved")[] | undefined;
817
829
  workspaces?: Record<string, {
@@ -1090,6 +1102,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1090
1102
  entry?: string | string[] | undefined;
1091
1103
  project?: string | string[] | undefined;
1092
1104
  } | undefined;
1105
+ 'nano-spawn'?: string | boolean | string[] | {
1106
+ config?: string | string[] | undefined;
1107
+ entry?: string | string[] | undefined;
1108
+ project?: string | string[] | undefined;
1109
+ } | undefined;
1093
1110
  'nano-staged'?: string | boolean | string[] | {
1094
1111
  config?: string | string[] | undefined;
1095
1112
  entry?: string | string[] | undefined;
@@ -1170,6 +1187,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
1170
1187
  entry?: string | string[] | undefined;
1171
1188
  project?: string | string[] | undefined;
1172
1189
  } | undefined;
1190
+ orval?: string | boolean | string[] | {
1191
+ config?: string | string[] | undefined;
1192
+ entry?: string | string[] | undefined;
1193
+ project?: string | string[] | undefined;
1194
+ } | undefined;
1173
1195
  oxfmt?: string | boolean | string[] | {
1174
1196
  config?: string | string[] | undefined;
1175
1197
  entry?: string | string[] | undefined;
@@ -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);
@@ -24,7 +24,7 @@ export const formatTrace = (node, toRelative, isReferenced, memberStatuses) => {
24
24
  const childPrefix = isLast ? ' ' : '│ ';
25
25
  const entryMarker = child.isEntry ? dim(' ⎆') : '';
26
26
  const isLeaf = child.children.length === 0;
27
- const leafMarker = isLeaf && !child.via?.startsWith('reExport') ? (isReferenced ? ok(' ✓') : fail(' ✗')) : '';
27
+ const leafMarker = isLeaf ? (isReferenced ? ok(' ✓') : fail(' ✗')) : '';
28
28
  lines.push(`${dim(prefix)}${dim(connector)}${file(toRelative(child.filePath))}${dim(':')}${formatVia(child)}${entryMarker}${leafMarker}`);
29
29
  if (child.refs.length > 0) {
30
30
  const refsPrefix = isLeaf ? ' ' : '│';
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.14.2";
1
+ export declare const version = "6.15.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.14.2';
1
+ export const version = '6.15.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.14.2",
3
+ "version": "6.15.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -82,8 +82,8 @@
82
82
  "get-tsconfig": "4.14.0",
83
83
  "jiti": "^2.7.0",
84
84
  "minimist": "^1.2.8",
85
- "oxc-parser": "^0.130.0",
86
- "oxc-resolver": "^11.19.1",
85
+ "oxc-parser": "^0.133.0",
86
+ "oxc-resolver": "^11.20.0",
87
87
  "picomatch": "^4.0.4",
88
88
  "smol-toml": "^1.6.1",
89
89
  "strip-json-comments": "5.0.3",
@@ -99,7 +99,6 @@
99
99
  "@types/picomatch": "^4.0.1",
100
100
  "@types/webpack": "^5.28.5",
101
101
  "@typescript/native-preview": "7.0.0-dev.20260512.1",
102
- "@wdio/types": "^9.20.0",
103
102
  "codeclimate-types": "^0.3.1",
104
103
  "prettier": "^3.8.1",
105
104
  "tsx": "^4.21.0"
package/schema.json CHANGED
@@ -185,6 +185,10 @@
185
185
  "treatConfigHintsAsErrors": {
186
186
  "title": "Exit with non-zero code (1) if there are any configuration hints",
187
187
  "type": "boolean"
188
+ },
189
+ "treatTagHintsAsErrors": {
190
+ "title": "Exit with non-zero code (1) if there are any tag hints",
191
+ "type": "boolean"
188
192
  }
189
193
  },
190
194
  "unevaluatedProperties": false,
@@ -556,6 +560,10 @@
556
560
  "title": "Mocha plugin configuration (https://knip.dev/reference/plugins/msw)",
557
561
  "$ref": "#/definitions/plugin"
558
562
  },
563
+ "nano-spawn": {
564
+ "title": "nano-spawn plugin configuration (https://knip.dev/reference/plugins/nano-spawn)",
565
+ "$ref": "#/definitions/plugin"
566
+ },
559
567
  "nano-staged": {
560
568
  "title": "nano-staged plugin configuration (https://knip.dev/reference/plugins/nano-staged)",
561
569
  "$ref": "#/definitions/plugin"
@@ -624,6 +632,10 @@
624
632
  "title": "openapi-ts plugin configuration (https://knip.dev/reference/plugins/openapi-ts)",
625
633
  "$ref": "#/definitions/plugin"
626
634
  },
635
+ "orval": {
636
+ "title": "orval plugin configuration (https://knip.dev/reference/plugins/orval)",
637
+ "$ref": "#/definitions/plugin"
638
+ },
627
639
  "oxfmt": {
628
640
  "title": "oxfmt plugin configuration (https://knip.dev/reference/plugins/oxfmt)",
629
641
  "$ref": "#/definitions/plugin"
@@ -1,6 +0,0 @@
1
- export declare function getStats(values: number[]): {
2
- min: number;
3
- max: number;
4
- sum: number;
5
- median: number;
6
- };
package/dist/util/math.js DELETED
@@ -1,11 +0,0 @@
1
- export function getStats(values) {
2
- if (values.length === 0)
3
- return { min: 0, max: 0, sum: 0, median: 0 };
4
- const sorted = values.sort((a, b) => a - b);
5
- const min = sorted[0];
6
- const max = sorted[sorted.length - 1];
7
- const sum = sorted.reduce((a, b) => a + b, 0);
8
- const mid = Math.floor(sorted.length / 2);
9
- const median = sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2;
10
- return { min, max, sum, median };
11
- }