Skip to content

Commit

Permalink
fix(api-core): find forgeConfig file
Browse files Browse the repository at this point in the history
  • Loading branch information
smallsung committed Oct 9, 2024
1 parent 5775c61 commit 31432de
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions packages/api/core/src/util/forge-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,12 @@ export default async (dir: string): Promise<ResolvedForgeConfig> => {
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;
}
}
Expand Down

0 comments on commit 31432de

Please sign in to comment.