Skip to content

Commit

Permalink
Update broccoli-babel-transpiler to v8.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Oct 10, 2022
1 parent 5fd9fff commit b0e0d87
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 39 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const getBabelOptions = require('./lib/get-babel-options');
const findApp = require('./lib/find-app');
const emberPlugins = require('./lib/ember-plugins');
const cacheKeyForTree = require('calculate-cache-key-for-tree');
const merge = require('lodash.merge');

const APP_BABEL_RUNTIME_VERSION = new WeakMap();
const PROJECTS_WITH_VALID_EMBER_CLI = new WeakSet();
Expand Down Expand Up @@ -91,7 +92,7 @@ module.exports = {
return options;
} else {
// legacy codepath
return Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), options);
return merge({}, this._buildBroccoliBabelTranspilerOptions(config), { babel: options });
}
},

Expand Down Expand Up @@ -126,20 +127,19 @@ module.exports = {

let options = {
annotation: providedAnnotation || `Babel: ${_parentName(this.parent)}`,
sourceMaps,
throwUnlessParallelizable,
filterExtensions: this.getSupportedExtensions(config),
plugins: []
babel: { plugins: [], sourceMaps },
};

if (shouldCompileModules) {
options.moduleIds = true;
options.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath;
options.babel.moduleIds = true;
options.babel.getModuleId = require("./lib/relative-module-paths").getRelativeModulePath;
}

options.highlightCode = _shouldHighlightCode(this.parent);
options.babelrc = false;
options.configFile = false;
options.babel.highlightCode = _shouldHighlightCode(this.parent);
options.babel.babelrc = false;
options.babel.configFile = false;

return options;
},
Expand All @@ -148,7 +148,7 @@ module.exports = {
let config = _config || this._getAddonOptions();
let description = `000${++count}`.slice(-3);
let postDebugTree = this._debugTree(inputTree, `${description}:input`);
let options = Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), this.buildBabelOptions('babel', config));
let options = merge({}, this._buildBroccoliBabelTranspilerOptions(config), { babel: this.buildBabelOptions('babel', config) });
let output;

const customAddonConfig = config['ember-cli-babel'];
Expand Down Expand Up @@ -306,6 +306,6 @@ module.exports = {

// detect if running babel would do nothing... and do nothing instead
_shouldDoNothing(options) {
return !options.sourceMaps && !options.plugins.length;
return !options.babel.sourceMaps && !options.babel.plugins.length;
}
};
49 changes: 26 additions & 23 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ describe('ember-cli-babel', function() {

let result = this.addon._buildBroccoliBabelTranspilerOptions(options);

expect(result.babelrc).to.be.false;
expect(result.babel.babelrc).to.be.false;
});

it('provides an annotation including parent name - addon', function() {
Expand Down Expand Up @@ -1632,37 +1632,41 @@ describe('ember-cli-babel', function() {
};

let result = this.addon._buildBroccoliBabelTranspilerOptions(options);
expect(result.sourceMaps).to.equal('inline');
expect(result.babel.sourceMaps).to.equal('inline');
});

it('disables reading `.babelrc`', function() {
let options = {};

let result = this.addon._buildBroccoliBabelTranspilerOptions(options);

expect(result.babelrc).to.be.false;
expect(result.babel.babelrc).to.be.false;
});
});

