@dotenvx/dotenvx 1.39.1 → 1.40.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,13 @@
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.39.1...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.40.0...main)
6
+
7
+ ## [1.40.0](https://github.com/dotenvx/dotenvx/compare/v1.39.1...v1.40.0)
8
+
9
+ ### Added
10
+
11
+ * Smarter `ext precommit` and `ext prebuild` – catch duplicate KEYs in the same .env file where one is mistakenly left unencrypted ([#567](https://github.com/dotenvx/dotenvx/pull/567))
6
12
 
7
13
  ## [1.39.1](https://github.com/dotenvx/dotenvx/compare/v1.39.0...v1.39.1)
8
14
 
package/README.md CHANGED
@@ -2289,7 +2289,7 @@ Use dotenvx directly in code.
2289
2289
 
2290
2290
  ### Pro 🏆
2291
2291
 
2292
- *Secrets Management – Done Right. Cloak your private keys and treat secrets like code.*
2292
+ *Secrets Management – Done Right. Encrypted, Cloaked, Secrets as Code.*
2293
2293
 
2294
2294
  * <details><summary>`pro keypair`</summary><br>
2295
2295
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.39.1",
2
+ "version": "1.40.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -1,7 +1,7 @@
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, skipConvertingWindowsNewlines = false) {
4
+ function dotenvParse (src, skipExpandForDoubleQuotes = false, skipConvertingWindowsNewlines = false, collectAllValues = false) {
5
5
  const obj = {}
6
6
 
7
7
  // Convert buffer to string
@@ -35,8 +35,18 @@ function dotenvParse (src, skipExpandForDoubleQuotes = false, skipConvertingWind
35
35
  value = value.replace(/\\t/g, '\t') // tabs
36
36
  }
37
37
 
38
- // Add to object
39
- obj[key] = value
38
+ if (collectAllValues) {
39
+ // handle scenario where user mistakenly includes plaintext duplicate in .env:
40
+ //
41
+ // # .env
42
+ // HELLO="World"
43
+ // HELLO="enrypted:1234"
44
+ obj[key] = obj[key] || []
45
+ obj[key].push(value)
46
+ } else {
47
+ // Add to object
48
+ obj[key] = value
49
+ }
40
50
  }
41
51
 
42
52
  return obj
@@ -3,12 +3,21 @@ const isEncrypted = require('./isEncrypted')
3
3
  const isPublicKey = require('./isPublicKey')
4
4
 
5
5
  function isFullyEncrypted (src) {
6
- const parsed = dotenvParse(src)
6
+ const parsed = dotenvParse(src, false, false, true) // collect all values
7
7
 
8
- for (const [key, value] of Object.entries(parsed)) {
9
- const result = isEncrypted(value) || isPublicKey(key, value)
10
- if (!result) {
11
- return false
8
+ for (const [key, values] of Object.entries(parsed)) {
9
+ // handle scenario where user mistakenly includes plaintext duplicate in .env:
10
+ //
11
+ // # .env
12
+ // HELLO="World"
13
+ // HELLO="enrypted:1234"
14
+ //
15
+ // key => [value1, ...]
16
+ for (const value of values) {
17
+ const result = isEncrypted(value) || isPublicKey(key, value)
18
+ if (!result) {
19
+ return false
20
+ }
12
21
  }
13
22
  }
14
23
 
@@ -93,11 +93,24 @@ class Precommit {
93
93
  }
94
94
  }
95
95
 
96
+ _isInGitRepo () {
97
+ try {
98
+ childProcess.execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' })
99
+ return true
100
+ } catch {
101
+ return false
102
+ }
103
+ }
104
+
96
105
  _isFileToBeCommitted (filePath) {
97
106
  try {
107
+ if (!this._isInGitRepo()) {
108
+ // consider file to be committed if there is an error (not a git repo)
109
+ return true
110
+ }
111
+
98
112
  const output = childProcess.execSync('git diff HEAD --name-only').toString()
99
113
  const files = output.split('\n')
100
-
101
114
  return files.includes(filePath)
102
115
  } catch (error) {
103
116
  // consider file to be committed if there is an error (not using git)