fix(smartshell): avoid triple shell nesting, improve WSL path filtering, and use chunked log buffer to reduce memory usage
This commit is contained in:
@@ -28,6 +28,17 @@ export class ShellEnv {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if running under Windows Subsystem for Linux
|
||||
*/
|
||||
private static _isWSL(): boolean {
|
||||
return !!(
|
||||
process.env.WSL_DISTRO_NAME ||
|
||||
process.env.WSLENV ||
|
||||
(process.platform === 'linux' && process.env.PATH?.includes('/mnt/c/'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* imports path into the shell from env if available and returns it with
|
||||
*/
|
||||
@@ -39,18 +50,16 @@ export class ShellEnv {
|
||||
commandPaths = commandPaths.concat(process.env.SMARTSHELL_PATH.split(':'));
|
||||
}
|
||||
|
||||
// lets filter for unwanted paths
|
||||
// Windows WSL
|
||||
commandPaths = commandPaths.filter((commandPathArg) => {
|
||||
const filterResult =
|
||||
!commandPathArg.startsWith('/mnt/c/') &&
|
||||
!commandPathArg.startsWith('Files/1E') &&
|
||||
!commandPathArg.includes(' ');
|
||||
if (!filterResult) {
|
||||
// console.log(`${commandPathArg} will be filtered!`);
|
||||
}
|
||||
return filterResult;
|
||||
});
|
||||
// Only filter out WSL-specific paths when actually running under WSL
|
||||
if (ShellEnv._isWSL()) {
|
||||
commandPaths = commandPaths.filter((commandPathArg) => {
|
||||
return (
|
||||
!commandPathArg.startsWith('/mnt/c/') &&
|
||||
!commandPathArg.startsWith('Files/1E') &&
|
||||
!commandPathArg.includes(' ')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
commandResult = `PATH=${commandPaths.join(':')} && ${commandStringArg}`;
|
||||
return commandResult;
|
||||
@@ -89,14 +98,12 @@ export class ShellEnv {
|
||||
}
|
||||
pathString += ` && `;
|
||||
|
||||
switch (this.executor) {
|
||||
case 'bash':
|
||||
commandResult = `bash -c '${pathString}${sourceString}${commandArg}'`;
|
||||
break;
|
||||
case 'sh':
|
||||
commandResult = `${pathString}${sourceString}${commandArg}`;
|
||||
break;
|
||||
}
|
||||
// For both bash and sh executors, build the command string directly.
|
||||
// The shell nesting is handled by spawn() using the appropriate shell binary.
|
||||
// Previously bash executor wrapped in `bash -c '...'` which caused triple
|
||||
// shell nesting (Node spawn sh -> bash -c -> command). Now spawn() uses
|
||||
// shell: '/bin/bash' directly, so we don't need the extra wrapping.
|
||||
commandResult = `${pathString}${sourceString}${commandArg}`;
|
||||
commandResult = this._setPath(commandResult);
|
||||
return commandResult;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user