Skip to content

Commit

Permalink
[BUGFIX lts] Adds the babel-helpers injection plugin back
Browse files Browse the repository at this point in the history
Helpers were no longer being externalized in our builds, which adds a
significant amount to the final payload. This adds them back into the
build.

Also fixes an issue where the template compiler was not being included
in the vendor folder for Ember.

ensure async helpers are inlined in dev

Cherry-picked from PR emberjs#18291
  • Loading branch information
Chris Garrett authored and Timothy Asquith committed Nov 27, 2019
1 parent 889085c commit 22ffa39
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
22 changes: 0 additions & 22 deletions broccoli/transforms/inject-babel-helpers.js

This file was deleted.

13 changes: 12 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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 isProduction = process.env.EMBER_ENV === 'production';

Expand Down Expand Up @@ -71,6 +72,10 @@ module.exports = {
let appOptions = this.app && this.app.options;
let babelOptions = (parentOptions || appOptions || {}).babel;

// 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 options = {
'ember-cli-babel': {
disableDebugTooling: true,
Expand All @@ -79,6 +84,7 @@ module.exports = {
babel: Object.assign({}, babelOptions, {
loose: true,
plugins: [
injectBabelHelpers(isEmberSource),
buildDebugMacroPlugin(!isProduction),
[
require.resolve('@babel/plugin-transform-block-scoping'),
Expand Down Expand Up @@ -157,6 +163,11 @@ module.exports = {
files: ['jquery.js'],
});

let templateCompiler = new Funnel(tree, {
destDir: 'ember',
include: ['ember-template-compiler.js', 'ember-template-compiler.map'],
});

let ember;
let targets = (this.project && this.project.targets && this.project.targets.browsers) || [];

Expand All @@ -178,6 +189,6 @@ module.exports = {
});
}

return new MergeTrees([ember, jquery]);
return new MergeTrees([ember, templateCompiler, jquery]);
},
};
31 changes: 31 additions & 0 deletions lib/transforms/inject-babel-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

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() {
return 'babel-core';
};

return injectBabelHelpersPlugin;
}

module.exports = injectBabelHelpers;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"test:browserstack": "node bin/run-browserstack-tests.js"
},
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/plugin-transform-block-scoping": "^7.4.4",
"@babel/plugin-transform-object-assign": "^7.2.0",
"babel-plugin-debug-macros": "^0.3.2",
Expand All @@ -69,7 +70,6 @@
"resolve": "^1.11.1"
},
"devDependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@babel/preset-env": "^7.5.5",
"@glimmer/compiler": "0.38.5-alpha.2",
"@glimmer/env": "^0.1.7",
Expand Down

0 comments on commit 22ffa39

Please sign in to comment.