MCPcopy
hub / github.com/di-sukharev/opencommit / configDotenv

Function configDotenv

out/cli.cjs:2043–2088  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

2041 return { parsed };
2042 }
2043 function configDotenv(options) {
2044 const dotenvPath = path5.resolve(process.cwd(), ".env");
2045 let encoding = "utf8";
2046 const debug5 = Boolean(options && options.debug);
2047 if (options && options.encoding) {
2048 encoding = options.encoding;
2049 } else {
2050 if (debug5) {
2051 _debug("No encoding is specified. UTF-8 is used by default");
2052 }
2053 }
2054 let optionPaths = [dotenvPath];
2055 if (options && options.path) {
2056 if (!Array.isArray(options.path)) {
2057 optionPaths = [_resolveHome(options.path)];
2058 } else {
2059 optionPaths = [];
2060 for (const filepath of options.path) {
2061 optionPaths.push(_resolveHome(filepath));
2062 }
2063 }
2064 }
2065 let lastError;
2066 const parsedAll = {};
2067 for (const path6 of optionPaths) {
2068 try {
2069 const parsed = DotenvModule.parse(fs7.readFileSync(path6, { encoding }));
2070 DotenvModule.populate(parsedAll, parsed, options);
2071 } catch (e3) {
2072 if (debug5) {
2073 _debug(`Failed to load ${path6} ${e3.message}`);
2074 }
2075 lastError = e3;
2076 }
2077 }
2078 let processEnv = process.env;
2079 if (options && options.processEnv != null) {
2080 processEnv = options.processEnv;
2081 }
2082 DotenvModule.populate(processEnv, parsedAll, options);
2083 if (lastError) {
2084 return { parsed: parsedAll, error: lastError };
2085 } else {
2086 return { parsed: parsedAll };
2087 }
2088 }
2089 function config8(options) {
2090 if (_dotenvKey(options).length === 0) {
2091 return DotenvModule.configDotenv(options);

Callers

nothing calls this directly

Calls 4

_debugFunction · 0.85
_resolveHomeFunction · 0.85
pushMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…