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 21, 2022
1 parent 5fd9fff commit 1460db8
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 39 deletions.
36 changes: 26 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ module.exports = {
return options;
} else {
// legacy codepath
return Object.assign({}, this._buildBroccoliBabelTranspilerOptions(config), options);
let transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config);

return {
...transpilerOptions,
babel: {
...transpilerOptions.babel,
...options,
},
};
}
},

Expand Down Expand Up @@ -126,20 +134,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 +155,16 @@ 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 transpilerOptions = this._buildBroccoliBabelTranspilerOptions(config);
let babelOptions = this.buildBabelOptions('babel', config);
let options = {
...transpilerOptions,
babel: {
...transpilerOptions.babel,
...babelOptions,
},
};

let output;

const customAddonConfig = config['ember-cli-babel'];
Expand Down Expand Up @@ -306,6 +322,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
2 changes: 1 addition & 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 Down
Loading

0 comments on commit 1460db8

Please sign in to comment.