


































@@ -1,6 +1,6 @@
11#!/usr/bin/env -S node --import tsx
223-import { execFileSync, execSync } from "node:child_process";
3+import { execFileSync } from "node:child_process";
44import {
55existsSync,
66lstatSync,
@@ -43,7 +43,10 @@ import {
4343import {
4444collectInstalledPackageErrors,
4545normalizeInstalledBinaryVersion,
46+resolveInstalledBinaryCommandInvocation,
47+resolveInstalledBinaryPath,
4648} from "./openclaw-npm-postpublish-verify.ts";
49+import { resolveNpmRunner } from "./npm-runner.mjs";
4750import { listStaticExtensionAssetOutputs } from "./runtime-postbuild.mjs";
4851import { sparkleBuildFloorsFromShortVersion, type SparkleBuildFloors } from "./sparkle-build.ts";
4952import { buildCmdExeCommandLine } from "./windows-cmd-helpers.mjs";
@@ -244,8 +247,48 @@ function checkSkillShellScriptsExecutable() {
244247}
245248}
246249250+export function resolveReleaseNpmCommand(
251+args: string[],
252+params: {
253+comSpec?: string;
254+env?: NodeJS.ProcessEnv;
255+execPath?: string;
256+existsSync?: typeof existsSync;
257+platform?: NodeJS.Platform;
258+} = {},
259+) {
260+return resolveNpmRunner({
261+comSpec: params.comSpec,
262+env: params.env,
263+execPath: params.execPath,
264+existsSync: params.existsSync,
265+npmArgs: args,
266+platform: params.platform,
267+});
268+}
269+270+function execNpm(
271+args: string[],
272+options: {
273+cwd?: string;
274+encoding: BufferEncoding;
275+maxBuffer?: number;
276+stdio: "inherit" | ["ignore", "pipe", "pipe"];
277+},
278+): string {
279+const invocation = resolveReleaseNpmCommand(args, { env: process.env });
280+return execFileSync(invocation.command, invocation.args, {
281+ ...options,
282+ ...(invocation.env ? { env: invocation.env } : {}),
283+ ...(invocation.shell !== undefined ? { shell: invocation.shell } : {}),
284+ ...(invocation.windowsVerbatimArguments !== undefined
285+ ? { windowsVerbatimArguments: invocation.windowsVerbatimArguments }
286+ : {}),
287+});
288+}
289+247290function runPackDry(): PackResult[] {
248-const raw = execSync("npm pack --dry-run --json --ignore-scripts", {
291+ const raw = execNpm(["pack", "--dry-run", "--json", "--ignore-scripts"], {
249292encoding: "utf8",
250293stdio: ["ignore", "pipe", "pipe"],
251294maxBuffer: 1024 * 1024 * 100,
@@ -254,15 +297,11 @@ function runPackDry(): PackResult[] {
254297}
255298256299function runPack(packDestination: string): PackResult[] {
257-const raw = execFileSync(
258-"npm",
259-["pack", "--json", "--ignore-scripts", "--pack-destination", packDestination],
260-{
261-encoding: "utf8",
262-stdio: ["ignore", "pipe", "pipe"],
263-maxBuffer: 1024 * 1024 * 100,
264-},
265-);
300+ const raw = execNpm(["pack", "--json", "--ignore-scripts", "--pack-destination", packDestination], {
301+encoding: "utf8",
302+stdio: ["ignore", "pipe", "pipe"],
303+maxBuffer: 1024 * 1024 * 100,
304+});
266305return JSON.parse(raw) as PackResult[];
267306}
268307@@ -279,8 +318,7 @@ function resolvePackedTarballPath(packDestination: string, results: PackResult[]
279318}
280319281320function installPackedTarball(prefixDir: string, tarballPath: string, cwd: string): void {
282-execFileSync(
283-"npm",
321+execNpm(
284322[
285323"install",
286324"-g",
@@ -300,19 +338,13 @@ function installPackedTarball(prefixDir: string, tarballPath: string, cwd: strin
300338}
301339302340function resolveGlobalRoot(prefixDir: string, cwd: string): string {
303-return execFileSync("npm", ["root", "-g", "--prefix", prefixDir], {
341+return execNpm(["root", "-g", "--prefix", prefixDir], {
304342 cwd,
305343encoding: "utf8",
306344stdio: ["ignore", "pipe", "pipe"],
307345}).trim();
308346}
309347310-function resolveInstalledBinaryPath(prefixDir: string): string {
311-return process.platform === "win32"
312- ? join(prefixDir, "openclaw.cmd")
313- : join(prefixDir, "bin", "openclaw");
314-}
315-316348export function createPackedBundledPluginPostinstallEnv(
317349env: NodeJS.ProcessEnv = process.env,
318350): NodeJS.ProcessEnv {
@@ -420,16 +452,13 @@ function verifyPackedInstalledPackage(params: {
420452prefixDir: string;
421453tmpRoot: string;
422454}): void {
423-const installedBinaryVersion = execFileSync(
424-resolveInstalledBinaryPath(params.prefixDir),
425-["--version"],
426-{
427-cwd: params.tmpRoot,
428-encoding: "utf8",
429-shell: process.platform === "win32",
430-stdio: ["ignore", "pipe", "pipe"],
431-},
432-).trim();
455+const invocation = resolveInstalledBinaryCommandInvocation(params.prefixDir, ["--version"]);
456+const installedBinaryVersion = execFileSync(invocation.command, invocation.args, {
457+cwd: params.tmpRoot,
458+encoding: "utf8",
459+stdio: ["ignore", "pipe", "pipe"],
460+windowsVerbatimArguments: invocation.windowsVerbatimArguments,
461+}).trim();
433462const errors = collectPackedInstalledPackageVerificationErrors({
434463expectedVersion: params.expectedVersion,
435464 installedBinaryVersion,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。