2017-10-09 03:15:27 +00:00
|
|
|
# Working with Packages
|
2017-09-29 08:07:20 +00:00
|
|
|
|
2017-10-09 03:15:27 +00:00
|
|
|
As we are using `yarn` for managing packages, here are some helpful tips for
|
|
|
|
whenever you need to work with them.
|
2017-09-29 08:07:20 +00:00
|
|
|
|
2017-10-09 03:06:14 +00:00
|
|
|
### Install packages
|
2017-09-29 08:07:20 +00:00
|
|
|
|
2017-10-09 03:06:14 +00:00
|
|
|
To ensure you have the right version of dependencies, run this command after
|
|
|
|
cloning or switching branches.
|
2017-09-29 08:07:20 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
> yarn
|
|
|
|
```
|
|
|
|
|
|
|
|
This will restore the versions stored in the lock file to the `node_modules`
|
|
|
|
folder.
|
|
|
|
|
2017-10-09 03:06:14 +00:00
|
|
|
### Add new packages
|
|
|
|
|
|
|
|
Rather than updating the `package.json` explicitly, you can install new
|
|
|
|
dependencies via the `yarn` command line:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
# adds the package to the dependencies list
|
2017-10-09 03:15:27 +00:00
|
|
|
> yarn add [package-name]
|
2017-10-09 03:06:14 +00:00
|
|
|
# adds the package to the devDependencies list
|
2017-10-09 03:15:27 +00:00
|
|
|
> yarn add [package-name] --dev
|
2017-10-09 03:06:14 +00:00
|
|
|
```
|
|
|
|
|
2017-09-29 08:07:20 +00:00
|
|
|
### Updating packages
|
|
|
|
|
|
|
|
To see which packages have newer versions available:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
> yarn outdated
|
|
|
|
```
|
|
|
|
|
2023-04-21 13:31:40 +00:00
|
|
|
To upgrade a package to its latest version:
|
2017-09-29 08:07:20 +00:00
|
|
|
|
|
|
|
```sh
|
2018-07-19 12:11:41 +00:00
|
|
|
> yarn upgrade --latest [package-name]
|
2017-09-29 08:07:20 +00:00
|
|
|
```
|
|
|
|
|
2020-10-11 11:41:15 +00:00
|
|
|
To upgrade a package to a specific version (or [version range](https://docs.npmjs.com/misc/semver#x-ranges-12x-1x-12-)):
|
2018-07-19 12:11:41 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
> yarn upgrade [package-name]@[version]
|
|
|
|
```
|
2017-10-09 03:15:27 +00:00
|
|
|
|
|
|
|
### Removing packages
|
|
|
|
|
|
|
|
To remove any packages that are no longer needed:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
> yarn remove [package-name]
|
2018-07-19 12:11:41 +00:00
|
|
|
```
|
2018-08-09 19:11:59 +00:00
|
|
|
|
|
|
|
### Upgrading Yarn
|
|
|
|
|
|
|
|
Desktop uses a local version of `yarn` to ensure one version is used on all
|
|
|
|
platforms that we develop on. To upgrade Desktop to the latest version of `yarn`:
|
|
|
|
|
|
|
|
- download the `yarn-x-y.z.js` file from the latest release on [GitHub](https://github.com/yarnpkg/yarn/releases)
|
|
|
|
- add it to the root `vendor` folder on disk
|
|
|
|
- remove any previous version
|
|
|
|
- edit `.yarnrc` to use this new version (ensuring the `x.y.z` matches the
|
|
|
|
version you just downloaded)
|
|
|
|
|
|
|
|
```
|
|
|
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
|
|
# yarn lockfile v1
|
|
|
|
|
|
|
|
yarn-path "./vendor/yarn-x.y.z.js"
|
|
|
|
```
|
|
|
|
|
|
|
|
- edit `app/.yarnrc` to use this new version (ensuring the `x.y.z` matches the
|
|
|
|
version you just downloaded)
|
|
|
|
|
|
|
|
```
|
|
|
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
|
|
# yarn lockfile v1
|
|
|
|
|
|
|
|
yarn-path "../vendor/yarn-x.y.z.js"
|
|
|
|
```
|
|
|
|
|
|
|
|
- Commit these changes and open a pull request to get them reviewed
|