From 63c55875b58342d8aa497ba680c1ba41e2e50023 Mon Sep 17 00:00:00 2001 From: terrydash <16539525+terrydash@users.noreply.github.com> Date: Sat, 31 May 2025 00:01:52 +0900 Subject: [PATCH] add env var for setting file (#147) Co-authored-by: Xu, Guoxu | Terry | CNTD --- src/utils/path.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/path.ts b/src/utils/path.ts index b3b6efa..b8dbdde 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -16,8 +16,9 @@ const rootDir = dirname(dirname(__dirname)); * @returns The path to the file */ export const getConfigFilePath = (filename: string, description = 'Configuration'): string => { - // Try to find the correct path to the file + const envPath = process.env.MCPHUB_SETTING_PATH; const potentialPaths = [ + ...(envPath ? [envPath] : []), // Prioritize process.cwd() as the first location to check path.resolve(process.cwd(), filename), // Use path relative to the root directory @@ -25,13 +26,13 @@ export const getConfigFilePath = (filename: string, description = 'Configuration // If installed with npx, may need to look one level up path.join(dirname(rootDir), filename) ]; - + for (const filePath of potentialPaths) { if (fs.existsSync(filePath)) { return filePath; } } - + // If all paths do not exist, use default path // Using the default path is acceptable because it ensures the application can proceed // even if the configuration file is missing. This fallback is particularly useful in