Skip to content

Commit

Permalink
Merge pull request #234 from dfreeman/update-babel-7-deps
Browse files Browse the repository at this point in the history
Update to work with latest Babel 7 beta
  • Loading branch information
rwjblue authored Aug 3, 2018
2 parents 580b201 + 0d64d41 commit 5573a6d
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 393 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
language: node_js
node_js:
- "4"
- "6"
- "7"
- "8"
- "10"

sudo: false

Expand All @@ -15,7 +14,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
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ init:
environment:
MOCHA_REPORTER: "mocha-appveyor-reporter"
matrix:
- nodejs_version: "4"
- nodejs_version: "6"
- nodejs_version: "7"
# - nodejs_version: "8"
- nodejs_version: "8"
- nodejs_version: "10"

cache:
- '%APPDATA%\npm-cache'
Expand Down
37 changes: 28 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const clone = require('clone');
const path = require('path');
const semver = require('semver');

// From https://github.com/babel/babel-preset-env/tree/v1.6.1#options (linked from our README)
const PRESET_ENV_OPTIONS = ['spec', 'loose', 'modules', 'debug', 'include', 'exclude', 'useBuiltIns'];

let count = 0;

function addBaseDir(Plugin) {
Expand All @@ -20,6 +23,10 @@ function addBaseDir(Plugin) {
return Plugin;
}

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

module.exports = {
name: 'ember-cli-babel',
configKey: 'ember-cli-babel',
Expand Down Expand Up @@ -217,6 +224,7 @@ module.exports = {

if (shouldCompileModules) {
options.moduleIds = true;
options.getModuleId = getRelativeModulePath;
}

options.highlightCode = false;
Expand All @@ -232,18 +240,22 @@ module.exports = {

const DebugMacros = require('babel-plugin-debug-macros');
const isProduction = process.env.EMBER_ENV === 'production';
const isDebug = !isProduction;

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

externalizeHelpers: {
global: 'Ember'
},

debugTools: {
isDebug,
source: '@ember/debug',
assertPredicateIndex: 1
}
Expand All @@ -269,10 +281,16 @@ module.exports = {
let options = config.options;

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

for (let key of PRESET_ENV_OPTIONS) {
if (key in options) {
presetOptions[key] = options[key];
}
}

presetOptions.modules = false;
presetOptions.targets = targets;

let presetEnvPlugins = this._presetEnv({ assertVersion() {} }, presetOptions).plugins;

Expand Down Expand Up @@ -304,9 +322,10 @@ module.exports = {
},

_getModulesPlugin() {
const { moduleResolve } = require('amd-name-resolver');
const ModulesTransform = addBaseDir(require('@babel/plugin-transform-modules-amd'));
const ModuleResolver = addBaseDir(require('babel-plugin-module-resolver'));
const resolvePath = addBaseDir(require('amd-name-resolver').moduleResolve);
const resolvePath = addBaseDir((name, child) => moduleResolve(name, getRelativeModulePath(child)));

return [
[ModuleResolver, { resolvePath }],
Expand Down
8 changes: 4 additions & 4 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env mocha, node */
'use strict';

const co = require('co');
Expand Down Expand Up @@ -204,7 +205,7 @@ describe('ember-cli-babel', function() {
expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n if (true) {\n console.log('debug mode!');\n }\n});`
"foo.js": `define("foo", [], function () {\n "use strict";\n\n if (true\n /* DEBUG */\n ) {\n console.log('debug mode!');\n }\n});`
});
}));

Expand Down Expand Up @@ -250,7 +251,7 @@ describe('ember-cli-babel', function() {
expect(
output.read()
).to.deep.equal({
"foo.js": `define("foo", [], function () {\n "use strict";\n\n if (false) {\n console.log('debug mode!');\n }\n});`
"foo.js": `define("foo", [], function () {\n "use strict";\n\n if (false\n /* DEBUG */\n ) {\n console.log('debug mode!');\n }\n});`
});
}));

Expand Down Expand Up @@ -700,12 +701,11 @@ describe('ember-cli-babel', function() {
this.addon._shouldCompileModules = () => true;

let expectedPlugin = require('babel-plugin-module-resolver').default;
let resolvePath = require('amd-name-resolver').moduleResolve;

let result = this.addon.buildBabelOptions();
let found = result.plugins.find(plugin => plugin[0] === expectedPlugin);

expect(found).to.deep.equal([expectedPlugin, { resolvePath }]);
expect(typeof found[1].resolvePath).to.equal('function');
});

it('does not include resolveModuleSource when not compiling modules', function() {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"test": "mocha node-tests && ember test"
},
"dependencies": {
"@babel/plugin-transform-modules-amd": "^7.0.0-beta.44",
"@babel/preset-env": "^7.0.0-beta.44",
"@babel/plugin-transform-modules-amd": "^7.0.0-beta.55",
"@babel/preset-env": "^7.0.0-beta.55",
"amd-name-resolver": "0.0.7",
"babel-plugin-debug-macros": "^0.2.0-beta.2",
"babel-plugin-debug-macros": "^0.2.0-beta.6",
"babel-plugin-module-resolver": "^3.1.1",
"babel-polyfill": "^7.0.0-beta.0",
"broccoli-babel-transpiler": "^7.0.0-beta.3",
Expand Down Expand Up @@ -73,7 +73,7 @@
"resolve": "^1.3.3"
},
"engines": {
"node": "^4.5 || 6.* || >= 7.*"
"node": "6.* || 8.* || >= 10.*"
},
"changelog": {
"repo": "babel/ember-cli-babel",
Expand Down
Loading

0 comments on commit 5573a6d

Please sign in to comment.