Skip to content
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

Babel 7 #140

Merged
merged 49 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3ba6419
Update to babel-preset-env@2.
rwjblue Apr 28, 2017
168c7bf
Fix isPluginRequired for babel-preset-env@2 restructuring.
rwjblue Apr 28, 2017
2937889
Fix test for handling __esModule on plugins.
rwjblue Apr 28, 2017
e1ad188
Update broccoli-babel-transpiler to 7.
rwjblue Apr 28, 2017
da9200e
7.0.0-alpha.1
rwjblue Apr 28, 2017
664b75c
Disable loading configuration from `.babelrc`.
rwjblue Apr 28, 2017
a272d3c
7.0.0-alpha.2
rwjblue Apr 28, 2017
3fd54ca
Remove deprecations and deprecated options.
rwjblue May 3, 2017
e99a294
Update to Babel 7 beta
t-sauer Sep 18, 2017
17dc479
v7.0.0-beta.1
rwjblue Nov 5, 2017
d951a86
Merge branch 'master' into babel-7
rwjblue Apr 19, 2018
49d847a
Update to broccoli-babel-transpiler@7.0.0-beta.2.
rwjblue Apr 19, 2018
32c887d
Update yarn.lock to latest allowed versions...
rwjblue Apr 19, 2018
625d478
Update babel-plugin-debug-macros to 0.2.0-beta.1.
rwjblue Apr 19, 2018
2bfd99e
Migrate to @babel/preset-env.
rwjblue Apr 19, 2018
0af6a43
Update babel-plugin-debug-macros (fixes an error with baseDir)
rwjblue Apr 19, 2018
f8e6fa6
Fix issue around resolveModuleSource.
rwjblue Apr 19, 2018
d248d52
Update to broccoli-babel-transpiler@7.0.0-beta.3.
rwjblue Apr 19, 2018
a03eb86
Ensure all plugins are `.default` unwrapped, and have a baseDir.
rwjblue Apr 19, 2018
f32a226
Fix testing fixtures for babel@7 output.
rwjblue Apr 19, 2018
ae5100b
Update to @babel/plugin-transform-modules-amd (scoped package).
rwjblue Apr 19, 2018
1bac516
Fixup tests checking for plugins.
rwjblue Apr 19, 2018
964e09b
fixup! Update to @babel/plugin-transform-modules-amd (scoped package).
rwjblue Apr 19, 2018
bd91836
Merge remote-tracking branch 'origin/master' into babel-7
rwjblue Apr 19, 2018
580b201
7.0.0-beta.2
rwjblue Apr 19, 2018
0d64d41
Update to work with latest Babel 7 beta
dfreeman Aug 3, 2018
5573a6d
Merge pull request #234 from dfreeman/update-babel-7-deps
rwjblue Aug 3, 2018
f37a740
Handle Windows paths
dfreeman Aug 3, 2018
22629a5
Merge pull request #235 from dfreeman/update-babel-7-deps
rwjblue Aug 3, 2018
86f24ae
7.0.0-beta.3
rwjblue Aug 3, 2018
ff6773f
Merge origin/master into babel-7
rwjblue Aug 3, 2018
f9e4f17
Fix file: reference in package.json.
rwjblue Aug 3, 2018
b96e5cb
Use correct preset env...
rwjblue Aug 4, 2018
6d11f44
Merge pull request #237 from babel/rwjblue-patch-1
rwjblue Aug 4, 2018
a185133
Get tests passing with throwUnlessParallelizable: true
dfreeman Aug 5, 2018
932a1d0
Merge pull request #239 from dfreeman/green-tests
rwjblue Aug 6, 2018
7008a5f
Use release version of broccoli-babel-transpiler.
rwjblue Aug 6, 2018
1e494d6
Update babel-polyfill -> @babel/polyfill.
rwjblue Aug 6, 2018
e53e927
Update dependencies.
rwjblue Aug 6, 2018
b4ea00d
7.0.0-beta.4
rwjblue Aug 6, 2018
cf8f7ee
Fix issue with @babel/polyfill update.
rwjblue Aug 6, 2018
1167211
Remove stray .only.
rwjblue Aug 6, 2018
9671601
7.0.0-beta.5
rwjblue Aug 6, 2018
2ea0e47
Remove brittle (and unneeded) tests.
rwjblue Aug 6, 2018
b4528ff
Update test to properly match plugin style.
rwjblue Aug 6, 2018
eb03764
Merge changes from master...
rwjblue Aug 28, 2018
6955f46
Drop support for ember-cli < 2.13.
rwjblue Aug 28, 2018
1ea60c3
Merge branch 'master' into babel-7
rwjblue Aug 28, 2018
d01d724
Prevent issues with @babel/preset-env getting unknown options.
rwjblue Aug 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ matrix:
fast_finish: true
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary
- node_js: "8"

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
Expand Down
95 changes: 29 additions & 66 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-env node */
'use strict';

