当前位置:网站首页>Recognize pnpm: faster, higher performance NPM
Recognize pnpm: faster, higher performance NPM
2022-06-26 06:58:00 【Code Taoist】
What is? PNPM?
PNPM yes Node.js Used in substitution NPM Another package manager for , representative “Performant NPM”.
PNPM The main purpose of is to keep all packages in one global ( Centralized ) In storage , And use them when other projects need them by creating hard links .
Use PNPM be better than NPM The advantages of
- Save a lot of disk space .
- Installing software packages takes more time .
- It is right. mono Built in support for repositories .
Now? , Let's try to understand PNPM How it actually works .
So , I need two applications to understand PNPM Use the concepts behind the scenario .
These are two applications package.json file :
{
"name": "application1",
"version": "0.0.0",
"private": true,
"main": "app.js",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.4",
"csurf": "^1.10.0",
"debug": "~2.6.9",
"ejs": "~2.6.1",
"express": "~4.16.1",
"express-session": "^1.17.0"
}
}
{
“name”: “application2”,
“version”: “0.0.0”,
“private”: true,
“main”: “app.js”,
“scripts”: {
“start”: “node ./bin/www”
},
“dependencies”: {
“cookie-parser”: “~1.4.4”,
“csurf”: “^.10.0”,
“debug”: “~2.6.9”,
“powerbi-client”: “^.16.5”,
“rxjs”: “^.5.3”
}
}install
First , I use... By running the following command npm Installed pnpm:
npm install -g pnpmBe careful : My system has been installed with Nodejs v16.13.2 and NPM v6.28.0.
We can test by running the following instructions PNPM Is the installation successful :
pnpm -vThe above command is used to check which version of pnpm.
PNPM And NPM What's the difference? ?
In order to understand their working differences , I am for npm and pnpm Two directories are created respectively , Both use two sample applications , And use npm and pnpm Install the software packages in different directories .
npm
application 1:
[email protected]:~/npm-demo$ npm install
added 71 packages, and audited 72 packages in 1s
found 0 vulnerabilitiesapplication 2:
[email protected]:~/npm-demo2$ npm install
added 27 packages, and audited 28 packages in 9s
found 0 vulnerabilitiesad locum , As you can see ,npm In the application 1 Installed in 71 A package , In the application 2 Installed in 27 A package , This is very good .
however , If you look at these two applications from the front package.json file , You will find that both have something in common Three bags .
Even if the application 2 Need some installed dependencies ( In the application 1 in ), We can't reuse what has been npm Dependencies installed by another project in .
pnpm
application 1:
[email protected]:~/pnpm-demo$ pnpm install
Packages: +67
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: /home/rach/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm
Progress: resolved 67, reused 0, downloaded 67, added 67, done
dependencies:
+ cookie-parser 1.4.6
+ csurf 1.11.0
+ debug 2.6.9 (4.3.3 is available)
+ ejs 2.6.2 (3.1.6 is available)
+ express 4.16.4 (4.17.2 is available)
+ express-session 1.17.2application 2:
[email protected]:~/pnpm-demo2$ pnpm install
Packages: +27
+++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
Content-addressable store is at: /home/rach/.pnpm-store/v3
Virtual store is at: node_modules/.pnpm
dependencies:
+ cookie-parser 1.4.6
+ csurf 1.11.0
+ debug 2.6.9 (4.3.3 is available)
+ powerbi-client 2.19.1
+ rxjs 6.6.7 (7.5.2 is available)
Progress: resolved 27, reused 18, downloaded 9, added 27, doneFrom output , We can notice that pnpm In the application 1 Installed in 67 A package , In the application 2 Installed in 27 A package . however , If you look at the last line in the output —— speed of progress , You will find that it reuses what has been done for the application 1 Installed 18 A package .
“ stay pnpm in , If you have installed a package for another project , Then they will always be reused , This saves a lot of disk space , This makes it more than npm faster 、 More efficient .”
This is amazing !
But where are these packages stored ?
Use pnpm install, Especially this line in the output ,“Packages are hardlinked from the content-addressable store to the virtual store”, Shows how it works .
Content addressed storage is a storage mechanism , The data is stored on the hard disk by assigning a permanent location and addressing it with a unique identifier .

In the screenshot above , You can see that a file named “.pnpm-store” Hidden directory for .
Hidden files can be system or application files stored on a hard disk drive with a permanent location , And hidden to prevent any accidental changes .
This hidden directory —— .pnpm-store go by the name of “ Content addressable storage ”, All downloaded dependencies are stored in it .
Whenever you download a dependency ,pnpm First, check whether the dependency exists in this store .
Hard links are just exact copies of the original file , It also points to the hard drive ( Of the original document ) Same position .
If a dependency already exists in this store , be pnpm Retrieve the same content by creating hard links .
Conclusion
By explaining pnpm And npm The difference between , And the use of pnpm Instead of npm The benefits that can be obtained , We are right. pnpm With a simple understanding . You've tried before pnpm Do you ? What do you think of it ? Do you have any idea ?
边栏推荐
- Report on China's potassium fluoride Market Survey and suggestions for future development strategic planning 2022
- Market survey of China's coal to liquid industry and analysis report on investment competitiveness during the "14th five year plan" 2022-2027
- Turris omnia: an open source router technology favored by hackers
- How to set MySQL triggers is a simple tutorial for novices
- Operation mode and investment planning report of China's financial warehousing industry during the "14th five year plan" period 2022-2027
- Decompile Android applications, interview Android
- Professional course - Code question record
- Open source demo| you draw and I guess -- make your life more interesting
- DS18B20 details
- 数据挖掘是什么?
猜你喜欢

STM 32 uses cube to generate Tim to trigger ADC and transmit through DMA
![[micro service series] protocol buffer dynamic analysis](/img/86/357d55c77cc67d6413af2de59bf395.png)
[micro service series] protocol buffer dynamic analysis

unity之EasyAR使用
![[digital signal processing] basic sequence (unit step sequence | relationship between unit step sequence and unit pulse sequence | rectangular sequence | relationship between rectangular sequence and](/img/0c/3aeb7f93576181bbc46d2d1a1aa0e7.jpg)
[digital signal processing] basic sequence (unit step sequence | relationship between unit step sequence and unit pulse sequence | rectangular sequence | relationship between rectangular sequence and

Past events of Xinhua III

SecureCRT运行SparkShell 删除键出现乱码的解法

Interviewer: what is the difference between a test plan and a test plan?

“试用期避免被辞退“ 指南攻略

NumPy学习挑战第四关-NumPy数组属性

One chip realizes functions such as spray 𞓜 ws2812 drive | key touch | LED display | voice broadcast chip and simplifies the design of humidifier products
随机推荐
Research Report on sales scale forecast and investment opportunities of China's jewelry industry 2022-2027
专业课-代码题记录
Show statement usage supplement
我在腾讯做测试的这几年...
cocoscreator播放Spine动画
数据湖架构之Hudi编译篇
淺析一道經典題
SQL 查询语句
遇到女司机业余开滴滴,日入500!
I have been testing at Tencent for several years
海量日志采集工具——Flume
SQL query statement
Six stones Management: exaggerating the achievements, whether the parties themselves know
My SQL (II)
Research Report on China's surfactant market demand and future investment opportunities 2022
Solve the problem of transparency at the bottom of dialog
China's wind farm operation industry's "fourteenth five year plan" planning direction and investment risk prediction report 2022-2027
Rust中的过程宏
OCA Security Alliance (cybersecurity mesh)
如何把数据库的数据传给复选框