Guidelines for migrating from Yarn 1 to Yarn 2

Author : xuzhiping   2022-11-16 15:40:53 Browse: 1185
Category : JavaScript

Abstract: About Global installation Using a single package manager throughout the system has always been a problem. To maintain stability,...

About Global installation

Yarn 1 to Yarn 2

Using a single package manager throughout the system has always been a problem. To maintain stability, you need to perform installation operations across environments and using the same package manager version. Otherwise, we may introduce unexpected major risks between versions, after all, this is why the concept of lock file was first introduced! In a sense, since Yarn is your first project dependency, "lock it" is also appropriate.

Therefore, Yarn 2 and higher should be managed as a project. Don't worry, the change is small! Just ensure that the Yarn binary file is installed globally first. We will use this binary file to generate the local binary file:

Npm install-g yarn

When you follow the above instructions (running the yarn -- version command from your home directory will output information similar to 1.22.0), go to the next section to learn how to actually enable Yarn 2 in your project.

You may have noticed that the global installation of Yarn belongs to the "classic version" sequence (i.e. 1. x). This is deliberately arranged! An additional advantage of this arrangement is that projects configured for Yarn 1 will continue to use Yarn 1 without having to suddenly force migration to the Yarn 2. x configuration format. If Yarn was "project locked" in the beginning, we would not have to do so.

Install by project

1.Globally install the latest version of Yarn:

Npm install-g yarn

2.Enter the project directory:

Cd ~ / path/to/project

3.Run the following command:

Yarn set version berry

"Berry" is the code name for the Yarn 2 release sequence and the name of our code repository!

4.Submit new and modified documents.

Refer to Which files need to be added to the .gitignore configuration file?

Update to the latest version

If you want to update Yarn to the latest version later, run:

Yarn set version latest

Yarn will download the latest binaries from our website and install them in your project. Then, don't forget to update the dependencies and submit the update results!

Install the latest build of the master branch

Over time, even the latest version is not up to date, so you may want to try the latest branch of master code to check if the Bug has been repaired. This has become very simple in Yarn 2! Simply run the following command:

Yarn set version from sources

Similarly, you can use the-- branch parameter to specify that a specific PR is to be installed:

Yarn set version from sources-branch 1211
Label :
    Sign in for comments!
Comment list (0)

Powered by TorCMS (https://github.com/bukun/TorCMS).