From 615aa25266cf024027aca178f16f75bd115a9901 Mon Sep 17 00:00:00 2001 From: sigoden Date: Fri, 18 Oct 2024 19:28:57 +0800 Subject: fix: js/py dotenv unexpectedly overrides existing env vars (#113) --- scripts/run-agent.js | 5 ++++- scripts/run-agent.py | 4 +++- scripts/run-tool.js | 5 ++++- scripts/run-tool.py | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/run-agent.js b/scripts/run-agent.js index 7add1e2..6a02792 100755 --- a/scripts/run-agent.js +++ b/scripts/run-agent.js @@ -75,7 +75,10 @@ async function loadEnv(filePath) { if (line.trim().startsWith("#") || line.trim() === "") return; const [key, ...value] = line.split("="); - process.env[key.trim()] = value.join("=").trim(); + const envName = key.trim(); + if (!process.env[envName]) { + process.env[envName] = value.join("=").trim(); + } }); } catch { } } diff --git a/scripts/run-agent.py b/scripts/run-agent.py index b97dcd1..5c925ba 100755 --- a/scripts/run-agent.py +++ b/scripts/run-agent.py @@ -67,7 +67,9 @@ def load_env(file_path): continue key, *value = line.split("=") - os.environ[key.strip()] = "=".join(value).strip() + env_name = key.strip() + if env_name not in os.environ: + os.environ[env_name] = "=".join(value).strip() except FileNotFoundError: pass diff --git a/scripts/run-tool.js b/scripts/run-tool.js index 9c86482..d610772 100755 --- a/scripts/run-tool.js +++ b/scripts/run-tool.js @@ -62,7 +62,10 @@ async function loadEnv(filePath) { if (line.trim().startsWith("#") || line.trim() === "") return; const [key, ...value] = line.split("="); - process.env[key.trim()] = value.join("=").trim(); + const envName = key.trim(); + if (!process.env[envName]) { + process.env[envName] = value.join("=").trim(); + } }); } catch { } } diff --git a/scripts/run-tool.py b/scripts/run-tool.py index 4b6af78..99af580 100755 --- a/scripts/run-tool.py +++ b/scripts/run-tool.py @@ -62,7 +62,9 @@ def load_env(file_path): continue key, *value = line.split("=") - os.environ[key.strip()] = "=".join(value).strip() + env_name = key.strip() + if env_name not in os.environ: + os.environ[env_name] = "=".join(value).strip() except FileNotFoundError: pass -- cgit v1.2.3