Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid repeatedly checking the ember-cli version #377

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 WeakSet();

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