Fix processRunner exports, runtimeEnvironment leak, and null exit code message
- Remove unnecessary exports from processRunner.ts: toRuntimeCommandOptions, ManagedChildProcess, RuntimeCommandOptions, spawnPipedProcess, ProcessSpawnOptions, ProcessSpawnSyncOptions, killProcessTree - Destructure runtimeEnvironment out of options in toRuntimeCommandOptions to prevent leaking it into ChildProcess.make - Handle null exit code in detailFromResult to produce a clear message instead of 'Command exited with code null' Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
df5009c70b
commit
04ffe3b247
2 files changed
+12
-8
No files matched your search
@@ -24,16 +24,16 @@ interface RuntimeShellOptions {
|
||||
shell?: boolean | string | undefined;
|
||||
}
|
||||
|
||||
export interface ProcessSpawnOptions extends ProcessSpawnBaseOptions {
|
||||
interface ProcessSpawnOptions extends ProcessSpawnBaseOptions {
|
||||
stdio?: StdioOptions | undefined;
|
||||
detached?: boolean | undefined;
|
||||
}
|
||||
|
||||
export interface RuntimeCommandOptions extends ChildProcess.CommandOptions {
|
||||
interface RuntimeCommandOptions extends ChildProcess.CommandOptions {
|
||||
runtimeEnvironment?: ServerRuntimeEnvironment | undefined;
|
||||
}
|
||||
|
||||
export interface ProcessSpawnSyncOptions extends ProcessSpawnBaseOptions {
|
||||
interface ProcessSpawnSyncOptions extends ProcessSpawnBaseOptions {
|
||||
stdio?: StdioOptions | undefined;
|
||||
detached?: boolean | undefined;
|
||||
encoding?: BufferEncoding | undefined;
|
||||
@@ -90,11 +90,12 @@ function toSpawnOptions(options: ProcessSpawnOptions) {
|
||||
};
|
||||
}
|
||||
|
||||
export function toRuntimeCommandOptions(
|
||||
function toRuntimeCommandOptions(
|
||||
options: RuntimeCommandOptions = {},
|
||||
): ChildProcess.CommandOptions {
|
||||
const { runtimeEnvironment: _, ...rest } = options;
|
||||
return {
|
||||
...options,
|
||||
...rest,
|
||||
shell: options.shell ?? shouldUseShell(options),
|
||||
};
|
||||
}
|
||||
@@ -107,7 +108,7 @@ export function makeRuntimeCommand(
|
||||
return ChildProcess.make(command, [...args], toRuntimeCommandOptions(options));
|
||||
}
|
||||
|
||||
export interface ManagedChildProcess {
|
||||
interface ManagedChildProcess {
|
||||
readonly scope: Scope.Closeable;
|
||||
readonly handle: ChildProcessSpawner.ChildProcessHandle;
|
||||
}
|
||||
@@ -135,7 +136,7 @@ function spawnProcess(
|
||||
return spawn(command, args, toSpawnOptions(options));
|
||||
}
|
||||
|
||||
export function spawnPipedProcess(
|
||||
function spawnPipedProcess(
|
||||
command: string,
|
||||
args: readonly string[],
|
||||
options: Omit<ProcessSpawnOptions, "stdio" | "detached"> = {},
|
||||
@@ -252,7 +253,7 @@ const DEFAULT_MAX_BUFFER_BYTES = 8 * 1024 * 1024;
|
||||
* wrapper, leaving the actual command running. Use `taskkill /T` to kill the
|
||||
* entire process tree instead.
|
||||
*/
|
||||
export function killProcessTree(
|
||||
function killProcessTree(
|
||||
child: ChildProcessHandle,
|
||||
options: {
|
||||
runtimeEnvironment?: ServerRuntimeEnvironment | undefined;
|
||||
|
||||
@@ -76,6 +76,9 @@ function detailFromResult(
|
||||
if (stderr) return stderr;
|
||||
const stdout = nonEmptyTrimmed(result.stdout);
|
||||
if (stdout) return stdout;
|
||||
if (result.code === null) {
|
||||
return "Command was terminated before reporting an exit code.";
|
||||
}
|
||||
if (result.code !== 0) {
|
||||
return `Command exited with code ${result.code}.`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user