-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Move custom options to "ember-cli-babel" options hash #105
Changes from all commits
32b8115
bbf6375
90e3a48
a086fa8
d23a360
d332718
f3110af
df21fbb
4c130df
21d46fe
90a8228
b231816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ var resolve = require('resolve'); | |
|
||
module.exports = { | ||
name: 'ember-cli-babel', | ||
configKey: 'ember-cli-babel', | ||
|
||
init: function() { | ||
this._super.init && this._super.init.apply(this, arguments); | ||
|
@@ -16,6 +17,7 @@ module.exports = { | |
var dep = checker.for('ember-cli', 'npm'); | ||
|
||
this._shouldSetupRegistryInIncluded = !dep.satisfies('>=0.2.0'); | ||
this._shouldShowBabelDeprecations = !dep.lt('2.11.0-beta.2'); | ||
}, | ||
|
||
setupPreprocessorRegistry: function(type, registry) { | ||
|
@@ -25,14 +27,33 @@ module.exports = { | |
name: 'ember-cli-babel', | ||
ext: 'js', | ||
toTree: function(tree) { | ||
return require('broccoli-babel-transpiler')(tree, getBabelOptions(addon)); | ||
return require('broccoli-babel-transpiler')(tree, addon._getBabelOptions()); | ||
} | ||
}); | ||
}, | ||
|
||
shouldIncludePolyfill: function() { | ||
var options = getAddonOptions(this); | ||
return options.includePolyfill === true; | ||
var addonOptions = this._getAddonOptions(); | ||
var babelOptions = addonOptions.babel; | ||
var customOptions = addonOptions['ember-cli-babel']; | ||
|
||
if (this._shouldShowBabelDeprecations && !this._polyfillDeprecationPrinted && | ||
babelOptions && 'includePolyfill' in babelOptions) { | ||
|
||
this._polyfillDeprecationPrinted = true; | ||
|
||
// we can use writeDeprecateLine() here because the warning will only be shown on newer Ember CLIs | ||
this.ui.writeDeprecateLine( | ||
'Putting the "includePolyfill" option in "babel" is deprecated, please put it in "ember-cli-babel" instead.'); | ||
} | ||
|
||
if (customOptions && 'includePolyfill' in customOptions) { | ||
return customOptions.includePolyfill === true; | ||
} else if (babelOptions && 'includePolyfill' in babelOptions) { | ||
return babelOptions.includePolyfill === true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
|
||
importPolyfill: function(app) { | ||
|
@@ -69,74 +90,100 @@ module.exports = { | |
if (this.shouldIncludePolyfill()) { | ||
this.importPolyfill(app); | ||
} | ||
} | ||
}; | ||
}, | ||
|
||
function getAddonOptions(addonContext) { | ||
var baseOptions = (addonContext.parent && addonContext.parent.options) || (addonContext.app && addonContext.app.options); | ||
return baseOptions && baseOptions.babel || {}; | ||
} | ||
|
||
function getBabelOptions(addonContext) { | ||
var options = clone(getAddonOptions(addonContext)); | ||
var ui = addonContext.ui; | ||
|
||
// pass a console object that wraps the addon's `UI` object | ||
options.console = { | ||
log: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeInfoLine) { | ||
ui.writeInfoLine(message); | ||
} else { | ||
ui.writeLine(message, 'INFO'); | ||
} | ||
}, | ||
|
||
warn: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeWarnLine) { | ||
ui.writeWarnLine(message); | ||
} else { | ||
ui.writeLine(message, 'WARN'); | ||
} | ||
}, | ||
|
||
error: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeError) { | ||
ui.writeError(message); | ||
} else { | ||
ui.writeLine(message, 'ERROR'); | ||
} | ||
_getAddonOptions: function() { | ||
return (this.parent && this.parent.options) || (this.app && this.app.options) || {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That second check shouldn't be required unless we're going way back in support. (Before 0.2.0.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nathanhammond that is pretty much the original code and not modified by me (see https://github.com/babel/ember-cli-babel/blob/b9a0dc232f4038bf6c95de51f71b04faff08406d/index.js#L76) |
||
}, | ||
|
||
_shouldCompileModules: function(addonOptions) { | ||
var babelOptions = addonOptions.babel; | ||
var customOptions = addonOptions['ember-cli-babel']; | ||
|
||
if (this._shouldShowBabelDeprecations && !this._modulesDeprecationPrinted && | ||
babelOptions && 'compileModules' in babelOptions) { | ||
|
||
this._modulesDeprecationPrinted = true; | ||
|
||
// we can use writeDeprecateLine() here because the warning will only be shown on newer Ember CLIs | ||
this.ui.writeDeprecateLine( | ||
'Putting the "compileModules" option in "babel" is deprecated, please put it in "ember-cli-babel" instead.'); | ||
} | ||
}; | ||
|
||
// Ensure modules aren't compiled unless explicitly set to compile | ||
options.blacklist = options.blacklist || ['es6.modules']; | ||
if (customOptions && 'compileModules' in customOptions) { | ||
return customOptions.compileModules === true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same story: can we check to see if it is in both places here as well and |
||
} else if (babelOptions && 'compileModules' in babelOptions) { | ||
return babelOptions.compileModules === true; | ||
} else { | ||
return false; | ||
} | ||
}, | ||
|
||
// do not enable non-standard transforms | ||
if (!('nonStandard' in options)) { | ||
options.nonStandard = false; | ||
} | ||
_getBabelOptions: function() { | ||
var addonOptions = this._getAddonOptions(); | ||
var options = clone(addonOptions.babel || {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
var compileModules = this._shouldCompileModules(addonOptions); | ||
|
||
var ui = this.ui; | ||
|
||
// pass a console object that wraps the addon's `UI` object | ||
options.console = { | ||
log: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeInfoLine) { | ||
ui.writeInfoLine(message); | ||
} else { | ||
ui.writeLine(message, 'INFO'); | ||
} | ||
}, | ||
|
||
warn: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeWarnLine) { | ||
ui.writeWarnLine(message); | ||
} else { | ||
ui.writeLine(message, 'WARN'); | ||
} | ||
}, | ||
|
||
error: function(message) { | ||
// fallback needed for support of ember-cli < 2.2.0 | ||
if (ui.writeError) { | ||
ui.writeError(message); | ||
} else { | ||
ui.writeLine(message, 'ERROR'); | ||
} | ||
} | ||
}; | ||
|
||
// Don't include the `includePolyfill` flag, since Babel doesn't care | ||
delete options.includePolyfill; | ||
// Ensure modules aren't compiled unless explicitly set to compile | ||
options.blacklist = options.blacklist || ['es6.modules']; | ||
|
||
if (options.compileModules === true) { | ||
if (options.blacklist.indexOf('es6.modules') >= 0) { | ||
options.blacklist.splice(options.blacklist.indexOf('es6.modules'), 1); | ||
// do not enable non-standard transforms | ||
if (!('nonStandard' in options)) { | ||
options.nonStandard = false; | ||
} | ||
|
||
// Remove custom options from `options` hash that is passed to Babel | ||
delete options.includePolyfill; | ||
delete options.compileModules; | ||
} else { | ||
if (options.blacklist.indexOf('es6.modules') < 0) { | ||
options.blacklist.push('es6.modules'); | ||
|
||
var blacklistModulesIndex = options.blacklist.indexOf('es6.modules'); | ||
if (compileModules) { | ||
if (blacklistModulesIndex >= 0) { | ||
options.blacklist.splice(blacklistModulesIndex, 1); | ||
} | ||
} else { | ||
if (blacklistModulesIndex < 0) { | ||
options.blacklist.push('es6.modules'); | ||
} | ||
} | ||
} | ||
|
||
// Ember-CLI inserts its own 'use strict' directive | ||
options.blacklist.push('useStrict'); | ||
options.highlightCode = false; | ||
// Ember-CLI inserts its own 'use strict' directive | ||
options.blacklist.push('useStrict'); | ||
options.highlightCode = false; | ||
|
||
return options; | ||
} | ||
return options; | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check to see if it is in both places here as well and
writeDeprecateLine
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - we can't rely on writeDeprecateLine as far back as this lib supports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue And I was proud of knowing this because of recent spelunking: #105 (comment)
It turns out that having an in-built ecosystem mental model is absurdly valuable...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue since the deprecation will only be triggered in recent CLIs we can just use
writeDeprecateLine
here@nathanhammond I'll move the deprecation check in front of everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point RE, newer CLI's only doing the deprecation. Maybe you can leave an inline comment (so future selves don't see it's use here as an excuse to use it for other ember-CLI deprecations)? I don't feel strongly either way though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done