diff --git a/scripts/gen-doc-graphs.spec.ts b/scripts/gen-doc-graphs.spec.ts index b529fc4c50..057054734e 100644 --- a/scripts/gen-doc-graphs.spec.ts +++ b/scripts/gen-doc-graphs.spec.ts @@ -9,7 +9,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { afterAll, describe, expect, it } from 'vitest' -import { EventRelationCollector, type PackageSource } from './gen-doc-graphs.ts' +import { collectPackageSources, EventRelationCollector } from './gen-doc-graphs.ts' import { TypeScriptProject } from './ts-project.ts' const FIXTURE: Record = { @@ -69,11 +69,7 @@ for (const [rel, content] of Object.entries(FIXTURE)) { writeFileSync(join(root, rel), content) } const project = new TypeScriptProject(root) -const sources = project.sourceFiles().flatMap((sourceFile): PackageSource[] => { - const rel = project.relativePath(sourceFile) - const match = /^packages\/[^/]+\/([^/]+)\/src\/.+\.ts$/.exec(rel) - return match?.[1] ? [{ rel, pkg: match[1], sourceFile }] : [] -}).sort((left, right) => left.rel.localeCompare(right.rel)) +const sources = collectPackageSources(project) afterAll(() => { rmSync(root, { recursive: true, force: true }) diff --git a/scripts/gen-doc-graphs.ts b/scripts/gen-doc-graphs.ts index b80885726f..23250e19e8 100644 --- a/scripts/gen-doc-graphs.ts +++ b/scripts/gen-doc-graphs.ts @@ -1050,14 +1050,22 @@ function unionSets(left: ReadonlySet, right: ReadonlySet): Set { return out } -function collectEventRelations(): Map { - const project = new TypeScriptProject(root) - const sources = project.sourceFiles().flatMap((sourceFile): PackageSource[] => { +/** + * Select the package source files of one project in deterministic order. + * @param project - the loaded repository TypeScript project. + * @returns `packages///src` files tagged with their package name. + */ +export function collectPackageSources(project: TypeScriptProject): PackageSource[] { + return project.sourceFiles().flatMap((sourceFile): PackageSource[] => { const rel = project.relativePath(sourceFile) const match = /^packages\/[^/]+\/([^/]+)\/src\/.+\.ts$/.exec(rel) return match?.[1] ? [{ rel, pkg: match[1], sourceFile }] : [] }).sort((left, right) => left.rel.localeCompare(right.rel)) - return new EventRelationCollector(project, sources).collect() +} + +function collectEventRelations(): Map { + const project = new TypeScriptProject(root) + return new EventRelationCollector(project, collectPackageSources(project)).collect() } function relationPackages(map: Map>, pkgsByShort: Map): string {