Skip to content

Commit

Permalink
Merge pull request #462 from bertdeblock/revert-breaking-changes-to-b…
Browse files Browse the repository at this point in the history
…uild-babel-options-method

Revert breaking changes to `buildBabelOptions` method
  • Loading branch information
ef4 authored Nov 3, 2022
2 parents 12e9167 + 188d15a commit 3ce768a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
48 changes: 29 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ module.exports = {
return options;
} else {
// legacy codepath
let transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config);

return {
...transpilerOptions,
babel: {
...transpilerOptions.babel,
...options,
},
};
return Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), options);
}
},

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

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

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

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

return options;
},
Expand All @@ -155,13 +148,30 @@ module.exports = {
let config = _config || this._getAddonOptions();
let description = `000${++count}`.slice(-3);
let postDebugTree = this._debugTree(inputTree, `${description}:input`);
let transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config);
let babelOptions = this.buildBabelOptions('babel', config);
let {
// Separate Babel options from `broccoli-babel-transpiler` options.
babelrc,
configFile,
getModuleId,
highlightCode,
moduleIds,
plugins,
sourceMaps,
...transpilerOptions
} = this._buildBroccoliBabelTranspilerOptions(config);
let options = {
...transpilerOptions,
// `broccoli-babel-transpiler` now expects all Babel options to be
// present under a `babel` key.
babel: {
...transpilerOptions.babel,
...babelOptions,
babelrc,
configFile,
getModuleId,
highlightCode,
moduleIds,
plugins,
sourceMaps,
...this.buildBabelOptions('babel', config),
},
};

Expand Down
40 changes: 20 additions & 20 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.babel.babelrc).to.be.false;
expect(result.babelrc).to.be.false;
});

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

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

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

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

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

Expand All @@ -1653,9 +1653,9 @@ describe('ember-cli-babel', function() {
let result = this.addon.buildBabelOptions();

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;
expect(result.moduleIds).to.be.true;
expect(result.babelrc).to.be.false;
expect(result.configFile).to.be.false;
});

it('returns broccoli-babel-transpiler options when asked for', function() {
Expand All @@ -1664,9 +1664,9 @@ describe('ember-cli-babel', function() {
let result = this.addon.buildBabelOptions('broccoli');

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;
expect(result.moduleIds).to.be.true;
expect(result.babelrc).to.be.false;
expect(result.configFile).to.be.false;
});

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

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

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

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

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

let result = this.addon.buildBabelOptions();

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

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

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

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

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

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

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

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

let options = this.addon.buildBabelOptions();

expect(options.babel.presets).to.deep.equal([
expect(options.presets).to.deep.equal([
[require.resolve('@babel/preset-env'), {
loose: true,
modules: false,
Expand Down

0 comments on commit 3ce768a

Please sign in to comment.