Skip to content

Commit b643068

Browse files
committed
properly await asc.compile()
1 parent f7ab5ee commit b643068

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

packages/cli/src/compiler/asc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface CompileOptions {
3434
// it requires an asynchronous wait. Whenever you call this function,
3535
// it doesn't matter how many times, just make sure you call `ready`
3636
// once before everything..
37-
export const compile = ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
37+
export const compile = async ({ inputFile, global, baseDir, libs, outputFile }: CompileOptions) => {
3838
const exitHandler = createExitHandler(inputFile);
3939

4040
setupExitHandler(exitHandler);
@@ -55,7 +55,7 @@ export const compile = ({ inputFile, global, baseDir, libs, outputFile }: Compil
5555
'--debug',
5656
];
5757

58-
assemblyScriptCompiler(compilerArgs, compilerDefaults);
58+
await assemblyScriptCompiler(compilerArgs, compilerDefaults);
5959

6060
// only if compiler succeeded, that is, when the line above doesn't throw
6161
removeExitHandler(exitHandler);

packages/cli/src/compiler/index.ts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,30 +246,41 @@ export default class Compiler {
246246
// Cache compiled files so identical input files are only compiled once
247247
const compiledFiles = new Map();
248248

249-
subgraph = subgraph.update('dataSources', (dataSources: any[]) =>
250-
dataSources.map((dataSource: any) =>
251-
dataSource.updateIn(['mapping', 'file'], (mappingPath: string) =>
252-
this._compileDataSourceMapping(
253-
this.protocol,
254-
dataSource,
249+
// Handle data sources
250+
const dataSources = subgraph.get('dataSources');
251+
const compiledDataSources = await Promise.all(
252+
dataSources.map(async (dataSource: any) => {
253+
const mappingPath = dataSource.getIn(['mapping', 'file']);
254+
const compiledPath = await this._compileDataSourceMapping(
255+
this.protocol,
256+
dataSource,
257+
mappingPath,
258+
compiledFiles,
259+
spinner,
260+
validate,
261+
);
262+
return dataSource.setIn(['mapping', 'file'], compiledPath);
263+
}),
264+
);
265+
subgraph = subgraph.set('dataSources', compiledDataSources);
266+
267+
// Handle templates if they exist
268+
const templates = subgraph.get('templates');
269+
if (templates !== undefined) {
270+
const compiledTemplates = await Promise.all(
271+
templates.map(async (template: any) => {
272+
const mappingPath = template.getIn(['mapping', 'file']);
273+
const compiledPath = await this._compileTemplateMapping(
274+
template,
255275
mappingPath,
256276
compiledFiles,
257277
spinner,
258-
validate,
259-
),
260-
),
261-
),
262-
);
263-
264-
subgraph = subgraph.update('templates', (templates: any) =>
265-
templates === undefined
266-
? templates
267-
: templates.map((template: any) =>
268-
template.updateIn(['mapping', 'file'], (mappingPath: string) =>
269-
this._compileTemplateMapping(template, mappingPath, compiledFiles, spinner),
270-
),
271-
),
272-
);
278+
);
279+
return template.setIn(['mapping', 'file'], compiledPath);
280+
}),
281+
);
282+
subgraph = subgraph.set('templates', compiledTemplates);
283+
}
273284

274285
return subgraph;
275286
},
@@ -332,7 +343,7 @@ export default class Compiler {
332343
return missingHandlers;
333344
}
334345

335-
_compileDataSourceMapping(
346+
async _compileDataSourceMapping(
336347
protocol: Protocol,
337348
dataSource: immutable.Map<any, any>,
338349
mappingPath: string,
@@ -386,7 +397,7 @@ export default class Compiler {
386397
}
387398
const global = path.relative(baseDir, this.globalsFile);
388399

389-
asc.compile({
400+
await asc.compile({
390401
inputFile,
391402
global,
392403
baseDir,
@@ -413,7 +424,7 @@ export default class Compiler {
413424
}
414425
}
415426

416-
_compileTemplateMapping(
427+
async _compileTemplateMapping(
417428
template: immutable.Collection<any, any>,
418429
mappingPath: string,
419430
compiledFiles: Map<any, any>,
@@ -467,7 +478,7 @@ export default class Compiler {
467478
}
468479
const global = path.relative(baseDir, this.globalsFile);
469480

470-
asc.compile({
481+
await asc.compile({
471482
inputFile,
472483
global,
473484
baseDir,

0 commit comments

Comments
 (0)