Skip to content

Commit

Permalink
create separate shell function
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Apr 22, 2024
1 parent 8d5522c commit 8fbb643
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion libs/wingsdk/src/shared/misc.ts
Original file line number Diff line number Diff line change
@@ -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"));
Expand All @@ -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<any> {
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
Expand Down
4 changes: 2 additions & 2 deletions libs/wingsdk/src/target-sim/container.inflight.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8fbb643

Please sign in to comment.