Skip to content

Commit

Permalink
Emit source file always return async
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed Jul 13, 2023
1 parent d7e7ed9 commit 9fd55a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions packages/compiler/src/config/config-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function loadTypeSpecConfigFile(
host: CompilerHost,
filePath: string
): Promise<TypeSpecConfig> {
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);
Expand Down Expand Up @@ -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<TypeSpecConfig> {
async function loadConfigFile(host: CompilerHost, filename: string): Promise<TypeSpecConfig> {
let diagnostics: Diagnostic[] = [];
const reportDiagnostic = (d: Diagnostic) => diagnostics.push(d);

let [data, file] = await loadFile<TypeSpecRawConfig>(host, filename, loadData, reportDiagnostic);
let [data, file] = await loadFile<TypeSpecRawConfig>(
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));
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/emitter-framework/asset-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ export function createAssetEmitter<T, TOptions extends object>(
return invokeTypeEmitter("tupleLiteralValues", tuple);
},

emitSourceFile(sourceFile) {
return typeEmitter.sourceFile(sourceFile);
async emitSourceFile(sourceFile) {
return await typeEmitter.sourceFile(sourceFile);
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/emitter-framework/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface AssetEmitter<T, TOptions extends object = Record<string, unknow
emitEnumMembers(en: Enum): EmitEntity<T>;
emitUnionVariants(union: Union): EmitEntity<T>;
emitTupleLiteralValues(tuple: Tuple): EmitEntity<T>;
emitSourceFile(sourceFile: SourceFile<T>): Promise<EmittedSourceFile> | EmittedSourceFile;
emitSourceFile(sourceFile: SourceFile<T>): Promise<EmittedSourceFile>;
/**
* Create a source file.
*
Expand Down

0 comments on commit 9fd55a4

Please sign in to comment.