knip 6.34.0 → 6.35.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 (79) hide show
  1. package/dist/CatalogCounselor.d.ts +2 -0
  2. package/dist/CatalogCounselor.js +30 -7
  3. package/dist/ConfigurationChief.d.ts +6 -0
  4. package/dist/ConfigurationChief.js +3 -5
  5. package/dist/ProjectPrincipal.d.ts +9 -10
  6. package/dist/ProjectPrincipal.js +45 -52
  7. package/dist/WorkspaceWorker.d.ts +3 -3
  8. package/dist/WorkspaceWorker.js +6 -6
  9. package/dist/YamlCatalogPeeker.d.ts +4 -0
  10. package/dist/YamlCatalogPeeker.js +17 -0
  11. package/dist/binaries/bash-parser.d.ts +1 -1
  12. package/dist/binaries/bash-parser.js +12 -58
  13. package/dist/binaries/command.d.ts +5 -0
  14. package/dist/binaries/command.js +47 -0
  15. package/dist/binaries/fallback.d.ts +2 -0
  16. package/dist/binaries/fallback.js +2 -0
  17. package/dist/binaries/plugins.d.ts +1 -0
  18. package/dist/binaries/plugins.js +2 -1
  19. package/dist/binaries/resolvers/pnpm.js +1 -0
  20. package/dist/binaries/util.d.ts +1 -0
  21. package/dist/binaries/util.js +12 -0
  22. package/dist/cli.js +8 -26
  23. package/dist/compilers/index.d.ts +3 -1866
  24. package/dist/compilers/index.js +17 -27
  25. package/dist/compilers/types.d.ts +4 -5
  26. package/dist/graph/analyze.js +71 -53
  27. package/dist/graph/build.d.ts +3 -3
  28. package/dist/graph/build.js +63 -31
  29. package/dist/plugins/_vue/auto-import.js +28 -4
  30. package/dist/plugins/index.d.ts +1 -0
  31. package/dist/plugins/index.js +2 -0
  32. package/dist/plugins/mise/index.d.ts +3 -0
  33. package/dist/plugins/mise/index.js +82 -0
  34. package/dist/plugins/mise/scripts.d.ts +7 -0
  35. package/dist/plugins/mise/scripts.js +108 -0
  36. package/dist/plugins/mise/types.d.ts +26 -0
  37. package/dist/plugins/mise/types.js +1 -0
  38. package/dist/plugins/rstest/index.js +3 -2
  39. package/dist/plugins/rstest/types.d.ts +3 -1
  40. package/dist/plugins/vite/helpers.d.ts +2 -2
  41. package/dist/plugins/vite/helpers.js +18 -11
  42. package/dist/plugins/vite/visitors/importMetaGlob.js +12 -0
  43. package/dist/plugins/vitest/index.js +5 -2
  44. package/dist/plugins/vitest/types.d.ts +1 -0
  45. package/dist/schema/configuration.d.ts +20 -4
  46. package/dist/schema/configuration.js +5 -6
  47. package/dist/schema/plugins.d.ts +5 -0
  48. package/dist/schema/plugins.js +1 -0
  49. package/dist/session/index.d.ts +1 -1
  50. package/dist/session/index.js +1 -1
  51. package/dist/session/session.js +22 -4
  52. package/dist/types/PluginNames.d.ts +2 -2
  53. package/dist/types/PluginNames.js +1 -0
  54. package/dist/types/config.d.ts +4 -4
  55. package/dist/types/module-graph.d.ts +2 -0
  56. package/dist/types.d.ts +1 -0
  57. package/dist/typescript/SourceFileManager.d.ts +13 -9
  58. package/dist/typescript/SourceFileManager.js +58 -22
  59. package/dist/typescript/get-imports-and-exports.js +2 -1
  60. package/dist/typescript/visitors/exports.js +8 -4
  61. package/dist/util/catalog.d.ts +5 -0
  62. package/dist/util/catalog.js +37 -17
  63. package/dist/util/create-options.d.ts +17 -3
  64. package/dist/util/create-options.js +14 -3
  65. package/dist/util/errors.d.ts +3 -1
  66. package/dist/util/errors.js +6 -1
  67. package/dist/util/file-entry-cache.js +2 -2
  68. package/dist/util/module-graph.js +1 -0
  69. package/dist/util/package-json.d.ts +1 -0
  70. package/dist/util/preprocessor.d.ts +6 -0
  71. package/dist/util/preprocessor.js +24 -0
  72. package/dist/util/reporter.d.ts +0 -1
  73. package/dist/util/reporter.js +0 -7
  74. package/dist/util/watch.d.ts +1 -1
  75. package/dist/util/watch.js +33 -15
  76. package/dist/version.d.ts +1 -1
  77. package/dist/version.js +1 -1
  78. package/package.json +7 -7
  79. package/schema.json +12 -0
@@ -1,7 +1,8 @@
1
- import { readFileSync } from 'node:fs';
2
1
  import { invalidateCache } from '../graph-explorer/cache.js';
