From 8fbb643d05196ca4610d61609581c53ac7807107 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Mon, 22 Apr 2024 13:44:55 -0400 Subject: [PATCH] create separate shell function --- libs/wingsdk/src/shared/misc.ts | 16 +++++++++++++++- .../wingsdk/src/target-sim/container.inflight.ts | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/wingsdk/src/shared/misc.ts b/libs/wingsdk/src/shared/misc.ts index dd3252a1770..d87cfb5a332 100644 --- a/libs/wingsdk/src/shared/misc.ts +++ b/libs/wingsdk/src/shared/misc.ts @@ -1,8 +1,9 @@ -import { ExecOptions, exec } from "child_process"; +import { ExecOptions, ExecFileOptions, exec, execFile } from "child_process"; import { readFileSync } from "fs"; import { promisify } from "util"; const execPromise = promisify(exec); +const execFilePromise = promisify(execFile); export function readJsonSync(file: string) { return JSON.parse(readFileSync(file, "utf-8")); @@ -27,6 +28,19 @@ export function normalPath(path: string) { * Just a helpful wrapper around `execFile` that returns a promise. */ export async function runCommand( + cmd: string, + args: string[], + options?: ExecFileOptions +): Promise { + const { stdout } = await execFilePromise(cmd, args, options); + return stdout; +} + +/** + * Just a helpful wrapper around `exec` that returns a promise. + * This will run commands through the shell, while `runCommand` doesn't. + */ +export async function shell( cmd: string, args: string[], options?: ExecOptions diff --git a/libs/wingsdk/src/target-sim/container.inflight.ts b/libs/wingsdk/src/target-sim/container.inflight.ts index 5af352047e8..b792a1c9d22 100644 --- a/libs/wingsdk/src/target-sim/container.inflight.ts +++ b/libs/wingsdk/src/target-sim/container.inflight.ts @@ -1,6 +1,6 @@ import { IContainerClient, HOST_PORT_ATTR } from "./container"; import { ContainerAttributes, ContainerSchema } from "./schema-resources"; -import { isPath, runCommand } from "../shared/misc"; +import { isPath, runCommand, shell } from "../shared/misc"; import { ISimulatorContext, ISimulatorResourceInstance, @@ -91,7 +91,7 @@ export class Container implements IContainerClient, ISimulatorResourceInstance { this.log(`starting container from image ${this.imageTag}`); this.log(`docker ${dockerRun.join(" ")}`); - await runCommand("docker", dockerRun, { + await shell("docker", dockerRun, { env: { ...process.env, [WING_STATE_DIR_ENV]: this.context.statedir,