MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / createApiDtsFiles

Function createApiDtsFiles

packages/tooling/src/typescript.ts:165–241  ·  view source on GitHub ↗
(
    dtsBaseDir: string,
    dtsFiles: string[],
    projectDir: string,
    outDir: string,
    logger: Logger
)

Source from the content-addressed store, hash-verified

163}
164
165export async function createApiDtsFiles(
166 dtsBaseDir: string,
167 dtsFiles: string[],
168 projectDir: string,
169 outDir: string,
170 logger: Logger
171) {
172 const commandLine = ts.parseCommandLine([]);
173 if (!commandLine.options.project) {
174 commandLine.options.project = path.resolve(projectDir, 'tsconfig.json');
175 }
176
177 const reportDiagnostic = createDiagnosticReporter(true, logger);
178
179 const parseConfigFileHost: ts.ParseConfigFileHost = ts.sys as any;
180 parseConfigFileHost.onUnRecoverableConfigFileDiagnostic = diagnostic => {
181 reportDiagnostic(diagnostic);
182 ts.sys.exit(ts.ExitStatus.InvalidProject_OutputsSkipped);
183 };
184
185 const parsedCommandLine = ts.getParsedCommandLineOfConfigFile(
186 commandLine.options.project!,
187 commandLine.options,
188 parseConfigFileHost,
189 /*extendedConfigCache*/ undefined,
190 commandLine.watchOptions
191 )!;
192
193 const removedSymbols = new Set<string>();
194
195 const program = ts.createProgram({
196 rootNames: dtsFiles,
197 options: parsedCommandLine.options,
198 projectReferences: parsedCommandLine.projectReferences,
199 host: ts.createCompilerHost(parsedCommandLine.options)
200 });
201
202 let sourceFiles = dtsFiles.map(f => program.getSourceFile(f)!);
203
204 const checker = program.getTypeChecker();
205
206 // Pass 1: Filter all exports
207 sourceFiles = sourceFiles.map(
208 s => ts.visitEachChild(s, filterDtsVisitor(checker, s, removedSymbols, logger.warn), undefined) as ts.SourceFile
209 );
210
211 // Pass 2: Filter imports of remoevd exports
212 sourceFiles = sourceFiles.map(
213 s => ts.visitEachChild(s, filterDtsImportsVisitor(checker, removedSymbols), undefined) as ts.SourceFile
214 );
215
216 // Pass 3: filter any files which do not have any exports
217 sourceFiles = sourceFiles.filter(s =>
218 s.statements.some(
219 e =>
220 ts.isExportDeclaration(e) ||
221 (ts.canHaveModifiers(e) && e.modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword))
222 )

Callers 1

writeBundleFunction · 0.90

Calls 7

createDiagnosticReporterFunction · 0.85
filterDtsVisitorFunction · 0.85
filterDtsImportsVisitorFunction · 0.85
filterMethod · 0.80
someMethod · 0.80
resolveMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected