Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Corepack instructions in installation.md #504

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If you have installed Node.js with `pnpm env` Corepack won't be installed on you
:::

```
corepack enable
corepack enable pnpm
```

If you installed Node.js using Homebrew, you'll need to install corepack separately:
Expand All @@ -76,18 +76,16 @@ If you installed Node.js using Homebrew, you'll need to install corepack separat
brew install corepack
```

This will automatically install pnpm on your system. However, it probably won't be the latest version of pnpm. To upgrade it, check what is the [latest pnpm version](https://github.com/pnpm/pnpm/releases/latest) and run:
This will automatically install pnpm on your system.

```
corepack prepare pnpm@<version> --activate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if I don't want to use the packageManager field just install the latest pnpm version globally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should expect Corepack to download the latest version on the first use. After that, if you want to manually bump it, you can run corepack install --global pnpm@latest (or the old corepack prepare command, that still works).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So corepack enable pnpm installs the latest version? It used to install some hardcoded stable version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short answer is "yes". The long answer is:
Technically, corepack enable pnpm only adds a binary on the PATH; pnpm will be downloaded only when it's first needed (so either when calling corepack pnpm … or using the pnpm bin created by corepack enable), and here are the steps that Corepack takes to determine what version to use:

  • if there's a local package.json with a "packageManager" field, use the version defined there.
  • otherwise, check if there's a cached global version, if so, use that.
  • otherwise, check if env variable COREPACK_DEFAULT_TO_LATEST was set to 0, in which case, use the hard coded version.
  • otherwise, use the latest version from the npm registry.
    It did use to default to the hardcoded version, but that was a while back.

```

With Node.js v16.17 or newer, you may install the `latest` version of pnpm by just specifying the tag:
You can pin the version of pnpm used on your project using the following command:

```
corepack prepare pnpm@latest --activate
corepack use pnpm@latest
```

This will add a `"packageManager"` field in your local `package.json` which will instruct Corepack to always use a specific version on that project. This can be useful if you want reproducability, as all developers who are using Corepack will use the same version as you. When a new version of pnpm is released, you can re-run the above command.

## Using npm

We provide two packages of pnpm CLI, `pnpm` and `@pnpm/exe`.
Expand Down
Loading