describe('buildBabelOptions', function() {
this.timeout(0);

it('returns broccoli-babel-transpiler options by default', function() {
this.addon.parent = { ...this.addon.parent, name: 'foo' };

let result = this.addon.buildBabelOptions();

expect(result.moduleIds).to.be.true;
expect(result.annotation).to.be;
expect(result.babelrc).to.be.false;
expect(result.configFile).to.be.false;
expect(result.annotation).to.equal('Babel: foo');
expect(result.babel.moduleIds).to.be.true;
expect(result.babel.babelrc).to.be.false;
expect(result.babel.configFile).to.be.false;
});

it('returns broccoli-babel-transpiler options when asked for', function() {
this.addon.parent = { ...this.addon.parent, name: 'foo' };

let result = this.addon.buildBabelOptions('broccoli');

expect(result.moduleIds).to.be.true;
expect(result.annotation).to.be;
expect(result.babelrc).to.be.false;
expect(result.configFile).to.be.false;
expect(result.annotation).to.equal('Babel: foo');
expect(result.babel.moduleIds).to.be.true;
expect(result.babel.babelrc).to.be.false;
expect(result.babel.configFile).to.be.false;
});

it('returns broccoli-babel-transpiler options with customizations when provided', function() {
Expand All @@ -1673,10 +1677,9 @@ describe('ember-cli-babel', function() {
});

expect(result.annotation).to.equal('hello!!!');
expect(result.moduleIds).to.be.true;
expect(result.annotation).to.be;
expect(result.babelrc).to.be.false;
expect(result.configFile).to.be.false;
expect(result.babel.moduleIds).to.be.true;
expect(result.babel.babelrc).to.be.false;
expect(result.babel.configFile).to.be.false;
});

it('returns babel options when asked for', function() {
Expand Down Expand Up @@ -1723,7 +1726,7 @@ describe('ember-cli-babel', function() {
});

let result = this.addon.buildBabelOptions();
expect(result.plugins).to.deep.include(plugin);
expect(result.babel.plugins).to.deep.include(plugin);
});

it('includes postTransformPlugins after preset-env plugins', function() {
Expand All @@ -1741,8 +1744,8 @@ describe('ember-cli-babel', function() {

let result = this.addon.buildBabelOptions();

expect(result.plugins).to.deep.include(plugin);
expect(result.plugins.slice(-1)).to.deep.equal([pluginAfter]);
expect(result.babel.plugins).to.deep.include(plugin);
expect(result.babel.plugins.slice(-1)).to.deep.equal([pluginAfter]);
expect(result.postTransformPlugins).to.be.undefined;
});

Expand All @@ -1762,7 +1765,7 @@ describe('ember-cli-babel', function() {
});

let result = this.addon.buildBabelOptions(options);
expect(result.presets).to.deep.equal([]);
expect(result.babel.presets).to.deep.equal([]);
});

it('user plugins are before preset-env plugins', function() {
Expand All @@ -1777,7 +1780,7 @@ describe('ember-cli-babel', function() {
});

let result = this.addon.buildBabelOptions();
expect(result.plugins[0]).to.equal(plugin);
expect(result.babel.plugins[0]).to.equal(plugin);
});

it('includes resolveModuleSource if compiling modules', function() {
Expand All @@ -1789,7 +1792,7 @@ describe('ember-cli-babel', function() {
compileModules: true,
}
});
let found = result.plugins.find(plugin => plugin[0] === expectedPlugin);
let found = result.babel.plugins.find(plugin => plugin[0] === expectedPlugin);

expect(typeof found[1].resolvePath).to.equal('function');
});
Expand All @@ -1803,7 +1806,7 @@ describe('ember-cli-babel', function() {
compileModules: false,
}
});
let found = result.plugins.find(plugin => plugin[0] === expectedPlugin);
let found = result.babel.plugins.find(plugin => plugin[0] === expectedPlugin);

expect(found).to.equal(undefined);
});
Expand Down Expand Up @@ -1839,7 +1842,7 @@ describe('ember-cli-babel', function() {

let options = this.addon.buildBabelOptions();

expect(options.presets).to.deep.equal([
expect(options.babel.presets).to.deep.equal([
[require.resolve('@babel/preset-env'), {
loose: true,
modules: false,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"babel-plugin-ember-data-packages-polyfill": "^0.1.2",
"babel-plugin-ember-modules-api-polyfill": "^3.5.0",
"babel-plugin-module-resolver": "^3.2.0",
"broccoli-babel-transpiler": "^7.8.0",
"broccoli-babel-transpiler": "^8.0.0-beta.1",
"broccoli-debug": "^0.6.4",
"broccoli-funnel": "^2.0.2",
"broccoli-source": "^2.1.2",
Expand All @@ -68,6 +68,7 @@
"ember-cli-babel-plugin-helpers": "^1.1.1",
"ember-cli-version-checker": "^4.1.0",
"ensure-posix-path": "^1.0.2",
"lodash.merge": "^4.6.2",
"resolve-package-path": "^3.1.0",
"semver": "^5.5.0"
},
Expand Down
Loading

0 comments on commit b0e0d87

Please sign in to comment.