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
}