mirror of
https://github.com/hanzoai/cross-env.git
synced 2026-09-24 16:58:15 +00:00
fix: exit code should be set to 1 when os kills child process (#177)
* fixes #150 exit code when os kills child process * Update .all-contributorsrc
This commit is contained in:
committed by
Kent C. Dodds
parent
450dae9c93
commit
d5170bfc55
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"projectName": "cross-env",
|
||||
"projectOwner": "kentcdodds",
|
||||
"repoType": "github",
|
||||
"files": [
|
||||
"README.md"
|
||||
],
|
||||
@@ -163,6 +164,15 @@
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
},
|
||||
{
|
||||
"login": "bithavoc",
|
||||
"name": "Johan Hernandez",
|
||||
"avatar_url": "https://avatars3.githubusercontent.com/u/219289?v=4",
|
||||
"profile": "http://bithavoc.io",
|
||||
"contributions": [
|
||||
"code"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ Run scripts that set and use environment variables across platforms
|
||||
[![downloads][downloads-badge]][npm-stat]
|
||||
|
||||
[![MIT License][license-badge]][LICENSE]
|
||||
[](#contributors)
|
||||
[](#contributors)
|
||||
[![PRs Welcome][prs-badge]][prs]
|
||||
[![Donate][donate-badge]][donate]
|
||||
[![Code of Conduct][coc-badge]][coc]
|
||||
@@ -158,7 +158,7 @@ Thanks goes to these people ([emoji key][emojis]):
|
||||
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](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") | [<img src="https://avatars1.githubusercontent.com/u/499038?v=3" width="100px;"/><br /><sub><b>Ya Zhuang </b></sub>](https://zhuangya.me)<br />[🔌](#plugin-zhuangya "Plugin/utility libraries") [📖](https://github.com/kentcdodds/cross-env/commits?author=zhuangya "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/3440094?v=3" width="100px;"/><br /><sub><b>James Harris</b></sub>](https://wopian.me)<br />[📖](https://github.com/kentcdodds/cross-env/commits?author=wopian "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/8941730?v=3" width="100px;"/><br /><sub><b>compumike08</b></sub>](https://github.com/compumike08)<br />[🐛](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") | [<img src="https://avatars1.githubusercontent.com/u/2270425?v=3" width="100px;"/><br /><sub><b>Daniel Rodríguez Rivero</b></sub>](https://github.com/danielo515)<br />[🐛](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") | [<img src="https://avatars2.githubusercontent.com/u/1508477?v=3" width="100px;"/><br /><sub><b>Jonas Keinholz</b></sub>](https://github.com/inyono)<br />[🐛](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") | [<img src="https://avatars3.githubusercontent.com/u/1656170?v=3" width="100px;"/><br /><sub><b>Hugo Wood</b></sub>](https://github.com/hgwood)<br />[🐛](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") |
|
||||
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
||||
| [<img src="https://avatars0.githubusercontent.com/u/3715715?v=3" width="100px;"/><br /><sub><b>Thiebaud Thomas</b></sub>](https://github.com/thomasthiebaud)<br />[🐛](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") | [<img src="https://avatars1.githubusercontent.com/u/1715800?v=3" width="100px;"/><br /><sub><b>Daniel Rey López</b></sub>](https://daniel.blog)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Tests") | [<img src="https://avatars2.githubusercontent.com/u/6374832?v=3" width="100px;"/><br /><sub><b>Amila Welihinda</b></sub>](http://amilajack.com)<br />[🚇](#infra-amilajack "Infrastructure (Hosting, Build-Tools, etc)") | [<img src="https://avatars1.githubusercontent.com/u/1396?v=3" width="100px;"/><br /><sub><b>Paul Betts</b></sub>](https://twitter.com/paulcbetts)<br />[🐛](https://github.com/kentcdodds/cross-env/issues?q=author%3Apaulcbetts "Bug reports") [💻](https://github.com/kentcdodds/cross-env/commits?author=paulcbetts "Code") | [<img src="https://avatars1.githubusercontent.com/u/6371670?v=3" width="100px;"/><br /><sub><b>Turner Hayes</b></sub>](https://github.com/turnerhayes)<br />[🐛](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") | [<img src="https://avatars2.githubusercontent.com/u/22251956?v=4" width="100px;"/><br /><sub><b>Suhas Karanth</b></sub>](https://github.com/sudo-suhas)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Tests") | [<img src="https://avatars3.githubusercontent.com/u/512692?v=4" width="100px;"/><br /><sub><b>Sven</b></sub>](https://github.com/sventschui)<br />[💻](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") |
|
||||
| [<img src="https://avatars0.githubusercontent.com/u/5522668?v=4" width="100px;"/><br /><sub><b>D. Nicolás Lopez Zelaya</b></sub>](https://github.com/NicoZelaya)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=NicoZelaya "Code") |
|
||||
| [<img src="https://avatars0.githubusercontent.com/u/5522668?v=4" width="100px;"/><br /><sub><b>D. Nicolás Lopez Zelaya</b></sub>](https://github.com/NicoZelaya)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=NicoZelaya "Code") | [<img src="https://avatars3.githubusercontent.com/u/219289?v=4" width="100px;"/><br /><sub><b>Johan Hernandez</b></sub>](http://bithavoc.io)<br />[💻](https://github.com/kentcdodds/cross-env/commits?author=bithavoc "Code") |
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
|
||||
|
||||
+48
-24
@@ -62,33 +62,40 @@ it(`should handle quoted scripts`, () => {
|
||||
crossEnv(['GREETING=Hi', 'NAME=Joe', 'echo $GREETING && echo $NAME'], {
|
||||
shell: true,
|
||||
})
|
||||
expect(
|
||||
crossSpawnMock.spawn,
|
||||
).toHaveBeenCalledWith('echo $GREETING && echo $NAME', [], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: Object.assign({}, process.env, {
|
||||
GREETING: 'Hi',
|
||||
NAME: 'Joe',
|
||||
}),
|
||||
})
|
||||
expect(crossSpawnMock.spawn).toHaveBeenCalledWith(
|
||||
'echo $GREETING && echo $NAME',
|
||||
[],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: Object.assign({}, process.env, {
|
||||
GREETING: 'Hi',
|
||||
NAME: 'Joe',
|
||||
}),
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it(`should handle escaped characters`, () => {
|
||||
// this escapes \,",' and $
|
||||
crossEnv(['GREETING=Hi', 'NAME=Joe', 'echo \\"\\\'\\$GREETING\\\'\\" && echo $NAME'], {
|
||||
shell: true,
|
||||
})
|
||||
expect(
|
||||
crossSpawnMock.spawn,
|
||||
).toHaveBeenCalledWith("echo \"'$GREETING'\" && echo $NAME", [], {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: Object.assign({}, process.env, {
|
||||
GREETING: 'Hi',
|
||||
NAME: 'Joe',
|
||||
}),
|
||||
})
|
||||
crossEnv(
|
||||
['GREETING=Hi', 'NAME=Joe', 'echo \\"\\\'\\$GREETING\\\'\\" && echo $NAME'],
|
||||
{
|
||||
shell: true,
|
||||
},
|
||||
)
|
||||
expect(crossSpawnMock.spawn).toHaveBeenCalledWith(
|
||||
'echo "\'$GREETING\'" && echo $NAME',
|
||||
[],
|
||||
{
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
env: Object.assign({}, process.env, {
|
||||
GREETING: 'Hi',
|
||||
NAME: 'Joe',
|
||||
}),
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it(`should do nothing given no command`, () => {
|
||||
@@ -133,6 +140,24 @@ it(`should propagate kill signals`, () => {
|
||||
expect(crossSpawnMock.__mock.spawned.kill).toHaveBeenCalledWith('SIGBREAK')
|
||||
})
|
||||
|
||||
it(`should propagate unhandled exit signal`, () => {
|
||||
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
|
||||
spawnExitCallback(spawnExitCode)
|
||||
expect(process.exit).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it(`should propagate regular 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 = 0
|
||||
spawnExitCallback(spawnExitCode)
|
||||
expect(process.exit).toHaveBeenCalledWith(0)
|
||||
})
|
||||
|
||||
it(`should keep backslashes`, () => {
|
||||
isWindowsMock.__mock.returnValue = true
|
||||
crossEnv(['echo', '\\\\\\\\someshare\\\\somefolder'])
|
||||
@@ -147,7 +172,6 @@ it(`should keep backslashes`, () => {
|
||||
isWindowsMock.__mock.reset()
|
||||
})
|
||||
|
||||
|
||||
function testEnvSetting(expected, ...envSettings) {
|
||||
if (expected.APPDATA === 2) {
|
||||
// kill the APPDATA to test both is undefined
|
||||
|
||||
+5
-2
@@ -25,7 +25,10 @@ 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', process.exit)
|
||||
proc.on('exit', code => {
|
||||
// exit code could be null when OS kills the process(out of memory, etc)
|
||||
process.exit(code === null ? 1 : code)
|
||||
})
|
||||
return proc
|
||||
}
|
||||
return null
|
||||
@@ -61,7 +64,7 @@ function parseCommand(args) {
|
||||
const re = /\\\\|(\\)?'|([\\])(?=[$"\\])/g
|
||||
// Eliminate all matches except for "\'" => "'"
|
||||
return a.replace(re, m => {
|
||||
if (m === "\\\\") return "\\"
|
||||
if (m === '\\\\') return '\\'
|
||||
if (m === "\\'") return "'"
|
||||
return ''
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user