From 31432de73128bee2ee8812278e25a4a8df4231a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=B8=85=E8=A5=BF?= <928200407@qq.com> Date: Wed, 9 Oct 2024 08:50:51 +0800 Subject: [PATCH] fix(api-core): find forgeConfig file --- packages/api/core/src/util/forge-config.ts | 27 ++++------------------ 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/packages/api/core/src/util/forge-config.ts b/packages/api/core/src/util/forge-config.ts index 350baac933..e0fad85420 100644 --- a/packages/api/core/src/util/forge-config.ts +++ b/packages/api/core/src/util/forge-config.ts @@ -124,31 +124,12 @@ export default async (dir: string): Promise => { forgeConfig = packageJSON.config && packageJSON.config.forge ? packageJSON.config.forge : null; } - if (!forgeConfig || typeof forgeConfig === 'string') { - const iterator = (() => { - const file = typeof forgeConfig === 'string' ? forgeConfig : false; - const extensions = ['.js', ...Object.keys(interpret.extensions)]; - let index = -1; - return { - [Symbol.iterator]: () => ({ - next() { - if (index >= extensions.length) return { done: true, value: '' }; - let value: string | false; - if (index < 0) { - index = 0; - value = file; - } - value ||= `forge.config${extensions[index++]}`; - return { value }; - }, - }), - }; - })(); - for (const file of iterator) { - const pathToConfig = path.resolve(dir, file); + if (!forgeConfig || !['object', 'string'].includes(typeof forgeConfig)) { + for (const extension of ['.js', ...Object.keys(interpret.extensions)]) { + const pathToConfig = path.resolve(dir, `forge.config${extension}`); if (await fs.pathExists(pathToConfig)) { rechoir.prepare(interpret.extensions, pathToConfig, dir); - forgeConfig = file; + forgeConfig = `forge.config${extension}`; break; } }