@dotenvx/dotenvx 1.11.0 → 1.11.1
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.11.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.11.1...main)
|
|
6
|
+
|
|
7
|
+
## 1.11.1
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* support encryption of `export KEY` variables and preserve `#!shebangs` ([#357](https://github.com/dotenvx/dotenvx/pull/357))
|
|
6
12
|
|
|
7
13
|
## 1.11.0
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -39,6 +39,14 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// preserve shebang
|
|
43
|
+
const [firstLine, ...remainingLines] = envSrc.split('\n')
|
|
44
|
+
let firstLinePreserved = ''
|
|
45
|
+
if (firstLine.startsWith('#!')) {
|
|
46
|
+
firstLinePreserved = firstLine + '\n'
|
|
47
|
+
envSrc = remainingLines.join('\n')
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
// generate key pair
|
|
43
51
|
const { publicKey, privateKey } = keyPair(existingPrivateKey)
|
|
44
52
|
|
|
@@ -66,7 +74,7 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
|
|
|
66
74
|
''
|
|
67
75
|
].join('\n')
|
|
68
76
|
|
|
69
|
-
envSrc = `${prependPublicKey}\n${envSrc}`
|
|
77
|
+
envSrc = `${firstLinePreserved}${prependPublicKey}\n${envSrc}`
|
|
70
78
|
keysSrc = keysSrc.length > 1 ? keysSrc : `${firstTimeKeysSrc}\n`
|
|
71
79
|
|
|
72
80
|
let privateKeyAdded = false
|
|
@@ -7,13 +7,15 @@ function replace (src, key, value) {
|
|
|
7
7
|
const parsed = dotenv.parse(src)
|
|
8
8
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
9
9
|
const regex = new RegExp(
|
|
10
|
-
// Match the key at the start of a line
|
|
11
|
-
`(^|\\n)
|
|
10
|
+
// Match the key at the start of a line, following a newline, or prefaced by export
|
|
11
|
+
`(^|\\n)\\s*(export\\s+)?${key}\\s*=\\s*` +
|
|
12
|
+
// `(^|\\n)${key}\\s*=\\s*` +
|
|
12
13
|
// Non-capturing group to handle different types of quotations and unquoted values
|
|
13
14
|
'(?:' +
|
|
14
15
|
'(["\'`])' + // Match an opening quote
|
|
15
16
|
'.*?' + // Non-greedy match for any characters within quotes
|
|
16
|
-
'\\2' + // Match the corresponding closing quote
|
|
17
|
+
// '\\2' + // Match the corresponding closing quote
|
|
18
|
+
'\\3' + // Match the corresponding closing quote
|
|
17
19
|
'|' +
|
|
18
20
|
// Match unquoted values; account for escaped newlines
|
|
19
21
|
'(?:[^#\\n\\\\]|\\\\.)*' + // Use non-capturing group for any character except #, newline, or backslash, or any escaped character
|
|
@@ -21,7 +23,7 @@ function replace (src, key, value) {
|
|
|
21
23
|
'gs' // Global and dotAll mode to treat string as single line
|
|
22
24
|
)
|
|
23
25
|
|
|
24
|
-
output = src.replace(regex, `$1${formatted}`)
|
|
26
|
+
output = src.replace(regex, `$1$2${formatted}`)
|
|
25
27
|
} else {
|
|
26
28
|
// append
|
|
27
29
|
if (src.endsWith('\n')) {
|