@dotenvx/dotenvx 1.34.0 → 1.36.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 CHANGED
@@ -2,7 +2,22 @@
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.34.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.36.0...main)
6
+
7
+ ## [1.36.0](https://github.com/dotenvx/dotenvx/compare/v1.35.0...v1.36.0)
8
+
9
+ ### Changed
10
+
11
+ * `--strict` flag respects (doesn't throw) anything in `--ignore` flag ([#527](https://github.com/dotenvx/dotenvx/pull/527))
12
+
13
+ ## [1.35.0](https://github.com/dotenvx/dotenvx/compare/v1.34.0...v1.35.0)
14
+
15
+ ### Added
16
+
17
+ * `npx dotenvx precommit` support as a convenience ([#523](https://github.com/dotenvx/dotenvx/pull/523))
18
+ * `main.get` method ([#524](https://github.com/dotenvx/dotenvx/pull/524))
19
+
20
+ The addition of `main.get` facilitates what we term Decryption at Access, a concept explored in greater detail in our [whitepaper](https://dotenvx.com/dotenvx.pdf).
6
21
 
7
22
  ## [1.34.0](https://github.com/dotenvx/dotenvx/compare/v1.33.0...v1.34.0)
8
23
 
package/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  * multi-environment
7
7
  * encrypted envs
8
8
 
9
+ [Read the whitepaper](https://dotenvx.com/dotenvx.pdf)
10
+
9
11
   
10
12
 
11
13
 
@@ -19,7 +21,7 @@ npm install @dotenvx/dotenvx --save
19
21
  ```js
20
22
  // index.js
21
23
  require('@dotenvx/dotenvx').config()
22
- // or import('@dotenvx/dotenvx/config') if you're using esm
24
+ // or import '@dotenvx/dotenvx/config' // for esm
23
25
 
24
26
  console.log(`Hello ${process.env.HELLO}`)
25
27
  ```
@@ -524,6 +526,8 @@ More examples
524
526
  Hello local
525
527
  ```
526
528
 
529
+ Note subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above `local` wins – from the first file.
530
+
527
531
  </details>
528
532
 
529
533
  * <details><summary>`--overload` flag</summary><br>
@@ -538,6 +542,8 @@ More examples
538
542
  Hello World
539
543
  ```
540
544
 
545
+ Note that with `--overload` subsequent files DO override pre-existing variables defined in previous files.
546
+
541
547
  * <details><summary>`--verbose` flag</summary><br>
542
548
 
543
549
  ```sh
@@ -798,6 +804,8 @@ More examples
798
804
  Hello local
799
805
  ```
800
806
 
807
+ Note subsequent files do NOT override pre-existing variables defined in previous files or env. This follows historic principle. For example, above `local` wins – from the first file.
808
+
801
809
  </details>
802
810
  * <details><summary>`run --env HELLO=String`</summary><br>
803
811
 
@@ -827,6 +835,8 @@ More examples
827
835
  Hello World
828
836
  ```
829
837
 
838
+ Note that with `--overload` subsequent files DO override pre-existing variables defined in previous files.
839
+
830
840
  </details>
831
841
  * <details><summary>`DOTENV_PRIVATE_KEY=key run`</summary><br>
832
842
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.34.0",
2
+ "version": "1.36.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -62,13 +62,13 @@ async function run () {
62
62
  }
63
63
 
64
64
  for (const error of processedEnv.errors || []) {
65
- if (options.strict) throw error // throw immediately if strict
66
-
67
65
  if (ignore.includes(error.code)) {
68
66
  logger.verbose(`ignored: ${error.message}`)
69
67
  continue // ignore error
70
68
  }
71
69
 
70
+ if (options.strict) throw error // throw if strict and not ignored
71
+
72
72
  if (error.code === 'MISSING_ENV_FILE') {
73
73
  if (!options.convention) { // do not output error for conventions (too noisy)
74
74
  console.error(error.message)
@@ -3,15 +3,19 @@ const path = require('path')
3
3
 
4
4
  const HOOK_SCRIPT = `#!/bin/sh
5
5
 
6
- if ! command -v dotenvx 2>&1 >/dev/null
6
+ if command -v dotenvx 2>&1 >/dev/null
7
7
  then
8
+ dotenvx ext precommit
9
+ elif npx dotenvx -V >/dev/null 2>&1
10
+ then
11
+ npx dotenvx ext precommit
12
+ else
8
13
  echo "[dotenvx][precommit] 'dotenvx' command not found"
9
14
  echo "[dotenvx][precommit] ? install it with [curl -fsS https://dotenvx.sh | sh]"
10
15
  echo "[dotenvx][precommit] ? other install options [https://dotenvx.com/docs/install]"
11
16
  exit 1
12
17
  fi
13
-
14
- dotenvx ext precommit`
18
+ `
15
19
 
16
20
  class InstallPrecommitHook {
17
21
  constructor () {
package/src/lib/main.d.ts CHANGED
@@ -194,6 +194,13 @@ export interface SetOptions {
194
194
  * Set a .env convention (available conventions: 'nextjs')
195
195
  */
196
196
  convention?: string;
197
+
198
+ /**
199
+ * Specify whether the variable has to be encrypted
200
+ * @default true
201
+ * @example require('@dotenvx/dotenvx').config(key, value, { encrypt: false } })
202
+ */
203
+ encrypt?: boolean;
197
204
  }
198
205
 
199
206
  export type SetOutput = {
package/src/lib/main.js CHANGED
@@ -9,6 +9,7 @@ const { getColor, bold } = require('./../shared/colors')
9
9
  const Ls = require('./services/ls')
10
10
  const Run = require('./services/run')
11
11
  const Sets = require('./services/sets')
12
+ const Get = require('./services/get')
12
13
  const Keypair = require('./services/keypair')
13
14
  const Genexample = require('./services/genexample')
14
15
 
@@ -57,7 +58,6 @@ const config = function (options = {}) {
57
58
  let lastError
58
59
  /** @type {Record<string, string>} */
59
60
  const parsedAll = {}
60
-
61
61
  for (const processedEnv of processedEnvs) {
62
62
  if (processedEnv.type === 'envVaultFile') {
63
63
  logger.verbose(`loading env from encrypted ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
@@ -69,12 +69,13 @@ const config = function (options = {}) {
69
69
  }
70
70
 
71
71
  for (const error of processedEnv.errors || []) {
72
- if (strict) throw error // throw immediately if strict
73
-
74
72
  if (ignore.includes(error.code)) {
73
+ logger.verbose(`ignored: ${error.message}`)
75
74
  continue // ignore error
76
75
  }
77
76
 
77
+ if (strict) throw error // throw if strict and not ignored
78
+
78
79
  lastError = error // surface later in { error }
79
80
 
80
81
  if (error.code === 'MISSING_ENV_FILE') {
@@ -234,6 +235,58 @@ const set = function (key, value, options = {}) {
234
235
  }
235
236
  }
236
237
 
238
+ /* @type {import('./main').get} */
239
+ const get = function (key, options = {}) {
240
+ const envs = buildEnvs(options)
241
+
242
+ // ignore
243
+ const ignore = options.ignore || []
244
+
245
+ const { parsed, errors } = new Get(key, envs, options.overload, process.env.DOTENV_KEY, options.all, options.envKeysFile).run()
246
+
247
+ for (const error of errors || []) {
248
+ if (ignore.includes(error.code)) {
249
+ continue // ignore error
250
+ }
251
+
252
+ if (options.strict) throw error // throw immediately if strict
253
+
254
+ console.error(error.message)
255
+ if (error.help) {
256
+ console.error(error.help)
257
+ }
258
+ }
259
+
260
+ if (key) {
261
+ const single = parsed[key]
262
+ if (single === undefined) {
263
+ return undefined
264
+ } else {
265
+ return single
266
+ }
267
+ } else {
268
+ if (options.format === 'eval') {
269
+ let inline = ''
270
+ for (const [key, value] of Object.entries(parsed)) {
271
+ inline += `${key}=${escape(value)}\n`
272
+ }
273
+ inline = inline.trim()
274
+
275
+ return inline
276
+ } else if (options.format === 'shell') {
277
+ let inline = ''
278
+ for (const [key, value] of Object.entries(parsed)) {
279
+ inline += `${key}=${value} `
280
+ }
281
+ inline = inline.trim()
282
+
283
+ return inline
284
+ } else {
285
+ return parsed
286
+ }
287
+ }
288
+ }
289
+
237
290
  /** @type {import('./main').ls} */
238
291
  const ls = function (directory, envFile, excludeEnvFile) {
239
292
  return new Ls(directory, envFile, excludeEnvFile).run()
@@ -260,6 +313,7 @@ module.exports = {
260
313
  parse,
261
314
  // actions related
262
315
  set,
316
+ get,
263
317
  ls,
264
318
  keypair,
265
319
  genexample,