I’ve been researching on optimization that can be done in one of the project’s CI pipeline. The issue is that the whole process can take a very long time including time to set up the project and running all the tests. So I’ve been looking at pnpm to manage the installation of the JavaScript’s dependencies in the CI.

From my experience, the time taken to install the packages can be reduced to just seven seconds (from around almost two minutes, with cache primed) so this is a very welcomed changes. Every second matters.

Once I got the pnpm installed, it’s pretty much a drop-in replacement for npm.

Here’s a short steps that I’ve taken to migrate an existing JavaScript to use pnpm:

  1. Delete node_modules.
  2. Migrate any workspaces defined in package.json to its own specific pnpm-workspace.yaml.
  3. Run pnpm import. This will allow pnpm to create its own version of the lockfile, pnpm-lock.yaml based on the current lockfile used in the project (packages-lock.json/yarn.lock).
  4. Install the dependencies via pnpm i.
  5. Replace any npm run command with pnpm, eg: pnpm build instead of npm run build.

That’s it!