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
:
- Delete
node_modules
. - Migrate any
workspaces
defined inpackage.json
to its own specificpnpm-workspace.yaml
. - Run
pnpm import
. This will allowpnpm
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
). - Install the dependencies via
pnpm i
. - Replace any
npm run
command withpnpm
, eg:pnpm build
instead ofnpm run build
.
That’s it!