Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does yarn work when it encounters ^ (caret)?

How does yarn work when it encounter a ^ (caret) in package.json dependencies?

Let's say I have react: ^16.0.0 and when I yarn install, it will create a lock on that version (16.0.0).

Now sometime later when react 16.1.0 is released, and I yarn install again with the lock file, will yarn upgrade it to that version or follow what is in the lock file which is 16.0.0?

Thanks.

like image 622
Alexander Avatar asked Nov 28 '17 08:11

Alexander


People also ask

How does Yarn Work?

Here i am explaining architecture and working of YARN in detail. YARN was introduced in Hadoop 2.0. In Hadoop 1.0 a map-reduce job is run through a job tracker and multiple task trackers. Job of job tracker is to monitor the progress of map-reduce job, handle the resource allocation and scheduling etc.

What are the components of yarn?

YARN has basically these component: It has two main component: Job Scheduler and Application Manager. Job of scheduler is allocate the resources with the given scheduling method and job of Application Manager is to monitor the progress of submitted application like map-reduce job. It has all the info of available resources.

What is yarn in Hadoop?

YARN means Yet Another Resource Negotiator. Resource Manager and Node Manager were introduced along with YARN into the Hadoop framework. YARN Components like Client, Resource Manager, Node Manager, Job History Server, Application Master, and Container.

Why does yarn take so long to install packages?

Whenever yarn installs a package, it caches it. So any time yarn sees a request for an installation for a package, it will first try to install it from its cache which makes it much faster. Also yarn, being a tool that is of this new age of concurrent coding, executes downloads in parallel threads to make the best use of resource utilization.


2 Answers

yarn install will install the exact version in the lockfile. That's the great benefit of a lockfile, everyone working on your project gets the exact same version of the package regardless of when the do yarn install. (e.g. I do yarn install today, when 16.0.0 is the current version, but you do yarn install tomorrow when 16.1.0 is the current version. We'll still both get 16.0.0 because that's what our lockfile says we should get. Our development environments are exactly the same, which is what we want. Likewise if we deploy in 2 weeks when 16.2.0 is the current version, 16.0.0 will get deployed; thus our dev and prod environments are exactly the same, too)

If 16.1.0 is released and you want to update your project to use it, use yarn upgrade. Note that you can upgrade all of your packages, or just one specific package, as well as update to the latest version of a package or a specific version of a package. https://yarnpkg.com/lang/en/docs/cli/upgrade/

Version Control Your package.json and yarn.lock

By adding these two files to version control, you'll easily be able to revert your project to a specific point in time in regards to your packages.

like image 93
KayakinKoder Avatar answered Oct 12 '22 01:10

KayakinKoder


The selected answer is wrong.

caret means following

^3.1.4 will allow a version range from >=3.1.4 <4.0.0
like image 26
thecaveman Avatar answered Oct 12 '22 01:10

thecaveman