Don't load user's shell env on app startup (#4681)

Co-authored-by: Michael Neale <michael.neale@gmail.com>
This commit is contained in:
Jack Amadeo
2025-09-23 20:38:07 -04:00
committed by GitHub
parent 44d01e2432
commit 44115a67ce
7 changed files with 48 additions and 93 deletions
-38
View File
@@ -1,38 +0,0 @@
import { execSync } from 'child_process';
import log from './logger';
export function loadShellEnv(isProduction: boolean = false): void {
// Only proceed if running on macOS and in production mode
if (process.platform !== 'darwin' || !isProduction) {
log.info(
`Skipping zsh environment loading: ${
process.platform !== 'darwin' ? 'Not running on macOS' : 'Not in production mode'
}`
);
return;
}
try {
log.info('LOADING ENV');
const shell = process.env.SHELL || '/bin/bash'; // Detect user's shell
const envStr = execSync(`${shell} -l -i -c 'env'`, {
encoding: 'utf-8',
});
// Parse and set environment variables
envStr.split('\n').forEach((line) => {
const matches = line.match(/^([^=]+)=(.*)$/);
if (matches) {
const [, key, value] = matches;
log.info(`Setting ${key}`);
process.env[key] = value;
}
});
log.info('Successfully loaded zsh environment variables');
} catch (error) {
log.error('Failed to load zsh environment variables:', error);
}
}