Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { readFileSync } from 'fs';
import globby from 'globby';
import * as path from 'path';
import { parseUsageCollection } from './ts_parser';
import { TelemetryRC } from './config';
import { createKibanaProgram, getAllSourceFiles } from './ts_program';

const COLLECTOR_RE = /makeUsageCollector|makeStatsCollector/;

export async function getProgramPaths({
root,
exclude,
Expand Down Expand Up @@ -53,8 +56,17 @@ export async function getProgramPaths({
}

export function* extractCollectors(fullPaths: string[], tsConfig: any) {
const program = createKibanaProgram(fullPaths, tsConfig);
const sourceFiles = getAllSourceFiles(fullPaths, program);
// Pre-filter to only files that reference collector APIs so TS doesn't
// parse thousands of unrelated source files (36K → ~70 root files).
// TS still resolves transitive imports needed for type-checking.
const collectorPaths = fullPaths.filter((p) => COLLECTOR_RE.test(readFileSync(p, 'utf-8')));

if (collectorPaths.length === 0) {
return;
}

const program = createKibanaProgram(collectorPaths, tsConfig);
const sourceFiles = getAllSourceFiles(collectorPaths, program);

for (const sourceFile of sourceFiles) {
yield* parseUsageCollection(sourceFile, program);
Expand Down
Loading