Dmitri
Dmitri

Reputation: 36310

How to disable yarn interactive prompt for yarn upgrade

I am adding the yarn upgrade command to a bash file. I want to run command to upgrade a specific package to a specific version.

yarn upgrade [email protected]

But if the specific version is not found in remote npm repository currently yarn opens up a prompt to select from available versions, like this one:

Couldn't find any versions for "mypackage" that matches "5.9.5"
Please choose a version of "mypackage" from this list: (Use arrow keys)

This is not working well in the bash file. What I need is a simple error that package was not found and an exit with non 0 exit code.

Is it possible to do that? Is there an option in yarn to disable this interactive selector or maybe there is a bash trick to disable this interaction and turn in into a simple exit code?

Upvotes: 3

Views: 4964

Answers (2)

Jon Madison
Jon Madison

Reputation: 456

If you're on unix, you can use the command yes to pipe an empty string to everything and it will act as if it made the first selection to the list, i.e.

By default, yes, emits a stream of y characters, but if you give it an argument it will emit that stream over and again to stdout. so in this case, you'll use:

yes " " | yarn upgrade [email protected]

--non-interactive will fail, and you may (or probably) don't want that.

Upvotes: 1

Hanxue
Hanxue

Reputation: 12766

Use yarn upgrade with the --non-interactive flag. You will get a non-zero exit code if it fails

$ yarn upgrade [email protected] --non-interactive
yarn upgrade v1.13.0
[1/5] 🔍  Validating package.json...
[2/5] 🔍  Resolving packages...
error Couldn't find any versions for "webpack-merge" that matches "4.2.29"
info Visit https://yarnpkg.com/en/docs/cli/upgrade for documentation about this command.
$ echo $?
1

Upvotes: 1

Related Questions