@dotenvx/dotenvx 1.38.0 → 1.38.2
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 +15 -1
- package/README.md +14 -0
- package/package.json +1 -1
- package/src/lib/helpers/append.js +1 -1
- package/src/lib/helpers/dotenvParse.js +4 -2
- package/src/lib/helpers/replace.js +1 -1
- package/src/lib/main.d.ts +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,21 @@
|
|
|
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/v1.38.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.38.2...main)
|
|
6
|
+
|
|
7
|
+
## [1.38.2](https://github.com/dotenvx/dotenvx/compare/v1.38.1...v1.38.2)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add typescript types for `main.get`.
|
|
12
|
+
|
|
13
|
+
## [1.38.1](https://github.com/dotenvx/dotenvx/compare/v1.38.0...v1.38.1)
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
* Support `encrypt` when mutliline contains windows `CRLF` (`\r\n`) ([#534](https://github.com/dotenvx/dotenvx/pull/534))
|
|
18
|
+
|
|
19
|
+
Note: dotenvx will convert these `\r\n` newlines to `\n`. Our recommendation is to stop using `CRLF` - its origin is from typewriter days. Instead, set your editor or gitattributes to use `LF`.
|
|
6
20
|
|
|
7
21
|
## [1.38.0](https://github.com/dotenvx/dotenvx/compare/v1.37.0...v1.38.0)
|
|
8
22
|
|
package/README.md
CHANGED
|
@@ -2212,6 +2212,20 @@ More examples
|
|
|
2212
2212
|
dotenvx.set('HELLO', 'World', { path: '.env' })
|
|
2213
2213
|
```
|
|
2214
2214
|
|
|
2215
|
+
</details>
|
|
2216
|
+
* <details><summary>`get(KEY)` - <i>Decryption at Access</i></summary><br>
|
|
2217
|
+
|
|
2218
|
+
Programatically get an environment variable at access/runtime.
|
|
2219
|
+
|
|
2220
|
+
```js
|
|
2221
|
+
// index.js
|
|
2222
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
2223
|
+
const decryptedValue = dotenvx.get('HELLO')
|
|
2224
|
+
console.log(decryptedValue)
|
|
2225
|
+
```
|
|
2226
|
+
|
|
2227
|
+
This is known as *Decryption at Access* and is written about in [the whitepaper](https://dotenvx.com/dotenvx.pdf).
|
|
2228
|
+
|
|
2215
2229
|
</details>
|
|
2216
2230
|
|
|
2217
2231
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ function append (src, key, appendValue) {
|
|
|
7
7
|
let output
|
|
8
8
|
let newPart = ''
|
|
9
9
|
|
|
10
|
-
const parsed = dotenvParse(src, true) // skip expanding \n
|
|
10
|
+
const parsed = dotenvParse(src, true, true) // skip expanding \n and skip converting \r\n
|
|
11
11
|
const _quotes = quotes(src)
|
|
12
12
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
13
13
|
const quote = _quotes[key]
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// historical dotenv.parse - https://github.com/motdotla/dotenv)
|
|
2
2
|
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg
|
|
3
3
|
|
|
4
|
-
function dotenvParse (src, skipExpandForDoubleQuotes = false) {
|
|
4
|
+
function dotenvParse (src, skipExpandForDoubleQuotes = false, skipConvertingWindowsNewlines = false) {
|
|
5
5
|
const obj = {}
|
|
6
6
|
|
|
7
7
|
// Convert buffer to string
|
|
8
8
|
let lines = src.toString()
|
|
9
9
|
|
|
10
10
|
// Convert line breaks to same format
|
|
11
|
-
|
|
11
|
+
if (!skipConvertingWindowsNewlines) {
|
|
12
|
+
lines = lines.replace(/\r\n?/mg, '\n')
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
let match
|
|
14
16
|
while ((match = LINE.exec(lines)) != null) {
|
|
@@ -7,7 +7,7 @@ function replace (src, key, replaceValue) {
|
|
|
7
7
|
let output
|
|
8
8
|
let newPart = ''
|
|
9
9
|
|
|
10
|
-
const parsed = dotenvParse(src, true) // skip expanding \n
|
|
10
|
+
const parsed = dotenvParse(src, true, true) // skip expanding \n and skip converting \r\n
|
|
11
11
|
const _quotes = quotes(src)
|
|
12
12
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
13
13
|
const quote = _quotes[key]
|
package/src/lib/main.d.ts
CHANGED
|
@@ -232,6 +232,50 @@ export function set(
|
|
|
232
232
|
options?: SetOptions
|
|
233
233
|
): SetOutput;
|
|
234
234
|
|
|
235
|
+
export interface GetOptions {
|
|
236
|
+
/**
|
|
237
|
+
* Suppress specific errors like MISSING_ENV_FILE. The error keys can be found
|
|
238
|
+
* in src/lib/helpers/errors.js
|
|
239
|
+
* @default []
|
|
240
|
+
* @example require('@dotenvx/dotenvx').get('KEY', { ignore: ['MISSING_ENV_FILE'] })
|
|
241
|
+
*/
|
|
242
|
+
ignore?: string[];
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Override any environment variables that have already been set on your machine with values from your .env file.
|
|
246
|
+
* @default false
|
|
247
|
+
* @example require('@dotenvx/dotenvx').get('KEY', { overload: true })
|
|
248
|
+
* @alias overload
|
|
249
|
+
*/
|
|
250
|
+
overload?: boolean;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Customize the path to your .env.keys file. This is useful with monorepos.
|
|
254
|
+
* @default []
|
|
255
|
+
* @example require('@dotenvx/dotenvx').get('KEY', { envKeysFile: '../../.env.keys'} })
|
|
256
|
+
*/
|
|
257
|
+
envKeysFile?: string;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Throw immediately if an error is encountered - like a missing .env file.
|
|
261
|
+
* @default false
|
|
262
|
+
* @example require('@dotenvx/dotenvx').get('KEY', { strict: true })
|
|
263
|
+
*/
|
|
264
|
+
strict?: boolean;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Get a single environment variable.
|
|
269
|
+
*
|
|
270
|
+
* @see https://dotenvx.com/docs
|
|
271
|
+
* @param key - KEY
|
|
272
|
+
* @param options - additional options. example: `{ overload: true }`
|
|
273
|
+
*/
|
|
274
|
+
export function get(
|
|
275
|
+
key: string,
|
|
276
|
+
options?: GetOptions
|
|
277
|
+
): string;
|
|
278
|
+
|
|
235
279
|
/**
|
|
236
280
|
* List all env files in the current working directory
|
|
237
281
|
*
|