From 036f5d3d5cd458f02bc5aabdea17ee95eaaf93f9 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Tue, 19 Jan 2021 14:25:39 -0500 Subject: [PATCH] Avoid repeatedly checking the `ember-cli` version 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. --- index.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 6fd8b47e..1f346b1f 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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); } }, @@ -54,7 +59,7 @@ module.exports = { /** * Default babel options - * @param {*} config + * @param {*} config */ _getDefaultBabelOptions(config = {}) { let emberCLIBabelConfig = config["ember-cli-babel"]; @@ -67,7 +72,7 @@ module.exports = { providedAnnotation = emberCLIBabelConfig.annotation; throwUnlessParallelizable = emberCLIBabelConfig.throwUnlessParallelizable; } - + if (config.babel && "sourceMaps" in config.babel) { sourceMaps = config.babel.sourceMaps; } @@ -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." );