* Process public API exports from dist folder or API markdown files
(
distPath: string,
sourceRoot: string,
)
| 299 | * Process public API exports from dist folder or API markdown files |
| 300 | */ |
| 301 | private async processPublicApi( |
| 302 | distPath: string, |
| 303 | sourceRoot: string, |
| 304 | ): Promise<void> { |
| 305 | logger.info("Processing public API exports"); |
| 306 | |
| 307 | try { |
| 308 | // First, try to parse API markdown files from the source root |
| 309 | logger.info("Checking for *.api.md files in source root"); |
| 310 | const apiMarkdownExports = |
| 311 | await parseApiMarkdownExports(sourceRoot); |
| 312 | |
| 313 | if ( |
| 314 | apiMarkdownExports.apiMdFiles.size > 0 && |
| 315 | apiMarkdownExports.symbolToFiles.size > 0 |
| 316 | ) { |
| 317 | logger.info( |
| 318 | `Found ${apiMarkdownExports.apiMdFiles.size} relevant *.api.md file(s) with ${apiMarkdownExports.symbolToFiles.size} symbol(s)`, |
| 319 | ); |
| 320 | |
| 321 | // Map symbols from API markdown files directly to source files |
| 322 | const symbolToSourceFiles = new Map<string, Set<string>>(); |
| 323 | |
| 324 | for (const [symbolName] of apiMarkdownExports.symbolToFiles) { |
| 325 | const sourceFiles = new Set<string>(); |
| 326 | |
| 327 | // Find the corresponding source file for this symbol |
| 328 | const sourceFile = this.findSourceFileForSymbol( |
| 329 | symbolName, |
| 330 | sourceRoot, |
| 331 | ); |
| 332 | if (sourceFile) { |
| 333 | sourceFiles.add(sourceFile); |
| 334 | } |
| 335 | |
| 336 | if (sourceFiles.size > 0) { |
| 337 | symbolToSourceFiles.set(symbolName, sourceFiles); |
| 338 | logger.debug( |
| 339 | `Public API symbol: ${symbolName} -> ${Array.from(sourceFiles).join(", ")}`, |
| 340 | ); |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | // Store in configuration |
| 345 | Configuration.mainData.publicApiExports = symbolToSourceFiles; |
| 346 | |
| 347 | logger.info( |
| 348 | `Loaded ${symbolToSourceFiles.size} public API symbol(s) from ${apiMarkdownExports.apiMdFiles.size} *.api.md file(s) (using API Markdown parser)`, |
| 349 | ); |
| 350 | } else { |
| 351 | // Fall back to index.d.ts parsing |
| 352 | logger.info( |
| 353 | "No relevant *.api.md files found, falling back to index.d.ts parsing", |
| 354 | ); |
| 355 | |
| 356 | const publicApiExports = await parsePublicApi(distPath); |
| 357 | |
| 358 | if (publicApiExports.symbolToFiles.size === 0) { |
no test coverage detected