mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:00:42 +00:00
fix: handle native pnpm execpath
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createPnpmRunnerSpawnSpec, resolvePnpmRunner } from "../../scripts/pnpm-runner.mjs";
|
||||
|
||||
describe("resolvePnpmRunner", () => {
|
||||
it("uses npm_execpath when it points to pnpm", () => {
|
||||
it("uses npm_execpath when it points to a JS pnpm entrypoint", () => {
|
||||
expect(
|
||||
resolvePnpmRunner({
|
||||
npmExecPath: "/home/test/.cache/node/corepack/v1/pnpm/10.32.1/bin/pnpm.cjs",
|
||||
@@ -22,6 +25,29 @@ describe("resolvePnpmRunner", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("uses npm_execpath when it points to a shebang pnpm script", () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
|
||||
const npmExecPath = path.join(tempDir, "pnpm");
|
||||
writeFileSync(npmExecPath, "#!/usr/bin/env node\nconsole.log('pnpm');\n");
|
||||
|
||||
try {
|
||||
expect(
|
||||
resolvePnpmRunner({
|
||||
npmExecPath,
|
||||
nodeExecPath: "/usr/local/bin/node",
|
||||
pnpmArgs: ["exec", "vitest", "run"],
|
||||
platform: "linux",
|
||||
}),
|
||||
).toEqual({
|
||||
command: "/usr/local/bin/node",
|
||||
args: [npmExecPath, "exec", "vitest", "run"],
|
||||
shell: false,
|
||||
});
|
||||
} finally {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("prepends node args when launching pnpm through node", () => {
|
||||
expect(
|
||||
resolvePnpmRunner({
|
||||
@@ -44,6 +70,28 @@ describe("resolvePnpmRunner", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to bare pnpm when npm_execpath points to a native pnpm binary", () => {
|
||||
const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
|
||||
const npmExecPath = path.join(tempDir, "pnpm");
|
||||
writeFileSync(npmExecPath, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
|
||||
|
||||
try {
|
||||
expect(
|
||||
resolvePnpmRunner({
|
||||
npmExecPath,
|
||||
pnpmArgs: ["exec", "vitest", "run"],
|
||||
platform: "linux",
|
||||
}),
|
||||
).toEqual({
|
||||
command: "pnpm",
|
||||
args: ["exec", "vitest", "run"],
|
||||
shell: false,
|
||||
});
|
||||
} finally {
|
||||
rmSync(tempDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("falls back to bare pnpm on non-Windows when npm_execpath is missing", () => {
|
||||
expect(
|
||||
resolvePnpmRunner({
|
||||
|
||||
Reference in New Issue
Block a user