Saltar al contenido principal
Version: 7.x

Motivaci贸n

Saving disk space

An illustration of the pnpm content-addressable store. On the illustration there are two projects with node_modules. The files in the node_modules directories are hard links to the same files in the content-addressable store.

Cuando usas npm, las dependencias se instalan en almacenamientos individuales, lo que provoca que descargues la misma dependencia por cada proyecto que dependa de esta. Con pnpm, esa dependencia sera almacenada en un almacenamiento compartido, as铆:

  1. Si dependes de diferentes versiones de una dependencia, solo los archivos que difieren ser谩n agregados al almacenamiento. Por ejemplo, si tiene 100 archivos, y una nueva version ha cambiado un solo de esos archivos, pnpm update solo actualizar谩 1 nuevo archivo en el almacenamiento, en vez de clonar toda la dependencia solo para un cambio en particular.
  2. Todos los archivos son guardados en un solo lugar del disco duro. Cuando los paquetes que son instalados, sus archivos son hard-linked a un solo lugar, sin consumir espacio adicional en su disco duro. Esto te permitir谩 compartir tus dependencias de la misma version en diferentes proyectos.

Como resultado, usted ahorra un mont贸n de espacio en su disco duro proporcional al numero de proyectos y dependencias, y tu disfrutaras de instalaciones mas r谩pidas!

Boosting installation speed

pnpm perfoms installation in three stages:

  1. Dependency resolution. All required dependencies are identified and fetched to the store.
  2. Directory structure calculation. The node_modules directory structure is calculated based on the dependencies.
  3. Linking dependencies. All remaining dependencies are fetched and hard linked from the store to node_modules.

An illustration of the pnpm install process. Packages are resolved, fetched, and hard linked as soon as possible.

This approach is significantly faster than the traditional three-stage installation process of resolving, fetching, and writing all dependencies to node_modules.

An illustration of how package managers like Yarn Classic or npm install dependencies.

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.

An illustration of a node_modules directory created by pnpm. Packages in the root node_modules are symlinks to directories inside the node_modules/.pnpm 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:

tip

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.