-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Exit process with code 1 when outdated dependencies are found #3484
Conversation
src/cli/commands/outdated.js
Outdated
@@ -44,6 +44,9 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg | |||
}); | |||
|
|||
reporter.table(['Package', 'Current', 'Wanted', 'Latest', 'Package Type', 'URL'], body); | |||
process.on('exit', () => | |||
process.exitCode = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like a hack.
We prefer to have a single exit code in cli/index.js that will be set code 1 if the command returned a rejected promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting the change but could you find a less hacky way? Modifying global process variable will make the code harder to reason in the future.
Also please add screenshots of the change in Test Plan section of the description
Good idea. What do you think of the update? This is an alternative way of setting the exit code:
|
@@ -155,11 +155,16 @@ if (command.requireLockfile && !fs.existsSync(path.join(config.cwd, constants.LO | |||
// | |||
const run = (): Promise<void> => { | |||
invariant(command, 'missing command'); | |||
return command.run(config, reporter, commander, commander.args).then(() => { | |||
return command.run(config, reporter, commander, commander.args).then(exitCode => { | |||
reporter.close(); | |||
if (outputWrapper) { | |||
reporter.footer(false); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would not work well, commands may resolve with non numeric values.
Also at line 337 in this file a rejection of run() promise causes process.exit(1) already.
Can you just throw an error in the outdated command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error causes the yarn-error.log
file to be written and error message stuff to be printed. Am I missing something here?
I did a find all of function run
and none of the run
functions return anything. They all have the signature of Promise<void>
. I've updated the PR again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks, @KishanBagaria!
It wasn't commander that was preventing Another alternative way to do this: |
I think this is better than modifying process, thanks @KishanBagaria! |
Summary
Fixes #3483
Test plan
![](https://cloud.githubusercontent.com/assets/1093313/26403763/0680efa8-40ad-11e7-85b4-d33be1da0d2c.png)