From 1e432899a5f8321917c615e7c15de32a39de94a0 Mon Sep 17 00:00:00 2001 From: Denis Golovin Date: Mon, 28 Oct 2024 23:40:55 -0700 Subject: [PATCH] fix: use close event to resolve process.exec instead of exti Doc says stdout/stderr can stil be open even after process exit and that can lead to loss of output text Signed-off-by: Denis Golovin --- packages/main/src/plugin/util/exec.spec.ts | 24 +++++++++++----------- packages/main/src/plugin/util/exec.ts | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/main/src/plugin/util/exec.spec.ts b/packages/main/src/plugin/util/exec.spec.ts index d75905096e73c..ca3858a2e168e 100644 --- a/packages/main/src/plugin/util/exec.spec.ts +++ b/packages/main/src/plugin/util/exec.spec.ts @@ -78,7 +78,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -106,7 +106,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -133,7 +133,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(1); } }), @@ -246,7 +246,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -283,7 +283,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -320,7 +320,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -357,7 +357,7 @@ describe('exec', () => { stdout: { on, setEncoding: vi.fn() }, stderr: { on, setEncoding: vi.fn() }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -393,7 +393,7 @@ describe('exec', () => { stdout: { on, setEncoding: vi.fn() }, stderr: { on, setEncoding: vi.fn() }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -426,7 +426,7 @@ describe('exec', () => { stdout: { on, setEncoding: vi.fn() }, stderr: { on, setEncoding: vi.fn() }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -463,7 +463,7 @@ describe('exec', () => { stdout: { on, setEncoding: vi.fn() }, stderr: { on, setEncoding: vi.fn() }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -496,7 +496,7 @@ describe('exec', () => { stdout: { on, setEncoding: vi.fn() }, stderr: { on, setEncoding: vi.fn() }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), @@ -527,7 +527,7 @@ describe('exec', () => { stdout: { on, setEncoding: setEncodingMock }, stderr: { on, setEncoding: setEncodingMock }, on: vi.fn().mockImplementation((event: string, cb: (arg0: number) => void) => { - if (event === 'exit') { + if (event === 'close') { cb(0); } }), diff --git a/packages/main/src/plugin/util/exec.ts b/packages/main/src/plugin/util/exec.ts index 2703a18f7a3fb..e1363967d883b 100644 --- a/packages/main/src/plugin/util/exec.ts +++ b/packages/main/src/plugin/util/exec.ts @@ -210,7 +210,7 @@ export class Exec { reject(errResult); }); - childProcess.on('exit', exitCode => { + childProcess.on('close', exitCode => { if (exitCode === 0) { const result: RunResult = { command,