knip 6.14.1 → 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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/CacheConsultant.d.ts +1 -0
  3. package/dist/CacheConsultant.js +2 -0
  4. package/dist/ConfigurationChief.d.ts +12 -0
  5. package/dist/ConfigurationChief.js +7 -10
  6. package/dist/DependencyDeputy.d.ts +0 -4
  7. package/dist/DependencyDeputy.js +6 -18
  8. package/dist/IssueCollector.d.ts +1 -0
  9. package/dist/IssueCollector.js +10 -20
  10. package/dist/IssueFixer.js +10 -15
  11. package/dist/ProjectPrincipal.d.ts +0 -2
  12. package/dist/ProjectPrincipal.js +1 -9
  13. package/dist/WorkspaceWorker.js +6 -1
  14. package/dist/binaries/resolvers/bun.js +9 -8
  15. package/dist/cli.js +3 -1
  16. package/dist/compilers/compilers.d.ts +3 -0
  17. package/dist/compilers/compilers.js +9 -13
  18. package/dist/compilers/index.d.ts +21 -0
  19. package/dist/compilers/scss.js +9 -3
  20. package/dist/graph/analyze.js +7 -1
  21. package/dist/graph/build.js +0 -2
  22. package/dist/manifest/index.js +11 -14
  23. package/dist/plugins/astro/index.js +1 -0
  24. package/dist/plugins/graphql-codegen/index.js +4 -0
  25. package/dist/plugins/index.d.ts +2 -0
  26. package/dist/plugins/index.js +4 -0
  27. package/dist/plugins/nano-spawn/index.d.ts +3 -0
  28. package/dist/plugins/nano-spawn/index.js +15 -0
  29. package/dist/plugins/nano-spawn/visitors/nano-spawn.d.ts +2 -0
  30. package/dist/plugins/nano-spawn/visitors/nano-spawn.js +25 -0
  31. package/dist/plugins/orval/index.d.ts +3 -0
  32. package/dist/plugins/orval/index.js +16 -0
  33. package/dist/plugins/orval/resolveFromAST.d.ts +2 -0
  34. package/dist/plugins/orval/resolveFromAST.js +11 -0
  35. package/dist/plugins/orval/types.d.ts +9 -0
  36. package/dist/plugins/orval/types.js +1 -0
  37. package/dist/plugins/serverless-framework/index.js +11 -6
  38. package/dist/plugins/serverless-framework/types.d.ts +7 -0
  39. package/dist/plugins/typescript/index.js +1 -1
  40. package/dist/plugins/vite/helpers.d.ts +1 -1
  41. package/dist/plugins/vite/helpers.js +43 -36
  42. package/dist/plugins/vite/index.js +2 -6
  43. package/dist/plugins/webdriver-io/index.js +3 -3
  44. package/dist/plugins/webdriver-io/types.d.ts +5 -1
  45. package/dist/reporters/github-actions.d.ts +1 -1
  46. package/dist/reporters/github-actions.js +19 -1
  47. package/dist/reporters/index.d.ts +1 -1
  48. package/dist/reporters/symbols.js +2 -1
  49. package/dist/reporters/trace.d.ts +3 -1
  50. package/dist/reporters/trace.js +48 -16
  51. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  52. package/dist/reporters/util/configuration-hints.js +3 -2
  53. package/dist/schema/configuration.d.ts +32 -1
  54. package/dist/schema/configuration.js +1 -0
  55. package/dist/schema/plugins.d.ts +10 -0
  56. package/dist/schema/plugins.js +2 -0
  57. package/dist/types/PluginNames.d.ts +2 -2
  58. package/dist/types/PluginNames.js +2 -0
  59. package/dist/types/issues.d.ts +1 -0
  60. package/dist/types/project.d.ts +0 -1
  61. package/dist/typescript/resolve-module-names.d.ts +0 -1
  62. package/dist/typescript/resolve-module-names.js +0 -17
  63. package/dist/typescript/visitors/walk.js +7 -0
  64. package/dist/util/Performance.d.ts +13 -28
  65. package/dist/util/Performance.js +41 -72
  66. package/dist/util/cli-arguments.d.ts +3 -1
  67. package/dist/util/cli-arguments.js +4 -0
  68. package/dist/util/create-input-handler.js +3 -1
  69. package/dist/util/create-options.d.ts +22 -0
  70. package/dist/util/create-options.js +2 -1
  71. package/dist/util/disk-cache.d.ts +1 -0
  72. package/dist/util/disk-cache.js +8 -0
  73. package/dist/util/gitignore-cache.js +5 -11
  74. package/dist/util/glob-cache.js +2 -8
  75. package/dist/util/glob-core.js +4 -7
  76. package/dist/util/jiti.js +1 -0
  77. package/dist/util/load-tsconfig.js +0 -3
  78. package/dist/util/trace.js +1 -1
  79. package/dist/version.d.ts +1 -1
  80. package/dist/version.js +1 -1
  81. package/package.json +3 -4
  82. package/schema.json +12 -0
  83. package/dist/util/math.d.ts +0 -6
  84. package/dist/util/math.js +0 -11
@@ -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.1";
1
+ export declare const version = "6.15.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.14.1';
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.1",
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
- }