Skip to content

Commit

Permalink
fix(sdk): unable to use util.exec in preflight (#7019)
Browse files Browse the repository at this point in the history
fixes: #6915

## Checklist

- [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted)
- [ ] Description explains motivation and solution
- [ ] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
tsuf239 authored Aug 22, 2024
1 parent eca0508 commit 9f49b16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 6 additions & 0 deletions examples/tests/sdk_tests/util/exec.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ let assertThrows = inflight (expected: str, block: (): void) => {
assert(error);
};

let output1 = util.exec("echo", ["-n", "Hello, Wing!"]);

expect.equal(output1.stdout, "Hello, Wing!");
expect.equal(output1.stderr, "");
expect.equal(output1.status, 0);


test "exec()" {
// "exec() with valid program"
Expand Down
13 changes: 6 additions & 7 deletions libs/wingsdk/src/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { exec, execFile } from "child_process";
import { exec, execFileSync } from "child_process";
import { createHash } from "crypto";
import { promisify } from "util";
import { nanoid, customAlphabet } from "nanoid";
Expand All @@ -9,7 +9,6 @@ import { InflightClient } from "../core";
import { Duration, IInflight } from "../std";

const execPromise = promisify(exec);
const execFilePromise = promisify(execFile);

/**
* Describes what to do with a standard I/O stream for a child process.
Expand Down Expand Up @@ -223,11 +222,11 @@ export class Util {
* @param opts `ExecOptions`, such as the working directory and environment variables.
* @returns A struct containing `stdout`, `stderr` and exit `status` of the executed program.
*/
public static async exec(
public static exec(
program: string,
args: Array<string>,
opts?: ExecOptions
): Promise<Output> {
): Output {
const execOpts = {
windowsHide: true,
shell: false,
Expand All @@ -239,10 +238,10 @@ export class Util {
};

try {
const { stdout, stderr } = await execFilePromise(program, args, execOpts);
const stdout = execFileSync(program, args, execOpts);
return {
stdout: stdout.toString(),
stderr: stderr.toString(),
stderr: "",
status: 0,
};
} catch (error: any) {
Expand All @@ -252,7 +251,7 @@ export class Util {
return {
stdout: error.stdout.toString(),
stderr: error.stderr.toString(),
status: error.code,
status: error.status,
};
}
}
Expand Down

0 comments on commit 9f49b16

Please sign in to comment.