fix(dotenv): load gateway.env compatibility fallback (#61084)

* fix(dotenv): load gateway env fallback

* fix(dotenv): preserve legacy cli env loading

* fix(dotenv): keep gateway fallback scoped to default profile
This commit is contained in:
scoootscooob
2026-04-04 18:24:29 -07:00
committed by GitHub
parent 9860db5cea
commit 6ab1b43081
4 changed files with 250 additions and 20 deletions

View File

@@ -1,14 +1,17 @@
import path from "node:path";
import { resolveStateDir } from "../config/paths.js";
import { loadRuntimeDotEnvFile, loadWorkspaceDotEnvFile } from "../infra/dotenv.js";
import { loadGlobalRuntimeDotEnvFiles, loadWorkspaceDotEnvFile } from "../infra/dotenv.js";
export function loadCliDotEnv(opts?: { quiet?: boolean }) {
const quiet = opts?.quiet ?? true;
const cwdEnvPath = path.join(process.cwd(), ".env");
loadWorkspaceDotEnvFile(cwdEnvPath, { quiet });
// Then load the global fallback from the active state dir without overriding
// any env vars that were already set or loaded from CWD.
const globalEnvPath = path.join(resolveStateDir(process.env), ".env");
loadRuntimeDotEnvFile(globalEnvPath, { quiet });
// Then load the global fallback set without overriding any env vars that
// were already set or loaded from CWD. This includes the Ubuntu fresh-install
// gateway.env compatibility path.
loadGlobalRuntimeDotEnvFiles({
quiet,
stateEnvPath: path.join(resolveStateDir(process.env), ".env"),
});
}