orcastrator 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/gh.js +27 -23
- package/package.json +1 -1
package/dist/utils/gh.js
CHANGED
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
2
|
+
function spawnProcess(cmd, args) {
|
|
3
|
+
// Use Bun.spawn when available, fall back to Node.js child_process
|
|
4
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
5
|
+
return (async () => {
|
|
6
|
+
const proc = globalThis.Bun.spawn([cmd, ...args], {
|
|
7
|
+
stdout: "pipe",
|
|
8
|
+
stderr: "pipe"
|
|
9
|
+
});
|
|
10
|
+
const [stdout, stderr, exitCode] = await Promise.all([
|
|
11
|
+
new Response(proc.stdout).text(),
|
|
12
|
+
new Response(proc.stderr).text(),
|
|
13
|
+
proc.exited
|
|
14
|
+
]);
|
|
15
|
+
return { stdout, stderr, exitCode };
|
|
16
|
+
})();
|
|
4
17
|
}
|
|
5
|
-
return new
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
let stdout = "";
|
|
20
|
+
let stderr = "";
|
|
21
|
+
const child = nodeSpawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
22
|
+
child.stdout?.on("data", (d) => { stdout += d.toString(); });
|
|
23
|
+
child.stderr?.on("data", (d) => { stderr += d.toString(); });
|
|
24
|
+
child.on("close", (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }));
|
|
25
|
+
child.on("error", () => resolve({ stdout, stderr, exitCode: 1 }));
|
|
26
|
+
});
|
|
6
27
|
}
|
|
7
28
|
export async function checkGhCli() {
|
|
8
29
|
try {
|
|
9
|
-
const
|
|
10
|
-
stdout: "pipe",
|
|
11
|
-
stderr: "pipe"
|
|
12
|
-
});
|
|
13
|
-
const exitCode = await proc.exited;
|
|
30
|
+
const { exitCode } = await spawnProcess("which", ["gh"]);
|
|
14
31
|
return exitCode === 0;
|
|
15
32
|
}
|
|
16
33
|
catch {
|
|
@@ -18,18 +35,5 @@ export async function checkGhCli() {
|
|
|
18
35
|
}
|
|
19
36
|
}
|
|
20
37
|
export async function runGh(args) {
|
|
21
|
-
|
|
22
|
-
stdout: "pipe",
|
|
23
|
-
stderr: "pipe"
|
|
24
|
-
});
|
|
25
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
26
|
-
decodeStream(proc.stdout),
|
|
27
|
-
decodeStream(proc.stderr),
|
|
28
|
-
proc.exited
|
|
29
|
-
]);
|
|
30
|
-
return {
|
|
31
|
-
stdout,
|
|
32
|
-
stderr,
|
|
33
|
-
exitCode
|
|
34
|
-
};
|
|
38
|
+
return spawnProcess("gh", args);
|
|
35
39
|
}
|