Created by: larixer
Yarn 2+ getting started instructions advise to use Yarn 2+ via corepack
. corepack
is shipped with the latest versions of Node 14.x, 16.x and future Node versions. corepack
uses Yarn 1.x by default for all the CLI commands that are available only in Yarn 1.x or both in Yarn 1.x and Yarn 2+. However yarn dlx
cli command which become available in Yarn 2+ only gets routed to Yarn 2+ by corepack
.
When the user has corepack
enabled and executes yarn dlx create-react-app
, he naturally should expect that the initialized React app will use Yarn 2+. This PR is devoted to make this happen.
The PR gets Yarn version from process.env.npm_config_user_agent
and stores it into packageManager
field of package.json
in the generated app. corepack
uses packageManager
field and routes all the yarn ...
command to the Yarn version specified in this field.
Credits should go to @merceyz for the process.env.npm_config_user_agent
idea.