@dotenvx/dotenvx 1.27.0 → 1.29.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,13 +2,25 @@
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.27.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.29.0...main)
6
+
7
+ ## [1.29.0](https://github.com/dotenvx/dotenvx/compare/v1.28.0...v1.29.0)
8
+
9
+ ### Added
10
+
11
+ * add `--ignore` flag to suppress specified errors. example: `dotenvx run --ignore=MISSING_ENV_FILE` ([#485](https://github.com/dotenvx/dotenvx/pull/485))
12
+
13
+ ## [1.28.0](https://github.com/dotenvx/dotenvx/compare/v1.27.0...v1.28.0)
14
+
15
+ ### Changed
16
+
17
+ * `.env.keys` file is generated WITHOUT quotes going forward. This is to minimize friction around Docker gotchas to developers - old versions of Docker do not support `--env-file` containing quoted keys/values. ([#480](https://github.com/dotenvx/dotenvx/pull/480)) ([additional note](https://github.com/dotenvx/dotenvx/issues/465#issuecomment-2515279676))
6
18
 
7
19
  ## [1.27.0](https://github.com/dotenvx/dotenvx/compare/v1.26.2...v1.27.0)
8
20
 
9
21
  ### Added
10
22
 
11
- * add support for `\t` expansion when double quoted. (e.g. `TAB="hi\tfriend"` becomes `hi friend`) ([#479](https://github.com/dotenvx/dotenvx/pull/479))
23
+ * add support for `\t` expansion when double quoted. (e.g. `TAB="hi\tfriend"` becomes `hi friend`) ([#479](https://github.com/dotenvx/dotenvx/pull/479))
12
24
 
13
25
  ## [1.26.2](https://github.com/dotenvx/dotenvx/compare/v1.26.1...v1.26.2)
14
26
 
package/README.md CHANGED
@@ -983,6 +983,18 @@ More examples
983
983
 
984
984
  This can be useful in `ci` scripts where you want to fail the ci if your `.env` file could not be decrypted at runtime.
985
985
 
986
+ </details>
987
+ * <details><summary>`run --ignore`</summary><br>
988
+
989
+ Ignore errors like `MISSING_ENV_FILE`.
990
+
991
+ ```sh
992
+ $ echo "console.log('Hello ' + process.env.HELLO)" > index.js
993
+
994
+ $ dotenvx run -f .env.missing --ignore=MISSING_ENV_FILE -- node index.js
995
+ ...
996
+ ```
997
+
986
998
  </details>
987
999
  * <details><summary>`run --convention=nextjs`</summary><br>
988
1000
 
@@ -1695,9 +1707,17 @@ More examples
1695
1707
 
1696
1708
  ```sh
1697
1709
  $ dotenvx ext gitignore
1698
- creating .gitignore
1699
- appending .env* to .gitignore
1700
- done
1710
+ ignored .env* (.gitignore)
1711
+ ```
1712
+
1713
+ </details>
1714
+ * <details><summary>`ext gitignore --pattern`</summary><br>
1715
+
1716
+ Gitignore specific pattern(s) of `.env` files.
1717
+
1718
+ ```sh
1719
+ $ dotenvx ext gitignore --pattern .env.keys
1720
+ ✔ ignored .env.keys (.gitignore)
1701
1721
  ```
1702
1722
 
1703
1723
  </details>
@@ -1707,7 +1727,7 @@ More examples
1707
1727
 
1708
1728
  ```sh
1709
1729
  $ dotenvx ext precommit
1710
- [dotenvx][precommit] success
1730
+ [dotenvx][precommit] .env files (1) protected (encrypted or gitignored)
1711
1731
  ```
1712
1732
 
1713
1733
  </details>
@@ -1717,7 +1737,7 @@ More examples
1717
1737
 
1718
1738
  ```sh
1719
1739
  $ dotenvx ext precommit --install
1720
- [dotenvx][precommit] dotenvx precommit installed [.git/hooks/pre-commit]
1740
+ [dotenvx][precommit] dotenvx ext precommit installed [.git/hooks/pre-commit]
1721
1741
  ```
1722
1742
 
1723
1743
  </details>
@@ -1728,6 +1748,7 @@ More examples
1728
1748
  Add it to your `Dockerfile`.
1729
1749
 
1730
1750
  ```sh
1751
+ # Dockerfile
1731
1752
  RUN curl -fsS https://dotenvx.sh | sh
1732
1753
 
1733
1754
  ...
@@ -1780,6 +1801,8 @@ More examples
1780
1801
  Hello World
1781
1802
  ```
1782
1803
 
1804
+ It defaults to looking for a `.env` file.
1805
+
1783
1806
  </details>
1784
1807
  * <details><summary>`config(path: ['.env.local', '.env'])` - multiple files</summary><br>
1785
1808
 
@@ -1811,7 +1834,7 @@ More examples
1811
1834
  </details>
1812
1835
  * <details><summary>`config(overload: true)` - overload</summary><br>
1813
1836
 
1814
- User `overload` to overwrite the prior set value.
1837
+ Use `overload` to overwrite the prior set value.
1815
1838
 
1816
1839
  ```ini
1817
1840
  # .env.local
@@ -1858,6 +1881,29 @@ More examples
1858
1881
  Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
1859
1882
  ```
1860
1883
 
1884
+ </details>
1885
+ * <details><summary>`config(ignore:)` - ignore</summary><br>
1886
+
1887
+ Use `ignore` to suppress specific errors like `MISSING_ENV_FILE`.
1888
+
1889
+ ```ini
1890
+ # .env
1891
+ HELLO="World"
1892
+ ```
1893
+
1894
+ ```js
1895
+ // index.js
1896
+ require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], ignore: ['MISSING_ENV_FILE']})
1897
+
1898
+ console.log(`Hello ${process.env.HELLO}`)
1899
+ ```
1900
+
1901
+ ```sh
1902
+ $ node index.js
1903
+ [dotenvx@1.24.5] injecting env (1) from .env.local, .env
1904
+ Hello World
1905
+ ```
1906
+
1861
1907
  </details>
1862
1908
  * <details><summary>`parse(src)`</summary><br>
1863
1909
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.27.0",
2
+ "version": "1.29.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -13,6 +13,8 @@ function get (key) {
13
13
  const options = this.opts()
14
14
  logger.debug(`options: ${JSON.stringify(options)}`)
15
15
 
16
+ const ignore = options.ignore || []
17
+
16
18
  let envs = []
17
19
  // handle shorthand conventions - like --convention=nextjs
18
20
  if (options.convention) {
@@ -27,6 +29,10 @@ function get (key) {
27
29
  for (const error of errors || []) {
28
30
  if (options.strict) throw error // throw immediately if strict
29
31
 
32
+ if (ignore.includes(error.code)) {
33
+ continue // ignore error
34
+ }
35
+
30
36
  console.error(error.message)
31
37
  if (error.help) {
32
38
  console.error(error.help)
@@ -14,6 +14,8 @@ async function run () {
14
14
  const options = this.opts()
15
15
  logger.debug(`options: ${JSON.stringify(options)}`)
16
16
 
17
+ const ignore = options.ignore || []
18
+
17
19
  if (commandArgs.length < 1) {
18
20
  const hasSeparator = process.argv.indexOf('--') !== -1
19
21
 
@@ -62,6 +64,11 @@ async function run () {
62
64
  for (const error of processedEnv.errors || []) {
63
65
  if (options.strict) throw error // throw immediately if strict
64
66
 
67
+ if (ignore.includes(error.code)) {
68
+ logger.verbose(`ignored: ${error.message}`)
69
+ continue // ignore error
70
+ }
71
+
65
72
  if (error.code === 'MISSING_ENV_FILE') {
66
73
  if (!options.convention) { // do not output error for conventions (too noisy)
67
74
  console.error(error.message)
@@ -60,6 +60,7 @@ program.command('run')
60
60
  .option('-o, --overload', 'override existing env variables')
61
61
  .option('--strict', 'process.exit(1) on any errors (default: false)', false)
62
62
  .option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
63
+ .option('--ignore <errorCodes...>', 'error code(s) to ignore (example: --ignore=MISSING_ENV_FILE)')
63
64
  .action(function (...args) {
64
65
  this.envs = envs
65
66
  runAction.apply(this, args)
@@ -77,6 +78,7 @@ program.command('get')
77
78
  .option('-o, --overload', 'override existing env variables')
78
79
  .option('--strict', 'process.exit(1) on any errors (default: false)', false)
79
80
  .option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
81
+ .option('--ignore <errorCodes...>', 'error code(s) to ignore (example: --ignore=MISSING_ENV_FILE)')
80
82
  .option('-a, --all', 'include all machine envs as well')
81
83
  .option('-pp, --pretty-print', 'pretty print output')
82
84
  .option('--format <type>', 'format of the output (json, shell, eval)', 'json')
@@ -15,7 +15,7 @@ class Errors {
15
15
  missingEnvFile () {
16
16
  const code = 'MISSING_ENV_FILE'
17
17
  const message = `[${code}] missing ${this.envFilepath} file (${this.filepath})`
18
- const help = `[${code}] ? add one with [echo "HELLO=World" > ${this.envFilepath}]`
18
+ const help = `[${code}] https://github.com/dotenvx/dotenvx/issues/484`
19
19
 
20
20
  const e = new Error(message)
21
21
  e.code = code
package/src/lib/main.js CHANGED
@@ -28,6 +28,9 @@ const config = function (options = {}) {
28
28
  // overload
29
29
  const overload = options.overload || options.override
30
30
 
31
+ // ignore
32
+ const ignore = options.ignore || []
33
+
31
34
  // strict
32
35
  const strict = options.strict
33
36
 
@@ -86,19 +89,23 @@ const config = function (options = {}) {
86
89
  for (const error of processedEnv.errors || []) {
87
90
  if (strict) throw error // throw immediately if strict
88
91
 
92
+ if (ignore.includes(error.code)) {
93
+ continue // ignore error
94
+ }
95
+
89
96
  lastError = error // surface later in { error }
90
97
 
91
98
  if (error.code === 'MISSING_ENV_FILE') {
92
99
  if (!options.convention) { // do not output error for conventions (too noisy)
93
100
  console.error(error.message)
94
101
  if (error.help) {
95
- logger.help(error.help)
102
+ console.error(error.help)
96
103
  }
97
104
  }
98
105
  } else {
99
106
  console.error(error.message)
100
107
  if (error.help) {
101
- logger.help(error.help)
108
+ console.error(error.help)
102
109
  }
103
110
  }
104
111
  }
@@ -132,7 +132,7 @@ class Encrypt {
132
132
  ].join('\n')
133
133
  const appendPrivateKey = [
134
134
  `# ${filename}`,
135
- `${privateKeyName}="${privateKey}"`,
135
+ `${privateKeyName}=${privateKey}`,
136
136
  ''
137
137
  ].join('\n')
138
138
 
@@ -137,7 +137,7 @@ class Sets {
137
137
  ].join('\n')
138
138
  const appendPrivateKey = [
139
139
  `# ${filename}`,
140
- `${privateKeyName}="${privateKey}"`,
140
+ `${privateKeyName}=${privateKey}`,
141
141
  ''
142
142
  ].join('\n')
143
143