@dotenvx/dotenvx 1.24.1 → 1.24.3

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,9 +2,21 @@
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.24.1...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.24.3...main)
6
6
 
7
- ## 1.24.1
7
+ ## [1.24.3](https://github.com/dotenvx/dotenvx/compare/v1.24.2...1.24.3)
8
+
9
+ ### Changed
10
+
11
+ * 🐞 fix command substitution for more complex commands ([#455](https://github.com/dotenvx/dotenvx/pull/455))
12
+
13
+ ## [1.24.2](https://github.com/dotenvx/dotenvx/compare/v1.24.1...1.24.2)
14
+
15
+ ### Changed
16
+
17
+ * treat pre-existing expandable values as literal in `process.env` ([#450](https://github.com/dotenvx/dotenvx/pull/450))
18
+
19
+ ## [1.24.1](https://github.com/dotenvx/dotenvx/compare/v1.24.0...1.24.1)
8
20
 
9
21
  ### Changed
10
22
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.24.1",
2
+ "version": "1.24.3",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -49,7 +49,7 @@ class Parse {
49
49
  }
50
50
 
51
51
  // expand empty, double, or backticks
52
- if (quote !== "'") {
52
+ if (quote !== "'" && !this.processEnv[key]) {
53
53
  this.parsed[key] = resolveEscapeSequences(this.expand(this.parsed[key]))
54
54
  }
55
55
 
@@ -122,12 +122,13 @@ class Parse {
122
122
  }
123
123
 
124
124
  eval (value) {
125
- const matches = value.match(/\$\([^()]+\)/) || []
125
+ // Match everything between the outermost $() using a regex with non-capturing groups
126
+ const matches = value.match(/\$\(([^)]+(?:\)[^(]*)*)\)/g) || []
126
127
 
127
128
  return matches.reduce(function (newValue, match) {
128
- const command = match.substring(2, match.length - 1) // get command
129
- const value = chomp(execSync(command).toString()) // execute command
130
- return newValue.replace(match, value) // replace with command value
129
+ const command = match.slice(2, -1) // Extract command by removing $() wrapper
130
+ const result = chomp(execSync(command).toString()) // execute command
131
+ return newValue.replace(match, result) // Replace match with result
131
132
  }, value)
132
133
  }
133
134
 
@@ -141,11 +142,8 @@ class Parse {
141
142
 
142
143
  let result = value
143
144
  let match
144
- const seen = new Set() // self-referential checker
145
145
 
146
146
  while ((match = regex.exec(result)) !== null) {
147
- seen.add(result)
148
-
149
147
  const [template, bracedExpression, unbracedExpression] = match
150
148
  const expression = bracedExpression || unbracedExpression
151
149
 
@@ -162,12 +160,6 @@ class Parse {
162
160
 
163
161
  const key = r.shift()
164
162
 
165
- // short-circuit if exact value already in process.env already
166
- // const inProcessEnv = Object.prototype.hasOwnProperty.call(this.processEnv, key)
167
- // if (!this.overload && !!this.processEnv[key] && (env[key] === this.processEnv[key])) {
168
- // return this.processEnv[key]
169
- // }
170
-
171
163
  if ([':+', '+'].includes(splitter)) {
172
164
  defaultValue = env[key] ? r.join(splitter) : ''
173
165
  value = null
@@ -177,16 +169,16 @@ class Parse {
177
169
  }
178
170
 
179
171
  if (value) {
180
- // self-referential check
181
- if (seen.has(value)) {
182
- result = result.replace(template, defaultValue)
183
- } else {
184
- result = result.replace(template, value)
185
- }
172
+ result = result.replace(template, value)
186
173
  } else {
187
174
  result = result.replace(template, defaultValue)
188
175
  }
189
176
 
177
+ // if the result equaled what was in env then stop expanding - handle self-referential check as well
178
+ if (result === env[key]) {
179
+ break
180
+ }
181
+
190
182
  regex.lastIndex = 0 // reset regex search position to re-evaluate after each replacement
191
183
  }
192
184