@adonisjs/env
Version:
Environment variable manager for Node.js
96 lines (92 loc) • 2.79 kB
JavaScript
var __defProp = Object.defineProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
// src/loader.ts
import { fileURLToPath } from "node:url";
import { readFile } from "node:fs/promises";
import { isAbsolute, join } from "node:path";
// src/debug.ts
import { debuglog } from "node:util";
var debug_default = debuglog("adonisjs:env");
// src/loader.ts
var EnvLoader = class {
constructor(appRoot, loadExampleFile = false) {
this.
this.
}
/**
* Optionally read a file from the disk
*/
async
try {
const contents = await readFile(filePath, "utf-8");
return { contents, fileExists: true };
} catch (error) {
if (error.code !== "ENOENT") {
throw error;
}
return { contents: "", fileExists: false };
}
}
/**
* Load contents of the main dot-env file and the current
* environment dot-env file
*/
async load() {
const ENV_PATH = process.env.ENV_PATH;
const NODE_ENV = process.env.NODE_ENV;
const envFiles = [];
if (debug_default.enabled) {
debug_default("ENV_PATH variable is %s", ENV_PATH ? "set" : "not set");
debug_default("NODE_ENV variable is %s", NODE_ENV ? "set" : "not set");
}
const baseEnvPath = ENV_PATH ? isAbsolute(ENV_PATH) ? ENV_PATH : join(this.
if (debug_default.enabled) {
debug_default('dot-env files base path "%s"', baseEnvPath);
}
if (NODE_ENV) {
const nodeEnvLocalFile = join(baseEnvPath, `.env.${NODE_ENV}.local`);
envFiles.push({
path: nodeEnvLocalFile,
...await this.
});
}
if (!NODE_ENV || !["test", "testing"].includes(NODE_ENV)) {
const envLocalFile = join(baseEnvPath, ".env.local");
envFiles.push({
path: envLocalFile,
...await this.
});
}
if (NODE_ENV) {
const nodeEnvFile = join(baseEnvPath, `.env.${NODE_ENV}`);
envFiles.push({
path: nodeEnvFile,
...await this.
});
}
const envFile = join(baseEnvPath, ".env");
envFiles.push({
path: envFile,
...await this.
});
if (this.
const envExampleFile = join(baseEnvPath, ".env.example");
envFiles.push({
path: envExampleFile,
...await this.
});
}
return envFiles;
}
};
export {
__export,
debug_default,
EnvLoader
};
//# sourceMappingURL=chunk-VIQ26ZGM.js.map