Skip to content

Commit 021bdd3

Browse files
authored
Merge pull request #733 from KxSystems/ee-path
[REPL] var expansion in .env
2 parents fe83ddf + 471601a commit 021bdd3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/utils/core.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,16 @@ function loadEnvironment(folder: string, env: { [key: string]: string }) {
140140
const [key, value] = trimmed.split("=");
141141
if (key && value !== undefined) {
142142
env[key.trim()] = value
143+
// Normalize
143144
.replace(/["']/gs, "")
144-
.replace(/(?:\$HOME|~)/gs, homedir())
145+
// Variable expansion
146+
.replace(
147+
/\$([A-Za-z_]+[A-Za-z0-9_]*)|\${([A-Za-z0-9_]*)}|%([A-Za-z_]+[A-Za-z0-9_]*)%/g,
148+
(match, a, b, c) => {
149+
const v = a ?? b ?? c;
150+
return env[v] ?? process.env[v] ?? match;
151+
},
152+
)
145153
.trim();
146154
}
147155
}

0 commit comments

Comments
 (0)