knip 5.62.0 → 5.63.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +22 -24
  2. package/dist/CacheConsultant.d.ts +3 -9
  3. package/dist/CacheConsultant.js +5 -5
  4. package/dist/ConfigurationChief.d.ts +588 -38
  5. package/dist/ConfigurationChief.js +43 -124
  6. package/dist/ConsoleStreamer.d.ts +2 -3
  7. package/dist/ConsoleStreamer.js +2 -2
  8. package/dist/DependencyDeputy.d.ts +2 -6
  9. package/dist/IssueCollector.d.ts +4 -12
  10. package/dist/IssueCollector.js +10 -10
  11. package/dist/IssueFixer.d.ts +3 -14
  12. package/dist/IssueFixer.js +11 -21
  13. package/dist/PrincipalFactory.d.ts +3 -2
  14. package/dist/PrincipalFactory.js +11 -11
  15. package/dist/ProjectPrincipal.d.ts +5 -3
  16. package/dist/ProjectPrincipal.js +17 -11
  17. package/dist/WorkspaceWorker.d.ts +4 -9
  18. package/dist/WorkspaceWorker.js +8 -12
  19. package/dist/binaries/bash-parser.js +1 -1
  20. package/dist/binaries/fallback.js +4 -2
  21. package/dist/binaries/package-manager/pnpm.js +6 -1
  22. package/dist/cli.js +43 -60
  23. package/dist/compilers/index.d.ts +34 -4
  24. package/dist/graph/analyze.d.ts +3 -8
  25. package/dist/graph/analyze.js +24 -27
  26. package/dist/graph/build.d.ts +3 -17
  27. package/dist/graph/build.js +60 -47
  28. package/dist/index.d.ts +3 -6
  29. package/dist/index.js +23 -62
  30. package/dist/plugins/astro/index.d.ts +1 -0
  31. package/dist/plugins/astro/index.js +4 -0
  32. package/dist/plugins/index.d.ts +24 -1
  33. package/dist/plugins/index.js +6 -0
  34. package/dist/plugins/lefthook/index.js +2 -0
  35. package/dist/plugins/node-modules-inspector/index.d.ts +12 -0
  36. package/dist/plugins/node-modules-inspector/index.js +17 -0
  37. package/dist/plugins/nuxt/index.js +4 -3
  38. package/dist/plugins/nuxt/types.d.ts +3 -2
  39. package/dist/plugins/playwright/index.js +8 -1
  40. package/dist/plugins/playwright/types.d.ts +20 -14
  41. package/dist/plugins/pnpm/index.d.ts +7 -0
  42. package/dist/plugins/pnpm/index.js +8 -0
  43. package/dist/plugins/preconstruct/index.js +2 -1
  44. package/dist/plugins/react-router/index.js +18 -8
  45. package/dist/plugins/rsbuild/index.js +28 -2
  46. package/dist/plugins/rsbuild/types.d.ts +11 -0
  47. package/dist/plugins/rslib/index.d.ts +10 -0
  48. package/dist/plugins/rslib/index.js +15 -0
  49. package/dist/plugins/rslib/types.d.ts +1 -0
  50. package/dist/plugins/rspack/index.js +1 -1
  51. package/dist/plugins/typescript/index.d.ts +1 -1
  52. package/dist/plugins.js +3 -2
  53. package/dist/reporters/codeclimate.d.ts +1 -1
  54. package/dist/reporters/codeclimate.js +10 -10
  55. package/dist/reporters/codeowners.d.ts +1 -1
  56. package/dist/reporters/codeowners.js +5 -5
  57. package/dist/reporters/compact.d.ts +1 -1
  58. package/dist/reporters/compact.js +7 -7
  59. package/dist/reporters/disclosure.d.ts +1 -1
  60. package/dist/reporters/disclosure.js +2 -2
  61. package/dist/reporters/index.d.ts +6 -6
  62. package/dist/reporters/json.d.ts +1 -1
  63. package/dist/reporters/json.js +3 -3
  64. package/dist/reporters/markdown.d.ts +1 -1
  65. package/dist/reporters/markdown.js +4 -4
  66. package/dist/reporters/symbols.js +4 -2
  67. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  68. package/dist/reporters/util/configuration-hints.js +58 -23
  69. package/dist/reporters/util/util.d.ts +2 -4
  70. package/dist/reporters/util/util.js +6 -6
  71. package/dist/reporters/watch.d.ts +3 -4
  72. package/dist/reporters/watch.js +5 -5
  73. package/dist/schema/configuration.d.ts +176 -8
  74. package/dist/schema/plugins.d.ts +69 -0
  75. package/dist/schema/plugins.js +3 -0
  76. package/dist/types/PluginNames.d.ts +2 -2
  77. package/dist/types/PluginNames.js +3 -0
  78. package/dist/types/config.d.ts +4 -10
  79. package/dist/types/entries.d.ts +3 -0
  80. package/dist/types/entries.js +1 -0
  81. package/dist/types/issues.d.ts +4 -3
  82. package/dist/types/{cli.d.ts → options.d.ts} +2 -2
  83. package/dist/types/options.js +1 -0
  84. package/dist/types/package-json.d.ts +5 -0
  85. package/dist/types/project.d.ts +1 -7
  86. package/dist/types/tsconfig-json.d.ts +14 -0
  87. package/dist/types/tsconfig-json.js +1 -0
  88. package/dist/typescript/ast-helpers.js +1 -1
  89. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  90. package/dist/typescript/get-imports-and-exports.js +9 -10
  91. package/dist/util/Performance.js +16 -6
  92. package/dist/util/cli-arguments.d.ts +1 -2
  93. package/dist/util/cli-arguments.js +3 -13
  94. package/dist/util/create-options.d.ts +1219 -0
  95. package/dist/util/create-options.js +112 -0
  96. package/dist/util/debug.js +3 -4
  97. package/dist/util/errors.d.ts +1 -1
  98. package/dist/util/file-entry-cache.js +3 -3
  99. package/dist/util/fs.d.ts +1 -1
  100. package/dist/util/get-included-issue-types.d.ts +9 -13
  101. package/dist/util/get-included-issue-types.js +10 -16
  102. package/dist/util/get-referenced-inputs.js +1 -1
  103. package/dist/util/glob-core.d.ts +1 -1
  104. package/dist/util/glob-core.js +8 -7
  105. package/dist/util/glob.d.ts +1 -0
  106. package/dist/util/glob.js +1 -1
  107. package/dist/util/input.d.ts +1 -1
  108. package/dist/util/input.js +1 -1
  109. package/dist/util/is-identifier-referenced.d.ts +1 -1
  110. package/dist/util/is-identifier-referenced.js +19 -19
  111. package/dist/util/load-config.d.ts +1 -0
  112. package/dist/util/load-config.js +24 -0
  113. package/dist/util/package-json.d.ts +2 -1
  114. package/dist/util/package-json.js +24 -12
  115. package/dist/util/parse-and-convert-gitignores.js +2 -0
  116. package/dist/util/path.d.ts +4 -4
  117. package/dist/util/path.js +5 -7
  118. package/dist/util/reporter.js +3 -3
  119. package/dist/util/require.js +1 -2
  120. package/dist/util/table.js +1 -3
  121. package/dist/util/tag.d.ts +1 -1
  122. package/dist/util/to-source-path.d.ts +1 -1
  123. package/dist/util/to-source-path.js +5 -5
  124. package/dist/util/trace.d.ts +6 -6
  125. package/dist/util/trace.js +18 -22
  126. package/dist/util/watch.d.ts +2 -5
  127. package/dist/util/watch.js +3 -3
  128. package/dist/version.d.ts +1 -1
  129. package/dist/version.js +1 -1
  130. package/package.json +10 -15
  131. package/schema.json +12 -0
  132. package/dist/util/unwrap-function.d.ts +0 -1
  133. package/dist/util/unwrap-function.js +0 -13
  134. /package/dist/{types/cli.js → plugins/rslib/types.js} +0 -0
