knip 6.44.2 → 6.45.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 (218) hide show
  1. package/dist/ConfigurationChief.d.ts +23 -1033
  2. package/dist/ConfigurationChief.js +71 -15
  3. package/dist/DependencyDeputy.d.ts +10 -6
  4. package/dist/DependencyDeputy.js +51 -27
  5. package/dist/IssueCollector.d.ts +14 -11
  6. package/dist/IssueCollector.js +25 -20
  7. package/dist/IssueFixer.js +1 -1
  8. package/dist/PackagePeeker.d.ts +6 -0
  9. package/dist/PackagePeeker.js +43 -14
  10. package/dist/ProjectPrincipal.d.ts +6 -3
  11. package/dist/ProjectPrincipal.js +83 -32
  12. package/dist/WorkspaceWorker.d.ts +5 -1
  13. package/dist/WorkspaceWorker.js +39 -22
  14. package/dist/binaries/bash-parser.js +1 -7
  15. package/dist/binaries/command.d.ts +3 -3
  16. package/dist/binaries/command.js +6 -2
  17. package/dist/binaries/fallback.js +1 -1
  18. package/dist/binaries/plugins.d.ts +4 -1
  19. package/dist/binaries/plugins.js +66 -18
  20. package/dist/binaries/resolvers/npm.js +7 -5
  21. package/dist/binaries/resolvers/npx.js +8 -40
  22. package/dist/binaries/util.d.ts +13 -1
  23. package/dist/binaries/util.js +35 -1
  24. package/dist/cli.js +10 -84
  25. package/dist/configuration-hints.d.ts +16 -0
  26. package/dist/configuration-hints.js +64 -0
  27. package/dist/constants.d.ts +2 -1
  28. package/dist/constants.js +2 -0
  29. package/dist/graph/SubpathReferences.d.ts +33 -0
  30. package/dist/graph/SubpathReferences.js +114 -0
  31. package/dist/graph/analyze.d.ts +4 -1
  32. package/dist/graph/analyze.js +16 -5
  33. package/dist/graph/build.d.ts +3 -1
  34. package/dist/graph/build.js +47 -23
  35. package/dist/graph-explorer/operations/resolve-export-origins.js +1 -1
  36. package/dist/plugins/angular/index.js +10 -17
  37. package/dist/plugins/aws-cdk/index.d.ts +3 -0
  38. package/dist/plugins/aws-cdk/index.js +32 -0
  39. package/dist/plugins/aws-cdk/types.d.ts +5 -0
  40. package/dist/plugins/aws-cdk/types.js +1 -0
  41. package/dist/plugins/babel/index.d.ts +1 -1
  42. package/dist/plugins/babel/index.js +19 -5
  43. package/dist/plugins/bun/index.js +8 -7
  44. package/dist/plugins/c8/index.js +17 -4
  45. package/dist/plugins/changesets/index.js +3 -2
  46. package/dist/plugins/commitizen/index.js +6 -3
  47. package/dist/plugins/commitlint/index.js +10 -11
  48. package/dist/plugins/cypress/index.js +4 -2
  49. package/dist/plugins/danger/index.js +1 -1
  50. package/dist/plugins/docusaurus/helpers.js +6 -6
  51. package/dist/plugins/docusaurus/index.js +2 -2
  52. package/dist/plugins/electron-forge/index.js +2 -2
  53. package/dist/plugins/electron-vite/index.js +2 -2
  54. package/dist/plugins/eleventy/index.js +3 -2
  55. package/dist/plugins/eslint/helpers.js +4 -3
  56. package/dist/plugins/eslint/resolveFromAST.js +2 -2
  57. package/dist/plugins/evalite/index.d.ts +3 -0
  58. package/dist/plugins/evalite/index.js +26 -0
  59. package/dist/plugins/flue/index.js +2 -2
  60. package/dist/plugins/github-action/index.js +2 -2
  61. package/dist/plugins/github-actions/index.js +2 -2
  62. package/dist/plugins/graphql-codegen/index.js +13 -9
  63. package/dist/plugins/index.d.ts +5 -0
  64. package/dist/plugins/index.js +10 -0
  65. package/dist/plugins/jest/index.js +5 -5
  66. package/dist/plugins/knex/index.js +2 -2
  67. package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +2 -2
  68. package/dist/plugins/lunaria/index.js +5 -2
  69. package/dist/plugins/markdownlint/index.js +8 -2
  70. package/dist/plugins/marko/index.js +2 -2
  71. package/dist/plugins/marko/taglibs.d.ts +1 -1
  72. package/dist/plugins/marko/taglibs.js +4 -28
  73. package/dist/plugins/mdx/index.d.ts +2 -1
  74. package/dist/plugins/mdx/index.js +7 -4
  75. package/dist/plugins/mdxlint/index.js +18 -15
  76. package/dist/plugins/mikro-orm/index.d.ts +3 -0
  77. package/dist/plugins/mikro-orm/index.js +77 -0
  78. package/dist/plugins/mikro-orm/types.d.ts +21 -0
  79. package/dist/plugins/mikro-orm/types.js +1 -0
  80. package/dist/plugins/msw/index.js +6 -3
  81. package/dist/plugins/msw/types.d.ts +1 -1
  82. package/dist/plugins/netlify/index.js +7 -3
  83. package/dist/plugins/next/index.js +63 -9
  84. package/dist/plugins/next/types.d.ts +5 -0
  85. package/dist/plugins/next-mdx/resolveFromAST.js +15 -10
  86. package/dist/plugins/nitro/index.js +5 -6
  87. package/dist/plugins/node/index.js +4 -4
  88. package/dist/plugins/npm-package-json-lint/index.js +10 -3
  89. package/dist/plugins/nuxt/index.js +18 -10
  90. package/dist/plugins/nuxt/types.d.ts +4 -0
  91. package/dist/plugins/nx/index.js +6 -3
  92. package/dist/plugins/openclaw/index.js +11 -11
  93. package/dist/plugins/oxlint/index.js +2 -2
  94. package/dist/plugins/payload/index.js +1 -1
  95. package/dist/plugins/playwright/index.js +3 -3
  96. package/dist/plugins/pm2/index.js +7 -7
  97. package/dist/plugins/prettier/index.js +2 -1
  98. package/dist/plugins/prisma/index.js +2 -2
  99. package/dist/plugins/quasar/resolveFromAST.js +14 -9
  100. package/dist/plugins/react-router/index.js +2 -2
  101. package/dist/plugins/release-it/index.js +6 -2
  102. package/dist/plugins/remix/index.js +3 -3
  103. package/dist/plugins/retry-cli/index.d.ts +3 -0
  104. package/dist/plugins/retry-cli/index.js +14 -0
  105. package/dist/plugins/rollup/index.js +1 -4
  106. package/dist/plugins/rstest/index.js +3 -3
  107. package/dist/plugins/semantic-release/index.js +3 -3
  108. package/dist/plugins/serverless-framework/index.js +10 -8
  109. package/dist/plugins/solidjs-vite-plugin/resolveFromAST.js +2 -2
  110. package/dist/plugins/stencil/resolveFromAST.js +5 -5
  111. package/dist/plugins/stryker/index.js +2 -2
  112. package/dist/plugins/swc/index.js +4 -3
  113. package/dist/plugins/tailwind/index.js +2 -2
  114. package/dist/plugins/tanstack-router/index.js +2 -2
  115. package/dist/plugins/ts-node/index.js +6 -1
  116. package/dist/plugins/turbo/index.js +3 -3
  117. package/dist/plugins/typedoc/index.js +2 -2
  118. package/dist/plugins/typescript/content-mappers.d.ts +1 -1
  119. package/dist/plugins/typescript/index.js +6 -9
  120. package/dist/plugins/varlock/scan.js +1 -1
  121. package/dist/plugins/vite/helpers.d.ts +1 -0
  122. package/dist/plugins/vite/helpers.js +13 -3
  123. package/dist/plugins/vite/index.js +5 -2
  124. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  125. package/dist/plugins/vitest/index.js +14 -16
  126. package/dist/plugins/vue/index.js +1 -1
  127. package/dist/plugins/web-test-runner/index.d.ts +3 -0
  128. package/dist/plugins/web-test-runner/index.js +86 -0
  129. package/dist/plugins/wrangler/index.js +3 -3
  130. package/dist/plugins/yarn/index.js +5 -5
  131. package/dist/plugins.js +2 -5
  132. package/dist/reporters/github-actions.js +3 -7
  133. package/dist/reporters/json.d.ts +1 -0
  134. package/dist/reporters/json.js +1 -0
  135. package/dist/reporters/util/configuration-hints.d.ts +3 -1
  136. package/dist/reporters/util/configuration-hints.js +40 -21
  137. package/dist/reporters/util/util.d.ts +1 -1
  138. package/dist/run-cli.d.ts +2 -0
  139. package/dist/run-cli.js +82 -0
  140. package/dist/run.js +12 -0
  141. package/dist/session/incremental.d.ts +1 -0
  142. package/dist/session/incremental.js +1 -0
  143. package/dist/session/watch.js +2 -1
  144. package/dist/types/PluginNames.d.ts +2 -2
  145. package/dist/types/PluginNames.js +5 -0
  146. package/dist/types/args.d.ts +3 -1
  147. package/dist/types/config.d.ts +17 -10
  148. package/dist/types/configuration.d.ts +45 -0
  149. package/dist/types/configuration.js +1 -0
  150. package/dist/types/issues.d.ts +4 -0
  151. package/dist/types/module-graph.d.ts +1 -0
  152. package/dist/types/options.d.ts +1 -0
  153. package/dist/types/package-json.d.ts +3 -8
  154. package/dist/types/workspace.d.ts +1 -0
  155. package/dist/typescript/get-imports-and-exports.js +18 -6
  156. package/dist/typescript/resolve-module-names.js +7 -45
  157. package/dist/typescript/visitors/calls.d.ts +1 -1
  158. package/dist/typescript/visitors/calls.js +14 -10
  159. package/dist/typescript/visitors/exports.js +16 -26
  160. package/dist/typescript/visitors/imports.d.ts +2 -1
  161. package/dist/typescript/visitors/imports.js +41 -24
  162. package/dist/typescript/visitors/members.d.ts +1 -1
  163. package/dist/typescript/visitors/members.js +38 -24
  164. package/dist/typescript/visitors/shadow.d.ts +2 -0
  165. package/dist/typescript/visitors/shadow.js +25 -0
  166. package/dist/typescript/visitors/walk.d.ts +20 -12
  167. package/dist/typescript/visitors/walk.js +78 -48
  168. package/dist/util/Performance.d.ts +25 -3
  169. package/dist/util/Performance.js +51 -27
  170. package/dist/util/cli-arguments.d.ts +2 -1
  171. package/dist/util/cli-arguments.js +4 -2
  172. package/dist/util/create-input-handler.js +138 -119
  173. package/dist/util/create-options.d.ts +4 -2071
  174. package/dist/util/create-options.js +6 -4
  175. package/dist/util/create-workspace-graph.js +2 -1
  176. package/dist/util/errors.d.ts +5 -2
  177. package/dist/util/errors.js +11 -18
  178. package/dist/util/fs.js +4 -2
  179. package/dist/util/input.d.ts +2 -2
  180. package/dist/util/input.js +2 -2
  181. package/dist/util/is-plugin-name.d.ts +2 -0
  182. package/dist/util/is-plugin-name.js +3 -0
  183. package/dist/util/jiti.d.ts +2 -1
  184. package/dist/util/jiti.js +10 -3
  185. package/dist/util/load-config.d.ts +1 -1
  186. package/dist/util/load-config.js +3 -2
  187. package/dist/util/loader.js +3 -2
  188. package/dist/util/map-workspaces.js +23 -1
  189. package/dist/util/module-graph.js +1 -0
  190. package/dist/util/modules.d.ts +2 -0
  191. package/dist/util/modules.js +78 -0
  192. package/dist/util/package-json.d.ts +12 -5
  193. package/dist/util/package-json.js +54 -26
  194. package/dist/util/parse-and-convert-gitignores.d.ts +2 -2
  195. package/dist/util/parse-and-convert-gitignores.js +5 -5
  196. package/dist/util/parse-configuration.d.ts +2 -0
  197. package/dist/util/parse-configuration.js +66 -0
  198. package/dist/util/plugin.js +8 -12
  199. package/dist/util/resolve.d.ts +1 -0
  200. package/dist/util/resolve.js +3 -2
  201. package/dist/util/scripts.d.ts +0 -5
  202. package/dist/util/scripts.js +1 -32
  203. package/dist/util/to-source-path.d.ts +4 -1
  204. package/dist/util/to-source-path.js +2 -2
  205. package/dist/util/unhandled-rejection.d.ts +8 -0
  206. package/dist/util/unhandled-rejection.js +29 -0
  207. package/dist/util/validation.d.ts +11 -0
  208. package/dist/util/validation.js +68 -0
  209. package/dist/util/watch.d.ts +3 -1
  210. package/dist/util/watch.js +5 -2
  211. package/dist/version.d.ts +1 -1
  212. package/dist/version.js +1 -1
  213. package/package.json +6 -7
  214. package/schema.json +34 -0
  215. package/dist/schema/configuration.d.ts +0 -3103
  216. package/dist/schema/configuration.js +0 -94
  217. package/dist/schema/plugins.d.ts +0 -1019
  218. package/dist/schema/plugins.js +0 -215
