# Conflicts: # packages/client/connection/src/client/fixture.ts # packages/client/connection/tests/fake-api.ts # packages/client/runtime/src/client/workspaces/service.ts # packages/client/runtime/tests/fake-api.ts # packages/client/ui-workspace/src/client/WorkspaceBrowser.tsx # packages/client/ui-workspace/src/client/WorkspacePicker.tsx # packages/client/ui-workspace/tests/workspace-picker.spec.tsx # packages/host/apiproxy/README.i18n.yaml # packages/host/apiproxy/src/api-proxy.ts # packages/host/apiproxy/src/api/host.schema.ts # packages/host/apiproxy/src/api/host.ts # packages/host/apiproxy/src/api/rpc-map.ts # packages/host/apiproxy/src/fetch/client.ts # packages/host/apiproxy/src/fetch/handler.ts # packages/host/apiproxy/tests/api-proxy-workspace.spec.ts # packages/host/apiproxy/tests/client-handler.spec.ts # packages/host/apiproxy/tests/fetch-carrier.spec.ts
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
/** Shared no-shell `execFile` runner for native host dialogs and openers. */
|
|
|
|
import { execFile } from 'node:child_process'
|
|
|
|
/** Testable command boundary; native implementations never invoke a shell. */
|
|
export type NativeCommandRunner = (
|
|
command: string,
|
|
args: readonly string[],
|
|
signal: AbortSignal,
|
|
) => Promise<{ stdout: string; stderr: string }>
|
|
|
|
/**
|
|
* Run a host command with utf8 stdio, abort propagation, and Windows hide.
|
|
* @param command - executable path or PATH name.
|
|
* @param args - argv (never a shell string).
|
|
* @param signal - caller/connection lifetime; abort terminates the child.
|
|
* @returns captured stdout/stderr on exit 0.
|
|
*/
|
|
export const runNativeCommand: NativeCommandRunner = (command, args, signal) =>
|
|
new Promise((resolve, reject) => {
|
|
execFile(
|
|
command,
|
|
[...args],
|
|
{ encoding: 'utf8', signal, windowsHide: true },
|
|
(error, stdout, stderr) => {
|
|
if (error !== null) {
|
|
const failure = Object.assign(new Error(error.message, { cause: error }), {
|
|
code: error.code,
|
|
stdout,
|
|
stderr,
|
|
})
|
|
reject(failure)
|
|
return
|
|
}
|
|
resolve({ stdout, stderr })
|
|
},
|
|
)
|
|
})
|