Skip to content

Commit

Permalink
fix: js/py dotenv unexpectedly overrides existing env vars (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Oct 18, 2024
1 parent fb62dd5 commit 615aa25
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Argcfile.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
set -e

# @meta dotenv

BIN_DIR=bin
TMP_DIR="cache/tmp"

Expand Down
5 changes: 4 additions & 1 deletion scripts/run-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/run-agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion scripts/run-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/run-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 615aa25

Please sign in to comment.