@@ -97,13 +97,13 @@ Examples:
9797/**
9898 * Run ts2swift for a single input file (programmatic API, no process I/O).
9999 * @param {string[] } filePaths - Paths to the .d.ts files
100- * @param {{ tsconfigPath: string, logLevel?: keyof typeof DiagnosticEngine.LEVELS, globalFiles?: string[] } } options
100+ * @param {{ tsconfigPath: string, logLevel?: keyof typeof DiagnosticEngine.LEVELS, globalFiles?: string[], diagnosticEngine?: DiagnosticEngine } } options
101101 * @returns {string } Generated Swift source
102102 * @throws {Error } on parse/type-check errors (diagnostics are included in the message)
103103 */
104104export function run ( filePaths , options ) {
105- const { tsconfigPath, logLevel = 'info' , globalFiles = [ ] } = options ;
106- const diagnosticEngine = new DiagnosticEngine ( logLevel ) ;
105+ const { tsconfigPath, logLevel = 'info' , globalFiles = [ ] , diagnosticEngine } = options ;
106+ const engine = diagnosticEngine ?? new DiagnosticEngine ( logLevel ) ;
107107
108108 const configFile = ts . readConfigFile ( tsconfigPath , ts . sys . readFile ) ;
109109 const configParseResult = ts . parseJsonConfigFileContent (
@@ -164,7 +164,7 @@ export function run(filePaths, options) {
164164 const bodies = [ ] ;
165165 const globalFileSet = new Set ( globalFiles ) ;
166166 for ( const inputPath of [ ...filePaths , ...globalFiles ] ) {
167- const processor = new TypeProcessor ( program . getTypeChecker ( ) , diagnosticEngine , {
167+ const processor = new TypeProcessor ( program . getTypeChecker ( ) , engine , {
168168 defaultImportFromGlobal : globalFileSet . has ( inputPath ) ,
169169 } ) ;
170170 const result = processor . processTypeDeclarations ( program , inputPath ) ;
@@ -247,7 +247,7 @@ export function main(args) {
247247
248248 let swiftOutput ;
249249 try {
250- swiftOutput = run ( filePaths , { tsconfigPath, logLevel, globalFiles } ) ;
250+ swiftOutput = run ( filePaths , { tsconfigPath, logLevel, globalFiles, diagnosticEngine } ) ;
251251 } catch ( /** @type {unknown } */ err ) {
252252 if ( err instanceof Error ) {
253253 diagnosticEngine . print ( "error" , err . message ) ;
0 commit comments