Skip to content

Commit

Permalink
refactor loadConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Aug 10, 2024
1 parent 65a14df commit a965fb9
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,18 +883,17 @@ function resolveFiles(filesArg: Set<string>): [Set<string>, Set<string>] {
}

async function loadConfig(rootDir: string): Promise<Config> {
const filenames: string[] = [];
for (const prefix of ["", ".config/"]) {
for (const ext of ["js", "ts", "mjs", "mts"]) {
filenames.push(`${prefix}updates${prefix ? "" : ".config"}.${ext}`);
}
}
let config: Config = {};
try {
({default: config} = await Promise.any([
"updates.config.js",
"updates.config.ts",
"updates.config.mjs",
"updates.config.mts",
".config/updates.js",
".config/updates.ts",
".config/updates.mjs",
".config/updates.mts",
].map(str => import(join(rootDir, ...str.split("/"))))));
({default: config} = await Promise.any(filenames.map(str => {
return import(join(rootDir, ...str.split("/")));
})));
} catch {}
return config;
}
Expand Down

0 comments on commit a965fb9

Please sign in to comment.