Skip to content

Commit c65f3b3

Browse files
committed
fix: propagate SIGINT exit status on POSIX
1 parent 6129083 commit c65f3b3

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

bin/index.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ describe('exiting conditions', () => {
185185
expect(exit.code).toBeGreaterThan(0);
186186
});
187187

188-
it('is of success when a SIGINT is sent', async () => {
188+
it('propagates SIGINT on POSIX when interrupted', async () => {
189189
// Windows doesn't support sending signals like on POSIX platforms.
190190
// However, in a console, processes can be interrupted with CTRL+C (like a SIGINT).
191191
// This is what we simulate here with the help of a wrapper application.
@@ -204,7 +204,9 @@ describe('exiting conditions', () => {
204204
const lines = await child.getLogLines();
205205
const exit = await child.exit;
206206

207-
expect(exit.code).toBe(0);
207+
expect(exit).toMatchObject(
208+
isWindows ? { code: 0, signal: null } : { code: null, signal: 'SIGINT' },
209+
);
208210
expect(lines).toContainEqual(
209211
expect.stringMatching(
210212
createKillMessage(

bin/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ assertDeprecated(
225225
'Use commas as name separators instead.',
226226
);
227227

228+
let interruptedBySigint = false;
229+
if (process.platform !== 'win32') {
230+
// On POSIX, exit with SIGINT after children finish so shell callers don't treat Ctrl+C as
231+
// a successful run.
232+
process.once('SIGINT', () => {
233+
interruptedBySigint = true;
234+
});
235+
}
236+
228237
// Get names of commands by the specified separator
229238
const names = (args.names || '').split(args.nameSeparator);
230239

@@ -269,6 +278,6 @@ concurrently(
269278
additionalArguments: args.passthroughArguments ? additionalArguments : undefined,
270279
},
271280
).result.then(
272-
() => process.exit(0),
273-
() => process.exit(1),
281+
() => (interruptedBySigint ? process.kill(process.pid, 'SIGINT') : process.exit(0)),
282+
() => (interruptedBySigint ? process.kill(process.pid, 'SIGINT') : process.exit(1)),
274283
);

0 commit comments

Comments
 (0)