From 9fd55a476025ad7156625310c2b47c1423da83b5 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Thu, 13 Jul 2023 11:52:17 -0400 Subject: [PATCH] Emit source file always return async --- packages/compiler/src/config/config-loader.ts | 21 ++++++++++++------- .../src/emitter-framework/asset-emitter.ts | 4 ++-- .../compiler/src/emitter-framework/types.ts | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/packages/compiler/src/config/config-loader.ts b/packages/compiler/src/config/config-loader.ts index 92191851960..8783e9c2fb2 100644 --- a/packages/compiler/src/config/config-loader.ts +++ b/packages/compiler/src/config/config-loader.ts @@ -103,7 +103,7 @@ export async function loadTypeSpecConfigFile( host: CompilerHost, filePath: string ): Promise { - const config = await loadConfigFile(host, filePath, jsyaml.load); + const config = await loadConfigFile(host, filePath); if (config.diagnostics.length === 0 && config.extends) { const extendPath = resolvePath(getDirectoryPath(filePath), config.extends); const parent = await loadTypeSpecConfigFile(host, extendPath); @@ -157,15 +157,22 @@ async function searchConfigFile( return stat?.isFile() === true ? pkgPath : undefined; } -async function loadConfigFile( - host: CompilerHost, - filename: string, - loadData: (content: string) => any -): Promise { +async function loadConfigFile(host: CompilerHost, filename: string): Promise { let diagnostics: Diagnostic[] = []; const reportDiagnostic = (d: Diagnostic) => diagnostics.push(d); - let [data, file] = await loadFile(host, filename, loadData, reportDiagnostic); + let [data, file] = await loadFile( + host, + filename, + (content) => { + return jsyaml.load(content, { + listener: (eventType, state) => { + console.log("LOaded", eventType, state.result); + }, + }) as any; + }, + reportDiagnostic + ); if (data) { diagnostics = diagnostics.concat(configValidator.validate(data, file)); diff --git a/packages/compiler/src/emitter-framework/asset-emitter.ts b/packages/compiler/src/emitter-framework/asset-emitter.ts index 0fa98dd961a..a313d398f82 100644 --- a/packages/compiler/src/emitter-framework/asset-emitter.ts +++ b/packages/compiler/src/emitter-framework/asset-emitter.ts @@ -432,8 +432,8 @@ export function createAssetEmitter( return invokeTypeEmitter("tupleLiteralValues", tuple); }, - emitSourceFile(sourceFile) { - return typeEmitter.sourceFile(sourceFile); + async emitSourceFile(sourceFile) { + return await typeEmitter.sourceFile(sourceFile); }, }; diff --git a/packages/compiler/src/emitter-framework/types.ts b/packages/compiler/src/emitter-framework/types.ts index 98bebb8ac37..dcf8bd721a4 100644 --- a/packages/compiler/src/emitter-framework/types.ts +++ b/packages/compiler/src/emitter-framework/types.ts @@ -41,7 +41,7 @@ export interface AssetEmitter; emitUnionVariants(union: Union): EmitEntity; emitTupleLiteralValues(tuple: Tuple): EmitEntity; - emitSourceFile(sourceFile: SourceFile): Promise | EmittedSourceFile; + emitSourceFile(sourceFile: SourceFile): Promise; /** * Create a source file. *