const VersionChecker = require('ember-cli-version-checker');
Expand All @@ -16,9 +15,11 @@ module.exports = {
this._super.init && this._super.init.apply(this, arguments);

let checker = new VersionChecker(this);
let dep = this.emberCLIChecker = checker.for('ember-cli', 'npm');
let dep = checker.for('ember-cli', 'npm');

this._shouldShowBabelDeprecations = !dep.lt('2.11.0-beta.2');
if (dep.lt('2.13.0')) {
throw new Error(`ember-cli-babel@7 (used by ${this._parentName()} at ${this.parent.root}) cannot be used by ember-cli versions older than 2.13, you used ${dep.version}`);
}
},

buildBabelOptions(_config) {
Expand Down Expand Up @@ -61,23 +62,10 @@ module.exports = {

_shouldIncludePolyfill() {
let addonOptions = this._getAddonOptions();
let babelOptions = addonOptions.babel;
let 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;
}
Expand All @@ -103,7 +91,7 @@ module.exports = {
const UnwatchedDir = require('broccoli-source').UnwatchedDir;

// Find babel-core's browser polyfill and use its directory as our vendor tree
let polyfillDir = path.dirname(require.resolve('babel-polyfill/dist/polyfill'));
let polyfillDir = path.dirname(require.resolve('@babel/polyfill/dist/polyfill'));

return new Funnel(new UnwatchedDir(polyfillDir), {
destDir: 'babel-polyfill'
Expand All @@ -125,8 +113,8 @@ module.exports = {
// if no targets are setup, assume that all plugins are required
if (!targets) { return true; }

const isPluginRequired = require('babel-preset-env').isPluginRequired;
const pluginList = require('babel-preset-env/data/plugins');
const isPluginRequired = require('@babel/preset-env').isPluginRequired;
const pluginList = require('@babel/preset-env/data/plugins');

return isPluginRequired(targets, pluginList[pluginName]);
},
Expand All @@ -150,32 +138,10 @@ module.exports = {
},

_getAddonProvidedConfig(addonOptions) {
let babelOptions = clone(addonOptions.babel || {});

// used only to support using ember-cli-babel@6 at the
// top level (app or addon during development) on ember-cli
// older than 2.13
//
// without this, we mutate the same shared `options.babel.plugins`
// that is used to transpile internally (via `_prunedBabelOptions`
// in older ember-cli versions)
let babel6Options = clone(addonOptions.babel6 || {});

let options;
// options.modules is set only for things assuming babel@5 usage
if (babelOptions.modules) {
// using babel@5 configuration with babel@6
// without overriding here we would trigger
// an error
options = Object.assign({}, babel6Options);
} else {
// shallow merge both babelOptions and babel6Options
// (plugins/postTransformPlugins are handled separately)
options = Object.assign({}, babelOptions, babel6Options);
}
let options = clone(addonOptions.babel || {});

let plugins = [].concat(babelOptions.plugins, babel6Options.plugins).filter(Boolean);
let postTransformPlugins = [].concat(babelOptions.postTransformPlugins, babel6Options.postTransformPlugins).filter(Boolean);
let plugins = options.plugins || [];
let postTransformPlugins = options.postTransformPlugins || [];

return {
options,
Expand Down Expand Up @@ -222,12 +188,12 @@ module.exports = {
).filter(Boolean);

options.presets = [
shouldRunPresetEnv && this._getPresetEnvPlugins(addonProvidedConfig),
shouldRunPresetEnv && this._getPresetEnv(addonProvidedConfig),
].filter(Boolean);

if (shouldCompileModules) {
options.moduleIds = true;
options.resolveModuleSource = require('amd-name-resolver').moduleResolve;
options.getModuleId = require('./lib/relative-module-paths').getRelativeModulePath;
}

options.highlightCode = false;
Expand All @@ -242,12 +208,13 @@ module.exports = {
if (addonOptions.disableDebugTooling) { return; }

const isProduction = process.env.EMBER_ENV === 'production';
const isDebug = !isProduction;

let options = {
flags: [
{
source: '@glimmer/env',
flags: { DEBUG: !isProduction, CI: !!process.env.CI }
flags: { DEBUG: isDebug, CI: !!process.env.CI }
}
],

Expand All @@ -256,7 +223,7 @@ module.exports = {
},

debugTools: {
isDebug: !isProduction,
isDebug,
source: '@ember/debug',
assertPredicateIndex: 1
}
Expand All @@ -277,27 +244,28 @@ module.exports = {
}
},

_getPresetEnvPlugins(config) {
_getPresetEnv(config) {
let options = config.options;

let targets = this._getTargets();
let targets = this.project && this.project.targets;
let presetOptions = Object.assign({}, options, {
modules: false,
targets
});

let presetEnvPlugins = this._presetEnv(presetOptions);
return presetEnvPlugins;
},
// delete any properties added to `options.babel` that
// are invalid for @babel/preset-env
delete presetOptions.sourceMaps;
delete presetOptions.plugins;
delete presetOptions.postTransformPlugins;

_presetEnv(presetOptions) {
return [require.resolve('babel-preset-env'), presetOptions];
return [require.resolve('@babel/preset-env'), presetOptions];
},

_getTargets() {
let targets = this.project && this.project.targets;

let parser = require('babel-preset-env/lib/targets-parser').default;
let parser = require('@babel/preset-env/lib/targets-parser').default;
if (typeof targets === 'object' && targets !== null) {
return parser(targets);
} else {
Expand All @@ -306,8 +274,12 @@ module.exports = {
},

_getModulesPlugin() {
const resolvePath = require('./lib/relative-module-paths').resolveRelativeModulePath;
resolvePath.baseDir = () => __dirname;

return [
[require.resolve('babel-plugin-transform-es2015-modules-amd'), { noInterop: true }]
[require.resolve('babel-plugin-module-resolver'), { resolvePath }],
[require.resolve('@babel/plugin-transform-modules-amd'), { noInterop: true }],
];
},

Expand All @@ -325,18 +297,9 @@ module.exports = {
// will use any provided configuration
_shouldCompileModules(options) {
let addonOptions = options['ember-cli-babel'];
let babelOptions = options.babel;

if (addonOptions && 'compileModules' in addonOptions) {
return addonOptions.compileModules;
} else if (babelOptions && 'compileModules' in babelOptions) {
if (this._shouldShowBabelDeprecations && !this._compileModulesDeprecationPrinted) {
this._compileModulesDeprecationPrinted = 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.');
}

return babelOptions.compileModules;
} else {
return semver.gt(this.project.emberCLIVersion(), '2.12.0-alpha.1');
}
Expand Down
26 changes: 26 additions & 0 deletions lib/relative-module-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env node */
'use strict';

const path = require('path');
const ensurePosix = require('ensure-posix-path');
const { moduleResolve } = require('amd-name-resolver');

function getRelativeModulePath(modulePath) {
return ensurePosix(path.relative(process.cwd(), modulePath));
}

function resolveRelativeModulePath(name, child) {
return moduleResolve(name, getRelativeModulePath(child));
}

module.exports = {
getRelativeModulePath,
resolveRelativeModulePath
};

Object.keys(module.exports).forEach((key) => {
module.exports[key]._parallelBabel = {
requireFile: __filename,
useMethod: key
};
});
Loading