@@ -50,23 +50,52 @@ export class PackagePeeker {
50
50
  let valuePos = colonPos + 1;
51
51
  while (valuePos > 0 && this.manifestStr[valuePos]?.trim() === '')
52
52
  valuePos++;
53
- if (colonPos !== -1 && this.manifestStr.startsWith(value, valuePos)) {
54
- const pos = propertyPos + 1;
55
- let line = 1;
56
- let lineStart = 0;
57
- for (let index = 0; index < pos; index++) {
58
- if (this.manifestStr[index] === '\n') {
59
- line++;
60
- lineStart = index + 1;
53
+ if (colonPos !== -1 && this.manifestStr.startsWith(value, valuePos))
54
+ return this.toLocation(propertyPos + 1);
55
+ propertyPos = this.manifestStr.indexOf(property, propertyPos + property.length);
56
+ }
57
+ }
58
+ getPropertyLocation(section, property) {
59
+ const str = this.manifestStr;
60
+ let depth = 0;
61
+ let isInSection = false;
62
+ for (let i = 0; i < str.length; i++) {
63
+ const ch = str[i];
64
+ if (ch === '"') {
65
+ const start = i + 1;
66
+ let end = start;
67
+ while (end < str.length && str[end] !== '"')
68
+ end += str[end] === '\\' ? 2 : 1;
69
+ let next = end + 1;
70
+ while (str.charCodeAt(next) <= 32)
71
+ next++;
72
+ if (str[next] === ':') {
73
+ const key = str.slice(start, end);
74
+ if (depth === 1) {
75
+ isInSection = key === section;
76
+ if (isInSection && property === undefined)
77
+ return this.toLocation(start);
61
78
  }
79
+ else if (depth === 2 && isInSection && key === property)
80
+ return this.toLocation(start);
62
81
  }
63
- return {
64
- line,
65
- col: pos - lineStart + 1,
66
- pos,
67
- };
82
+ i = end;
83
+ }
84
+ else if (ch === '{' || ch === '[')
85
+ depth++;
86
+ else if (ch === '}' || ch === ']')
87
+ depth--;
88
+ }
89
+ }
90
+ toLocation(pos) {
91
+ let line = 1;
92
+ let lineStart = 0;
93
+ for (let index = 0; index < pos; index++) {
94
+ if (this.manifestStr[index] === '\n') {
95
+ line++;
96
+ lineStart = index + 1;
68
97
  }
69
- propertyPos = this.manifestStr.indexOf(property, propertyPos + property.length);
70
98
  }
99
+ return { line, col: pos - lineStart + 1, pos };
71
100
  }
72
101
  }
@@ -12,6 +12,7 @@ import type { ToSourceFilePath, WorkspacePackageTargetHandler } from './util/to-
12
12
  export declare class ProjectPrincipal {
13
13
  entryPaths: Set<string>;
14
14
  projectPaths: Set<string>;
15
+ private claimedEntryPaths;
15
16
  programPaths: Set<string>;
16
17
  skipExportsAnalysis: Set<string>;
17
18
  private includeExportsAnalysis;
@@ -42,7 +43,7 @@ export declare class ProjectPrincipal {
42
43
  addRootDirs(rootDirs: string[] | undefined, scope: string): void;
43
44
  collectConfigurationImports(configurationFiles: ConfigurationFiles): void;
44
45
  init(): void;
45
- private hasAcceptedExtension;
46
+ hasAcceptedExtension(filePath: string): boolean;
46
47
  addEntryPath(filePath: string, options?: {
47
48
  skipExportsAnalysis: boolean;
48
49
  }): void;
@@ -51,9 +52,11 @@ export declare class ProjectPrincipal {
51
52
  }): void;
52
53
  addProgramPath(filePath: string): void;
53
54
  addProjectPath(filePath: string): void;
55
+ claimEntryPath(filePath: string): void;
56
+ releaseEntryClaims(): void;
54
57
  removeProjectPath(filePath: string): void;
55
- walkAndAnalyze(analyzeFile: (filePath: string, parseResult: ParseResult | undefined, sourceText: string, cachedFile?: FileNode) => Iterable<string> | undefined): Promise<void>;
56
- getUsedResolvedFiles(): Promise<Set<string>>;
58
+ walkAndAnalyze(analyzeFile: (filePath: string, parseResult: ParseResult | undefined, sourceText: string, cachedFile?: FileNode) => Iterable<string> | undefined, onSpecifier: (specifier: string, filePath: string) => void): Promise<void>;
59
+ getUsedResolvedFiles(onSpecifier: (specifier: string, filePath: string) => void): Promise<Set<string>>;
57
60
  private resolveSpecifier;
58
61
  getUnreferencedFiles(): string[];
59
62
  private getCachedFile;
@@ -8,6 +8,7 @@ import { buildVisitor } from './typescript/visitors/walk.js';
8
8
  import { createCustomModuleResolver, createGlobAliasResolver } from './typescript/resolve-module-names.js';
9
9
  import { SourceFileManager } from './typescript/SourceFileManager.js';
10
10
  import { compact } from './util/array.js';
11
+ import { debugLog } from './util/debug.js';
11
12
  import { timerify } from './util/Performance.js';
12
13
  import { extname, isInNodeModules, toAbsolute } from './util/path.js';
13
14
  const copyFileNode = (file) => ({
@@ -18,9 +19,19 @@ const copyFileNode = (file) => ({
18
19
  externalRefs: new Set(file.imports.externalRefs),
19
20
  },
20
21
  });
22
+ const tryParseFile = (filePath, sourceText) => {
23
+ try {
24
+ return _parseFile(filePath, sourceText);
25
+ }
26
+ catch (error) {
27
+ debugLog('*', `Unable to parse ${filePath} (${error instanceof Error ? error.message : String(error)})`);
28
+ return undefined;
29
+ }
30
+ };
21
31
  export class ProjectPrincipal {
22
32
  entryPaths = new Set();
23
33
  projectPaths = new Set();
34
+ claimedEntryPaths = new Map();
24
35
  programPaths = new Set();
25
36
  skipExportsAnalysis = new Set();
26
37
  includeExportsAnalysis = new Set();
@@ -128,6 +139,7 @@ export class ProjectPrincipal {
128
139
  }
129
140
  addEntryPath(filePath, options) {
130
141
  if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
142
+ this.claimedEntryPaths.delete(filePath);
131
143
  this.entryPaths.add(filePath);
132
144
  this.projectPaths.add(filePath);
133
145
  if (options) {
@@ -159,7 +171,24 @@ export class ProjectPrincipal {
159
171
  this.deletedFiles.delete(filePath);
160
172
  }
161
173
  }
174
+ claimEntryPath(filePath) {
175
+ if (this.entryPaths.has(filePath) || isInNodeModules(filePath) || !this.hasAcceptedExtension(filePath))
176
+ return;
177
+ this.claimedEntryPaths.set(filePath, this.projectPaths.has(filePath));
178
+ this.entryPaths.add(filePath);
179
+ this.projectPaths.add(filePath);
180
+ this.onPathAdded?.(filePath);
181
+ }
182
+ releaseEntryClaims() {
183
+ for (const [filePath, isProjectPath] of this.claimedEntryPaths) {
184
+ this.entryPaths.delete(filePath);
185
+ if (!isProjectPath)
186
+ this.projectPaths.delete(filePath);
187
+ }
188
+ this.claimedEntryPaths.clear();
189
+ }
162
190
  removeProjectPath(filePath) {
191
+ this.claimedEntryPaths.delete(filePath);
163
192
  this.entryPaths.delete(filePath);
164
193
  this.projectPaths.delete(filePath);
165
194
  this.skipExportsAnalysis.delete(filePath);
@@ -167,19 +196,37 @@ export class ProjectPrincipal {
167
196
  this.invalidateFile(filePath);
168
197
  this.deletedFiles.add(filePath);
169
198
  }
170
- async walkAndAnalyze(analyzeFile) {
199
+ async walkAndAnalyze(analyzeFile, onSpecifier) {
171
200
  this.resolvedFiles.clear();
172
- const visited = new Set([...this.entryPaths, ...this.programPaths]);
173
- this.onPathAdded = p => visited.add(p);
201
+ const visited = new Set(this.entryPaths);
202
+ for (const filePath of this.programPaths)
203
+ visited.add(filePath);
204
+ const queue = [...visited];
205
+ const extracted = new Set();
206
+ const enqueue = (p) => {
207
+ if (!visited.has(p)) {
208
+ visited.add(p);
209
+ queue.push(p);
210
+ }
211
+ };
212
+ this.onPathAdded = p => {
213
+ if (this.projectPaths.has(p) && extracted.delete(p))
214
+ queue.push(p);
215
+ else
216
+ enqueue(p);
217
+ };
174
218
  try {
175
- for (const filePath of visited) {
219
+ for (let i = 0; i < queue.length; i++) {
220
+ const filePath = queue[i];
176
221
  const isProjectPath = this.projectPaths.has(filePath);
222
+ if (!isProjectPath)
223
+ extracted.add(filePath);
177
224
  const cachedFile = isProjectPath ? this.getCachedFile(filePath) : undefined;
178
225
  if (cachedFile) {
179
226
  const internalPaths = analyzeFile(filePath, undefined, '', cachedFile);
180
227
  if (internalPaths)
181
228
  for (const p of internalPaths)
182
- visited.add(p);
229
+ enqueue(p);
183
230
  continue;
184
231
  }
185
232
  const loaded = this.fileManager.loadSourceText(filePath);
@@ -189,24 +236,23 @@ export class ProjectPrincipal {
189
236
  analyzeFile(filePath, undefined, '');
190
237
  continue;
191
238
  }
192
- try {
193
- const result = _parseFile(filePath, sourceText);
194
- this.fileManager.sourceTextCache.delete(filePath);
195
- if (isProjectPath) {
196
- const internalPaths = analyzeFile(filePath, result, sourceText);
197
- if (internalPaths)
198
- for (const p of internalPaths)
199
- visited.add(p);
200
- }
201
- else {
202
- for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
203
- const resolved = this.resolveSpecifier(specifier, filePath);
204
- if (resolved && !isInNodeModules(resolved))
205
- visited.add(resolved);
206
- }
207
- }
239
+ const result = tryParseFile(filePath, sourceText);
240
+ if (!result)
241
+ continue;
242
+ this.fileManager.sourceTextCache.delete(filePath);
243
+ if (isProjectPath) {
244
+ const internalPaths = analyzeFile(filePath, result, sourceText);
245
+ if (internalPaths)
246
+ for (const p of internalPaths)
247
+ enqueue(p);
208
248
  }
209
- catch {
249
+ else {
250
+ for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
251
+ onSpecifier(specifier, filePath);
252
+ const resolved = this.resolveSpecifier(specifier, filePath);
253
+ if (resolved && !isInNodeModules(resolved))
254
+ enqueue(resolved);
255
+ }
210
256
  }
211
257
  }
212
258
  }
@@ -215,24 +261,29 @@ export class ProjectPrincipal {
215
261
  }
216
262
  this.resolvedFiles = visited;
217
263
  }
218
- async getUsedResolvedFiles() {
264
+ async getUsedResolvedFiles(onSpecifier) {
219
265
  this.resolvedFiles.clear();
220
266
  const visited = new Set([...this.entryPaths, ...this.programPaths]);
221
- for (const filePath of visited) {
222
- const loaded = this.fileManager.loadSourceText(filePath);
223
- const sourceText = typeof loaded === 'string' ? loaded : await loaded;
224
- if (!sourceText)
225
- continue;
226
- try {
227
- const result = _parseFile(filePath, sourceText);
267
+ this.onPathAdded = p => visited.add(p);
268
+ try {
269
+ for (const filePath of visited) {
270
+ const loaded = this.fileManager.loadSourceText(filePath);
271
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
272
+ if (!sourceText)
273
+ continue;
274
+ const result = tryParseFile(filePath, sourceText);
275
+ if (!result)
276
+ continue;
228
277
  for (const specifier of extractSpecifiers(result, sourceText, filePath)) {
278
+ onSpecifier(specifier, filePath);
229
279
  const resolved = this.resolveSpecifier(specifier, filePath);
230
280
  if (resolved && !isInNodeModules(resolved))
231
281
  visited.add(resolved);
232
282
  }
233
283
  }
234
- catch {
235
- }
284
+ }
285
+ finally {
286
+ this.onPathAdded = undefined;
236
287
  }
237
288
  this.resolvedFiles = visited;
238
289
  const usedFiles = new Set();
@@ -12,9 +12,11 @@ import type { ConfigurationFiles } from './session/configuration.ts';
12
12
  type WorkspaceManagerOptions = {
13
13
  name: string;
14
14
  dir: string;
15
+ configKey?: string;
15
16
  config: WorkspaceConfiguration;
16
17
  manifest: PackageJson;
17
18
  dependencies: DependencySet;
19
+ allDependencies: DependencySet;
18
20
  rootManifest: Manifest | undefined;
19
21
  handleInput: HandleInput;
20
22
  handleConfigLoadError: () => void;
@@ -36,10 +38,12 @@ type CacheItem = {
36
38
  export declare class WorkspaceWorker {
37
39
  name: string;
38
40
  dir: string;
41
+ configKey: string | undefined;
39
42
  config: WorkspaceConfiguration;
40
43
  manifest: Manifest;
41
44
  rootManifest: Manifest | undefined;
42
45
  dependencies: DependencySet;
46
+ allDependencies: DependencySet;
43
47
  handleInput: HandleInput;
44
48
  handleConfigLoadError: () => void;
45
49
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
@@ -54,7 +58,7 @@ export declare class WorkspaceWorker {
54
58
  cache: CacheConsultant<Partial<Record<PluginName, CacheItem>>>;
55
59
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
56
60
  configurationFiles: ConfigurationFiles | undefined;
57
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, handleConfigLoadError, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, configurationFiles, options, }: WorkspaceManagerOptions);
61
+ constructor({ name, dir, configKey, config, manifest, dependencies, allDependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, handleConfigLoadError, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, configurationFiles, options, }: WorkspaceManagerOptions);
58
62
  init(): Promise<void>;
59
63
  private determineEnabledPlugins;
60
64
  private getConfigForPlugin;
@@ -1,5 +1,7 @@
1
1
  import picomatch from 'picomatch';
2
+ import { isDynamicPattern } from 'tinyglobby';
2
3
  import { _getInputsFromScripts } from './binaries/index.js';
4
+ import { getScriptCommands } from './binaries/plugins.js';
3
5
  import { CacheConsultant } from './CacheConsultant.js';
4
6
  import { isDefaultPattern } from './ConfigurationChief.js';
5
7
  import { DEFAULT_EXTENSIONS, ROOT_WORKSPACE_NAME } from './constants.js';
@@ -12,7 +14,7 @@ import { compact } from './util/array.js';
12
14
  import { debugLog, debugLogArray, debugLogObject } from './util/debug.js';
13
15
  import { _glob, hasNoProductionSuffix, hasProductionSuffix, negate } from './util/glob.js';
14
16
  import { expandIgnorePatterns } from './util/parse-and-convert-gitignores.js';
15
- import { isCatalog, isConfig, toConfig, toDebugString, toEntry, toProductionEntry, } from './util/input.js';
17
+ import { isConfig, isEntry, toDebugString, toEntry, toProductionEntry, } from './util/input.js';
16
18
  import { filterTransitiveDependencies } from './util/filter-transitive-dependencies.js';
17
19
  import { timerify } from './util/Performance.js';
18
20
  import { basename, dirname, extname, join, relative, toRelative } from './util/path.js';
@@ -20,15 +22,17 @@ import { extractPatternExtensions } from './util/pattern-extensions.js';
20
22
  import { formatCauseMessage } from './util/errors.js';
21
23
  import { logError } from './util/log.js';
22
24
  import { loadConfigForPlugin } from './util/plugin.js';
23
- import { ELLIPSIS } from './util/string.js';
25
+ import { hasUnhandledRejection, trackConfigLoad } from './util/unhandled-rejection.js';
24
26
  const nullConfig = { config: null, entry: null, project: null };
25
27
  export class WorkspaceWorker {
26
28
  name;
27
29
  dir;
30
+ configKey;
28
31
  config;
29
32
  manifest;
30
33
  rootManifest;
31
34
  dependencies;
35
+ allDependencies;
32
36
  handleInput;
33
37
  handleConfigLoadError;
34
38
  findWorkspaceByFilePath;
@@ -43,13 +47,15 @@ export class WorkspaceWorker {
43
47
  cache;
44
48
  configFilesMap;
45
49
  configurationFiles;
46
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, handleConfigLoadError, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, configurationFiles, options, }) {
50
+ constructor({ name, dir, configKey, config, manifest, dependencies, allDependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, handleConfigLoadError, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, configurationFiles, options, }) {
47
51
  this.name = name;
48
52
  this.dir = dir;
53
+ this.configKey = configKey;
49
54
  this.config = config;
50
55
  this.manifest = createManifest(manifest);
51
56
  this.rootManifest = rootManifest;
52
57
  this.dependencies = dependencies;
58
+ this.allDependencies = allDependencies;
53
59
  this.negatedWorkspacePatterns = negatedWorkspacePatterns;
54
60
  this.ignoredWorkspacePatterns = ignoredWorkspacePatterns;
55
61
  this.enabledPluginsInAncestors = enabledPluginsInAncestors;
@@ -83,7 +89,13 @@ export class WorkspaceWorker {
83
89
  const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
84
90
  if (isEnabledInAncestor ||
85
91
  (typeof plugin.isEnabled === 'function' &&
86
- (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies: this.dependencies, config: this.config })))) {
92
+ (await plugin.isEnabled({
93
+ cwd: this.dir,
94
+ manifest,
95
+ dependencies: this.dependencies,
96
+ config: this.config,
97
+ getScriptCommands,
98
+ })))) {
87
99
  this.enabledPluginsMap[pluginName] = true;
88
100
  enabledPlugins.push(pluginName);
89
101
  }
@@ -182,7 +194,7 @@ export class WorkspaceWorker {
182
194
  continue;
183
195
  if (this.options.cwd !== this.dir && plugin.isRootOnly)
184
196
  continue;
185
- await plugin.registerCompilers({ cwd, hasDependency, registerCompiler });
197
+ await plugin.registerCompilers({ cwd, dependencies: this.allDependencies, hasDependency, registerCompiler });
186
198
  }
187
199
  }
188
200
  async resolveSourceMaps() {
@@ -224,7 +236,7 @@ export class WorkspaceWorker {
224
236
  const rootManifest = this.rootManifest;
225
237
  const getManifest = this.getManifest;
226
238
  const baseOptions = { manifest, rootManifest, cwd, rootCwd, containingFilePath, getManifest };
227
- const baseScriptOptions = { ...baseOptions, isProduction, enabledPlugins: this.enabledPlugins };
239
+ const baseScriptOptions = { ...baseOptions, isProduction, enabledPlugins: this.enabledPlugins, getScriptCommands };
228
240
  const [productionScripts, developmentScripts] = getFilteredScripts(manifest.scripts ?? {});
229
241
  const inputsFromManifest = _getInputsFromScripts(Object.values(developmentScripts), baseOptions);
230
242
  const productionInputsFromManifest = _getInputsFromScripts(Object.values(productionScripts), baseOptions);
@@ -267,13 +279,13 @@ export class WorkspaceWorker {
267
279
  };
268
280
  for (const input of [...inputsFromManifest, ...productionInputsFromManifest]) {
269
281
  const inputContainingFilePath = input.containingFilePath ?? containingFilePath;
270
- if (isCatalog(input)) {
271
- inputs.push({ ...input, containingFilePath: inputContainingFilePath });
272
- }
273
- else if (isConfig(input)) {
282
+ if (isConfig(input)) {
274
283
  storeConfigFilePath(input.pluginName, { ...input, containingFilePath: inputContainingFilePath });
275
284
  }
276
- else if (!isProduction || input.production) {
285
+ else if (isProduction && isEntry(input) && !isDynamicPattern(input.specifier)) {
286
+ inputs.push({ ...input, type: 'deferResolveEntry', containingFilePath: inputContainingFilePath });
287
+ }
288
+ else {
277
289
  inputs.push({ ...input, containingFilePath: inputContainingFilePath });
278
290
  }
279
291
  }
@@ -375,10 +387,13 @@ export class WorkspaceWorker {
375
387
  if (!cache.resolveConfig) {
376
388
  const isLoad = typeof plugin.isLoadConfig === 'function' ? plugin.isLoadConfig(resolveOpts, this.dependencies) : true;
377
389
  if (isLoad) {
390
+ const resolveConfig = plugin.resolveConfig;
378
391
  try {
379
- const localConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
380
- if (localConfig) {
381
- const inputs = await plugin.resolveConfig(localConfig, resolveOpts);
392
+ const inputs = await trackConfigLoad(configFilePath, this.cache, async () => {
393
+ const localConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
394
+ return localConfig ? await resolveConfig(localConfig, resolveOpts) : undefined;
395
+ });
396
+ if (inputs) {
382
397
  if (plugin.isFilterTransitiveDependencies && !isManifest) {
383
398
  filterTransitiveDependencies(inputs, configFilePath, this.readRawFile);
384
399
  }
@@ -415,8 +430,7 @@ export class WorkspaceWorker {
415
430
  inputs.push(toEntry(configFilePath));
416
431
  cache.configFile = toEntry(configFilePath);
417
432
  }
418
- storeConfigFilePath(pluginName, toConfig(pluginName, configFilePath));
419
- if (hasLoadConfigError) {
433
+ if (hasLoadConfigError || hasUnhandledRejection()) {
420
434
  this.cache.removeEntry(configFilePath);
421
435
  }
422
436
  else if (fd?.meta) {
@@ -480,12 +494,15 @@ export class WorkspaceWorker {
480
494
  const hints = [];
481
495
  const entries = this.config[type].filter(pattern => !pattern.startsWith('!'));
482
496
  const workspaceName = this.name;
497
+ const configKey = this.configKey;
498
+ const hint = (type, identifier) => configKey ? { type, identifier, workspaceName, configKey } : { type, identifier, workspaceName };
483
499
  const userDefinedPatterns = entries.filter(id => !isDefaultPattern(type, id));
484
500
  if (userDefinedPatterns.length === 0)
485
501
  return hints;
486
502
  if (filePaths.length === 0) {
487
- const identifier = `[${entries[0]}${entries.length > 1 ? `, ${ELLIPSIS}` : ''}]`;
488
- hints.push({ type: `${type}-empty`, identifier, workspaceName });
503
+ for (const pattern of userDefinedPatterns) {
504
+ hints.push(hint(`${type}-empty`, pattern.replace(/!$/, '')));
505
+ }
489
506
  return hints;
490
507
  }
491
508
  const dir = this.dir;
@@ -502,10 +519,10 @@ export class WorkspaceWorker {
502
519
  continue;
503
520
  const id = pattern.replace(/!$/, '');
504
521
  if (includedPaths.has(join(dir, id))) {
505
- hints.push({ type: `${type}-redundant`, identifier: pattern, workspaceName });
522
+ hints.push(hint(`${type}-redundant`, pattern));
506
523
  }
507
524
  else if (!hasMatch(picomatch(id))) {
508
- hints.push({ type: `${type}-empty`, identifier: pattern, workspaceName });
525
+ hints.push(hint(`${type}-empty`, pattern));
509
526
  }
510
527
  }
511
528
  if (type === 'project' && compilerExtensions) {
@@ -517,14 +534,14 @@ export class WorkspaceWorker {
517
534
  if (seen.has(ext) || DEFAULT_EXTENSIONS.has(ext) || compilerExtensions.has(ext))
518
535
  continue;
519
536
  seen.add(ext);
520
- hints.push({ type: 'project-extension-unregistered', identifier: ext, workspaceName });
537
+ hints.push(hint('project-extension-unregistered', ext));
521
538
  }
522
539
  }
523
540
  if (patternExtensions.size > 0) {
524
541
  for (const ext of compilerExtensions) {
525
542
  if (patternExtensions.has(ext))
526
543
  continue;
527
- hints.push({ type: 'project-extension-excluded', identifier: ext, workspaceName });
544
+ hints.push(hint('project-extension-excluded', ext));
528
545
  }
529
546
  }
530
547
  }
@@ -21,13 +21,7 @@ export const getDependenciesFromScript = (script, options) => {
21
21
  ...opts,
22
22
  });
23
23
  };
24
- const fromWords = (words, opts) => {
25
- const script = words
26
- .filter(word => word.text !== '--')
27
- .map(word => word.text)
28
- .join(' ');
29
- return getDependenciesFromScript(script, opts);
30
- };
24
+ const fromWords = (args, opts) => getDependenciesFromScript(toScript(args), opts);
31
25
  const definedFunctions = new Set();
32
26
  const collectFunctionNames = (statements) => {
33
27
  for (const stmt of statements)
@@ -1,5 +1,5 @@
1
- import type { Command, Word } from 'unbash';
2
- import type { BinaryResolverOptions, GetInputsFromScriptsOptions } from '../types/config.ts';
1
+ import type { Command } from 'unbash';
2
+ import type { BinaryResolverOptions, GetInputsFromScriptsOptions, ScriptArg } from '../types/config.ts';
3
3
  import { type Input } from '../util/input.ts';
4
4
  export declare const getInputsFromNodeOptions: (prefix: Command['prefix']) => Input[];
5
- export declare const getDependenciesFromCommand: (node: Pick<Command, 'name' | 'prefix' | 'args'>, options: BinaryResolverOptions, fromWords?: (words: Word[], options: GetInputsFromScriptsOptions) => Input[]) => Input[];
5
+ export declare const getDependenciesFromCommand: (node: Pick<Command, 'name' | 'prefix' | 'args'>, options: BinaryResolverOptions, fromWords?: (args: ScriptArg[], options: GetInputsFromScriptsOptions) => Input[]) => Input[];
@@ -4,7 +4,7 @@ import { extractBinary, isInNodeModulesBin, isRelativeNodeModulesBin } from '../
4
4
  import { getCommandWords } from '../util/scripts.js';
5
5
  import { resolve as fallbackResolve, spawningBinaries } from './fallback.js';
6
6
  import KnownResolvers, { isPackageManager } from './resolvers/index.js';
7
- import { resolve as resolverFromPlugins } from './plugins.js';
7
+ import { getWrappedCommand, resolve as resolverFromPlugins } from './plugins.js';
8
8
  import { parseNodeArgs, toCommandBinary } from './util.js';
9
9
  export const getInputsFromNodeOptions = (prefix) => {
10
10
  const inputs = [];
@@ -49,7 +49,11 @@ export const getDependenciesFromCommand = (node, options, fromWords = options.fr
49
49
  return [...resolverFromPlugins(binary, words, options), ...fromNodeOptions];
50
50
  }
51
51
  if (spawningBinaries.includes(binary)) {
52
- return [toCommandBinary(binary, options), ...fromWords(words, options), ...fromNodeOptions];
52
+ return [
53
+ toCommandBinary(binary, options),
54
+ ...fromWords(getWrappedCommand(binary, words, options.cwd) ?? [], options),
55
+ ...fromNodeOptions,
56
+ ];
53
57
  }
54
58
  if (binary in Plugins) {
55
59
  const inputs = fallbackResolve(binary, words, options);
@@ -4,7 +4,7 @@ import { toDeferResolve, toEntry } from '../util/input.js';
4
4
  import { isValidBinary } from '../util/modules.js';
5
5
  import { isAbsolute } from '../util/path.js';
6
6
  import { argsAfter, toCommandBinary } from './util.js';
7
- export const spawningBinaries = ['cross-env', 'retry-cli'];
7
+ export const spawningBinaries = ['cross-env'];
8
8
  const endOfCommandBinaries = ['dotenvx', 'env-cmd', 'op'];
9
9
  const positionals = new Set(['babel-node', 'esbuild', 'execa', 'jiti', 'oxnode', 'vite-node', 'zx']);
10
10
  const positionalBinaries = new Set(['concurrently']);
@@ -1,3 +1,6 @@
1
- import type { BinaryResolver } from '../types/config.ts';
1
+ import { type Word } from 'unbash';
2
+ import type { BinaryResolver, GetScriptCommands, ScriptArg } from '../types/config.ts';
2
3
  export declare const isWrapper: (binary: string) => boolean;
4
+ export declare const getWrappedCommand: (binary: string, words: Word[], cwd?: string) => ScriptArg[] | undefined;
5
+ export declare const getScriptCommands: GetScriptCommands;
3
6
  export declare const resolve: BinaryResolver;