Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@unifig/env

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unifig/env - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

3

dist/env.adapter.d.ts

@@ -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"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc