@dotenvx/dotenvx 0.43.1 → 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 CHANGED
@@ -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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.43.1",
2
+ "version": "0.43.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -7,19 +7,21 @@ 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
- `^${key}=` + // start of line with key
11
- '(?:' + // begin non-capturing group for handling both quoted and unquoted values
12
- '(["\'`])' + // capture opening quote (' or " or `)
13
- '[^\\1]*' + // match any character except the quote captured initially
14
- '\\1' + // match the same closing quote as captured at the start
15
- '|' + // OR
16
- '[^#\\n]*' + // match any characters until a # (comment) or newline
17
- ')' + // end non-capturing group
18
- '(\\n[^A-Z0-9_].*)*', // match subsequent lines that don't start with a letter, number, or underscore (continuation lines)
19
- 'm' // apply multiline mode, so ^ and $ match start and end of lines, not just the whole string
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
20
22
  )
21
23
 
22
- output = src.replace(regex, formatted)
24
+ output = src.replace(regex, `$1${formatted}`)
23
25
  } else {
24
26
  // append
25
27
  if (src.endsWith('\n')) {