Skip to content

Commit d45426d

Browse files
authored
Update dotEnv.ts
1 parent 04645e8 commit d45426d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/cli-v3/src/utilities/dotEnv.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ export function resolveDotEnvVars(cwd?: string, envFile?: string) {
1111
? resolve(cwd ?? process.cwd(), envFile)
1212
: ENVVAR_FILES.map((p) => resolve(cwd ?? process.cwd(), p));
1313

14-
dotenv.config({
15-
processEnv: result,
16-
path: envFilePath,
14+
// Load environment variables from the first found .env file
15+
const { parsed } = dotenv.config({
16+
path: Array.isArray(envFilePath) ? envFilePath.find(path => fs.existsSync(path)) : envFilePath,
1717
});
1818

19+
if (parsed) {
20+
Object.assign(result, parsed);
21+
}
22+
1923
env.TRIGGER_API_URL && (result.TRIGGER_API_URL = env.TRIGGER_API_URL);
2024

21-
// remove TRIGGER_API_URL and TRIGGER_SECRET_KEY, since those should be coming from the worker
25+
// Remove sensitive environment variables
2226
delete result.TRIGGER_API_URL;
2327
delete result.TRIGGER_SECRET_KEY;
2428
delete result.OTEL_EXPORTER_OTLP_ENDPOINT;
@@ -31,7 +35,8 @@ export function loadDotEnvVars(cwd?: string, envFile?: string) {
3135
? resolve(cwd ?? process.cwd(), envFile)
3236
: ENVVAR_FILES.map((p) => resolve(cwd ?? process.cwd(), p));
3337

38+
// Load the first found .env file
3439
dotenv.config({
35-
path: envFilePath,
40+
path: Array.isArray(envFilePath) ? envFilePath.find(path => fs.existsSync(path)) : envFilePath,
3641
});
3742
}

0 commit comments

Comments
 (0)