@dotenvx/dotenvx
Advanced tools
Comparing version 1.23.0 to 1.24.0
@@ -5,4 +5,28 @@ # Changelog | ||
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.23.0...main) | ||
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.24.0...main) | ||
## 1.24.0 | ||
### Added | ||
* support progressive append/update ([#445](https://github.com/dotenvx/dotenvx/pull/445)) | ||
```ini | ||
FOO=foo | ||
FOO=${FOO}bar | ||
# foobar | ||
``` | ||
* support alternate value expansion ([#445](https://github.com/dotenvx/dotenvx/pull/445)) | ||
<img width="1608" alt="image" src="https://github.com/user-attachments/assets/fdd55a0a-9b36-4cb3-b0c6-6b019441aef4"> | ||
### Changed | ||
* `dotenvx.parse` now maps to dotenvx's internal parser. (prior it was mapping to [dotenv's](https://github.com/motdotla/dotenv)) | ||
### Removed | ||
* removed `dotenvx.configDotenv()`. use `dotenvx.config()` ([#445](https://github.com/dotenvx/dotenvx/pull/445)) | ||
## 1.23.0 | ||
@@ -9,0 +33,0 @@ |
{ | ||
"version": "1.23.0", | ||
"version": "1.24.0", | ||
"name": "@dotenvx/dotenvx", | ||
@@ -34,4 +34,3 @@ "description": "a better dotenv–from the creator of `dotenv`", | ||
"prerelease": "npm test && npm run testshell", | ||
"release": "standard-version", | ||
"patch": "patch-package" | ||
"release": "standard-version" | ||
}, | ||
@@ -51,5 +50,4 @@ "funding": "https://dotenvx.com", | ||
"devDependencies": { | ||
"@yao-pkg/pkg": "^5.14.2", | ||
"capture-console": "^1.0.2", | ||
"patch-package": "^8.0.0", | ||
"pkg": "^5.8.1", | ||
"proxyquire": "^2.1.3", | ||
@@ -56,0 +54,0 @@ "sinon": "^14.0.1", |
const execa = require('execa') | ||
/* c8 ignore start */ | ||
const pkgArgs = process.pkg ? { PKG_EXECPATH: '' } : {} | ||
/* c8 ignore stop */ | ||
const execute = { | ||
execa (command, args, options) { | ||
return execa(command, args, options) | ||
return execa(command, args, { ...options, env: { ...options.env, ...pkgArgs } }) | ||
} | ||
@@ -7,0 +10,0 @@ } |
@@ -128,13 +128,2 @@ import type { URL } from 'url'; | ||
/** | ||
* Loads `.env` file contents into process.env. | ||
* | ||
* @see https://dotenvx.com/docs | ||
* | ||
* @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }` | ||
* @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } } | ||
* | ||
*/ | ||
export function configDotenv(options?: DotenvConfigOptions): DotenvConfigOutput; | ||
/** | ||
* Decrypt ciphertext | ||
@@ -141,0 +130,0 @@ * |
// @ts-check | ||
const path = require('path') | ||
const dotenv = require('dotenv') | ||
@@ -19,5 +18,4 @@ // shared | ||
const dotenvOptionPaths = require('./helpers/dotenvOptionPaths') | ||
const Parse = require('./helpers/parse') | ||
// proxies to dotenv | ||
/** @type {import('./main').config} */ | ||
@@ -166,10 +164,19 @@ const config = function (options = {}) { | ||
/** @type {import('./main').configDotenv} */ | ||
const configDotenv = function (options) { | ||
return dotenv.configDotenv(options) | ||
} | ||
/** @type {import('./main').parse} */ | ||
const parse = function (src, options = {}) { | ||
// allow user to set processEnv to read from | ||
let processEnv = process.env | ||
if (options && options.processEnv != null) { | ||
processEnv = options.processEnv | ||
} | ||
/** @type {import('./main').parse} */ | ||
const parse = function (src) { | ||
return dotenv.parse(src) | ||
// private decryption key | ||
const privateKey = null // implement later | ||
// overload | ||
const overload = options.overload || options.override | ||
const { parsed } = new Parse(src, privateKey, processEnv, overload).run() | ||
return parsed | ||
} | ||
@@ -206,3 +213,2 @@ | ||
config, | ||
configDotenv, | ||
parse, | ||
@@ -209,0 +215,0 @@ // actions related |
@@ -9,5 +9,4 @@ const fsx = require('./../helpers/fsx') | ||
const inject = require('./../helpers/inject') | ||
const decrypt = require('./../helpers/decrypt') | ||
const parseDecryptEvalExpand = require('./../helpers/parseDecryptEvalExpand') | ||
const Parse = require('./../helpers/parse') | ||
const parseEnvironmentFromDotenvKey = require('./../helpers/parseEnvironmentFromDotenvKey') | ||
@@ -64,11 +63,12 @@ const detectEncoding = require('./../helpers/detectEncoding') | ||
try { | ||
const { parsed, processEnv, warnings } = parseDecryptEvalExpand(env, null, this.processEnv) | ||
const { parsed, warnings, injected, preExisted } = new Parse(env, null, this.processEnv, this.overload).run() | ||
row.parsed = parsed | ||
row.warnings = warnings | ||
this.readableStrings.add(env) | ||
const { injected, preExisted } = this._inject(processEnv, parsed, this.overload, this.processEnv) | ||
row.injected = injected | ||
row.preExisted = preExisted | ||
this.inject(row.parsed) // inject | ||
this.readableStrings.add(env) | ||
for (const key of Object.keys(injected)) { | ||
@@ -96,10 +96,11 @@ this.uniqueInjectedKeys.add(key) // track uniqueInjectedKeys across multiple files | ||
const privateKey = findPrivateKey(envFilepath) | ||
const { parsed, processEnv, warnings } = parseDecryptEvalExpand(src, privateKey, this.processEnv) | ||
const { parsed, warnings, injected, preExisted } = new Parse(src, privateKey, this.processEnv, this.overload).run() | ||
row.parsed = parsed | ||
row.warnings = warnings | ||
const { injected, preExisted } = this._inject(processEnv, parsed, this.overload, this.processEnv) | ||
row.injected = injected | ||
row.preExisted = preExisted | ||
this.inject(row.parsed) // inject | ||
for (const key of Object.keys(injected)) { | ||
@@ -167,10 +168,10 @@ this.uniqueInjectedKeys.add(key) // track uniqueInjectedKeys across multiple files | ||
// parse this. it's the equivalent of the .env file | ||
const { parsed, processEnv, warnings } = parseDecryptEvalExpand(decrypted, null, this.processEnv) | ||
const { parsed, warnings, injected, preExisted } = new Parse(decrypted, null, this.processEnv, this.overload).run() | ||
row.parsed = parsed | ||
row.warnings = warnings | ||
const { injected, preExisted } = this._inject(processEnv, parsed, this.overload, this.processEnv) | ||
row.injected = injected | ||
row.preExisted = preExisted | ||
this.inject(row.parsed) // inject | ||
for (const key of Object.keys(injected)) { | ||
@@ -186,4 +187,6 @@ this.uniqueInjectedKeys.add(key) // track uniqueInjectedKeys across multiple files | ||
_inject (clonedProcessEnv, parsed, overload, processEnv) { | ||
return inject(clonedProcessEnv, parsed, overload, processEnv) | ||
inject (parsed) { | ||
for (const key of Object.keys(parsed)) { | ||
this.processEnv[key] = parsed[key] // inject to process.env | ||
} | ||
} | ||
@@ -190,0 +193,0 @@ |
7
216595
82
3650