diff --git a/.all-contributorsrc b/.all-contributorsrc index b8ec84d..bf23a0d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -173,6 +173,17 @@ "contributions": [ "code" ] + }, + { + "login": "jnielson94", + "name": "Jordan Nielson", + "avatar_url": "https://avatars3.githubusercontent.com/u/13559161?v=4", + "profile": "https://github.com/jnielson94", + "contributions": [ + "bug", + "code", + "test" + ] } ] } diff --git a/README.md b/README.md index ed8d292..ad3b11f 100755 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Run scripts that set and use environment variables across platforms [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-16-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -160,7 +160,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Tests") | [
Ya Zhuang ](https://zhuangya.me)
[πŸ”Œ](#plugin-zhuangya "Plugin/utility libraries") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya "Documentation") | [
James Harris](https://wopian.me)
[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian "Documentation") | [
compumike08](https://github.com/compumike08)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08 "Bug reports") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Documentation") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Tests") | [
Daniel RodrΓ­guez Rivero](https://github.com/danielo515)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515 "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Documentation") | [
Jonas Keinholz](https://github.com/inyono)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono "Tests") | [
Hugo Wood](https://github.com/hgwood)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Tests") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | [
Thiebaud Thomas](https://github.com/thomasthiebaud)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Athomasthiebaud "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Tests") | [
Daniel Rey LΓ³pez](https://daniel.blog)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Tests") | [
Amila Welihinda](http://amilajack.com)
[πŸš‡](#infra-amilajack "Infrastructure (Hosting, Build-Tools, etc)") | [
Paul Betts](https://twitter.com/paulcbetts)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Apaulcbetts "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=paulcbetts "Code") | [
Turner Hayes](https://github.com/turnerhayes)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Aturnerhayes "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Tests") | [
Suhas Karanth](https://github.com/sudo-suhas)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Tests") | [
Sven](https://github.com/sventschui)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Documentation") [πŸ’‘](#example-sventschui "Examples") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Tests") | -| [
D. NicolΓ‘s Lopez Zelaya](https://github.com/NicoZelaya)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=NicoZelaya "Code") | [
Johan Hernandez](http://bithavoc.io)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=bithavoc "Code") | +| [
D. NicolΓ‘s Lopez Zelaya](https://github.com/NicoZelaya)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=NicoZelaya "Code") | [
Johan Hernandez](http://bithavoc.io)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=bithavoc "Code") | [
Jordan Nielson](https://github.com/jnielson94)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ajnielson94 "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=jnielson94 "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=jnielson94 "Tests") | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 24c76fb..0d073ce 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -149,6 +149,16 @@ it(`should propagate unhandled exit signal`, () => { expect(process.exit).toHaveBeenCalledWith(1) }) +it(`should exit cleanly with SIGINT with a null exit code`, () => { + process.exit = jest.fn() + testEnvSetting({FOO_ENV: 'foo=bar'}, 'FOO_ENV="foo=bar"') + const spawnExitCallback = crossSpawnMock.__mock.spawned.on.mock.calls[0][1] + const spawnExitCode = null + const spawnExitSignal = 'SIGINT' + spawnExitCallback(spawnExitCode, spawnExitSignal) + expect(process.exit).toHaveBeenCalledWith(0) +}) + it(`should propagate regular exit code`, () => { process.exit = jest.fn() testEnvSetting({FOO_ENV: 'foo=bar'}, 'FOO_ENV="foo=bar"') diff --git a/src/index.js b/src/index.js index ce6a3c5..349e9c1 100644 --- a/src/index.js +++ b/src/index.js @@ -25,9 +25,14 @@ function crossEnv(args, options = {}) { process.on('SIGINT', () => proc.kill('SIGINT')) process.on('SIGBREAK', () => proc.kill('SIGBREAK')) process.on('SIGHUP', () => proc.kill('SIGHUP')) - proc.on('exit', code => { - // exit code could be null when OS kills the process(out of memory, etc) - process.exit(code === null ? 1 : code) + proc.on('exit', (code, signal) => { + let crossEnvExitCode = code + // exit code could be null when OS kills the process(out of memory, etc) or due to node handling it + // but if the signal is SIGINT the user exited the process so we want exit code 0 + if (crossEnvExitCode === null) { + crossEnvExitCode = signal === 'SIGINT' ? 0 : 1 + } + process.exit(crossEnvExitCode) //eslint-disable-line no-process-exit }) return proc }