Defines project-wide policies for your project.
Enforcing Yarn’s version across your project
When working inside a team, you usually end up in the situation where one of yourcolleagues uses a different version of Yarn than you. While usually inconsequential,it might sometimes cause subtle and hard to debug issues - for example your colleaguemight be on a version of Yarn that doesn’t support a feature you rely on, such asthe workspaces.
In order to alleviate this issue, you can specify the required Yarn version insidethe package.json
file, which will prompt your colleagues to use the same version asyou. Unfortunately, while technically strong, this technique adds an unwanted burdenon them - given that the Yarn binary is typically global, switching from a branch toanother might be particularly annoying if they change the version.
To fix that, yarn policies set-version
offers a simple way to check in your Yarnrelease within your repository. Once you run it, your configuration will be updatedin such a way that anyone running a Yarn command inside the project will always usethe version you set - and this transparently.
The command accepts various ways to set which version you want to use:
yarn policies set-version
will download the latest stable releaseyarn policies set-version --rc
will download the latest rc releaseyarn policies set-version 1.13.0
will download a specific versionyarn policies set-version '^1.12.0'
will download the latest minor
Under the hood, the command will simply download the single-file release from theGitHub repository, store it inside your project (inside the .yarn/releases
folder),then finally update your configuration to point to the new file (using yarn-path
).
Note that this command also is the preferred way to upgrade Yarn - it will work nomatter how you originally installed it, which might sometimes prove difficult tofigure out otherwise.