Skip to content

Commit

Permalink
[BUGFIX beta][FEAT] Adds a second dist build which targets IE
Browse files Browse the repository at this point in the history
This PR adds a second dist to the build which targets IE. This allows
the primary bundles to drop ES5 compilation from babel, and allows us to
choose which bundles we want to use based on the consuming application's
targets.

In the long run, we want to actually enable consuming apps to build the
Ember source code themselves. This is a temporary in-between measure to
address a bug in native classes, in which users who do _not_ have IE as
a build target cannot `.extend` from native classes due to conflicts
in transpilation vs actual native class syntax.
  • Loading branch information
pzuraq committed Nov 19, 2018
1 parent 0bbf1ce commit 02af025
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 451 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ jobs:

- stage: additional tests

env: TEST_SUITE=browserstack
env:
- TEST_SUITE=browserstack
- EMBER_ENV=production
- env:
- TEST_SUITE=built-tests
- EMBER_ENV=production
Expand Down
13 changes: 13 additions & 0 deletions bin/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function generateBuiltTests() {
// Container isn't publicly available.
// ember-testing and @ember/debug are stripped from prod/min.
var common = 'skipPackage=container,ember-testing,@ember/debug';

testFunctions.push(function() {
return run(common + '&nolint=true');
});
Expand All @@ -100,6 +101,18 @@ function generateBuiltTests() {
testFunctions.push(function() {
return run(common + '&enableoptionalfeatures=true&dist=prod&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&nolint=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&dist=min&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&dist=prod&prod=true');
});
testFunctions.push(function() {
return run(common + '&ie=true&enableoptionalfeatures=true&dist=prod&prod=true');
});
}

function generateOldJQueryTests() {
Expand Down
11 changes: 2 additions & 9 deletions broccoli/babel-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

const Funnel = require('broccoli-funnel');

module.exports = function(env) {
let file;
if (env === 'debug') {
file = 'external-helpers-dev.js';
} else if (env === 'prod') {
file = 'external-helpers-prod.js';
}

module.exports = function() {
return new Funnel('packages/external-helpers/lib', {
files: [file],
files: ['external-helpers.js'],
getDestinationPath() {
return 'ember-babel.js';
},
Expand Down
26 changes: 19 additions & 7 deletions broccoli/bootstrap-modules.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

const WriteFile = require('broccoli-file-creator');

function defaultExport(moduleExport) {
return `(function (m) { if (typeof module === "object" && module.exports) { module.exports = m } }(requireModule('${moduleExport}').default));\n`;
}
const { stripIndent } = require('common-tags');

function sideeffects(moduleExport) {
return `requireModule('${moduleExport}')`;
Expand All @@ -14,11 +11,26 @@ function umd(moduleExport) {
return `(function (m) { if (typeof module === "object" && module.exports) { module.exports = m } }(requireModule('${moduleExport}')));\n`;
}

module.exports = function bootstrapModule(moduleExport, type = 'sideeffects') {
function testing() {
return stripIndent`
var testing = requireModule('ember-testing');
Ember.Test = testing.Test;
Ember.Test.Adapter = testing.Adapter;
Ember.Test.QUnitAdapter = testing.QUnitAdapter;
Ember.setupForTesting = testing.setupForTesting;
`;
}

function empty() {
return '';
}

module.exports = function bootstrapModule(type, moduleExport) {
let moduleType = {
default: defaultExport,
umd,
empty,
sideeffects,
testing,
umd,
};

return new WriteFile('bootstrap', moduleType[type](moduleExport));
Expand Down
43 changes: 43 additions & 0 deletions broccoli/debug-macros.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const Babel = require('broccoli-babel-transpiler');
const FEATURES = require('./features');

module.exports = function debugMacros(tree, environment) {
let isDebug = environment !== 'production';

let plugins = [
[
'debug-macros',
{
debugTools: {
source: '@ember/debug',
assertPredicateIndex: 1,
isDebug,
},
externalizeHelpers: {
module: true,
},
flags: [
{ source: '@glimmer/env', flags: { DEBUG: isDebug } },
{
source: '@ember/canary-features',
flags: Object.assign(
// explicit list of additional exports within @ember/canary-features
// without adding this (with a null value) an error is thrown during
// the feature replacement process (e.g. XYZ is not a supported flag)
{
FEATURES: null,
DEFAULT_FEATURES: null,
isEnabled: null,
},
FEATURES
),
},
],
},
],
];

return new Babel(tree, { plugins });
};
4 changes: 0 additions & 4 deletions broccoli/deprecated-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ function svelte(infile, outfile) {
],
});

code = babel.transform(code, {
plugins: ['minify-dead-code-elimination'],
}).code;

fs.writeFileSync(outfile, code);
}

Expand Down
11 changes: 11 additions & 0 deletions broccoli/strip-for-prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

const Babel = require('broccoli-babel-transpiler');

module.exports = function stripForProd(tree) {
let options = {
plugins: [['filter-imports', { imports: { 'ember-babel': ['_classCallCheck'] } }]],
};

return new Babel(tree, options);
};
79 changes: 2 additions & 77 deletions broccoli/to-es5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,13 @@

const Babel = require('broccoli-babel-transpiler');
const injectBabelHelpers = require('./transforms/inject-babel-helpers');
const injectNodeGlobals = require('./transforms/inject-node-globals');
const enifed = require('./transforms/transform-define');
const FEATURES = require('./features');
const stripClassCallCheck = require('./transforms/strip-class-call-check');
const resolveModuleSource = require('amd-name-resolver').moduleResolve;

module.exports = function toES5(tree, _options) {
let options = Object.assign(
{
environment: 'developement',
},
_options
);
module.exports = function toES6(tree, _options) {
let options = Object.assign({}, _options);

let isDebug = options.environment !== 'production';

options.moduleIds = true;
options.resolveModuleSource = resolveModuleSource;
options.sourceMap = true;
options.plugins = [
injectBabelHelpers,
[
'debug-macros',
{
debugTools: {
source: '@ember/debug',
assertPredicateIndex: 1,
isDebug,
},
externalizeHelpers: {
module: true,
},
flags: [
{ source: '@glimmer/env', flags: { DEBUG: isDebug } },
{
source: '@ember/canary-features',
flags: Object.assign(
// explicit list of additional exports within @ember/canary-features
// without adding this (with a null value) an error is thrown during
// the feature replacement process (e.g. XYZ is not a supported flag)
{
FEATURES: null,
DEFAULT_FEATURES: null,
isEnabled: null,
},
FEATURES
),
},
],
},
],
['transform-es2015-template-literals', { loose: true }],
['transform-es2015-literals'],
['transform-es2015-arrow-functions'],
Expand All @@ -65,43 +21,12 @@ module.exports = function toES5(tree, _options) {
['check-es2015-constants'],
['transform-es2015-classes', { loose: true }],
['transform-object-assign'],
injectNodeGlobals,
['transform-es2015-modules-amd', { noInterop: true, strict: true }],
enifed,
];

if (options.transformDefine) {
options.plugins = [enifed];
delete options.transformDefine;
}

if (options.transformModules === false) {
options.plugins.pop();
options.plugins.pop();
delete options.moduleIds;
delete options.resolveModuleSource;
delete options.transformModules;
}

if (options.inlineHelpers) {
options.plugins.shift();
delete options.inlineHelpers;
}

delete options.environment;

return new Babel(tree, options);
};

function stripForProd(tree) {
let options = {
plugins: [
[stripClassCallCheck, { source: 'ember-babel' }],
['minify-dead-code-elimination', { optimizeRawSize: true }],
],
};

return new Babel(tree, options);
}

module.exports.stripForProd = stripForProd;
16 changes: 13 additions & 3 deletions broccoli/to-named-amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ const resolveModuleSource = require('amd-name-resolver').moduleResolve;
const enifed = require('./transforms/transform-define');
const injectNodeGlobals = require('./transforms/inject-node-globals');

module.exports = function processModulesOnly(tree, annotation) {
module.exports = function processModulesOnly(tree, strict = false) {
let transformOptions = { noInterop: true };

// These options need to be exclusive for some reason, even the key existing
// on the options hash causes issues.
if (strict) {
transformOptions.strict = true;
} else {
transformOptions.loose = true;
}

let options = {
sourceMap: true,
plugins: [
// ensures `@glimmer/compiler` requiring `crypto` works properly
// in both browser and node-land
injectNodeGlobals,
['transform-es2015-modules-amd', { loose: true, noInterop: true }],
['transform-es2015-modules-amd', transformOptions],
enifed,
],
moduleIds: true,
resolveModuleSource,
annotation,
};

return new Babel(tree, options);
Expand Down
87 changes: 0 additions & 87 deletions broccoli/transforms/strip-class-call-check.js

This file was deleted.

0 comments on commit 02af025

Please sign in to comment.