fix(scripts): share package-source selection to clear the jscpd clone

The spec duplicated collectEventRelations' source-selection block; extract
collectPackageSources and use it from both sides.
This commit is contained in:
imccyu
2026-07-30 11:33:35 +08:00
parent f988ca9b86
commit 7326b9b2a4
2 changed files with 14 additions and 10 deletions
+2 -6
View File
@@ -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<string, string> = {
@@ -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 })