@@ -27,7 +27,7 @@ export const getToSourcePathHandler = (chief) => {
27
27
  const srcFilePath = _syncGlob({ patterns: pattern })[0];
28
28
  toSourceMapCache.set(filePath, srcFilePath);
29
29
  if (srcFilePath && srcFilePath !== filePath) {
30
- debugLog('*', `Source mapping ${toRelative(filePath)} → ${toRelative(srcFilePath)}`);
30
+ debugLog('*', `Source mapping ${toRelative(filePath, chief.cwd)} → ${toRelative(srcFilePath, chief.cwd)}`);
31
31
  return srcFilePath;
32
32
  }
33
33
  }
@@ -35,10 +35,10 @@ export const getToSourcePathHandler = (chief) => {
35
35
  };
36
36
  };
37
37
  export const getToSourcePathsHandler = (chief) => {
38
- return async (specifiers, cwd, extensions = defaultExtensions) => {
38
+ return async (specifiers, dir, extensions = defaultExtensions) => {
39
39
  const patterns = new Set();
40
40
  for (const specifier of specifiers) {
41
- const absSpecifier = isAbsolute(specifier) ? specifier : join(cwd, specifier);
41
+ const absSpecifier = isAbsolute(specifier) ? specifier : join(dir, specifier);
42
42
  const ws = chief.findWorkspaceByFilePath(absSpecifier);
43
43
  if (ws?.srcDir && ws.outDir && !absSpecifier.startsWith(ws.srcDir) && absSpecifier.startsWith(ws.outDir)) {
44
44
  const pattern = absSpecifier.replace(ws.outDir, ws.srcDir).replace(matchExt, extensions);
@@ -48,8 +48,8 @@ export const getToSourcePathsHandler = (chief) => {
48
48
  patterns.add(absSpecifier);
49
49
  }
50
50
  }
51
- const filePaths = await _glob({ patterns: Array.from(patterns), cwd });
52
- debugLogArray(toRelative(cwd), 'Source mapping (package.json)', filePaths);
51
+ const filePaths = await _glob({ patterns: Array.from(patterns), cwd: dir });
52
+ debugLogArray(toRelative(dir, chief.cwd), 'Source mapping (package.json)', filePaths);
53
53
  return filePaths;
54
54
  };
55
55
  };
@@ -1,11 +1,11 @@
1
1
  import type { ModuleGraph } from '../types/module-graph.js';
2
- declare const isTrace: boolean;
3
- type CreateNode = {
2
+ import type { MainOptions } from './create-options.js';
3
+ type CreateNodeOpts = {
4
4
  identifier?: string;
5
5
  hasRef?: boolean;
6
6
  isEntry?: boolean;
7
7
  };
8
- type Create = (filePath: string, options?: CreateNode) => TraceNode;
8
+ type Create = (filePath: string, options?: CreateNodeOpts) => TraceNode;
9
9
  export type TraceNode = {
10
10
  filePath: string;
11
11
  identifier?: string;
@@ -13,8 +13,8 @@ export type TraceNode = {
13
13
  isEntry: boolean;
14
14
  children: Set<TraceNode>;
15
15
  };
16
- export { isTrace };
17
- export declare const printTrace: (node: TraceNode, filePath: string, identifier?: string) => void;
16
+ export declare const printTrace: (node: TraceNode, filePath: string, options: MainOptions, identifier?: string) => void;
18
17
  export declare const createNode: Create;
19
18
  export declare const addNodes: (node: TraceNode, id: string, importedSymbols: ModuleGraph, filePaths?: Set<string>) => void;
20
- export declare const createAndPrintTrace: (filePath: string, options?: CreateNode) => void;
19
+ export declare const createAndPrintTrace: (filePath: string, options: MainOptions, opts?: CreateNodeOpts) => void;
20
+ export {};
@@ -1,12 +1,8 @@
1
1
  import picocolors from 'picocolors';
2
- import parsedArgValues from './cli-arguments.js';
3
2
  import { toAbsolute, toRelative } from './path.js';
4
3
  const IS_ENTRY = ' ◯';
5
4
  const HAS_REF = ' ✓';
6
5
  const HAS_NO_REF = ' x';
7
- const { 'trace-export': traceExport, 'trace-file': traceFile, trace } = parsedArgValues;
8
- const isTrace = Boolean(trace || traceExport || traceFile);
9
- export { isTrace };
10
6
  const getPadding = (level, levels) => {
11
7
  let padding = '';
12
8
  for (let i = 0; i < level; i++)
@@ -20,7 +16,7 @@ const renderTrace = (node, level = 0, levels = new Set()) => {
20
16
  for (const child of node.children) {
21
17
  const isLast = ++index === size;
22
18
  const hasRef = child.hasRef === true;
23
- const rel = toRelative(child.filePath);
19
+ const rel = child.filePath;
24
20
  const file = hasRef ? rel : picocolors.dim(rel);
25
21
  const suffix = (hasRef ? HAS_REF : '') + (child.isEntry ? IS_ENTRY : '');
26
22
  const text = `${padding}${picocolors.dim(isLast ? '└─' : '├─')} ${file}${suffix}`;
@@ -34,19 +30,19 @@ const renderTrace = (node, level = 0, levels = new Set()) => {
34
30
  }
35
31
  }
36
32
  };
37
- export const printTrace = isTrace
38
- ? (node, filePath, identifier) => {
39
- if (traceExport && identifier && identifier !== traceExport)
40
- return;
41
- if (traceFile && filePath !== toAbsolute(traceFile))
42
- return;
43
- const suffix = (node.isEntry ? IS_ENTRY : '') + (node.children.size === 0 ? HAS_NO_REF : '');
44
- const header = `${toRelative(filePath)}${identifier ? `:${identifier}` : ''}${suffix}`;
45
- console.log(header);
46
- renderTrace(node);
47
- console.log();
48
- }
49
- : () => { };
33
+ export const printTrace = (node, filePath, options, identifier) => {
34
+ if (!options.isTrace)
35
+ return;
36
+ if (options.traceExport && identifier && identifier !== options.traceExport)
37
+ return;
38
+ if (options.traceFile && filePath !== toAbsolute(options.traceFile, options.cwd))
39
+ return;
40
+ const suffix = (node.isEntry ? IS_ENTRY : '') + (node.children.size === 0 ? HAS_NO_REF : '');
41
+ const header = `${toRelative(filePath, options.cwd)}${identifier ? `:${identifier}` : ''}${suffix}`;
42
+ console.log(header);
43
+ renderTrace(node);
44
+ console.log();
45
+ };
50
46
  export const createNode = (filePath, { hasRef = false, isEntry = false, identifier } = {}) => ({
51
47
  filePath,
52
48
  identifier,
@@ -66,9 +62,9 @@ export const addNodes = (node, id, importedSymbols, filePaths) => {
66
62
  addNode(node, filePath, { hasRef: Boolean(importedSymbols.get(filePath)?.traceRefs?.has(id)) });
67
63
  }
68
64
  };
69
- export const createAndPrintTrace = (filePath, options = {}) => {
70
- if (!isTrace || traceExport || traceFile)
65
+ export const createAndPrintTrace = (filePath, options, opts = {}) => {
66
+ if (!options.isTrace)
71
67
  return;
72
- const traceNode = createNode(filePath, options);
73
- printTrace(traceNode, filePath, options.identifier);
68
+ const traceNode = createNode(filePath, opts);
69
+ printTrace(traceNode, filePath, options, opts.identifier);
74
70
  };
@@ -4,22 +4,19 @@ import type { ConsoleStreamer } from '../ConsoleStreamer.js';
4
4
  import type { IssueCollector } from '../IssueCollector.js';
5
5
  import type { PrincipalFactory } from '../PrincipalFactory.js';
6
6
  import type { ProjectPrincipal } from '../ProjectPrincipal.js';
7
- import type { Report } from '../types/issues.js';
8
7
  import type { ModuleGraph } from '../types/module-graph.js';
8
+ import type { MainOptions } from './create-options.js';
9
9
  type Watch = {
10
10
  analyzedFiles: Set<string>;
11
11
  analyzeSourceFile: (filePath: string, principal: ProjectPrincipal) => void;
12
12
  chief: ConfigurationChief;
13
13
  collector: IssueCollector;
14
14
  analyze: () => Promise<void>;
15
- cwd: string;
16
15
  factory: PrincipalFactory;
17
16
  graph: ModuleGraph;
18
- isDebug: boolean;
19
17
  isIgnored: (path: string) => boolean;
20
- report: Report;
21
18
  streamer: ConsoleStreamer;
22
19
  unreferencedFiles: Set<string>;
23
20
  };
24
- export declare const getWatchHandler: ({ analyzedFiles, analyzeSourceFile, chief, collector, analyze, cwd, factory, graph, isDebug, isIgnored, report, streamer, unreferencedFiles, }: Watch) => Promise<WatchListener<string | Buffer<ArrayBufferLike>>>;
21
+ export declare const getWatchHandler: (options: MainOptions, { analyzedFiles, analyzeSourceFile, chief, collector, analyze, factory, graph, isIgnored, streamer, unreferencedFiles, }: Watch) => Promise<WatchListener<string | Buffer<ArrayBufferLike>>>;
25
22
  export {};
@@ -3,16 +3,16 @@ import { debugLog } from './debug.js';
3
3
  import { isFile } from './fs.js';
4
4
  import { updateImportMap } from './module-graph.js';
5
5
  import { join, toPosix } from './path.js';
6
- export const getWatchHandler = async ({ analyzedFiles, analyzeSourceFile, chief, collector, analyze, cwd, factory, graph, isDebug, isIgnored, report, streamer, unreferencedFiles, }) => {
6
+ export const getWatchHandler = async (options, { analyzedFiles, analyzeSourceFile, chief, collector, analyze, factory, graph, isIgnored, streamer, unreferencedFiles, }) => {
7
7
  const reportIssues = async (startTime) => {
8
8
  const { issues } = collector.getIssues();
9
- watchReporter({ report, issues, streamer, startTime, size: analyzedFiles.size, isDebug });
9
+ watchReporter(options, { issues, streamer, startTime, size: analyzedFiles.size });
10
10
  };
11
11
  const listener = async (eventType, filename) => {
12
12
  debugLog('*', `(raw) ${eventType} ${filename}`);
13
13
  if (typeof filename === 'string') {
14
14
  const startTime = performance.now();
15
- const filePath = join(cwd, toPosix(filename));
15
+ const filePath = join(options.cwd, toPosix(filename));
16
16
  if (isIgnored(filePath)) {
17
17
  debugLog('*', `ignoring ${eventType} ${filename}`);
18
18
  return;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.62.0";
1
+ export declare const version = "5.63.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.62.0';
1
+ export const version = '5.63.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.62.0",
3
+ "version": "5.63.1",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -22,10 +22,6 @@
22
22
  {
23
23
  "type": "opencollective",
24
24
  "url": "https://opencollective.com/knip"
25
- },
26
- {
27
- "type": "polar",
28
- "url": "https://polar.sh/webpro-nl"
29
25
  }
30
26
  ],
31
27
  "main": "./dist/index.js",
@@ -63,16 +59,16 @@
63
59
  "dependencies": {
64
60
  "@nodelib/fs.walk": "^1.2.3",
65
61
  "fast-glob": "^3.3.3",
66
- "formatly": "^0.2.4",
67
- "jiti": "^2.4.2",
62
+ "formatly": "^0.3.0",
63
+ "jiti": "^2.5.1",
68
64
  "js-yaml": "^4.1.0",
69
65
  "minimist": "^1.2.8",
70
- "oxc-resolver": "^11.1.0",
66
+ "oxc-resolver": "^11.6.2",
71
67
  "picocolors": "^1.1.1",
72
68
  "picomatch": "^4.0.1",
73
- "smol-toml": "^1.3.4",
69
+ "smol-toml": "^1.4.1",
74
70
  "strip-json-comments": "5.0.2",
75
- "zod": "^3.22.4",
71
+ "zod": "^3.25.0",
76
72
  "zod-validation-error": "^3.0.3"
77
73
  },
78
74
  "peerDependencies": {
@@ -82,17 +78,16 @@
82
78
  "devDependencies": {
83
79
  "@jest/types": "^29.6.3",
84
80
  "@release-it/bumper": "^7.0.5",
85
- "@types/bun": "1.2.15",
81
+ "@types/bun": "1.2.19",
86
82
  "@types/js-yaml": "^4.0.9",
87
83
  "@types/minimist": "^1.2.5",
88
84
  "@types/picomatch": "3.0.1",
89
85
  "@types/webpack": "^5.28.5",
90
- "@wdio/types": "^9.15.0",
86
+ "@wdio/types": "^9.16.2",
91
87
  "codeclimate-types": "^0.3.1",
92
88
  "glob": "^11.0.2",
93
- "release-it": "^19.0.3",
94
- "tsx": "^4.19.4",
95
- "type-fest": "^4.31.0",
89
+ "release-it": "^19.0.4",
90
+ "tsx": "^4.20.3",
96
91
  "typescript": "^5.5.2"
97
92
  },
98
93
  "engines": {
package/schema.json CHANGED
@@ -499,6 +499,10 @@
499
499
  "title": "node plugin configuration (https://knip.dev/reference/plugins/node)",
500
500
  "$ref": "#/definitions/plugin"
501
501
  },
502
+ "node-modules-inspector": {
503
+ "title": "node-modules-inspector plugin configuration (https://knip.dev/reference/plugins/node-modules-inspector)",
504
+ "$ref": "#/definitions/plugin"
505
+ },
502
506
  "node-test-runner": {
503
507
  "title": "node-test-runner plugin configuration (https://knip.dev/reference/plugins/node-test-runner)",
504
508
  "$ref": "#/definitions/plugin"
@@ -543,6 +547,10 @@
543
547
  "title": "playwright-test plugin configuration (https://knip.dev/reference/plugins/playwright-test)",
544
548
  "$ref": "#/definitions/plugin"
545
549
  },
550
+ "pnpm": {
551
+ "title": "pnpm plugin configuration (https://knip.dev/reference/plugins/pnpm)",
552
+ "$ref": "#/definitions/plugin"
553
+ },
546
554
  "postcss": {
547
555
  "title": "PostCSS plugin configuration (https://knip.dev/reference/plugins/postcss)",
548
556
  "$ref": "#/definitions/plugin"
@@ -591,6 +599,10 @@
591
599
  "title": "rsbuild plugin configuration (https://knip.dev/reference/plugins/rsbuild)",
592
600
  "$ref": "#/definitions/plugin"
593
601
  },
602
+ "rslib": {
603
+ "title": "rslib plugin configuration (https://knip.dev/reference/plugins/rslib)",
604
+ "$ref": "#/definitions/plugin"
605
+ },
594
606
  "rspack": {
595
607
  "title": "rspack plugin configuration (https://knip.dev/reference/plugins/rspack)",
596
608
  "$ref": "#/definitions/plugin"
@@ -1 +0,0 @@
1
- export declare const unwrapFunction: (maybeFunction: unknown) => Promise<any>;
@@ -1,13 +0,0 @@
1
- import { debugLogObject } from './debug.js';
2
- export const unwrapFunction = async (maybeFunction) => {
3
- if (typeof maybeFunction === 'function') {
4
- try {
5
- return await maybeFunction();
6
- }
7
- catch (error) {
8
- debugLogObject('*', 'Error executing function:', error);
9
- throw error;
10
- }
11
- }
12
- return maybeFunction;
13
- };
File without changes