@unifig/env
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -9,4 +9,5 @@ import { ConfigSource, IConfigAdapter } from '@unifig/core'; | ||
private readonly _envFilesPaths; | ||
constructor(options: EnvConfigAdapterOptions); | ||
constructor(options?: EnvConfigAdapterOptions); | ||
load(): Promise<ConfigSource>; | ||
private parseEnvFile; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,2 +6,3 @@ exports.EnvConfigAdapter = void 0; | ||
const fs_1 = require("fs"); | ||
const fg = require("fast-glob"); | ||
const dotenv_1 = require("dotenv"); | ||
@@ -22,26 +14,25 @@ const dotenv_expand_1 = require("dotenv-expand"); | ||
class EnvConfigAdapter { | ||
constructor(options) { | ||
constructor(options = {}) { | ||
var _a; | ||
this._options = options; | ||
this._envFilesPaths = [...((_a = options.envFilesPaths) !== null && _a !== void 0 ? _a : []), (0, path_1.resolve)(process.cwd(), '.env')]; | ||
this._envFilesPaths = [...((_a = options.envFilesPaths) !== null && _a !== void 0 ? _a : []), (0, path_1.join)(process.cwd(), '.env')]; | ||
} | ||
load() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let config = {}; | ||
for (const envFilePath of this._envFilesPaths) { | ||
if (!(0, fs_1.existsSync)(envFilePath)) { | ||
continue; | ||
} | ||
config = Object.assign(config, (0, dotenv_1.parse)((0, fs_1.readFileSync)(envFilePath))); | ||
if (this._options.expandVariables) { | ||
config = (0, dotenv_expand_1.expand)({ parsed: config }).parsed || config; | ||
} | ||
} | ||
if (!this._options.ignoreEnvVars) { | ||
Object.assign(config, process.env); | ||
} | ||
return config; | ||
}); | ||
async load() { | ||
const config = {}; | ||
const paths = await fg(this._envFilesPaths, { dot: true, unique: true }); | ||
for (const envFilePath of paths) { | ||
this.parseEnvFile(config, envFilePath); | ||
} | ||
if (!this._options.ignoreEnvVars) { | ||
Object.assign(config, process.env); | ||
} | ||
return config; | ||
} | ||
parseEnvFile(config, envFilePath) { | ||
Object.assign(config, (0, dotenv_1.parse)((0, fs_1.readFileSync)(envFilePath))); | ||
if (this._options.expandVariables) { | ||
Object.assign(config, (0, dotenv_expand_1.expand)({ parsed: config, ignoreProcessEnv: true }).parsed || config); | ||
} | ||
} | ||
} | ||
exports.EnvConfigAdapter = EnvConfigAdapter; |
export interface EnvConfigAdapterOptions { | ||
/** | ||
* Path to optional environment files to be loaded in given order. Values from them will be overwritten by process envs. | ||
* Path to optional environment files to be loaded in given order. Glob patterns are accepted. Values from them will be overwritten by process envs. | ||
*/ | ||
@@ -5,0 +5,0 @@ envFilesPaths?: string[]; |
{ | ||
"name": "@unifig/env", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Environmental variables adapter for unifig", | ||
@@ -22,4 +22,4 @@ "keywords": [ | ||
"build": "tsc --build tsconfig.build.json", | ||
"test": "jest --config ../../jest-units.config.json packages/core", | ||
"test:e2e": "jest --config ../../jest-e2e.config.json packages/core" | ||
"test": "jest --config ../../jest-units.config.json packages/env-adapter", | ||
"test:e2e": "jest --config ../../jest-e2e.config.json packages/env-adapter" | ||
}, | ||
@@ -32,3 +32,4 @@ "bugs": { | ||
"dotenv": "^16.0.3", | ||
"dotenv-expand": "^9.0.0" | ||
"dotenv-expand": "^9.0.0", | ||
"fast-glob": "^3.2.12" | ||
}, | ||
@@ -41,3 +42,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "0ae11fdae770f03cec2007daf3861476aa2ed229" | ||
"gitHead": "8578b78265ddc8eca2382bb4fe184a3e3d4fe8dd" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7249
4
82
+ Addedfast-glob@^3.2.12
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)