From 0e2322cb8fb353775bd81d1421514af501d4cc8e Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Tue, 29 Aug 2023 23:14:47 +0200 Subject: [PATCH] Reimplement getBabelConfigFile to be simpler --- .../next/src/build/get-babel-config-file.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/next/src/build/get-babel-config-file.ts b/packages/next/src/build/get-babel-config-file.ts index 29fa7584f4295..beb33a1ad3190 100644 --- a/packages/next/src/build/get-babel-config-file.ts +++ b/packages/next/src/build/get-babel-config-file.ts @@ -16,15 +16,12 @@ const BABEL_CONFIG_FILES = [ export async function getBabelConfigFile( dir: string ): Promise { - const babelConfigFile = await BABEL_CONFIG_FILES.reduce( - async (memo: Promise, filename) => { - const configFilePath = join(dir, filename) - return ( - (await memo) || - ((await fileExists(configFilePath)) ? configFilePath : undefined) - ) - }, - Promise.resolve(undefined) - ) - return babelConfigFile + for (const filename of BABEL_CONFIG_FILES) { + const configFilePath = join(dir, filename) + const exists = await fileExists(configFilePath) + if (!exists) { + continue + } + return configFilePath + } }