How to identify which version of Yarn is used by a project?

Viewed 391

For the OSS Review Toolkit project, I would like to identify which version of yarn is used by a given project in a given repository.

Which criteria should be used ? There is:

  • package.json/packageManager which requires Corepack and may not be used by all projects.
  • look at the version .yarn/releases/*
  • check the .yarnrc file: if this is yarnrc.yml then this is Yarn 2+.
  • the version in yarn.lock seems to not be related to the Yarn version used for the project (but please correct me if I am wrong).

Is there any other criteria that could be used to disambiguiate if this is a Yarn 1, 2 or 3 project ?

1 Answers

The frustrating answer is that there isn't an easy way (although there probably should be). Running yarn -v will simply show your global yarn version; not the local repo. You need to look for the same hints you listed.

Perhaps your collaborators can agree to make an arbitrary yarn script like this:

"set-yarn-ver": "yarn set version 1.22.11"
Related