( cwd: string, checker: NativeChecker, entry: SolutionReferences )
| 653 | // discover referenced projects in dependency-first topological order (post-order |
| 654 | // DFS) using a single native API process before opening each project |
| 655 | export const discoverNativeProjects = ( |
| 656 | cwd: string, |
| 657 | checker: NativeChecker, |
| 658 | entry: SolutionReferences |
| 659 | ): DiscoveredNativeProjects => { |
| 660 | const { sync } = loadNative(cwd, checker) |
| 661 | const api = new sync.API({ cwd }) |
| 662 | const ordered: string[] = [] |
| 663 | const diagnostics: string[] = entry.diagnostics ? [entry.diagnostics] : [] |
| 664 | let errors = entry.errors |
| 665 | const visiting = new Set<string>() |
| 666 | const visited = new Set<string>([canonicalConfigPath(entry.configPath, cwd)]) |
| 667 | let discovered = 1 |
| 668 | const visit = (configPath: string): void => { |
| 669 | const resolvedPath = resolve(cwd, configPath) |
| 670 | const key = canonicalConfigPath(resolvedPath, cwd) |
| 671 | if (visited.has(key) || visiting.has(key)) return |
| 672 | if (discovered >= maxSolutionProjects) { |
| 673 | throwError( |
| 674 | `Exceeded ${maxSolutionProjects} referenced projects while traversing project references. Run \`ark declare --tsconfig <path>\` for a single project.` |
| 675 | ) |
| 676 | } |
| 677 | discovered++ |
| 678 | visiting.add(key) |
| 679 | let parsed: tsgo.ParsedCommandLine | undefined |
| 680 | try { |
| 681 | parsed = api.parseConfigFile(resolvedPath) |
| 682 | } catch { |
| 683 | // openNative reports unreadable configs through its normal diagnostics |
| 684 | } |
| 685 | for (const ref of parsed?.projectReferences ?? []) { |
| 686 | visit( |
| 687 | /\.json$/i.test(ref.path) ? ref.path : join(ref.path, "tsconfig.json") |
| 688 | ) |
| 689 | } |
| 690 | visiting.delete(key) |
| 691 | visited.add(key) |
| 692 | if (!parsed || parsed.fileNames.length || !parsed.projectReferences?.length) |
| 693 | ordered.push(resolvedPath) |
| 694 | else { |
| 695 | // skipped intermediate solution configs won't go to openNative, so collect |
| 696 | // their config parsing diagnostics here (e.g. unknown compiler options) |
| 697 | try { |
| 698 | const proj = api |
| 699 | .createSnapshot({ openProjects: [resolvedPath] }) |
| 700 | .getConfiguredProject(resolvedPath) |
| 701 | const configDiags = proj?.program.getConfigFileParsingDiagnostics() |
| 702 | if (configDiags?.length) { |
| 703 | const formatted = sync.formatDiagnostics(configDiags, { |
| 704 | getCanonicalFileName: path => path, |
| 705 | getCurrentDirectory: () => cwd, |
| 706 | getNewLine: () => "\n" |
| 707 | }) |
| 708 | if (formatted) diagnostics.push(formatted) |
| 709 | errors += configDiags.filter( |
| 710 | diagnostic => diagnostic.category === sync.DiagnosticCategory.Error |
| 711 | ).length |
| 712 | } |
no test coverage detected