Skip to content

Commit b8c0479

Browse files
committed
Restore npm SIGINT behavior (reverts #41)
This reverts the behavioral change from #41. This change caused pnpm to improperly handle interactive shell Ctrl-C, trapping the received signal and also ignoring the abnormal exit of the script. This often results still in a quick exit (because the script has terminated), but with exit code 0. PR #41 resulted in incorrect behavior, which also diverges from npm (as well as `node --run`). As another problem, it made pnpm internally inconsistent as Ctrl-C results in non-zero in situations when lifecycles scripts are not actively running. Even in the context of pnpm run, a very quick Ctrl-C, prior to spawn, results in a non-zero pnpm exit. For additional discussion see: #51 Fixes: pnpm/pnpm#9626
1 parent 942123c commit b8c0479

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function runCmd_ (cmd, pkg, env, wd, opts, stage, unsafe, uid, gid, cb_) {
281281
proc.on('close', (code, signal) => {
282282
opts.log.silly('lifecycle', logid(pkg, stage), 'Returned: code:', code, ' signal:', signal)
283283
let err
284-
if (signal && signal !== 'SIGINT') {
284+
if (signal) {
285285
err = new PnpmError('CHILD_PROCESS_FAILED', `Command failed with signal "${signal}"`)
286286
process.kill(process.pid, signal)
287287
} else if (code) {

test/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ test('throw error signal kills child', async function (t) {
205205
stubProcessExit.restore()
206206
})
207207

208-
test('no error on INT signal from child', async function (t) {
208+
test('exit with error on INT signal from child', async function (t) {
209209
if (isWindows()) {
210210
// On Windows there is no way to get the INT signal
211211
return
@@ -233,7 +233,7 @@ test('no error on INT signal from child', async function (t) {
233233
const dir = fixture
234234
const pkg = require(path.join(fixture, 'package.json'))
235235

236-
await t.resolves(async () => {
236+
await t.rejects(async () => {
237237
await lifecycle(pkg, 'signal-int', fixture, {
238238
stdio: 'pipe',
239239
log,
@@ -243,14 +243,15 @@ test('no error on INT signal from child', async function (t) {
243243
})
244244

245245
stubProcessExit.restore()
246+
stubProcessExit.calledOnceWith(process.pid, 'SIGINT')
246247

247248
t.ok(
248-
!info.calledWithMatch(
249+
info.calledWithMatch(
249250
'lifecycle',
250251
'undefined~signal-int:',
251252
'Failed to exec signal-int script'
252253
),
253-
'INT signal intercepted incorrectly'
254+
'INT signal not intercepted'
254255
)
255256

256257
t.ok(

0 commit comments

Comments
 (0)