diff --git a/src/bootstrap.js b/src/bootstrap.js index f488770..d9f3227 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -5,6 +5,7 @@ const require = createRequire(import.meta.url); import { cosmiconfig } from "cosmiconfig"; import decamelize from "decamelize"; +import fs from "fs"; import path from "path"; import yargs from "yargs"; import { hideBin } from "yargs/helpers"; @@ -17,13 +18,22 @@ import logger from "./logger.js"; import { loadAllPlugins, resolveUserPlugins } from "./plugins.js"; async function getCosmiConfig(cosmiconfigOptions) { + let configFile; + if (process.env.V8R_CONFIG_FILE) { - cosmiconfigOptions.searchPlaces = [process.env.V8R_CONFIG_FILE]; + if (!fs.existsSync(process.env.V8R_CONFIG_FILE)) { + throw new Error(`File ${process.env.V8R_CONFIG_FILE} does not exist.`); + } + configFile = await cosmiconfig("v8r", cosmiconfigOptions).load( + process.env.V8R_CONFIG_FILE, + ); + } else { + cosmiconfigOptions.stopDir = process.cwd(); + configFile = (await cosmiconfig("v8r", cosmiconfigOptions).search( + process.cwd(), + )) || { config: {} }; } - cosmiconfigOptions.stopDir = process.cwd(); - const configFile = (await cosmiconfig("v8r", cosmiconfigOptions).search( - process.cwd(), - )) || { config: {} }; + if (configFile.filepath) { logger.info(`Loaded config file from ${getRelativeFilePath(configFile)}`); logger.info(