Skip to content

Commit 4389f84

Browse files
fix(process): skip codepage probe for UTF-8 output
Co-authored-by: 杨浩宇0668001029 <[email protected]>
1 parent 1ae9cd4 commit 4389f84

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/process/exec-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async function runCommandWithOutputEncoding(
139139
MAX_PRESERVED_PENDING_LINE_BYTES,
140140
);
141141
const maxPreservedOutputLines = Math.max(0, Math.floor(options.maxPreservedOutputLines ?? 16));
142-
const windowsEncoding = resolveWindowsConsoleEncoding();
142+
const windowsEncoding = forceUtf8 ? null : resolveWindowsConsoleEncoding();
143143
const cancelController = new AbortController();
144144
let termination: CommandTerminationReason | undefined;
145145
let childExitState: { code: number | null; signal: NodeJS.Signals | null } | undefined;

src/process/exec.windows.integration.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe("runUtf8CommandWithTimeout Windows integration", () => {
77
"keeps truncated UTF-8 head output on a code point boundary",
88
async () => {
99
const result = await runUtf8CommandWithTimeout(
10-
[process.execPath, "-e", "process.stdout.write('a😀z')"],
10+
[process.execPath, "-e", "process.stdout.write('a😀z'); process.stderr.write('b😀y')"],
1111
{
1212
maxOutputBytes: 3,
1313
outputCapture: "head",
@@ -16,7 +16,9 @@ describe("runUtf8CommandWithTimeout Windows integration", () => {
1616
);
1717

1818
expect(result.stdout).toBe("a");
19+
expect(result.stderr).toBe("b");
1920
expect(result.stdoutTruncatedBytes).toBe(5);
21+
expect(result.stderrTruncatedBytes).toBe(5);
2022
},
2123
);
2224
});

src/process/exec.windows.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,10 @@ describe("Windows command execution", () => {
533533

534534
it("keeps truncated UTF-8 head output on a code point boundary", async () => {
535535
execaMock.mockImplementationOnce(() =>
536-
createMockSubprocess({ stdoutChunks: [Buffer.from("a😀z", "utf8")] }),
536+
createMockSubprocess({
537+
stdoutChunks: [Buffer.from("a😀z", "utf8")],
538+
stderrChunks: [Buffer.from("b😀y", "utf8")],
539+
}),
537540
);
538541
await withMockedWindowsPlatform(async () => {
539542
await expect(
@@ -544,8 +547,11 @@ describe("Windows command execution", () => {
544547
}),
545548
).resolves.toMatchObject({
546549
stdout: "a",
550+
stderr: "b",
547551
stdoutTruncatedBytes: 5,
552+
stderrTruncatedBytes: 5,
548553
});
554+
expect(spawnSyncMock).not.toHaveBeenCalled();
549555
});
550556
});
551557

0 commit comments

Comments
 (0)