@dotenvx/dotenvx 2.37.0 → 2.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/README.md +14 -0
- package/package.json +1 -1
- package/src/lib/helpers/selectKeyStorage.js +1 -2
- package/src/lib/main.d.ts +29 -0
- package/src/lib/main.js +34 -16
- package/src/lib/resolvers/get.js +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v2.38.0...main)
|
|
6
|
+
|
|
7
|
+
## [2.38.0](https://github.com/dotenvx/dotenvx/compare/v2.37.0...v2.38.0) (2026-10-16)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add `getSync` convenience ([#1029](https://github.com/dotenvx/dotenvx/pull/1029))
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
* Default to file key storage in non-interactive mode ([#1028](https://github.com/dotenvx/dotenvx/pull/1028))
|
|
6
16
|
|
|
7
17
|
## [2.37.0](https://github.com/dotenvx/dotenvx/compare/v2.36.0...v2.37.0) (2026-10-15)
|
|
8
18
|
|
|
@@ -16,7 +26,6 @@ All notable changes to this project will be documented in this file. See [standa
|
|
|
16
26
|
❯ ◊ Enclaved
|
|
17
27
|
```
|
|
18
28
|
|
|
19
|
-
|
|
20
29
|
## [2.36.0](https://github.com/dotenvx/dotenvx/compare/v2.35.0...v2.36.0) (2026-10-14)
|
|
21
30
|
|
|
22
31
|
### Added
|
package/README.md
CHANGED
|
@@ -3232,6 +3232,20 @@ console.log(decryptedValue)
|
|
|
3232
3232
|
|
|
3233
3233
|
This is known as *Decryption at Access* and is written about in [the whitepaper](https://dotenvx.com/dotenvx.pdf).
|
|
3234
3234
|
|
|
3235
|
+
</details>
|
|
3236
|
+
<details><summary>`getSync(KEY)` - synchronous access</summary><br>
|
|
3237
|
+
|
|
3238
|
+
Synchronously resolve an environment variable without populating `process.env`. This is useful in configuration files that cannot await `get()`.
|
|
3239
|
+
|
|
3240
|
+
```js
|
|
3241
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
3242
|
+
const decryptedValue = dotenvx.getSync('HELLO', { path: '.env.credentials', strict: true })
|
|
3243
|
+
```
|
|
3244
|
+
|
|
3245
|
+
`getSync()` accepts the same options as `get()`, including masking, multiple paths, and error handling. Omit the key to return all values from the selected files. It blocks while files and providers are resolved.
|
|
3246
|
+
|
|
3247
|
+
If you already called `dotenvx.config()`, you can read the loaded value directly from `process.env.HELLO` instead.
|
|
3248
|
+
|
|
3235
3249
|
</details>
|
|
3236
3250
|
<details><summary>`get(KEY, {mask:})`</summary><br>
|
|
3237
3251
|
|
package/package.json
CHANGED
|
@@ -10,8 +10,7 @@ const selectConnectionResource = require('./selectConnectionResource')
|
|
|
10
10
|
const nativeNames = { darwin: 'macOS Keychain', win32: 'Windows Credential Manager', linux: 'Linux Secret Service' }
|
|
11
11
|
|
|
12
12
|
async function selectKeyStorage (options = {}) {
|
|
13
|
-
|
|
14
|
-
if (process.env.CI || options.noCreate || !process.stdin.isTTY || !process.stderr.isTTY) return defaultStorage
|
|
13
|
+
if (process.env.CI || options.noCreate || !process.stdin.isTTY || !process.stderr.isTTY) return 'file'
|
|
15
14
|
|
|
16
15
|
const groups = new Map()
|
|
17
16
|
const setup = new Map()
|
package/src/lib/main.d.ts
CHANGED
|
@@ -367,6 +367,12 @@ export function set(
|
|
|
367
367
|
|
|
368
368
|
export interface GetOptions {
|
|
369
369
|
|
|
370
|
+
/** Include all process environment variables when no key is supplied. */
|
|
371
|
+
all?: boolean;
|
|
372
|
+
|
|
373
|
+
/** Format the returned values when no key is supplied. */
|
|
374
|
+
format?: 'eval' | 'eval-export' | 'shell' | 'colon';
|
|
375
|
+
|
|
370
376
|
/**
|
|
371
377
|
* Specify a custom path if your file containing environment variables is located elsewhere.
|
|
372
378
|
* Can also be an array of strings, specifying multiple paths.
|
|
@@ -464,6 +470,29 @@ export function get(
|
|
|
464
470
|
options?: GetOptions
|
|
465
471
|
): Promise<string>;
|
|
466
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Synchronously resolve an environment variable without modifying process.env.
|
|
475
|
+
* Blocks while files and providers are resolved. Uses the same options as get().
|
|
476
|
+
*
|
|
477
|
+
* @example require('@dotenvx/dotenvx').getSync('KEY', { path: '.env.credentials' })
|
|
478
|
+
*/
|
|
479
|
+
export function getSync(
|
|
480
|
+
key: string,
|
|
481
|
+
options?: GetOptions
|
|
482
|
+
): string | undefined;
|
|
483
|
+
export function getSync(
|
|
484
|
+
key: undefined,
|
|
485
|
+
options: GetOptions & { format: NonNullable<GetOptions['format']> }
|
|
486
|
+
): string;
|
|
487
|
+
export function getSync(
|
|
488
|
+
key?: undefined,
|
|
489
|
+
options?: GetOptions & { format?: undefined }
|
|
490
|
+
): Record<string, string>;
|
|
491
|
+
export function getSync(
|
|
492
|
+
key: string | undefined,
|
|
493
|
+
options?: GetOptions
|
|
494
|
+
): string | Record<string, string> | undefined;
|
|
495
|
+
|
|
467
496
|
/**
|
|
468
497
|
* List all env files in the current working directory
|
|
469
498
|
*
|
package/src/lib/main.js
CHANGED
|
@@ -331,8 +331,21 @@ const set = async function (key, value, options = {}, events) {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
|
|
334
|
+
/** @type {import('./main').get} */
|
|
335
335
|
const get = async function (key, options = {}, events) {
|
|
336
|
+
const prepared = prepareGet(key, options)
|
|
337
|
+
const resolved = await getResolver(prepared.resolverOptions)
|
|
338
|
+
return getResult(key, prepared.options, resolved, events)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** @type {import('./main').getSync} */
|
|
342
|
+
const getSync = function (key, options = {}) {
|
|
343
|
+
const prepared = prepareGet(key, options)
|
|
344
|
+
const resolved = getResolver.sync(prepared.resolverOptions)
|
|
345
|
+
return getResult(key, prepared.options, resolved)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function prepareGet (key, options) {
|
|
336
349
|
options = normalizeDotenvConfigConvention(options)
|
|
337
350
|
options = normalizeDotenvConfigIgnore(options)
|
|
338
351
|
|
|
@@ -340,22 +353,26 @@ const get = async function (key, options = {}, events) {
|
|
|
340
353
|
const noArmor = resolveNoArmor(options)
|
|
341
354
|
const noNative = resolveNoNative(options)
|
|
342
355
|
|
|
343
|
-
|
|
344
|
-
|
|
356
|
+
return {
|
|
357
|
+
options,
|
|
358
|
+
resolverOptions: {
|
|
359
|
+
resolveDirectories: false,
|
|
360
|
+
key,
|
|
361
|
+
envs,
|
|
362
|
+
profile: options.profile,
|
|
363
|
+
overload: options.overload,
|
|
364
|
+
all: options.all,
|
|
365
|
+
envKeysFile: options.envKeysFile,
|
|
366
|
+
noArmor,
|
|
367
|
+
noNative,
|
|
368
|
+
no1Password: options.no1Password,
|
|
369
|
+
noBitwarden: options.noBitwarden
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
345
373
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
key,
|
|
349
|
-
envs,
|
|
350
|
-
profile: options.profile,
|
|
351
|
-
overload: options.overload,
|
|
352
|
-
all: options.all,
|
|
353
|
-
envKeysFile: options.envKeysFile,
|
|
354
|
-
noArmor,
|
|
355
|
-
noNative,
|
|
356
|
-
no1Password: options.no1Password,
|
|
357
|
-
noBitwarden: options.noBitwarden
|
|
358
|
-
})
|
|
374
|
+
function getResult (key, options, { parsed, errors }, events) {
|
|
375
|
+
const ignore = options.ignore || []
|
|
359
376
|
|
|
360
377
|
if (options.mask !== undefined) {
|
|
361
378
|
const showChar = options.mask === true ? 6 : options.mask
|
|
@@ -441,6 +458,7 @@ module.exports = {
|
|
|
441
458
|
// actions related
|
|
442
459
|
set,
|
|
443
460
|
get,
|
|
461
|
+
getSync,
|
|
444
462
|
ls,
|
|
445
463
|
// expose for libs depending on @dotenvx/dotenvx
|
|
446
464
|
setLogLevel,
|
package/src/lib/resolvers/get.js
CHANGED
|
@@ -61,6 +61,16 @@ async function get (options = {}) {
|
|
|
61
61
|
const processEnv = { ...(options.processEnv || process.env) }
|
|
62
62
|
const { processedEnvs } = await envsResolver(buildOptions(options, processEnv))
|
|
63
63
|
|
|
64
|
+
return resolveResult(options, processedEnvs, processEnv)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getSync (options = {}) {
|
|
68
|
+
const processEnv = { ...(options.processEnv || process.env) }
|
|
69
|
+
const { processedEnvs } = envsResolver.sync(buildOptions(options, processEnv))
|
|
70
|
+
return resolveResult(options, processedEnvs, processEnv)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function resolveResult (options, processedEnvs, processEnv) {
|
|
64
74
|
const resolved = result({
|
|
65
75
|
key: options.key,
|
|
66
76
|
all: options.all,
|
|
@@ -74,3 +84,4 @@ async function get (options = {}) {
|
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
module.exports = get
|
|
87
|
+
module.exports.sync = getSync
|