mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-29 03:01:18 +00:00
On Windows, PATH entries wrapped in double quotes (for example "C:\Program Files\nodejs") were rejected before Node could be probed, so startup/update Node runtime recovery and Node discovery under Bun failed. One shared parser now unwraps entries quoted at both ends (embedded quotes stay literal) for recovery and discovery, while relative-path rejection and POSIX splitting are unchanged. Supersedes #181652, thanks @Links2008. Co-authored-by: Links <222737184+Links2008@users.noreply.github.com>
27 lines
1 KiB
JavaScript
27 lines
1 KiB
JavaScript
import path from "node:path";
|
|
|
|
export function nodeRuntimePathEntries(value) {
|
|
const windows = process.platform === "win32";
|
|
return (value ?? "")
|
|
.split(windows ? ";" : ":")
|
|
.map((entry) => (windows ? entry.replace(/^"(.*)"$/, "$1") : entry))
|
|
.filter(Boolean);
|
|
}
|
|
|
|
/** Keep lifecycle children on the explicitly selected runtime without changing npm config. */
|
|
export function withNodeRuntimePath(env, nodePath, platform = process.platform) {
|
|
const paths = platform === "win32" ? path.win32 : path.posix;
|
|
const keys = Object.keys(env)
|
|
.toSorted()
|
|
.filter((key) => (platform === "win32" ? key.toUpperCase() === "PATH" : key === "PATH"));
|
|
const key = keys[0] ?? "PATH";
|
|
const directory = paths.dirname(nodePath);
|
|
const entries = (env[key] ? env[key].split(paths.delimiter) : []).filter(
|
|
(entry) => entry !== directory,
|
|
);
|
|
const result = { ...env };
|
|
for (const pathKey of keys.length ? keys : [key]) {
|
|
result[pathKey] = [directory, ...entries].join(paths.delimiter);
|
|
}
|
|
return result;
|
|
}
|