Skip to content

Commit

Permalink
Restructure to a better flow:
Browse files Browse the repository at this point in the history
1. Gather all files
2. Transpile to ES5
3. Debug macros + strip and prep for production
4. Gather files into bundles
5. Transform AMD and concat files

This flow ended up making the most sense to me given that we _must_ do
the AMD transform last. It keeps most major operations at a per-file
level, and saves the file-divying and concatting for last.
  • Loading branch information
pzuraq committed Nov 9, 2018
1 parent 7a296e2 commit 5aec3c4
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 457 deletions.
20 changes: 13 additions & 7 deletions bin/run-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@ function generateEachPackageTests() {
.forEach(generateTestsFor);
}

function generateBuiltTests(ie) {
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';

if (ie) {
common += '&ie=true';
}

testFunctions.push(function() {
return run(common + '&nolint=true');
});
Expand All @@ -105,6 +101,18 @@ function generateBuiltTests(ie) {
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 Expand Up @@ -184,7 +192,6 @@ switch (process.env.TEST_SUITE) {
case 'built-tests':
console.log('suite: built-tests');
generateBuiltTests();
generateBuiltTests(true);
runAndExit();
break;
case 'old-jquery-and-extend-prototypes':
Expand All @@ -196,7 +203,6 @@ switch (process.env.TEST_SUITE) {
case 'all':
console.log('suite: all');
generateBuiltTests();
generateBuiltTests(true);
generateOldJQueryTests();
generateExtendPrototypeTests();
generateEachPackageTests();
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 });
};
3 changes: 1 addition & 2 deletions broccoli/strip-for-prod.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

const Babel = require('broccoli-babel-transpiler');
const stripClassCallCheck = require('./transforms/strip-class-call-check');

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

Expand Down
82 changes: 0 additions & 82 deletions broccoli/to-es.js

This file was deleted.

48 changes: 28 additions & 20 deletions broccoli/to-es5.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
'use strict';

const toES = require('./to-es');
const Babel = require('broccoli-babel-transpiler');
const injectBabelHelpers = require('./transforms/inject-babel-helpers');

module.exports = function toES5(tree, _options) {
return toES(
tree,
[
['transform-es2015-template-literals', { loose: true }],
['transform-es2015-literals'],
['transform-es2015-arrow-functions'],
['transform-es2015-destructuring', { loose: true }],
['transform-es2015-spread', { loose: true }],
['transform-es2015-parameters'],
['transform-es2015-computed-properties', { loose: true }],
['transform-es2015-shorthand-properties'],
['transform-es2015-block-scoping', { throwIfClosureRequired: true }],
['check-es2015-constants'],
['transform-es2015-classes', { loose: true }],
['transform-object-assign'],
],
_options
);
module.exports = function toES6(tree, _options) {
let options = Object.assign({}, _options);

options.sourceMap = true;
options.plugins = [
injectBabelHelpers,
['transform-es2015-template-literals', { loose: true }],
['transform-es2015-literals'],
['transform-es2015-arrow-functions'],
['transform-es2015-destructuring', { loose: true }],
['transform-es2015-spread', { loose: true }],
['transform-es2015-parameters'],
['transform-es2015-computed-properties', { loose: true }],
['transform-es2015-shorthand-properties'],
['transform-es2015-block-scoping', { throwIfClosureRequired: true }],
['check-es2015-constants'],
['transform-es2015-classes', { loose: true }],
['transform-object-assign'],
];

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

return new Babel(tree, options);
};
7 changes: 0 additions & 7 deletions broccoli/to-es6.js

This file was deleted.

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
Loading

0 comments on commit 5aec3c4

Please sign in to comment.