Skip to content

Commit

Permalink
Avoid repeatedly checking the ember-cli version
Browse files Browse the repository at this point in the history
Since `ember-cli` is the process controlling the addon instantiation, we
only need to ensure that we are using the correct version once (not once
per ember-cli-babel instance).

Since `ember-cli-babel` is the single most commonly used addon, this
non-trivially reduces the amount of overhead during the early part of a
build.
  • Loading branch information
rwjblue committed Jan 19, 2021
1 parent fcffcfd commit 036f5d3
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const findApp = require('./lib/find-app');
const emberPlugins = require('./lib/ember-plugins');

const APP_BABEL_RUNTIME_VERSION = new WeakMap();
const PROJECTS_WITH_VALID_EMBER_CLI = new WeakMap();

let count = 0;

Expand All @@ -31,11 +32,15 @@ module.exports = {
init() {
this._super.init && this._super.init.apply(this, arguments);

let checker = new VersionChecker(this);
let dep = checker.for('ember-cli', 'npm');
if (!PROJECTS_WITH_VALID_EMBER_CLI.has(this.project)) {
let checker = new VersionChecker(this);
let dep = checker.for('ember-cli', 'npm');

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

PROJECTS_WITH_VALID_EMBER_CLI.add(this.project);
}
},

Expand All @@ -54,7 +59,7 @@ module.exports = {

/**
* Default babel options
* @param {*} config
* @param {*} config
*/
_getDefaultBabelOptions(config = {}) {
let emberCLIBabelConfig = config["ember-cli-babel"];
Expand All @@ -67,7 +72,7 @@ module.exports = {
providedAnnotation = emberCLIBabelConfig.annotation;
throwUnlessParallelizable = emberCLIBabelConfig.throwUnlessParallelizable;
}

if (config.babel && "sourceMaps" in config.babel) {
sourceMaps = config.babel.sourceMaps;
}
Expand Down Expand Up @@ -102,19 +107,19 @@ module.exports = {

const customAddonConfig = config['ember-cli-babel'];
const shouldUseBabelConfigFile = customAddonConfig && customAddonConfig.useBabelConfig;

if (shouldUseBabelConfigFile) {
let babelConfig = babel.loadPartialConfig({
root: this.parent.root,
rootMode: 'root',
envName: process.env.EMBER_ENV || process.env.BABEL_ENV || process.env.NODE_ENV || "development",
});

if (babelConfig.config === undefined) {
// should contain the file that we used for the config,
// should contain the file that we used for the config,
// if it is undefined then we didn't find any config and
// should error

throw new Error(
"Missing babel config file in the project root. Please double check if the babel config file exists or turn off the `useBabelConfig` option in your ember-cli-build.js file."
);
Expand Down

0 comments on commit 036f5d3

Please sign in to comment.