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

Exit process with code 1 when outdated dependencies are found #3484

Merged
merged 1 commit into from
May 24, 2017
Merged

Exit process with code 1 when outdated dependencies are found #3484

merged 1 commit into from
May 24, 2017

Conversation

KishanBagaria
Copy link
Contributor

@KishanBagaria KishanBagaria commented May 23, 2017

Summary
Fixes #3483

Test plan

@KishanBagaria KishanBagaria changed the title yarn outdated: Exit process with code 1 when outdated dependencies ar… Exit process with code 1 when outdated dependencies are found May 23, 2017
@@ -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
Copy link
Member

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

Copy link
Member

@bestander bestander left a 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

@KishanBagaria
Copy link
Contributor Author

KishanBagaria commented May 24, 2017

Good idea. What do you think of the update?

This is an alternative way of setting the exit code:

process.on('exit', () =>
  process.exit(EXIT_CODE)
);

NPM does it with process.exitCode = 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);
}
Copy link
Member

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?

Copy link
Contributor Author

@KishanBagaria KishanBagaria May 24, 2017

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.

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, @KishanBagaria!

@KishanBagaria
Copy link
Contributor Author

KishanBagaria commented May 24, 2017

It wasn't commander that was preventing process.exitCode = EXIT_CODE from working. It was yarn's exit method.

Another alternative way to do this:
The exit method in cli/index.js can be modified to not pass 0 to process.exit, and outdated.js can mutate process.exitCode = 1. That way the run function doesn't have to return anything.

@bestander
Copy link
Member

I think this is better than modifying process, thanks @KishanBagaria!

@bestander bestander merged commit c4f264f into yarnpkg:master May 24, 2017
@KishanBagaria KishanBagaria deleted the outdated-exit-code branch May 24, 2017 16:08
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.

2 participants