What is pnpm?
pnpm is a fast, disk space efficient package manager for JavaScript that works with the npm and Yarn registries. It uses hard links and symlinks to save disk space and improve installation speed. It also has a strict node_modules structure that helps to avoid issues with phantom dependencies.
What are pnpm's main functionalities?
Installing packages
Installs the lodash package into your project. This is similar to npm install or yarn add.
pnpm install lodash
Creating a new project
Initializes a new package.json file for your project, similar to npm init or yarn init.
pnpm init
Adding a package to dependencies
Adds the react package to your project's dependencies, similar to npm install react --save or yarn add react.
pnpm add react
Adding a package to devDependencies
Adds the typescript package to your project's devDependencies, similar to npm install typescript --save-dev or yarn add typescript --dev.
pnpm add --save-dev typescript
Updating packages
Updates all the packages in your project to their latest versions based on the specified ranges in package.json, similar to npm update or yarn upgrade.
pnpm update
Running scripts
Runs the script named 'build' specified in your package.json, similar to npm run build or yarn run build.
pnpm run build
Other packages similar to pnpm
npm
npm is the default package manager for Node.js and is the most widely used. It has a large ecosystem and is well-supported, but it can be slower and use more disk space compared to pnpm.
yarn
Yarn is a package manager that was created by Facebook to address some of npm's shortcomings. It introduced lockfiles and deterministic installations. Yarn is faster than npm but can still use more disk space compared to pnpm.
pnpm
Performant npm installations
pnpm is a fast implementation of npm install
. It is loosely based off ied.
⚠ Name change
The npm package was changed from pnpm.js
(0.15 and below) to pnpm
. The old package will no longer be updated. For old users, uninstall the old version and install the new one:
npm uninstall -g pnpm.js
npm install -g pnpm
Install
Install it via npm.
npm install -g pnpm
Use pnpm
in place of npm
. It overrides pnpm i
and pnpm install
—all other commands will passthru to npm
.
pnpm install lodash
Custom registries
pnpm uses whatever npm's configured to use as its registry. See: custom registries.
Preview release
pnpm
will stay in <1.0.0
until it's achieved feature parity with npm install
. See roadmap for details.
Benchmark
time npm i babel-preset-es2015 browserify chalk debug minimist mkdirp
66.15 real 15.60 user 3.54 sys
time pnpm i babel-preset-es2015 browserify chalk debug minimist mkdirp
11.04 real 6.85 user 2.85 sys
Design
pnpm
maintains a flat storage of all your dependencies in node_modules/.store
. They are then symlinked whereever they're needed.
See store layout for an explanation.
.
└─ node_modules/
├─ .store/
│ ├─ chalk@1.1.1/_/
│ │ └─ node_modules/
│ │ ├─ ansi-styles -> ../../../ansi-styles@2.1.0/_
│ │ └─ has-ansi -> ../../../has-ansi@2.0.0/_
│ ├─ ansi-styles@2.1.0/_/
│ └─ has-ansi@2.0.0/_/
└─ chalk -> .store/chalk@1.1.1/_
Prior art
Thanks
pnpm © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com ·
GitHub @rstacruz ·
Twitter @rstacruz