Skip to content

Commit 7421400

Browse files
committed
fix(release): preserve npm pack json output
1 parent 33afb1e commit 7421400

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

scripts/openclaw-prepack.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,29 @@ export function resolvePrepackCommandTimeoutMs(env: NodeJS.ProcessEnv = process.
117117
);
118118
}
119119

120+
export function resolvePrepackCommandStdio(
121+
options: SpawnSyncOptions,
122+
env: NodeJS.ProcessEnv = process.env,
123+
): SpawnSyncOptions["stdio"] {
124+
const requestedStdio = options.stdio ?? "inherit";
125+
const npmJsonOutput = env.npm_config_json === "true" || env.npm_config_json === "1";
126+
if (npmJsonOutput && requestedStdio === "inherit") {
127+
return ["inherit", 2, "inherit"];
128+
}
129+
return requestedStdio;
130+
}
131+
120132
export function runPrepackCommand(
121133
command: string,
122134
args: string[],
123135
options: SpawnSyncOptions = {},
124136
): ReturnType<typeof spawnSync> {
125137
const env = options.env ?? process.env;
126138
return spawnSync(command, args, {
127-
stdio: "inherit",
128139
...options,
129140
env,
130141
killSignal: options.killSignal ?? "SIGKILL",
142+
stdio: resolvePrepackCommandStdio(options, env),
131143
timeout: options.timeout ?? resolvePrepackCommandTimeoutMs(env),
132144
});
133145
}

test/openclaw-prepack.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { describe, expect, it } from "vitest";
33
import {
44
collectPreparedPrepackErrors,
5+
resolvePrepackCommandStdio,
56
resolvePrepackCommandTimeoutMs,
67
runPrepackCommand,
78
} from "../scripts/openclaw-prepack.ts";
@@ -26,6 +27,20 @@ describe("collectPreparedPrepackErrors", () => {
2627
});
2728

2829
describe("runPrepackCommand", () => {
30+
it("keeps prepack child stdout off npm pack JSON stdout", () => {
31+
expect(resolvePrepackCommandStdio({ stdio: "inherit" }, { npm_config_json: "true" })).toEqual([
32+
"inherit",
33+
2,
34+
"inherit",
35+
]);
36+
expect(
37+
resolvePrepackCommandStdio(
38+
{ stdio: ["ignore", "pipe", "pipe"] },
39+
{ npm_config_json: "true" },
40+
),
41+
).toEqual(["ignore", "pipe", "pipe"]);
42+
});
43+
2944
it("returns captured output for successful commands", () => {
3045
const result = runPrepackCommand(process.execPath, ["--eval", "process.stdout.write('ok')"], {
3146
encoding: "utf8",

0 commit comments

Comments
 (0)