fix: load shell environment variables on app startup (#7223)

Add shell-env integration to fetch environment variables from the user's
shell config files (.zshrc, .zshenv, etc.) so that proxy settings and
other exports are available in process.env for both Electron and CLI.
This commit is contained in:
lohit
2026-02-19 15:47:27 +00:00
committed by GitHub
parent 2fcfdfc338
commit 6ea079f6b1
7 changed files with 105 additions and 9 deletions

View File

@@ -0,0 +1,33 @@
/**
* Shell Environment Utility
*
* Fetches environment variables from the user's shell configuration files (e.g., .zshenv, .bashrc)
*/
const fetchShellEnv = async (): Promise<Record<string, string>> => {
// Windows handles environment variables differently - skip
if (process.platform === 'win32') {
return {};
}
try {
// shell-env is ESM-only, so we use dynamic import
const { shellEnv } = await import('shell-env');
const env = await shellEnv();
return env;
} catch (error) {
return {};
}
};
/**
* Initializes process.env with shell environment variables.
* Should be called early in the app startup.
*
* @returns The fetched shell environment variables
*/
export const initializeShellEnv = async (): Promise<Record<string, string>> => {
const shellEnvVars = await fetchShellEnv();
Object.assign(process.env, shellEnvVars);
return shellEnvVars;
};