3
2
  import { debugLog } from './debug.js';
3
+ import { hasErrorCause } from './errors.js';
4
4
  import { isFile } from './fs.js';
5
+ import { logError } from './log.js';
5
6
  import { updateImportMap } from './module-graph.js';
6
7
  import { toAbsolute, toPosix, toRelative } from './path.js';
7
8
  import { clearModuleResolutionCaches } from '../typescript/resolve-module-names.js';
@@ -13,11 +14,12 @@ const createUpdate = (options) => {
13
14
  return { duration, mem };
14
15
  };
15
16
  export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceFile, chief, collector, analyze, principal, graph, isIgnored, onFileChange, unreferencedFiles, entryPaths, }) => {
16
- const handleFileChanges = async (changes) => {
17
+ const added = new Set();
18
+ const deleted = new Set();
19
+ const modified = new Set();
20
+ const processFileChanges = async (changes) => {
17
21
  const startTime = performance.now();
18
- const added = new Set();
19
- const deleted = new Set();
20
- const modified = new Set();
22
+ let hasRelevantChanges = false;
21
23
  for (const change of changes) {
22
24
  const filePath = toAbsolute(change.filePath, options.cwd);
23
25
  const relativePath = toRelative(change.filePath, options.cwd);
@@ -28,23 +30,24 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
28
30
  const workspace = chief.findWorkspaceByFilePath(filePath);
29
31
  if (!workspace)
30
32
  continue;
33
+ hasRelevantChanges = true;
31
34
  switch (change.type) {
32
35
  case 'added':
33
36
  principal.addProjectPath(filePath);
34
- principal.deletedFiles.delete(filePath);
37
+ deleted.delete(filePath);
35
38
  if (principal.projectPaths.has(filePath))
36
39
  added.add(filePath);
37
40
  debugLog(workspace.name, `Watcher: + ${relativePath}`);
38
41
  break;
39
42
  case 'deleted':
40
43
  deleted.add(filePath);
44
+ added.delete(filePath);
41
45
  analyzedFiles.delete(filePath);
42
46
  principal.removeProjectPath(filePath);
43
47
  debugLog(workspace.name, `Watcher: - ${relativePath}`);
44
48
  break;
45
49
  default: {
46
- const cached = principal.fileManager.sourceTextCache.get(filePath);
47
- if (cached !== undefined && cached === readFileSync(filePath, 'utf8')) {
50
+ if (!principal.fileManager.hasChanged(filePath)) {
48
51
  debugLog(workspace.name, `Watcher: = ${relativePath}`);
49
52
  continue;
50
53
  }
@@ -55,31 +58,31 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
55
58
  }
56
59
  principal.invalidateFile(filePath);
57
60
  }
58
- if (added.size === 0 && deleted.size === 0 && modified.size === 0)
61
+ if (!hasRelevantChanges || (added.size === 0 && deleted.size === 0 && modified.size === 0))
59
62
  return;
60
63
  clearResolverCache();
61
64
  clearModuleResolutionCaches();
62
65
  clearGlobCache();
63
66
  invalidateCache(graph);
67
+ const filePaths = await principal.getUsedResolvedFiles();
64
68
  unreferencedFiles.clear();
65
69
  const cachedUnusedFiles = collector.purge();
66
70
  for (const filePath of added)
67
71
  cachedUnusedFiles.add(filePath);
68
72
  for (const filePath of deleted)
69
73
  cachedUnusedFiles.delete(filePath);
70
- const filePaths = principal.getUsedResolvedFiles();
71
74
  if (added.size > 0 || deleted.size > 0) {
72
75
  graph.clear();
73
76
  for (const filePath of filePaths) {
74
77
  const workspace = chief.findWorkspaceByFilePath(filePath);
75
78
  if (workspace) {
76
- analyzeSourceFile(filePath, principal);
79
+ await analyzeSourceFile(filePath);
77
80
  }
78
81
  }
79
82
  }
80
83
  else {
81
84
  for (const [filePath, file] of graph) {
82
- if (filePaths.includes(filePath)) {
85
+ if (filePaths.has(filePath)) {
83
86
  file.importedBy = undefined;
84
87
  }
85
88
  else {
@@ -94,7 +97,7 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
94
97
  if (!graph.has(filePath)) {
95
98
  const workspace = chief.findWorkspaceByFilePath(filePath);
96
99
  if (workspace) {
97
- analyzeSourceFile(filePath, principal);
100
+ await analyzeSourceFile(filePath);
98
101
  }
99
102
  }
100
103
  }
@@ -103,7 +106,7 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
103
106
  const workspace = chief.findWorkspaceByFilePath(filePath);
104
107
  if (workspace) {
105
108
  if (principal.projectPaths.has(filePath) || graph.has(filePath)) {
106
- analyzeSourceFile(filePath, principal);
109
+ await analyzeSourceFile(filePath);
107
110
  }
108
111
  }
109
112
  }
@@ -120,17 +123,32 @@ export const getSessionHandler = async (options, { analyzedFiles, analyzeSourceF
120
123
  collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
121
124
  for (const issue of collector.getRetainedIssues())
122
125
  collector.addIssue(issue);
126
+ added.clear();
127
+ deleted.clear();
128
+ modified.clear();
123
129
  const update = createUpdate({ startTime });
124
130
  if (onFileChange)
125
131
  onFileChange(Object.assign({ issues: getIssues().issues }, update));
126
132
  return update;
127
133
  };
134
+ const clearSourceText = () => principal.fileManager.sourceTextCache.clear();
135
+ let pending = Promise.resolve();
136
+ const handleFileChanges = (changes) => {
137
+ const update = pending.then(() => processFileChanges(changes));
138
+ pending = update.then(clearSourceText, clearSourceText);
139
+ return update;
140
+ };
128
141
  const listener = (eventType, filePath) => {
129
142
  debugLog('*', `(raw) ${eventType} ${filePath}`);
130
143
  if (typeof filePath === 'string') {
131
144
  const normalizedPath = toPosix(filePath);
132
145
  const type = eventType === 'rename' ? (isFile(options.cwd, normalizedPath) ? 'added' : 'deleted') : 'modified';
133
- handleFileChanges([{ type, filePath: normalizedPath }]);
146
+ handleFileChanges([{ type, filePath: normalizedPath }]).catch(error => {
147
+ const message = error instanceof Error ? error.message : String(error);
148
+ const reason = error instanceof Error && hasErrorCause(error) ? `\nReason: ${error.cause.message}` : '';
149
+ logError(message + reason);
150
+ process.exitCode = 2;
151
+ });
134
152
  }
135
153
  };
136
154
  const getIssues = () => collector.getIssues();
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "6.34.0";
1
+ export declare const version = "6.35.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '6.34.0';
1
+ export const version = '6.35.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "6.34.0",
3
+ "version": "6.35.0",
4
4
  "description": "Find and fix unused dependencies, exports and files in your TypeScript and JavaScript projects",
5
5
  "keywords": [
6
6
  "analysis",
@@ -85,25 +85,25 @@
85
85
  "formatly": "^0.7.0",
86
86
  "get-tsconfig": "4.14.3",
87
87
  "jiti": "^2.7.0",
88
- "oxc-parser": "^0.147.0",
88
+ "oxc-parser": "^0.148.0",
89
89
  "oxc-resolver": "11.24.2",
90
90
  "picomatch": "^4.0.7",
91
91
  "smol-toml": "^1.8.0",
92
92
  "strip-json-comments": "5.0.3",
93
93
  "tinyglobby": "^0.2.17",
94
- "unbash": "^4.0.10",
94
+ "unbash": "^4.0.11",
95
95
  "yaml": "^2.9.0",
96
96
  "zod": "^4.4.3"
97
97
  },
98
98
  "devDependencies": {
99
- "@jest/types": "^30.5.0",
100
- "@types/bun": "^1.4.0",
99
+ "@jest/types": "^30.5.1",
100
+ "@types/bun": "^1.4.1",
101
101
  "@types/picomatch": "^4.0.3",
102
102
  "codeclimate-types": "^0.3.1",
103
103
  "prettier": "^3.9.6",
104
- "tsx": "^4.23.12",
104
+ "tsx": "^4.23.13",
105
105
  "typescript": "7.0.2",
106
- "webpack": "^5.110.1"
106
+ "webpack": "^5.110.3"
107
107
  },
108
108
  "engines": {
109
109
  "node": "^20.19.0 || >=22.12.0"
package/schema.json CHANGED
@@ -173,6 +173,14 @@
173
173
  }
174
174
  }
175
175
  },
176
+ "preprocessor": {
177
+ "title": "Preprocess the results before providing them to the reporter(s)",
178
+ "oneOf": [{ "type": "string" }, { "$ref": "#/definitions/list" }]
179
+ },
180
+ "preprocessorOptions": {
181
+ "title": "Extra options to pass to the preprocessor",
182
+ "type": "object"
183
+ },
176
184
  "treatConfigHintsAsErrors": {
177
185
  "title": "Exit with non-zero code (1) if there are any configuration hints",
178
186
  "type": "boolean"
@@ -650,6 +658,10 @@
650
658
  "title": "metro plugin configuration (https://knip.dev/reference/plugins/metro)",
651
659
  "$ref": "#/definitions/plugin"
652
660
  },
661
+ "mise": {
662
+ "title": "mise plugin configuration (https://knip.dev/reference/plugins/mise)",
663
+ "$ref": "#/definitions/plugin"
664
+ },
653
665
  "mocha": {
654
666
  "title": "Mocha plugin configuration (https://knip.dev/reference/plugins/mocha)",
655
667
  "$ref": "#/definitions/plugin"