Skip to content

Commit

Permalink
allow loading from absolute path, validate env var
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Oct 23, 2024
1 parent cb721ae commit 921c039
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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(
Expand Down

0 comments on commit 921c039

Please sign in to comment.