Running Scripts and updating Yarn with CLI commands
There are times when you want to run a defined package scripts, yarn helps you to achieve that using the yarn run command other times you want to update the version of yarn you are using, yarn also has a command for that. This tutorial will be dedicated to both of these commands enjoy.
Yarn run
The yarn run command is used to run a script that you defined in the script section of your package.json file.
Here is an example of a script section in a package.json file:
yarn run [script] [<args>]
When there is a defined script object in your package, running this command will run the specified [script]. For instance, given a project with a script section as shown above; when you run yarn run test, it will run the script that is named test.
yarn run test -o --watch
Yarn will execute jest -o --watch when you run the command above. A script can also be any locally installed executable that exists in a node_modules/.bin/ folder.
You can equally leave out the run in this command, all scripts can be executed with its name:
Thus the command yarn test -o --watch is equivalent to yarn run test -o --watch.
It should be noted that the built-in cli commands have preferences over your own script , Hence, you should not always rely on this shortcut in other scripts.
yarn run env
When you run this command it will list environment variables that are available to the scripts at runtime.
If you want to override the yarn run env command, you will need to define your own env script in your package.json file.
yarn run
If no script is specified to the yarn run command, the run command lists all of the scripts that are available to run for a package.
Yarn self-update
This will update Yarn to the latest version.
However, this command is currently unavailable as at yarn v1.2.1, you will not be able to run yarn self-update. Follow our tutorial on yarn policies to see how you can enforce versions within a project.
To update your version of yarn please run curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
Previous:
Managing Dependencies with Yarn Prune, Publish, and Remove.
Next:
Managing Package versions with Yarn tag CLI commands.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/yarn/yarn-run-and-self-update-cli-commands.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics