Skip to content
Myr

Exit with non-zero code when subprocess terminated by signal (#2023)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent a0ca1bd · Browse files · 5 files+56 added−36 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+56 added−36 removed

  • tests:+48 added−28 removed
  • other:+8 added−8 removed

5 files+56 added−36 removed

modified:lib/command.js+8 added-8 removed
1038 unmodified lines
1039 });1040 }10411042 // By default terminate process when spawned process terminates.1043 // Suppressing the exit if exitCallback defined is a bit messy and of limited use, but does allow process to stay running!1043 const exitCallback = this._exitCallback;1045 if (!exitCallback) {1046 proc.on('close', process.exit.bind(process));1047 } else {1048 proc.on('close', () => {1049 exitCallback(new CommanderError(process.exitCode || 0, 'commander.executeSubCommandAsync', '(close)'));1050 });1051 }1044 proc.on('close', (code, _signal) => {1045 code = code ?? 1; // code is null if spawned process terminated due to a signal1046 if (!exitCallback) {1047 process.exit(code);1048 } else {1049 exitCallback(new CommanderError(code, 'commander.executeSubCommandAsync', '(close)'));1050 }1051 });1052 proc.on('error', (err) => {1053 // @ts-ignore1054 if (err.code === 'ENOENT') {1055 const executableDirMessage = executableDir
1135 unmodified lines
modified:tests/fixtures/pm+12 added-1 removed
1#!/usr/bin/env node23const path = require('node:path');3var { program } = require('../../');4const { program } = require('../../');56process.env.FORCE_COLOR = 0; // work-around bug in Jest: https://github.com/jestjs/jest/issues/1439178program
8 unmodified lines
17 .command('default', 'default command', { hidden: true, isDefault: true })18 .command('specifyInstall', 'specify install subcommand', { executableFile: 'pm-install' })19 .command('specifyPublish', 'specify publish subcommand', { executableFile: 'pm-publish' })20 .command('silent', 'silently succeed')21 .command('fail', 'exit with non-zero status code')22 .command('terminate', 'terminate due to signal');2324program25 .command('exit-override')26 .exitOverride((err) => { process.exit(err.exitCode); })27 .command('fail', 'exit with non-zero status code', { executableFile: path.join(__dirname, 'pm-fail.js') })28 .command('terminate', 'terminate due to signal', { executableFile: path.join(__dirname, 'pm-terminate.js') });2930program31 .parse(process.argv);
added:tests/fixtures/pm-fail.js+1 added
added:tests/fixtures/pm-terminate.js+1 added
modified:tests/command.executableSubcommand.signals.test.js+34 added-27 removed