Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
219 lines
6.1 KiB
JavaScript
219 lines
6.1 KiB
JavaScript
// Resolves and spawns pnpm commands portably across POSIX and Windows shells.
|
|
import { spawn } from "node:child_process";
|
|
import { accessSync, closeSync, constants, openSync, readSync, statSync } from "node:fs";
|
|
import path from "node:path";
|
|
import {
|
|
buildCmdExeCommandLine,
|
|
resolvePathEnvKey,
|
|
resolveWindowsCmdExePath,
|
|
} from "./windows-cmd-helpers.mjs";
|
|
|
|
function getPortableBasename(value) {
|
|
return value.split(/[/\\]/).at(-1) ?? value;
|
|
}
|
|
|
|
function getPortableExtension(value) {
|
|
return path.posix.extname(getPortableBasename(value)).toLowerCase();
|
|
}
|
|
|
|
function isPnpmExecPath(value) {
|
|
return /^pnpm(?:-cli)?(?:\.(?:[cm]?js|cmd|exe))?$/.test(getPortableBasename(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 isExecutableFile(value) {
|
|
try {
|
|
if (!statSync(value).isFile()) {
|
|
return false;
|
|
}
|
|
accessSync(value, constants.X_OK);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function isFile(value) {
|
|
try {
|
|
return statSync(value).isFile();
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function findExecutableOnPath(command, envPath, platform, env, cwd) {
|
|
if (typeof envPath !== "string" || envPath.length === 0) {
|
|
return null;
|
|
}
|
|
const extensions =
|
|
platform === "win32"
|
|
? (
|
|
env[Object.keys(env).find((key) => key.toLowerCase() === "pathext") ?? "PATHEXT"] ??
|
|
".COM;.EXE;.BAT;.CMD"
|
|
)
|
|
.split(";")
|
|
.filter(Boolean)
|
|
.map((extension) => extension.toLowerCase())
|
|
: [""];
|
|
const pathDelimiter = platform === "win32" ? ";" : path.delimiter;
|
|
for (const directory of envPath.split(pathDelimiter)) {
|
|
if (!directory) {
|
|
continue;
|
|
}
|
|
const resolvedDirectory = path.isAbsolute(directory) ? directory : path.resolve(cwd, directory);
|
|
for (const extension of extensions) {
|
|
const candidate = path.join(resolvedDirectory, `${command}${extension}`);
|
|
if (platform === "win32" ? isFile(candidate) : isExecutableFile(candidate)) {
|
|
return candidate;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function createWindowsRunner(command, args, comSpec) {
|
|
const extension = getPortableExtension(command);
|
|
if (extension === ".cmd" || extension === ".bat") {
|
|
return {
|
|
command: comSpec,
|
|
args: ["/d", "/s", "/c", buildCmdExeCommandLine(command, args)],
|
|
shell: false,
|
|
windowsVerbatimArguments: true,
|
|
};
|
|
}
|
|
return { command, args, shell: false };
|
|
}
|
|
|
|
function isNodeRunnablePnpmExecPath(value) {
|
|
if (!isPnpmExecPath(value)) {
|
|
return false;
|
|
}
|
|
const extension = getPortableExtension(value);
|
|
if (extension === ".js" || extension === ".cjs" || extension === ".mjs") {
|
|
return isFile(value);
|
|
}
|
|
if (extension.length > 0) {
|
|
return false;
|
|
}
|
|
return hasScriptShebang(value);
|
|
}
|
|
|
|
/**
|
|
* Resolves the command/args needed to invoke pnpm on the current platform.
|
|
*/
|
|
export function resolvePnpmRunner(params = {}) {
|
|
const pnpmArgs = params.pnpmArgs ?? [];
|
|
const nodeArgs = params.nodeArgs ?? [];
|
|
const npmExecPath = params.npmExecPath ?? process.env.npm_execpath;
|
|
const nodeExecPath = params.nodeExecPath ?? process.execPath;
|
|
const platform = params.platform ?? process.platform;
|
|
const env = params.env ?? process.env;
|
|
const comSpec = params.comSpec ?? (platform === "win32" ? resolveWindowsCmdExePath(env) : "");
|
|
const envPath = env[platform === "win32" ? resolvePathEnvKey(env) : "PATH"];
|
|
const cwd = params.cwd ?? process.cwd();
|
|
|
|
if (typeof npmExecPath === "string" && npmExecPath.length > 0 && isPnpmExecPath(npmExecPath)) {
|
|
if (isNodeRunnablePnpmExecPath(npmExecPath)) {
|
|
return {
|
|
command: nodeExecPath,
|
|
args: [...nodeArgs, npmExecPath, ...pnpmArgs],
|
|
shell: false,
|
|
};
|
|
}
|
|
|
|
const npmExecExtension = getPortableExtension(npmExecPath);
|
|
if (platform !== "win32" && npmExecExtension.length === 0 && isExecutableFile(npmExecPath)) {
|
|
return {
|
|
command: npmExecPath,
|
|
args: pnpmArgs,
|
|
shell: false,
|
|
};
|
|
}
|
|
if (platform === "win32" && npmExecExtension === ".exe") {
|
|
return {
|
|
command: npmExecPath,
|
|
args: pnpmArgs,
|
|
shell: false,
|
|
};
|
|
}
|
|
if (platform === "win32" && npmExecExtension === ".cmd") {
|
|
return {
|
|
command: comSpec,
|
|
args: ["/d", "/s", "/c", buildCmdExeCommandLine(npmExecPath, pnpmArgs)],
|
|
shell: false,
|
|
windowsVerbatimArguments: true,
|
|
};
|
|
}
|
|
}
|
|
|
|
const pnpmPath = findExecutableOnPath("pnpm", envPath, platform, env, cwd);
|
|
if (pnpmPath) {
|
|
return platform === "win32"
|
|
? createWindowsRunner(pnpmPath, pnpmArgs, comSpec)
|
|
: { command: pnpmPath, args: pnpmArgs, shell: false };
|
|
}
|
|
const corepackPath = findExecutableOnPath("corepack", envPath, platform, env, cwd);
|
|
if (corepackPath) {
|
|
const args = ["pnpm", ...pnpmArgs];
|
|
return platform === "win32"
|
|
? createWindowsRunner(corepackPath, args, comSpec)
|
|
: { command: corepackPath, args, shell: false };
|
|
}
|
|
|
|
if (platform === "win32") {
|
|
return createWindowsRunner("pnpm.cmd", pnpmArgs, comSpec);
|
|
}
|
|
|
|
return {
|
|
command: "pnpm",
|
|
args: pnpmArgs,
|
|
shell: false,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Creates a spawn-ready pnpm invocation with standard options.
|
|
*/
|
|
export function createPnpmRunnerSpawnSpec(params = {}) {
|
|
const env = params.env ?? process.env;
|
|
const runner = resolvePnpmRunner({ ...params, env });
|
|
return {
|
|
command: runner.command,
|
|
args: runner.args,
|
|
options: {
|
|
cwd: params.cwd,
|
|
detached: params.detached,
|
|
stdio: params.stdio ?? "inherit",
|
|
env: params.env ?? runner.env ?? process.env,
|
|
shell: runner.shell,
|
|
windowsVerbatimArguments: runner.windowsVerbatimArguments,
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Spawns a pnpm command using the portable runner resolution.
|
|
*/
|
|
export function spawnPnpmRunner(params = {}) {
|
|
const spawnSpec = createPnpmRunnerSpawnSpec(params);
|
|
return spawn(spawnSpec.command, spawnSpec.args, spawnSpec.options);
|
|
}
|