Managing Symlinks and upgrading Packages with Yarn CLI
In this tutorial we are going to show you how to unlink a previously created symlink for a package, this tutorial will also show you how to upgrade packages to their latest versions based on the range you specify.
Yarn unlink
This command will remove the symlinked package that is created with the
yarn link
command.This command has to be run in a folder that was previously used to create a link.
yarn unlink [package]
If you want to unlink a package that was symlinked during development in your project, all you need to do is to run yarn unlink [package].
Once this is done, you will have to run yarn or yarn install to reinstall the package that was linked.Continuing from the example we used in our tutorial on yarn link, we assumed two folders vue and vue-calendar are located next to each other with vue linked into the vue-calendar project.
$ cd vue
$ yarn unlink
yarn link v1.2.1
success Unregistered "vue".
$ cd ../vue-calendar
$ yarn unlink vue
yarn link v1.2.1
success Unregistered "vue".
Yarn upgrade
The yarn upgrade command is used to upgrade packages to their latest versions based on a specified range in your package.json file.
yarn upgrade [package | package@tag | package@version | --scope @scope]... [--ignore-engines] [--pattern]
Optionally, you can specify one or more package names. When you specify package names, it is only those packages that will be upgraded. However, when you do not specify a package name then all the dependencies will be upgraded.
[package]: when you specify only a package a package name, then this package will be upgraded to the latest patching version only.
[package@tag]: When you specify a package with a tag, then the package will be upgraded to the specified tag. A tag name is chosen by the project maintainers; this command is used to install an experimental or a long term support version of a package.
[package@version]: whenever you specify a package that contains a version, then the package will be upgraded to this version.
--ignore-engines: If you want to skip engines check, use this flag.
Here are examples:
yarn upgrade```
```yarn upgrade left-pad```
```yarn upgrade left-pad@^1.0.0```
```yarn upgrade left-pad gulp```
```yarn upgrade @react
yarn upgrade --pattern <pattern> upgrades all packages that match the pattern.
Examples:
yarn upgrade --pattern gulp```
```yarn upgrade left-pad --pattern "gulp|grunt"```
```yarn upgrade --latest --pattern "gulp-(match|newer)"
yarn upgrade [package]... --latest|-L [--caret | --tilde | --exact] [--pattern]
The upgrade --latest command will upgrade packages the same as the upgrade command, but it will ignore the version range that is specified in package.json. Instead, the version that is specified by the latest tag will be used (potentially upgrading the packages across major versions).
The package.json file will be updated in a way that reflects the latest version range. The existing range specifier in package.json will be reused by default if it is one of: ^, ~, <=, >, or if it is an exact version. Otherwise, it is changed to a caret (^). You can use one of the flags --caret, --tilde or --exact to explicitly specify a range.
Examples:
yarn upgrade --latest```
```yarn upgrade left-pad --latest```
```yarn upgrade left-pad grunt --latest --tilde
yarn upgrade (--scope|-S) @scope [--latest] [--pattern]
--scope @scope : When you specify a scope, only the packages that begin with that scope are upgraded. A scope has to begin with '@'.
--latest : This command will ignore the version range specified in package.json. Instead, the version that is specified by the latest tag will be used (potentially upgrading the packages across major versions).
Examples:
yarn upgrade --scope @vue```
```yarn upgrade -S @vue
Previous:
Managing Teams and Running tests with Yarn CLI.
Next:
Interactive Package upgrades with Yarn CLI.
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-unlink-and-yarn-upgrade-cli-commands.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics