Skip to content

Commit

Permalink
Allow processFilesFor{Target,Bundle,Package} to return a Promise.
Browse files Browse the repository at this point in the history
This paves the way for compiler plugins to use normal async/await rather
than using fibers and/or futures to wait for async compilation to finish.
  • Loading branch information
benjamn committed Jan 16, 2018
1 parent 9cc978e commit c7a9d61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
12 changes: 7 additions & 5 deletions tools/isobuild/bundler.js
Expand Up @@ -1246,10 +1246,12 @@ class Target {
buildmessage.enterJob('minifying app code', function () {
try {
var markedMinifier = buildmessage.markBoundary(minifier);
markedMinifier(staticFiles, { minifyMode });
dynamicFiles.forEach(file => {
markedMinifier([file], { minifyMode });
});
Promise.all([
markedMinifier(staticFiles, { minifyMode }),
...dynamicFiles.map(
file => markedMinifier([file], { minifyMode })
),
]).await();
} catch (e) {
buildmessage.exception(e);
}
Expand Down Expand Up @@ -1497,7 +1499,7 @@ class ClientTarget extends Target {
buildmessage.enterJob('minifying app stylesheet', function () {
try {
const markedMinifier = buildmessage.markBoundary(minifier);
markedMinifier(sources, { minifyMode });
Promise.await(markedMinifier(sources, { minifyMode }));
} catch (e) {
buildmessage.exception(e);
}
Expand Down
3 changes: 2 additions & 1 deletion tools/isobuild/compiler-plugin.js
Expand Up @@ -187,8 +187,9 @@ export class CompilerPluginProcessor {
var markedMethod = buildmessage.markBoundary(
sourceProcessor.userPlugin.processFilesForTarget.bind(
sourceProcessor.userPlugin));

try {
markedMethod(inputFiles);
Promise.await(markedMethod(inputFiles));
} catch (e) {
buildmessage.exception(e);
}
Expand Down
9 changes: 8 additions & 1 deletion tools/isobuild/compiler.js
Expand Up @@ -840,7 +840,9 @@ function runLinters({inputSourceArch, isopackCache, sources,
try {
var markedLinter = buildmessage.markBoundary(linter.bind(
sourceProcessor.userPlugin));
markedLinter(sourcesToLint, { globals: globalImports });
Promise.await(markedLinter(sourcesToLint, {
globals: globalImports
}));
} catch (e) {
buildmessage.exception(e);
}
Expand Down Expand Up @@ -1041,4 +1043,9 @@ export const KNOWN_ISOBUILD_FEATURE_PACKAGES = {
// This package requires functionality introduced in meteor-tool@1.5.0
// to enable dynamic module fetching via import(...).
'isobuild:dynamic-import': ['1.5.0'],

// This package ensures that processFilesFor{Bundle,Target,Package} are
// allowed to return a Promise instead of having to await async
// compilation using fibers and/or futures.
'isobuild:async-plugins': ['1.6.1'],
};

0 comments on commit c7a9d61

Please sign in to comment.