Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#222 (released in v7.0.0) replaced
dotenvwithnode:utilparseEnv. As part of that,expandEnvstopped usingdotenv-expandand switched to a single regex pass over the merged keys. Some.envfiles that expanded correctly in v6 no longer do. Comparingdotenv-expand@10.0.0(the version v6 used, called as before with{ ignoreProcessEnv: true, parsed: merge }) with the current code:A=$B,B=$C,C=valA=valA=$CA=${MISSING:-fallback}A=fallbackA=${MISSING:-fallback}A=${B:-x},B=setA=xA=set:-x}PRICE=\$5PRICE=$5PRICE=\$5The first row is the most common case: a value can only use another variable's expanded value if that variable comes earlier in the merged object. So it depends on key order (and, through the merge, on whether the value came from
.env,process.envordata). The third row shows that a default operator now produces a broken value even when the variable is set. (dotenv-expand returnedxthere, which doesn't match the shell either:B=set bash -c 'echo "${B:-x}"'printsset.)This replaces
expandVariables()with a small resolver that has the same syntax as before:$VAR,${VAR},${VAR:-default}(unset or empty),${VAR-default}(unset) and\$for a literal$.$VAR}and an unterminated${VAR) behave as before.Tests: two cases in
test/expand.test.js, one for chained references out of order and one for defaults, escapes, a numeric value and a self-reference. Both fail without the change.npm test(100% coverage, tstyche) andnpm run lintpass. I also updated theexpandEnvcomment in the README.