( cwd: string, tsconfig: string | undefined )
| 296 | )) |
| 297 | |
| 298 | const emitDeclarationsJs = ( |
| 299 | cwd: string, |
| 300 | tsconfig: string | undefined |
| 301 | ): Declarations => { |
| 302 | const ts = loadTypeScript(cwd) |
| 303 | const entryDiagnostics: ts.Diagnostic[] = [] |
| 304 | const entry = parseConfig(ts, cwd, tsconfig, entryDiagnostics) |
| 305 | if (entry.fileNames.length || !entry.projectReferences?.length) { |
| 306 | const frontend = openParsedJs(ts, cwd, entry, entryDiagnostics) |
| 307 | return declareWith(frontend, cwd) |
| 308 | } |
| 309 | // solution-style tsconfig: discover referenced projects in dependency-first |
| 310 | // topological order (post-order DFS), keeping cycle, diamond and max-project guards |
| 311 | const ordered: { |
| 312 | parsed: ts.ParsedCommandLine |
| 313 | diagnostics: ts.Diagnostic[] |
| 314 | }[] = [] |
| 315 | const visiting = new Set<string>() |
| 316 | const visited = new Set<string>() |
| 317 | const diagnostics: string[] = [] |
| 318 | let errors = 0 |
| 319 | let discovered = 0 |
| 320 | const visit = ( |
| 321 | configPath: string, |
| 322 | preparsed?: ts.ParsedCommandLine, |
| 323 | preparsedDiagnostics?: ts.Diagnostic[] |
| 324 | ): void => { |
| 325 | const key = canonicalConfigPath(configPath, cwd) |
| 326 | if (visited.has(key) || visiting.has(key)) return |
| 327 | if (discovered >= maxSolutionProjects) { |
| 328 | throwError( |
| 329 | `Exceeded ${maxSolutionProjects} referenced projects while traversing project references. Run \`ark declare --tsconfig <path>\` for a single project.` |
| 330 | ) |
| 331 | } |
| 332 | discovered++ |
| 333 | const localDiagnostics = preparsedDiagnostics ?? [] |
| 334 | const parsed = |
| 335 | preparsed ?? parseConfig(ts, cwd, configPath, localDiagnostics) |
| 336 | const resolvedKey = canonicalConfigPath( |
| 337 | parsed.options.configFilePath as string, |
| 338 | cwd |
| 339 | ) |
| 340 | if (visited.has(resolvedKey) || visiting.has(resolvedKey)) return |
| 341 | visiting.add(key) |
| 342 | visiting.add(resolvedKey) |
| 343 | for (const ref of referencePathsOf(ts, parsed)) visit(ref) |
| 344 | visiting.delete(key) |
| 345 | visiting.delete(resolvedKey) |
| 346 | visited.add(key) |
| 347 | visited.add(resolvedKey) |
| 348 | if (parsed.fileNames.length) |
| 349 | ordered.push({ parsed, diagnostics: localDiagnostics }) |
| 350 | else if (localDiagnostics.length) { |
| 351 | diagnostics.push(formatDiagnostics(ts, localDiagnostics, cwd)) |
| 352 | errors += localDiagnostics.filter( |
| 353 | d => d.category === ts.DiagnosticCategory.Error |
| 354 | ).length |
| 355 | } |
no test coverage detected