pnpm equivalent command for npm ci

22.8k Views Asked by At

What is the equivalent command for npm ci in pnpm?

According to the documentation for npm install:

pnpm install is used to install all dependencies for a project.

In a CI environment, installation fails if a lockfile is present but needs an update.

How is the "CI environment" defined?

What does the following mean? Dependencies could be updated, but the pnpm-lock.yaml is not touched?

pnpm i --frozen-lockfile # pnpm-lock.yaml is not updated

2

There are 2 best solutions below

0
On BEST ANSWER

What is the equivalent command for npm ci in pnpm?

The equivalent is

pnpm install --frozen-lockfile

However, even if you don't use --frozen-lockfile, pnpm will automatically use a faster installation strategy if the lockfile is up-to-date. This is controlled by the prefer-frozen-lockfile setting which is true by default.

How is the "CI environment" defined?

pnpm uses the is-ci package to detect whether the environment is a CI.

pnpm i --frozen-lockfile # pnpm-lock.yaml is not updated

It means that if the lockfile is not up-to-date with the package.json file then pnpm install will throw an exception instead of updating the lockfile. If the lockfile is up-to-date, pnpm will do any necessary updates to the node_modules.

2
On

It's an old question, but I found me in the same problem. Hope to help someone with this.

In Unix-like environments (e.g. Linux), use

CI=true pnpm i

You can even set in the package.json a script called ci with this command, what will make pnpm ci work as expected.

In other environments, the idea is the same. Set the CI env variable to something truthy.

Explanation

I'd investigate this question based on Zoltan Kochan's answer:

  1. I found that PNPM changed from using is-ci in favor of ci-info (from the same developer, and is-ci itself uses ci-info).
  2. In fact PNPM uses this to determine if it's a CI environment
  3. ci-info checks for several cloud vendors, but it follows the CI environment variable if it is set
  4. I have tested this, and you can view or clone the code from: https://gist.github.com/40b75f11125cd9986611ec6b9b97b8b4.git
  5. I've also opened an issue in the GitHub suggesting this command as a new feature.