mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(scripts): fix spawn EINVAL error on Windows in ui.js
This commit is contained in:
committed by
Peter Steinberger
parent
290f337594
commit
b60b44b42e
@@ -11,7 +11,9 @@ const uiDir = path.join(repoRoot, "ui");
|
||||
|
||||
function usage() {
|
||||
// keep this tiny; it's invoked from npm scripts too
|
||||
process.stderr.write("Usage: node scripts/ui.js <install|dev|build|test> [...args]\n");
|
||||
process.stderr.write(
|
||||
"Usage: node scripts/ui.js <install|dev|build|test> [...args]\n",
|
||||
);
|
||||
}
|
||||
|
||||
function which(cmd) {
|
||||
@@ -22,11 +24,16 @@ function which(cmd) {
|
||||
.filter(Boolean);
|
||||
const extensions =
|
||||
process.platform === "win32"
|
||||
? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM").split(";").filter(Boolean)
|
||||
? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT;.COM")
|
||||
.split(";")
|
||||
.filter(Boolean)
|
||||
: [""];
|
||||
for (const entry of paths) {
|
||||
for (const ext of extensions) {
|
||||
const candidate = path.join(entry, process.platform === "win32" ? `${cmd}${ext}` : cmd);
|
||||
const candidate = path.join(
|
||||
entry,
|
||||
process.platform === "win32" ? `${cmd}${ext}` : cmd,
|
||||
);
|
||||
try {
|
||||
if (fs.existsSync(candidate)) {
|
||||
return candidate;
|
||||
@@ -51,24 +58,31 @@ function resolveRunner() {
|
||||
}
|
||||
|
||||
function run(cmd, args) {
|
||||
const isWindows = process.platform === "win32"; // Windows support
|
||||
const child = spawn(cmd, args, {
|
||||
cwd: uiDir,
|
||||
stdio: "inherit",
|
||||
env: process.env,
|
||||
shell: isWindows,
|
||||
});
|
||||
child.on("exit", (code, signal) => {
|
||||
if (signal) {
|
||||
process.exit(1);
|
||||
child.on("error", (err) => {
|
||||
console.error(`Failed to launch ${cmd}:`, err);
|
||||
process.exit(1);
|
||||
});
|
||||
child.on("exit", (code) => {
|
||||
if (code !== 0) {
|
||||
process.exit(code ?? 1);
|
||||
}
|
||||
process.exit(code ?? 1);
|
||||
});
|
||||
}
|
||||
|
||||
function runSync(cmd, args, envOverride) {
|
||||
const isWindows = process.platform === "win32"; // Windows support
|
||||
const result = spawnSync(cmd, args, {
|
||||
cwd: uiDir,
|
||||
stdio: "inherit",
|
||||
env: envOverride ?? process.env,
|
||||
shell: isWindows,
|
||||
});
|
||||
if (result.signal) {
|
||||
process.exit(1);
|
||||
@@ -127,8 +141,11 @@ if (action === "install") {
|
||||
} else {
|
||||
if (!depsInstalled(action === "test" ? "test" : "build")) {
|
||||
const installEnv =
|
||||
action === "build" ? { ...process.env, NODE_ENV: "production" } : process.env;
|
||||
const installArgs = action === "build" ? ["install", "--prod"] : ["install"];
|
||||
action === "build"
|
||||
? { ...process.env, NODE_ENV: "production" }
|
||||
: process.env;
|
||||
const installArgs =
|
||||
action === "build" ? ["install", "--prod"] : ["install"];
|
||||
runSync(runner.cmd, installArgs, installEnv);
|
||||
}
|
||||
run(runner.cmd, ["run", script, ...rest]);
|
||||
|
||||
Reference in New Issue
Block a user