mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-11 00:02:38 +02:00
fix shell path issue on mac
This commit is contained in:
parent
72ed4bd6d9
commit
5e47bd4309
3 changed files with 18 additions and 6 deletions
|
|
@ -112,7 +112,9 @@ function initializeExecutionEnvironment(): void {
|
||||||
).trim();
|
).trim();
|
||||||
|
|
||||||
const env = JSON.parse(stdout) as Record<string, string>;
|
const env = JSON.parse(stdout) as Record<string, string>;
|
||||||
process.env = { ...env, ...process.env };
|
// Let the user's shell environment win for overlapping keys like PATH.
|
||||||
|
// Finder/launched GUI apps on macOS often start with a stripped PATH.
|
||||||
|
process.env = { ...process.env, ...env };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load shell environment', error);
|
console.error('Failed to load shell environment', error);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,15 @@ export interface RuntimeContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getExecutionShell(platform: NodeJS.Platform = process.platform): string {
|
export function getExecutionShell(platform: NodeJS.Platform = process.platform): string {
|
||||||
return platform === 'win32' ? (process.env.ComSpec || 'cmd.exe') : '/bin/sh';
|
if (platform === 'win32') {
|
||||||
|
return process.env.ComSpec || 'cmd.exe';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.SHELL) {
|
||||||
|
return process.env.SHELL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return platform === 'darwin' ? '/bin/zsh' : '/bin/sh';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getRuntimeContext(platform: NodeJS.Platform = process.platform): RuntimeContext {
|
export function getRuntimeContext(platform: NodeJS.Platform = process.platform): RuntimeContext {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ const execPromise = promisify(exec);
|
||||||
const COMMAND_SPLIT_REGEX = /(?:\|\||&&|;|\||\n|`|\$\(|\(|\))/;
|
const COMMAND_SPLIT_REGEX = /(?:\|\||&&|;|\||\n|`|\$\(|\(|\))/;
|
||||||
const ENV_ASSIGNMENT_REGEX = /^[A-Za-z_][A-Za-z0-9_]*=.*/;
|
const ENV_ASSIGNMENT_REGEX = /^[A-Za-z_][A-Za-z0-9_]*=.*/;
|
||||||
const WRAPPER_COMMANDS = new Set(['sudo', 'env', 'time', 'command']);
|
const WRAPPER_COMMANDS = new Set(['sudo', 'env', 'time', 'command']);
|
||||||
const EXECUTION_SHELL = getExecutionShell();
|
|
||||||
|
|
||||||
function sanitizeToken(token: string): string {
|
function sanitizeToken(token: string): string {
|
||||||
return token.trim().replace(/^['"()]+|['"()]+$/g, '');
|
return token.trim().replace(/^['"()]+|['"()]+$/g, '');
|
||||||
|
|
@ -84,11 +83,12 @@ export async function executeCommand(
|
||||||
}
|
}
|
||||||
): Promise<CommandResult> {
|
): Promise<CommandResult> {
|
||||||
try {
|
try {
|
||||||
|
const shell = getExecutionShell();
|
||||||
const { stdout, stderr } = await execPromise(command, {
|
const { stdout, stderr } = await execPromise(command, {
|
||||||
cwd: options?.cwd,
|
cwd: options?.cwd,
|
||||||
timeout: options?.timeout,
|
timeout: options?.timeout,
|
||||||
maxBuffer: options?.maxBuffer || 1024 * 1024, // default 1MB
|
maxBuffer: options?.maxBuffer || 1024 * 1024, // default 1MB
|
||||||
shell: EXECUTION_SHELL,
|
shell,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -161,8 +161,9 @@ export function executeCommandAbortable(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const shell = getExecutionShell();
|
||||||
const proc = spawn(command, [], {
|
const proc = spawn(command, [], {
|
||||||
shell: EXECUTION_SHELL,
|
shell,
|
||||||
cwd: options?.cwd,
|
cwd: options?.cwd,
|
||||||
detached: process.platform !== 'win32', // Create process group on Unix
|
detached: process.platform !== 'win32', // Create process group on Unix
|
||||||
stdio: ['ignore', 'pipe', 'pipe'],
|
stdio: ['ignore', 'pipe', 'pipe'],
|
||||||
|
|
@ -272,11 +273,12 @@ export function executeCommandSync(
|
||||||
}
|
}
|
||||||
): CommandResult {
|
): CommandResult {
|
||||||
try {
|
try {
|
||||||
|
const shell = getExecutionShell();
|
||||||
const stdout = execSync(command, {
|
const stdout = execSync(command, {
|
||||||
cwd: options?.cwd,
|
cwd: options?.cwd,
|
||||||
timeout: options?.timeout,
|
timeout: options?.timeout,
|
||||||
encoding: 'utf-8',
|
encoding: 'utf-8',
|
||||||
shell: EXECUTION_SHELL,
|
shell,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue