/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
integration/module-tests/find-all-modules.mts
60 строк
2 KB
Cheng-Hsuan Tsai
build: update cross-repo angular dependencies (main) (#33128)
23 апр 2026, 14:20
Не верифицирован
23 апр 2026, 14:20
4d48ccf
Код
Авторство
О чём код?
import * as fs from 'node:fs/promises'; import * as path from 'node:path'; import * as ts from 'typescript'; export async function findAllEntryPointsAndExportedModules(packagePath: string) { const packageJsonRaw = await fs.readFile(path.join(packagePath, 'package.json'), 'utf8'); const packageJson = JSON.parse(packageJsonRaw) as { name: string; exports: Record<string, Record<string, string>>; }; const tasks: Promise<{importPath: string; symbolName: string}[]>[] = []; for (const [subpath, conditions] of Object.entries(packageJson.exports)) { if (conditions.types === undefined) { continue; } tasks.push( (async () => { const dtsFile = path.join(packagePath, conditions.types); const dtsBundleFile = ts.createSourceFile( dtsFile, await fs.readFile(dtsFile, 'utf8'), ts.ScriptTarget.ESNext, false, ); return scanExportsForModules(dtsBundleFile).map(e => ({ importPath: path.posix.join(packageJson.name, subpath), symbolName: e, })); })(), ); } const moduleExports = (await Promise.all(tasks)).flat(); return { name: packageJson.name, packagePath, moduleExports, }; } function scanExportsForModules(sf: ts.SourceFile): string[] { const moduleExports: string[] = []; const visit = (node: ts.Node) => { if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) { moduleExports.push( ...node.exportClause.elements .filter(e => e.name.text.endsWith('Module')) .map(e => e.name.text), ); } }; ts.forEachChild(sf, visit); return moduleExports; }