Skip to content

Commit

Permalink
fix: use close event to resolve process.exec instead of exti
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dgolovin committed Oct 30, 2024
1 parent a96e101 commit 1e43289
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions packages/main/src/plugin/util/exec.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand All @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down Expand Up @@ -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);
}
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/plugin/util/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class Exec {
reject(errResult);
});

childProcess.on('exit', exitCode => {
childProcess.on('close', exitCode => {
if (exitCode === 0) {
const result: RunResult = {
command,
Expand Down

0 comments on commit 1e43289

Please sign in to comment.