@dotenvx/dotenvx 0.43.0 → 0.43.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/README.md +3 -3
- package/package.json +1 -1
- package/src/lib/helpers/replace.js +16 -3
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ brew install dotenvx/brew/dotenvx
|
|
|
32
32
|
```
|
|
33
33
|
> * [other global ways to install](https://dotenvx.com/docs/install)
|
|
34
34
|
>
|
|
35
|
-
>
|
|
35
|
+
> Install globally as a cli to unlock dotenv for ANY language, framework, or platform. 💥
|
|
36
36
|
>
|
|
37
37
|
> I am using (and recommending) this approach going forward. – [motdotla](https://github.com/motdotla)
|
|
38
38
|
|
|
@@ -45,10 +45,10 @@ $ echo "HELLO=World" > .env
|
|
|
45
45
|
$ echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
46
46
|
|
|
47
47
|
$ node index.js
|
|
48
|
-
Hello undefined
|
|
48
|
+
Hello undefined # without dotenvx
|
|
49
49
|
|
|
50
50
|
$ dotenvx run -- node index.js
|
|
51
|
-
Hello World
|
|
51
|
+
Hello World # with dotenvx
|
|
52
52
|
> :-D
|
|
53
53
|
```
|
|
54
54
|
|
package/package.json
CHANGED
|
@@ -6,9 +6,22 @@ function replace (src, key, value) {
|
|
|
6
6
|
|
|
7
7
|
const parsed = dotenv.parse(src)
|
|
8
8
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const regex = new RegExp(
|
|
10
|
+
// Match the key at the start of a line or following a newline
|
|
11
|
+
`(^|\\n)${key}\\s*=\\s*` +
|
|
12
|
+
// Non-capturing group to handle different types of quotations and unquoted values
|
|
13
|
+
'(?:' +
|
|
14
|
+
'(["\'`])' + // Match an opening quote
|
|
15
|
+
'.*?' + // Non-greedy match for any characters within quotes
|
|
16
|
+
'\\2' + // Match the corresponding closing quote
|
|
17
|
+
'|' +
|
|
18
|
+
// Match unquoted values; account for escaped newlines
|
|
19
|
+
'(?:[^#\\n\\\\]|\\\\.)*' + // Use non-capturing group for any character except #, newline, or backslash, or any escaped character
|
|
20
|
+
')',
|
|
21
|
+
'gs' // Global and dotAll mode to treat string as single line
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
output = src.replace(regex, `$1${formatted}`)
|
|
12
25
|
} else {
|
|
13
26
|
// append
|
|
14
27
|
if (src.endsWith('\n')) {
|