Skip to content

Commit

Permalink
[WIP] Use Babel if installed
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Aug 26, 2015
1 parent ab431e9 commit 3c91205
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 31 deletions.
95 changes: 64 additions & 31 deletions lib/broccoli/ember-app.js
Expand Up @@ -38,6 +38,7 @@ var merge = require('lodash/object/merge');
var omit = require('lodash/object/omit');
var ES3SafeFilter = require('broccoli-es3-safe-recast');
var Funnel = require('broccoli-funnel');
var stew = require('broccoli-stew');

module.exports = EmberApp;

Expand Down Expand Up @@ -139,6 +140,22 @@ EmberApp.prototype._initProject = function(options) {
@param {Boolean} isProduction
*/
EmberApp.prototype._initOptions = function(options, isProduction) {
var babelOptions = {};

if (this._addonInstalled('ember-cli-babel')) {
var amdNameResolver = require('amd-name-resolver');
babelOptions = {
babel: {
compileModules: true,
modules: 'amdStrict',
moduleIds: true,
exportModuleMetadata: true,
sourceMaps: !isProduction,
resolveModuleSource: amdNameResolver
}
};
}

this.options = merge(options, {
es3Safe: true,
storeConfigInMeta: true,
Expand All @@ -158,7 +175,7 @@ EmberApp.prototype._initOptions = function(options, isProduction) {
'ember-cli-qunit': {
disableContainerStyles: false
}
}, defaults);
}, babelOptions, defaults);

// needs a deeper merge than is provided above
this.options.outputPaths = merge(this.options.outputPaths, {
Expand Down Expand Up @@ -723,6 +740,7 @@ EmberApp.prototype._addonTree = function _addonTree() {
allowEmpty: true,
description: 'Funnel: Addon JS'
});
var transpiledAddonTree = addonES6;

// it is not currently possible to make Esperanto processing
// pre-existing AMD a no-op, so we have to remove the reexports
Expand All @@ -733,14 +751,16 @@ EmberApp.prototype._addonTree = function _addonTree() {
description: 'Funnel: Addon Re-exports'
});

var transpiledAddonTree = new ES6Modules(addonES6, {
description: 'ES6: Addon Trees',
esperantoOptions: {
absolutePaths: true,
strict: true,
_evilES3SafeReExports: this.options.es3Safe
}
});
if (!this._addonInstalled('ember-cli-babel')) {
transpiledAddonTree = new ES6Modules(addonES6, {
description: 'ES6: Addon Trees',
esperantoOptions: {
absolutePaths: true,
strict: true,
_evilES3SafeReExports: this.options.es3Safe
}
});
}

var reexportsAndTranspiledAddonTree = mergeTrees([
transpiledAddonTree,
Expand Down Expand Up @@ -889,7 +909,7 @@ EmberApp.prototype.appAndDependencies = function() {
var templates = this._processedTemplatesTree();
var config = this._configTree();

if (!this.registry.availablePlugins['ember-cli-babel'] && this.options.es3Safe) {
if (!this._addonInstalled('ember-cli-babel') && this.options.es3Safe) {
app = new ES3SafeFilter(app);
}

Expand Down Expand Up @@ -952,6 +972,15 @@ EmberApp.prototype._addAppTests = function(sourceTrees) {
}
};

/**
* @private
* @param {String} addonName The name of the addon we are checking to see if it's installed
* @return {Boolean}
*/
EmberApp.prototype._addonInstalled = function(addonName) {
return !!this.registry.availablePlugins[addonName];
};

/**
Returns the tree for javascript files
Expand All @@ -963,29 +992,33 @@ EmberApp.prototype.javascript = function() {
var applicationJs = this.appAndDependencies();
var legacyFilesToAppend = this.legacyFilesToAppend;
var appOutputPath = this.options.outputPaths.app.js;

var appJs = new ES6Modules(
new Funnel(applicationJs, {
include: [escapeRegExp(this.name + '/') + '**/*.js'],
description: 'Funnel: App JS Files'
}),

{
description: 'ES6: App Tree',
esperantoOptions: {
absolutePaths: true,
strict: true,
_evilES3SafeReExports: this.options.es3Safe
var appJs = applicationJs;

// Note: If ember-cli-babel is installed we have already performed the transpilation at this point
if (!this._addonInstalled('ember-cli-babel')) {
appJs = new ES6Modules(
new Funnel(applicationJs, {
include: [escapeRegExp(this.name + '/') + '**/*.js'],
description: 'Funnel: App JS Files'
}),

{
description: 'ES6: App Tree',
esperantoOptions: {
absolutePaths: true,
strict: true,
_evilES3SafeReExports: this.options.es3Safe
}
}
}
);
);

appJs = mergeTrees([
appJs,
this._processedEmberCLITree()
], {
annotation: 'TreeMerger (appJS & processedEmberCLITree)'
});
appJs = mergeTrees([
appJs,
this._processedEmberCLITree()
], {
annotation: 'TreeMerger (appJS & processedEmberCLITree)'
});
}

appJs = this.concatFiles(appJs, {
inputFiles: [this.name + '/**/*.js'],
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -70,6 +70,7 @@
],
"dependencies": {
"abbrev": "^1.0.5",
"amd-name-resolver": "0.0.2",
"bower": "^1.3.12",
"bower-config": "0.6.1",
"bower-endpoint-parser": "0.2.2",
Expand Down

0 comments on commit 3c91205

Please sign in to comment.