preface
- Duration: about 15 minutes
- Environment Preparation:
The Node > = v16.9
- Writing time: 2022-01-06
Old Official News (September 2020)
According to node.js official Envisioned Workflow chapter on Corepack:
The full npm package wouldn’t be included out of the box anymore
NPM package manager will no longer default out of the box
It is expected to be available on V17. PNPM and YARN have finally become first-class citizens. Even if we don’t go into the principles and pros and cons, we should also learn the basic concepts and how to use things that everyone has said are good. Fortunately, this only takes about 15 minutes.
To borrow this tweet from yarn author, did NPM become A-Doo because of patent 🐶?
Early experience
NPM will be officially abandoned by Node.js → Corepack.
Install Node.16.9.0 first and declare the corresponding package management tool in package.json:
Json {"name": "corepack-test", "packageManager": "[email protected]"}Copy the code
The play:
$PNPM install Usage Error $PNPM install Usage Error $PNPM install Usage Error This project is configured to use yarnCopy the code
Upgrade using command:
Corepack prepare [email protected] - activateCopy the code
💡 Warning: pnpm@latest is not supported. Semver must be used. You can query the corresponding semver in NPM Register. Package. The json in the same way.
💡 Tip: If the packageManager is specified in the package.json project and is installed globally, always use the version number specified by the project.
NPM common commands
NPM is the default Package manager for Node. As of this writing, it is version 8.3.0, so if you read some of the older popular articles, be aware that the version number of NPM is mentioned. Much of the analysis may be out of date for NPM8. Several advantages of YARN, for example, have been borrowed by NPM.
NPM commands are too common to learn. Other package management commands are similar. Here are some common NPM commands:
$NPM install express; $NPM install express; -g list global directory installed $NPM show Express # Show module details $NPM update # Upgrade all modules of the project in the current directory $NPM Update Express # Upgrade the specified module of the project in the current directory $NPM $NPM uninstall Express # Delete the specified moduleCopy the code
pNpM
1. Installation and upgrade
Corepack Enable is used to activate the installation. Upgrade to the specified version by corepack prepare [email protected] –activate.
Characteristics of 2.
By Zoltan Kochan, in one sentence:
Fast, disk space efficient package manager
Fast, disk space saving software package manager
The P is said to stand for Performant. Corepack for Node V16.13
- Fast: nearly twice as fast as similar tools
- Efficient: All files in node_modules are linked from a single storage location
- Support for single warehouse: built-in support for Monorepos
PNPM uses the Hard Link mechanism to improve performance. Shenyuan’s deep thoughts on modern package manager — why do I now recommend PNPM over NPM/YARN? Detailed analysis of principles and performance.
3. Quick learning – command line comparison table
Here’s a table of NPM equivalents to get you started:
NPM command | PNPM command | instructions |
---|---|---|
npm install |
pnpm install |
Alias: i. |
npm i <pkg> |
pnpm add <pkg> |
--save-prod, -P --save-dev, -D --save-optional, -O |
npm uninstall |
pnpm remove |
Aliases: rm, uninstall, UN |
yarn
1. Installation and upgrade
Corepack Enable is used to activate the installation. Upgrade to the specified version by corepack prepare [email protected] –activate. Upgrade to Berry: Corepack Prepare [email protected] — Activate
Characteristics of 2.
Yarn is published on Facebook and Github has 40.3 K Star. Used to be faster to install than NPM < 5; The installation process information is clean and more error friendly; Yarn. lock and other advantages, but not now. It can be considered basically convergent and is currently actively used.
3. Quick learning – command line comparison table
Here’s a table of NPM equivalents to get you started:
NPM command | PNPM command | instructions |
---|---|---|
npm install |
yarn install |
Install can be omitted in YARNyarn |
npm i <pkg> |
yarn add <pkg> |
The default-S Others include:--dev/-D .--optional/-O |
npm uninstall <pkg> |
yarn remove <pkg> |
cnpm
CNPM’s C stands for Company. Is a tool for setting up an internal NPM Registry.
Private npm registry and web for Company
CNPM can be used as a command line utility to install, also can set an alias, is essentially a pointing to https://registry.npmmirror.com NPM registry mirror, Sync with registry.npmjs.com at regular intervals (currently 10 minutes to ensure maximum synchronization with official services). NPM also uses a different cache directory and user configuration directory to avoid conflicts with NPM.
💡 Tip: Because CNPM and NPM can be mixed in a project, it is recommended not to mix. I directly use NPM with domestic source, not use CNPM command line.
Reference documentation
- 2020-09-27 Maël Nison@Github Corepack design
- NPM will be officially abandoned by Node.js → Corepack
- Zoomdong Pnpm: The most advanced package management tool
- 2021-02-22 Shenyuan deep Thoughts on modern package manager — Why do I recommend PNPM over NPM/YARN now?