From 082b22b21d42f9b2591be5d6693f9e7fdf94aa0d Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 7 Dec 2016 14:56:43 -0500 Subject: [PATCH 1/3] Provide helpful warnings / errors and fallback without this.options. When `this.options`, `this.options.babel`, or `this.options['ember-cli-babel']` have been clobbered, we do not handle the result gracefully. This adds some additonal warnings for various scenarios and adds fallback behavior to recover and avoid failures. --- lib/models/addon.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/models/addon.js b/lib/models/addon.js index c2c5b3776c..f02ebe6ba3 100644 --- a/lib/models/addon.js +++ b/lib/models/addon.js @@ -147,12 +147,12 @@ var Addon = CoreObject.extend({ throw new SilentError('An addon must define a `name` property.'); } - this.options = defaultsDeep(this.options, { + this.__originalOptions = this.options = defaultsDeep(this.options, { babel: DEFAULT_BABEL_CONFIG }); var emberCLIBabelConfigKey = this._emberCLIBabelConfigKey(); - this.options[emberCLIBabelConfigKey] = defaultsDeep(this.options[emberCLIBabelConfigKey], { + this.__originalOptions[emberCLIBabelConfigKey] = this.options[emberCLIBabelConfigKey] = defaultsDeep(this.options[emberCLIBabelConfigKey], { compileModules: true }); }, @@ -845,13 +845,38 @@ var Addon = CoreObject.extend({ compileAddon: function(tree) { this._requireBuildPackages(); + if (!this.options) { + this._warn( + 'Ember CLI addons manage their own module transpilation during the `treeForAddon` processing. ' + + '`' + this.name + '` (found at `' + this.root + '`) has removed `this.options` ' + + 'which conflicts with the addons ability to transpile its `addon/` files properly. ' + + 'Falling back to default babel configuration options.' + ); + + this.options = {}; + } + + if (!this.options.babel) { + this._warn( + 'Ember CLI addons manage their own module transpilation during the `treeForAddon` processing. ' + + '`' + this.name + '` (found at `' + this.root + '`) has overridden the `this.options.babel` ' + + 'options which conflicts with the addons ability to transpile its `addon/` files properly. ' + + 'Falling back to default babel configuration options.' + ); + + this.options.babel = this.__originalOptions.babel; + } + var emberCLIBabelConfigKey = this._emberCLIBabelConfigKey(); - if (!this.options[emberCLIBabelConfigKey].compileModules) { - throw new SilentError( + if (!this.options[emberCLIBabelConfigKey] || !this.options[emberCLIBabelConfigKey].compileModules) { + this._warn( 'Ember CLI addons manage their own module transpilation during the `treeForAddon` processing. ' + '`' + this.name + '` (found at `' + this.root + '`) has overridden the `this.options.' + emberCLIBabelConfigKey + '.compileModules` ' + 'value which conflicts with the addons ability to transpile its `addon/` files properly.' ); + + this.options[emberCLIBabelConfigKey] = this.options[emberCLIBabelConfigKey] || {}; + this.options[emberCLIBabelConfigKey].compileModules = true; } var addonJs = this.processedAddonJsFiles(tree); From 0f48a8a4503388f5cf089851530f447b986ca378 Mon Sep 17 00:00:00 2001 From: Brian Cardarella Date: Tue, 29 Nov 2016 07:08:43 -0800 Subject: [PATCH 2/3] Allow JS templates to be used in addons This patch will allow JS files to be used as templates in an addon. Without the `overwrite: true` there is a merge error as the merging at that point has a pre-compiled `.hbs` file in one tree and a post-compiled `.js` file in the other tree. If, however, you are relying on importing a template from another source and are using a `.js` file as the origin no template compilation takes place and the two trees have a similarly named file and a merge conflict results. It may be best to actually remove the original `.hbs` file from the original tree but that may add cost to the build step as those files are already being filtered out later. (cherry picked from commit ed99686e98acc7bd0afdbe67cd9c3bbb6de5da1b) --- lib/models/addon.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/models/addon.js b/lib/models/addon.js index f02ebe6ba3..44bad918d4 100644 --- a/lib/models/addon.js +++ b/lib/models/addon.js @@ -885,6 +885,7 @@ var Addon = CoreObject.extend({ var trees = [addonJs, templatesTree].filter(Boolean); var combinedJSAndTemplates = mergeTrees(trees, { + overwrite: true, annotation: 'Addon#compileAddon(' + this.name + ') ' }); From b28163149b1ca6ae6a5c83df60d95f73cb51da2b Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 7 Dec 2016 15:23:20 -0500 Subject: [PATCH 3/3] Do full transpilation when no JS preprocessors exist. Sadly, we cannot do "modules only" preprocessing due to changes in earlier versions of ember-cli where the second pass (that was intended for only modules transpilation) was actually implemented as a full babel transpile step. This brings back the prior behavior. --- lib/models/addon.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/models/addon.js b/lib/models/addon.js index 44bad918d4..57797ea266 100644 --- a/lib/models/addon.js +++ b/lib/models/addon.js @@ -975,7 +975,9 @@ var Addon = CoreObject.extend({ '(most likely `ember-cli-babel`) to in `dependencies` (NOT `devDependencies`) in ' + '`' + this.name + '`\'s `package.json`.'); - processedJsFiles = processModulesOnly(processedJsFiles); + var options = defaultsDeep({}, DEFAULT_BABEL_CONFIG); + + processedJsFiles = new Babel(processedJsFiles, options); } return processedJsFiles;