Skip to content

Commit

Permalink
Merge pull request #19057 from arthirm/lts-3-16
Browse files Browse the repository at this point in the history
Parallelize inject-babel-helpers plugin
  • Loading branch information
rwjblue authored Jul 29, 2020
2 parents f10f7b4 + ab33e5d commit 07d3aba
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const resolve = require('resolve');
const concatBundle = require('./concat-bundle');
const buildDebugMacroPlugin = require('./build-debug-macro-plugin');
const buildStripClassCallcheckPlugin = require('./build-strip-class-callcheck-plugin');
const injectBabelHelpers = require('./transforms/inject-babel-helpers');
const injectBabelHelpers = require('./transforms/inject-babel-helpers').injectBabelHelpers;
const debugTree = require('broccoli-debug').buildDebugCallback('ember-source:addon');

const PRE_BUILT_TARGETS = [
Expand Down Expand Up @@ -138,6 +138,7 @@ module.exports = {
// We want to enable async/generator helpers if we are developing locally,
// but not for any other project.
let isEmberSource = this.project.name() === 'ember-source';
let babelHelperPlugin = injectBabelHelpers(isEmberSource);

let options = {
'ember-cli-babel': {
Expand All @@ -147,7 +148,7 @@ module.exports = {
babel: Object.assign({}, babelOptions, {
loose: true,
plugins: [
injectBabelHelpers(isEmberSource),
babelHelperPlugin,
buildDebugMacroPlugin(!isProduction),
[
require.resolve('@babel/plugin-transform-block-scoping'),
Expand Down
50 changes: 30 additions & 20 deletions lib/transforms/inject-babel-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,39 @@
const { addNamed } = require('@babel/helper-module-imports');

function injectBabelHelpers(isEmberSource = false) {
function injectBabelHelpersPlugin() {
return {
pre(file) {
file.set('helperGenerator', function(name) {
if (name === 'extends') {
return addNamed(file.path, 'assign', '@ember/polyfills');
} else if (isEmberSource && name === 'asyncToGenerator') {
// Returning a falsy value will cause the helper to be inlined,
// which is fine for local tests
return false;
}

return addNamed(file.path, name, 'ember-babel');
});
},
};
}
let helperplugin = injectBabelHelpersPlugin;
helperplugin._parallelBabel = {
requireFile: __filename,
buildUsing: 'injectBabelHelpersPlugin',
params: { isEmberSource },
};

injectBabelHelpersPlugin.baseDir = function() {
helperplugin.baseDir = function() {
return 'babel-core';
};

return injectBabelHelpersPlugin;
return helperplugin;
}

function injectBabelHelpersPlugin(isEmberSource) {
return {
pre(file) {
file.set('helperGenerator', function(name) {
if (name === 'extends') {
return addNamed(file.path, 'assign', '@ember/polyfills');
} else if (isEmberSource && name === 'asyncToGenerator') {
// Returning a falsy value will cause the helper to be inlined,
// which is fine for local tests
return false;
}

return addNamed(file.path, name, 'ember-babel');
});
},
};
}

module.exports = injectBabelHelpers;
module.exports = {
injectBabelHelpers,
injectBabelHelpersPlugin,
};

0 comments on commit 07d3aba

Please sign in to comment.