mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:10:52 +00:00
fix: handle native pnpm execpath
This commit is contained in:
@@ -1,9 +1,43 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { closeSync, openSync, readSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { buildCmdExeCommandLine } from "./windows-cmd-helpers.mjs";
|
||||
|
||||
function isPnpmExecPath(value) {
|
||||
return /^pnpm(?:-cli)?(?:\.(?:c?js|cmd|exe))?$/.test(path.basename(value).toLowerCase());
|
||||
return /^pnpm(?:-cli)?(?:\.([cm]?js|cmd|exe))?$/.test(path.basename(value).toLowerCase());
|
||||
}
|
||||
|
||||
function hasScriptShebang(value) {
|
||||
let fd;
|
||||
try {
|
||||
fd = openSync(value, "r");
|
||||
const header = Buffer.alloc(2);
|
||||
return (
|
||||
readSync(fd, header, 0, header.length, 0) === header.length &&
|
||||
header[0] === 0x23 &&
|
||||
header[1] === 0x21
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
if (fd !== undefined) {
|
||||
closeSync(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isNodeRunnablePnpmExecPath(value) {
|
||||
if (!isPnpmExecPath(value)) {
|
||||
return false;
|
||||
}
|
||||
const extension = path.extname(value).toLowerCase();
|
||||
if (extension === ".js" || extension === ".cjs" || extension === ".mjs") {
|
||||
return true;
|
||||
}
|
||||
if (extension.length > 0) {
|
||||
return false;
|
||||
}
|
||||
return hasScriptShebang(value);
|
||||
}
|
||||
|
||||
export function resolvePnpmRunner(params = {}) {
|
||||
@@ -14,7 +48,11 @@ export function resolvePnpmRunner(params = {}) {
|
||||
const platform = params.platform ?? process.platform;
|
||||
const comSpec = params.comSpec ?? process.env.ComSpec ?? "cmd.exe";
|
||||
|
||||
if (typeof npmExecPath === "string" && npmExecPath.length > 0 && isPnpmExecPath(npmExecPath)) {
|
||||
if (
|
||||
typeof npmExecPath === "string" &&
|
||||
npmExecPath.length > 0 &&
|
||||
isNodeRunnablePnpmExecPath(npmExecPath)
|
||||
) {
|
||||
return {
|
||||
command: nodeExecPath,
|
||||
args: [...nodeArgs, npmExecPath, ...pnpmArgs],
|
||||
|
||||
Reference in New Issue
Block a user