Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents exiting the process on sigint in case of yarn run, fixes #8895. #9114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdevils
Copy link

@mdevils mdevils commented Nov 7, 2024

Prevents exiting the process on SIGINT in case of yarn run.

Current behavior:

When user presses ctrl+C yarn exits immediately and shell prompt is shown. If a run script needs some time to cleanup before exit and outputs something to terminal, it pollutes the prompt.

New behavior:

yarn doesn't make any decisions on when to exit, it just waits for the children.
Works the same as npm run now in that regard.

This PR fixes this issue: #8895

Test cases

Test script for this PR: example.js

const EXIT_CODE = 1;

setInterval(() => {
    console.log('tick');
}, 1000);

process.on('SIGINT', () => {
    console.log('SIGINT from script');
    setTimeout(() => process.exit(EXIT_CODE), 3000);
});

Regular case

Excerpt from package.json:

                "example": "node example.js",

Actual behavior with this script:

bash-3.2$ yarn run example
yarn run v1.22.22
$ node example.js
tick
tick
^CSIGINT from script

bash-3.2$ tick
tick
tick

New behavior with this script:

bash-3.2$ yarn example
yarn run v1.23.0-0
$ node example.js
tick
tick
^CSIGINT from script
tick
tick
tick
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
bash-3.2$

For reference, npm run behavior:

bash-3.2$ npm run example

> example
> node example.js

tick
tick
^CSIGINT from script
tick
tick
tick
bash-3.2$

Using pre/post scripts

Excerpt from package.json:

                "preexample": "node example.js",
                "example": "node example.js",
                "postexample": "node example.js"

Actual behavior with this script:

bash-3.2$ yarn example
yarn run v1.22.22
$ node example.js
tick
tick
^CSIGINT from script

bash-3.2$ tick
tick
tick

New behavior with this script:

bash-3.2$ yarn example
yarn run v1.23.0-0
$ node example.js
tick
tick
^CSIGINT from script
tick
tick
tick
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
bash-3.2$

For reference, npm run behavior:

bash-3.2$ npm run example

> preexample
> node example.js

tick
tick
^CSIGINT from script
tick
tick
tick
bash-3.2$

Using pre/post scripts with zero exit code

Excerpt from package.json:

                "preexample": "node example.js",
                "example": "node example.js",
                "postexample": "node example.js"

Modify example.js and set EXIT_CODE to 0.

Actual behavior:

bash-3.2$ yarn example
yarn run v1.22.22
$ node example.js
tick
tick
^CSIGINT from script

bash-3.2$ tick
tick
tick

New behavior:

bash-3.2$ yarn example
yarn run v1.23.0-0
$ node example.js
tick
tick
^CSIGINT from script
tick
tick
tick
$ node example.js
tick
tick
^CSIGINT from script
tick
tick
tick
$ node example.js
tick
tick
^CSIGINT from script
tick
tick
tick
✨  Done in 16.77s.
bash-3.2$

For reference npm behavior:

bash-3.2$ npm run example

> preexample
> node example.js

tick
tick
^CSIGINT from script
tick
tick
tick

> example
> node example.js

tick
tick
^CSIGINT from script
tick
tick
tick

> postexample
> node example.js

tick
tick
^CSIGINT from script
tick
tick
tick
bash-3.2$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant