Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX lts] Ensure transpiled builds work when babel helpers are not externalized #18291

Merged
merged 2 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -174,6 +185,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 @@ -70,7 +71,6 @@
"silent-error": "^1.1.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