mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
fix: preserve current Node for node.exe env wrappers (#103907)
* fix: preserve current Node for node.exe env wrappers * fix(scripts): preserve Windows Node aliases * chore: keep contributor PR release-note only --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
co-authored by
Peter Steinberger
parent
9dee9ebffa
commit
0e0c922cc5
@@ -48,10 +48,19 @@ export function parseRunWithEnvArgs(argv) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves node to the current executable so wrapper and child use the same runtime.
|
||||
* Resolves bare Node command names to the current executable so wrapper and child use the same
|
||||
* runtime. Windows command lookup is case-insensitive; explicit paths remain caller-owned.
|
||||
*/
|
||||
export function resolveSpawnCommand(command, args, execPath = process.execPath) {
|
||||
if (command === "node") {
|
||||
export function resolveSpawnCommand(
|
||||
command,
|
||||
args,
|
||||
execPath = process.execPath,
|
||||
platform = process.platform,
|
||||
) {
|
||||
const normalizedCommand = platform === "win32" ? command.toLowerCase() : command;
|
||||
const isNodeCommand =
|
||||
normalizedCommand === "node" || (platform === "win32" && normalizedCommand === "node.exe");
|
||||
if (isNodeCommand) {
|
||||
return {
|
||||
command: execPath,
|
||||
args,
|
||||
|
||||
@@ -143,10 +143,33 @@ describe("run-with-env", () => {
|
||||
expect(result.stderr).toContain("invalid environment assignment");
|
||||
});
|
||||
|
||||
it("uses the current Node executable for node commands", () => {
|
||||
expect(resolveSpawnCommand("node", ["scripts/run-vitest.mjs"], "node.exe")).toEqual({
|
||||
command: "node.exe",
|
||||
args: ["scripts/run-vitest.mjs"],
|
||||
it("uses the current Node executable for bare Node command names", () => {
|
||||
const args = ["scripts/run-vitest.mjs"];
|
||||
expect(resolveSpawnCommand("node", args, "/usr/bin/node", "linux")).toEqual({
|
||||
command: "/usr/bin/node",
|
||||
args,
|
||||
});
|
||||
for (const command of ["node", "NODE", "node.exe", "Node.Exe"]) {
|
||||
expect(resolveSpawnCommand(command, args, "C:\\Node24\\node.exe", "win32")).toEqual({
|
||||
command: "C:\\Node24\\node.exe",
|
||||
args,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves platform-specific and explicitly pathed commands", () => {
|
||||
const args = ["scripts/run-vitest.mjs"];
|
||||
for (const command of ["NODE", "node.exe", "C:\\Tools\\node.exe"]) {
|
||||
expect(resolveSpawnCommand(command, args, "/usr/bin/node", "linux")).toEqual({
|
||||
command,
|
||||
args,
|
||||
});
|
||||
}
|
||||
expect(
|
||||
resolveSpawnCommand("C:\\Tools\\node.exe", args, "C:\\Node24\\node.exe", "win32"),
|
||||
).toEqual({
|
||||
command: "C:\\Tools\\node.exe",
|
||||
args,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user