Motivazione
Saving disk space
Quando si usa npm, se hai 100 progetti che usano una dipendenza, avrai 100 copie di quella dipendenza salvata su disco. Con pnpm, la dipendenza sarà memorizzata in un archivio indirizzabile al contenuto, quindi:
- Se dipendi da versioni diverse della dipendenza, solo i file diversi sono aggiunti all'archivio. For instance, if it has 100 files, and a new
version has a change in only one of those files,
pnpm update
will only add 1 new file to the store, instead of cloning the entire dependency just for the singular change. - Tutti i file sono salvati in un'unica posizione sul disco. Quando i pacchetti vengono installati, i loro file sono collegati fisicamente da quella singola posizione, senza consumare spazio su disco aggiuntivo. Ciò consente di condividere dipendenze della stessa versione tra progetti.
Di conseguenza, è possibile risparmiare molto spazio su disco proporzionalmente al numero di progetti e dipendenze, e avrai installazioni molto più veloci!
Boosting installation speed
pnpm perfoms installation in three stages:
- Dependency resolution. All required dependencies are identified and fetched to the store.
- Directory structure calculation. The
node_modules
directory structure is calculated based on the dependencies. - Linking dependencies. All remaining dependencies are fetched and hard linked from the store to
node_modules
.
This approach is significantly faster than the traditional three-stage installation process of resolving, fetching, and writing all dependencies to node_modules
.
Creating a non-flat node_modules directory
When installing dependencies with npm or Yarn Classic, all packages are hoisted to the root of the modules directory. As a result, source code has access to dependencies that are not added as dependencies to the project.
By default, pnpm uses symlinks to add only the direct dependencies of the project into the root of the modules directory.
If you'd like more details about the unique node_modules
structure that pnpm
creates and why it works fine with the Node.js ecosystem, read:
If your tooling doesn't work well with symlinks, you may still use pnpm and set the node-linker setting to hoisted
. This will instruct pnpm to create a node_modules directory that is similar to those created by npm and Yarn Classic.