NPM YARN is different from PNPM

PNPM is a package management tool recently released. The official documentation address is www.pnpm.cn/

As soon as it came out, it was used by many open source projects, and the star number also exceeded 13K

What is the difference between NPM and NPM

The installation

npm install -g pnpm

use

pnpm install xxx

pnpm add xxx

.

Other commands are used in the same way as NPM commands

tree

I use the installation of Express in a project as an example

A Linux command tree is used to view the directory tree of the final installation

The installation

sudo apt-get install tree

use

Run the command in the directory to be displayed

tree -L 2

npm tree

NPM install tree

.├ ── ├─ ├─ ├─ ├─ package-lock-├ ─ download.json.├.js ├─ ├ _modulesCopy the code

pnpm tree

Final directory for PNPM installation

. ├ ─ ─ index. Js ├ ─ ─ node_modules │ ├ ─ ─ the PNPM / / cache directory │ ├ ─ ─ express - > / mnt/d/workspace/demo/blog/demo/work-note/pnpm-demo/pnpm/node_modules/.pnpm/registry.nlark.com + [email protected] / node_modul Es/express / │ │ ├ ─ ─ the History. The md │ │ ├ ─ ─ LICENSE │ │ ├ ─ ─ the Readme. Md │ │ ├ ─ ─ index. The js │ │ ├ ─ ─ lib │ │ │ ├ ─ ─ application. Js │ │ │ ├ ─ ─ express. Js │ │ │ ├ ─ ─ middleware │ │ │ │ ├ ─ ─ init. Js │ │ │ │ └ ─ ─ query. Js │ │ │ ├ ─ ─ request. Js │ │ │ ├ ─ ─ Response. Js │ │ │ ├ ─ ─ the router │ │ │ │ ├ ─ ─ index. The js │ │ │ │ ├ ─ ─ layer. The js │ │ │ │ └ ─ ─ the route. The js │ │ │ ├ ─ ─ utils. Js │ │ │ └ ─ ─ ├ ─ ├ ─ imme-types -> / mnt/d/workspace/demo/blog/demo/work-note/pnpm-demo/pnpm/node_modules/.pnpm/registry.npmmirror.com + [email protected] / nod ├─ ├─ download.json ├─ download.json e_modules/mime-types/ │ ├─ history.md │ ├─ download.js │ ├─ download.json └ ─ ─ PNPM - lock. YamlCopy the code

NPM/YARN Installation process

After NPM/YARN install is executed

After executing the command, the dependency tree is first built, and then the packages under each node go through the following four steps:

    1. Resolves the version range of a dependent package to a specific version number
    1. Download the tar package dependent on the corresponding version to the local offline image
    1. Decompress dependencies from offline images to the local cache
    1. Copies dependencies from the cache to the node_modules directory of the current directory

In the early version of NPM1 and Npm2, node_modules have a nested structure, resulting in slow download, low resource utilization, and repeated references and repeated downloads

After NPM3, the directory after yarn installation was a tiled structure, flat dependency, where we installed one Express, and there were a lot of other packages. But the problem is also obvious, 1) the structure is not stable, 2) is that the original NPM package has no permission to access, now because they are tiled, leading to access, this is also why the lock file, if other different packages rely on the same package version is not consistent

PNPM installation process

Node_modules, express is a soft link to the.pnpm directory in the same directory, which is the final installation address of the library. The folder name is domain name + package name @ version number, which largely avoids NPM determinations.

    1. The same version will not be installed again
    1. The node_modules structure is also more stable