From a670fc8316b76ca6bfe50360a41cc068b01e20f8 Mon Sep 17 00:00:00 2001 From: Arthi Ravi Shankar Date: Fri, 17 Jul 2020 15:46:28 -0700 Subject: [PATCH 1/2] Parallelize inject-babel-helpers plugin --- lib/index.js | 5 ++- lib/transforms/inject-babel-helpers.js | 53 ++++++++++++++++---------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/lib/index.js b/lib/index.js index d1c637a7cce..5fc92120dbd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = [ @@ -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': { @@ -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'), diff --git a/lib/transforms/inject-babel-helpers.js b/lib/transforms/inject-babel-helpers.js index 18cc33ed212..c01efbf413d 100644 --- a/lib/transforms/inject-babel-helpers.js +++ b/lib/transforms/inject-babel-helpers.js @@ -3,29 +3,40 @@ 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'); - }); - }, - }; - } - - injectBabelHelpersPlugin.baseDir = function() { + + let helperplugin = injectBabelHelpersPlugin; + helperplugin._parallelBabel = { + requireFile: __filename, + buildUsing: 'injectBabelHelpersPlugin', + params : { isEmberSource }, + }; + + 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 +}; From ab33e5dad566a9b869ec87636ac83832d83181e4 Mon Sep 17 00:00:00 2001 From: Arthi Ravi Shankar Date: Fri, 17 Jul 2020 15:46:28 -0700 Subject: [PATCH 2/2] Parallelize inject-babel-helpers plugin --- lib/index.js | 2 +- lib/transforms/inject-babel-helpers.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5fc92120dbd..02051db7d9d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -138,7 +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 babelHelperPlugin = injectBabelHelpers(isEmberSource); let options = { 'ember-cli-babel': { diff --git a/lib/transforms/inject-babel-helpers.js b/lib/transforms/inject-babel-helpers.js index c01efbf413d..2cb4c90564e 100644 --- a/lib/transforms/inject-babel-helpers.js +++ b/lib/transforms/inject-babel-helpers.js @@ -3,13 +3,12 @@ const { addNamed } = require('@babel/helper-module-imports'); function injectBabelHelpers(isEmberSource = false) { - let helperplugin = injectBabelHelpersPlugin; helperplugin._parallelBabel = { requireFile: __filename, buildUsing: 'injectBabelHelpersPlugin', - params : { isEmberSource }, - }; + params: { isEmberSource }, + }; helperplugin.baseDir = function() { return 'babel-core'; @@ -38,5 +37,5 @@ function injectBabelHelpersPlugin(isEmberSource) { module.exports = { injectBabelHelpers, - injectBabelHelpersPlugin + injectBabelHelpersPlugin, };