From f73a65b7fe414e1bec118e214aab678a2273392b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Sun, 28 Mar 2021 00:16:59 +0100 Subject: [PATCH] Only resolve `.babelrc` files when they are not disabled --- .../babel-core/src/config/config-chain.js | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/packages/babel-core/src/config/config-chain.js b/packages/babel-core/src/config/config-chain.js index d51a2102697e..5aa472ccfa40 100644 --- a/packages/babel-core/src/config/config-chain.js +++ b/packages/babel-core/src/config/config-chain.js @@ -201,56 +201,57 @@ export function* buildRootChain( mergeChain(configFileChain, result); } - const pkgData = - typeof context.filename === "string" - ? yield* findPackageData(context.filename) - : null; - let ignoreFile, babelrcFile; let isIgnored = false; const fileChain = emptyChain(); // resolve all .babelrc files if ( (babelrc === true || babelrc === undefined) && - pkgData && - babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory) + typeof context.filename === "string" ) { - ({ ignore: ignoreFile, config: babelrcFile } = yield* findRelativeConfig( - pkgData, - context.envName, - context.caller, - )); - - if (ignoreFile) { - fileChain.files.add(ignoreFile.filepath); - } + const pkgData = yield* findPackageData(context.filename); if ( - ignoreFile && - shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname) + pkgData && + babelrcLoadEnabled(context, pkgData, babelrcRoots, babelrcRootsDirectory) ) { - isIgnored = true; - } + ({ ignore: ignoreFile, config: babelrcFile } = yield* findRelativeConfig( + pkgData, + context.envName, + context.caller, + )); + + if (ignoreFile) { + fileChain.files.add(ignoreFile.filepath); + } - if (babelrcFile && !isIgnored) { - const validatedFile = validateBabelrcFile(babelrcFile); - const babelrcLogger = new ConfigPrinter(); - const result = yield* loadFileChain( - validatedFile, - context, - undefined, - babelrcLogger, - ); - if (!result) { + if ( + ignoreFile && + shouldIgnore(context, ignoreFile.ignore, null, ignoreFile.dirname) + ) { isIgnored = true; - } else { - babelRcReport = yield* babelrcLogger.output(); - mergeChain(fileChain, result); } - } - if (babelrcFile && isIgnored) { - fileChain.files.add(babelrcFile.filepath); + if (babelrcFile && !isIgnored) { + const validatedFile = validateBabelrcFile(babelrcFile); + const babelrcLogger = new ConfigPrinter(); + const result = yield* loadFileChain( + validatedFile, + context, + undefined, + babelrcLogger, + ); + if (!result) { + isIgnored = true; + } else { + babelRcReport = yield* babelrcLogger.output(); + mergeChain(fileChain, result); + } + } + + if (babelrcFile && isIgnored) { + fileChain.files.add(babelrcFile.filepath); + } } }