























@@ -1,10 +1,12 @@
1-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
1+import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
22import os from "node:os";
33import path from "node:path";
44import { describe, expect, it } from "vitest";
55import { createPnpmRunnerSpawnSpec, resolvePnpmRunner } from "../../scripts/pnpm-runner.mjs";
6677describe("resolvePnpmRunner", () => {
8+const posixIt = process.platform === "win32" ? it.skip : it;
9+810it("uses npm_execpath when it points to a JS pnpm entrypoint", () => {
911expect(
1012resolvePnpmRunner({
@@ -70,10 +72,34 @@ describe("resolvePnpmRunner", () => {
7072});
7173});
727473-it("falls back to bare pnpm when npm_execpath points to a native pnpm binary", () => {
75+it("executes native pnpm binaries from npm_execpath directly on non-Windows", () => {
76+const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
77+const npmExecPath = path.join(tempDir, "pnpm");
78+writeFileSync(npmExecPath, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
79+chmodSync(npmExecPath, 0o755);
80+81+try {
82+expect(
83+resolvePnpmRunner({
84+ npmExecPath,
85+pnpmArgs: ["exec", "vitest", "run"],
86+platform: "linux",
87+}),
88+).toEqual({
89+command: npmExecPath,
90+args: ["exec", "vitest", "run"],
91+shell: false,
92+});
93+} finally {
94+rmSync(tempDir, { recursive: true, force: true });
95+}
96+});
97+98+posixIt("falls back to bare pnpm when native npm_execpath is not executable", () => {
7499const tempDir = mkdtempSync(path.join(os.tmpdir(), "pnpm-runner-"));
75100const npmExecPath = path.join(tempDir, "pnpm");
76101writeFileSync(npmExecPath, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
102+chmodSync(npmExecPath, 0o644);
7710378104try {
79105expect(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。