Loko u ri muendli wa Node.js , kutani u tolovelane na npm na Yarn . U nga ha va ni vonelo leri tiyeke hambi ku ri ku tirhisa yin’wana ku tlula yin’wana. Ku ringana malembe, vaendli va swilo va ri karhi va lwisana na bloat — eka vuhlayiselo bya disk na nkarhi wo aka — loko va tirha na vafambisi va tiphasela ta Node.js, ngopfu-ngopfu npm .
Kutani, ku landzela pnpm , mufambisi wa tiphasela loyi a khomaka vuhlayiselo bya tiphasela hi ndlela yo hambana, a hlayisa ndhawu ya vatirhisi na ku hunguta nkarhi wo aka. Hi leyi ndlela leyi pnpm yi hlamuselaka ku hambana ha yona :
“Loko u nghenisa phasela, hi ri hlayisa exitolo xa misava hinkwayo eka muchini wa wena, ivi hi endla xihlanganisi xo tika eka rona ematshan’weni yo kopa. Eka vuhundzuluxeri byin’wana ni byin’wana bya modyuli, ku tshama ku ri ni kopi yin’we ntsena leyi hlayisiwaka eka disk. Loko u tirhisa npm kumbe yarn xikombiso, loko uri na 100 wa ti packages hiku tirhisa lodash, uta va na 100 wa ti copies ta lodash eka disk. pnpm yi ku pfumelela ku hlayisa ti-gigabyte ta ndhawu ya disk!”
A swi hlamarisi leswi pnpm yi kumaka ku koka, laha vaendli vo tala va yi endlaka mufambisi wa vona wa tiphasela wa ku hlawula. Ku fambisana na mpimo wolowo lowu kulaka wa ku amukeriwa, vaendli vo tala lava tirhisaka ti-app ta vona eka Heroku (ku fana na mina) a va lava ku vona pnpm yi seketeriwa.
Nkateko wa kona, pnpm yi kumeka hi ku tirhisa Corepack , leyi hangalasiweke na Node.js. Kutani, ku sukela hi May 2024, pnpm sweswi yi kumeka eka Heroku !
Eka post leyi, hi ta hlanganisa leswi swi lavekaka ku sungula hi pnpm eka Heroku. Naswona, hi ta tlhela hi kombisa yin’wana ya mimbuyelo ya vuhlayiselo na nkarhi wo aka leyi u yi kumaka hi ku yi tirhisa.
pnpm yi tumbuluxiwile ku tlhantlha mhaka ya nkarhi wo leha ya Node.js package manager ya vuhlayiselo lebyi nga lavekiki na ku pfumaleka ka vukorhokeri eka ku khoma ku titshega . npm na Yarn swi kopa ku titshega eka node_modules
ya phurojeke yin’wana na yin’wana. Ku hambana na sweswo, pnpm yi hlayisa tiphasela hinkwato ta tiphurojeke hinkwato eka xitolo xin’we xa misava hinkwayo ivi yi tumbuluxa swihlanganisi swo tika eka tiphasela leti ku tlula ku ti kopa. Xana leswi swi vula yini?
A hi tekeni leswaku hi na phurojeke ya Node.js leyi tirhisaka lodash
. Hi ntumbuluko, phurojeke yi ta va na folda node_modules
, kun’we na folda leyitsongo leyi vuriwaka lodash
, leyi taleke hi tifayela. Ku vula ntiyiso, [email protected]
yi na tifayela ta 639 na folda yin’wana leyitsongo leyi vuriwaka fp
, na tifayela tin’wana ta 415.
Sweswo swi tlula gidi ra tifayela ta lodash
ntsena!
Ndzi endlile tiphurojeke ta tsevu ta Node.js: timbirhi hi pnpm, timbirhi hi npm, na timbirhi hi Yarn. Un'wana na un'wana wa vona u tirhisa lodash
. A hi languteni vuxokoxoko bya yin’we ntsena ya tifayela eka folda ya ku titshega lodash
.
~/six-projects$ ls -i npm-foo/node_modules/lodash/lodash.js 14754214 -rw-rw-r-- 544098 npm-foo/node_modules/lodash/lodash.js ~/six-projects$ ls -i npm-bar/node_modules/lodash/lodash.js 14757384 -rw-rw-r-- 544098 npm-bar/node_modules/lodash/lodash.js ~/six-projects$ ls -i yarn-foo/node_modules/lodash/lodash.js 14760047 -rw-r--r-- 544098 yarn-foo/node_modules/lodash/lodash.js ~/six-projects$ ls -i yarn-bar/node_modules/lodash/lodash.js 14762739 -rw-r--r-- 544098 yarn-bar/node_modules/lodash/lodash.js ~/six-projects$ ls -i pnpm-foo/node_modules/lodash/lodash.js 15922696 -rw-rw-r-- 544098 pnpm-foo/node_modules/lodash/lodash.js ~/six-projects$ ls -i pnpm-bar/node_modules/lodash/lodash.js 15922696 -rw-rw-r-- 544098 pnpm-bar/node_modules/lodash/lodash.js
Fayili lodash.js
yi tlulanyana hafu ya megabyte hi vukulu. A hi voni swihlanganisi swo olova, kutani loko hi swi languta ro sungula, hakunene swi vonaka onge phurojeke yin’wana ni yin’wana yi ni khopi ya yona ya fayili leyi. Hambiswiritano, entiyisweni a swi tano.
Ndzi tirhise ls
na -i
flag ku kombisa inode ya fayili lodash.js
. U nga vona eka tiphurojeke pnpm-foo
na pnpm-bar
, tifayela leti hatimbirhi ti na inode yin’we ( 15922696
). Va kombetela eka fayili yin’we! Sweswo a swi tano eka npm kumbe Yarn.
Kutani, loko u ri na khume-mbirhi wa tiphurojeke leti tirhisaka npm kumbe Yarn, naswona tiphurojeke teto ti tirhisa lodash
, kutani u ta va na khume-mbirhi wa tikopi to hambana ta lodash
, kun’we ni tikopi leti humaka eka swin’wana leswi titshegeke eka tiphurojeke teto leti hi toxe ti tirhisaka lodash
. Eka pnpm, phurojeke yin’wana na yin’wana na ku titshega loku lavaka vuhundzuluxi lebyi byo karhi bya lodash
swi kombetela eka khopi leyi fanaka, yin’we, ya misava hinkwayo.
Khodi ya [email protected]
yi le hansi nyana ka 5 MB hi vukulu. Xana u nga tsakela ku va ni tikopi ta yona ta 100 leti nga lavekiki eka muchini wa wena, kumbe kopi yin’we ntsena ya misava hinkwayo?
Eku heleni ka siku, ku nghenisiwa ka ku titshega hi pnpm swi hatlisa swinene, swi lava ndhawu yitsongo ya disk na switirhisiwa switsongo. Eka vatumbuluxi lava tirhaka eka tiphurojeke to tala kumbe ku lawula ku titshega eka tipulatifomo ta le mapapa, pnpm yi nyika ndlela yo olova, yo hatlisa yo lawula tiphasela. Leswi swi endla leswaku pnpm yi va leyinene eka ndhawu yo tirhisa leyi olovisiweke ku fana na Heroku.
Xana u lunghekele ku sungula ku yi tirhisa? A hi fambeni hi ndlela leyi.
Hi leyi version ya Node.js leyi hi tirhaka na yona eka muchini wa hina:
$ node --version v20.18.0
Hilaha hi vuleke hakona laha henhla, Corepack yi ta na Node.js, kutani hi lava ntsena ku tirhisa corepack
ku pfumelela na ku tirhisa pnpm. Hi endla folda ya phurojeke ya hina. Kutani, hi fambisa swileriso leswi:
~/project-pnpm$ corepack enable pnpm ~/project-pnpm$ corepack use pnpm@latest Installing [email protected] in the project... Already up to date Done in 494ms
Leswi swi tumbuluxa fayili ya package.json
leyi langutekaka hi ndlela leyi:
{ "packageManager": "[email protected]+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" }
Leswi swi tlhela swi tumbuluxa fayili ya pnpm-lock.yaml
.
Endzhaku ka sweswo, hi engetela swilo leswi titshegeke eka phurojeke ya hina. Hi swikongomelo swa nkombiso, hi kopa nxaxamelo wa dependencies
na devDependencies
leswi kumekaka eka fayili leyi ya benchmarking package.json
eka GitHub . Sweswi, fayili ya hina package.json
yi languteka hi ndlela leyi:
{ "version": "0.0.1", "dependencies": { "animate.less": "^2.2.0", "autoprefixer": "^10.4.17", "babel-core": "^6.26.3", "babel-eslint": "^10.1.0", ... "webpack-split-by-path": "^2.0.0", "whatwg-fetch": "^3.6.20" }, "devDependencies": { "nan-as": "^1.6.1" }, "packageManager": "[email protected]+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" }
Kutani, hi nghenisa tiphasela.
~/project-pnpm$ pnpm install
Matirhiselo ya pnpm yafana swinene na npm kumbe yarn, naswona hikokwalaho yafanele kuva ya twisiseka. Laha hansi ku na tafula leri pimanisaka matirhiselo yo hambana ya swileriso leswi tolovelekeke (leswi tekiweke eka poso leyi ).
Sweswi hi kombiseke ndlela yo endla leswaku phurojeke yi tirha hi pnpm (swi olovile swinene, a swi tano ke?), hi lave ku pimanisa minkarhi yo aka ya vafambisi vo hambana va tiphasela loko hi tirha eka Heroku. Hi vekile tiphurojeke tinharhu leti nga na ku titshega loku fanaka — hi ku tirhisa npm, Yarn, na pnpm.
Xo sungula, hi nghena eka Heroku CLI ( heroku login
).
Kutani, hi endla app ya phurojeke. Hi ta kombisa magoza ya phurojeke ya npm.
~/project-npm$ heroku apps:create --stack heroku-24 npm-timing Creating ⬢ npm-timing... done, stack is heroku-24 https://npm-timing-5d4e30a1c656.herokuapp.com/ | https://git.heroku.com/npm-timing.git
Hi kumile buildpack leyi engetelaka switempe swa nkarhi eka magoza yo aka eka log ya Heroku leswaku hi ta kota ku hlayela minkarhi ya xiviri yo aka ya tiphurojeke ta hina. Hi lava ku engetela buildpack yoleyo eka phurojeke ya hina naswona hi endla leswaku yi tirha emahlweni ka buildpack ya ntolovelo ya Node.js . Sweswo hi swi endla hi swileriso swimbirhi leswi landzelaka:
~/project-npm$ heroku buildpacks:add \ --index=1 \ https://github.com/edmorley/heroku-buildpack-timestamps.git \ --app pnpm-timing ~/project-npm$ heroku buildpacks:add \ --index=2 heroku/nodejs \ --app npm-timing Buildpack added. Next release on npm-timing will use: 1. https://github.com/edmorley/heroku-buildpack-timestamps.git 2. heroku/nodejs Run git push heroku main to create a new release using these buildpacks.
Hi swona! Kutani, hi susumeta khodi ya phurojeke ya hina leyi lawuriwaka hi npm.
~/project-npm$ git push heroku main ... remote: Updated 4 paths from 5af8e67 remote: Compressing source files... done. remote: Building source: remote: remote: -----> Building on the Heroku-24 stack remote: -----> Using buildpacks: remote: 1. https://github.com/edmorley/heroku-buildpack-timestamps.git remote: 2. heroku/nodejs remote: -----> Timestamp app detected remote: -----> Node.js app detected ... remote: 2024-10-22 22:31:29 -----> Installing dependencies remote: 2024-10-22 22:31:29 Installing node modules remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 added 1435 packages, and audited 1436 packages in 11s remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 184 packages are looking for funding remote: 2024-10-22 22:31:41 run `npm fund` for details remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 96 vulnerabilities (1 low, 38 moderate, 21 high, 36 critical) remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 To address issues that do not require attention, run: remote: 2024-10-22 22:31:41 npm audit fix remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 To address all issues possible (including breaking changes), run: remote: 2024-10-22 22:31:41 npm audit fix --force remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 Some issues need review, and may require choosing remote: 2024-10-22 22:31:41 a different dependency. remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 Run `npm audit` for details. remote: 2024-10-22 22:31:41 npm notice remote: 2024-10-22 22:31:41 npm notice New minor version of npm available! 10.8.2 -> 10.9.0 remote: 2024-10-22 22:31:41 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0 remote: 2024-10-22 22:31:41 npm notice To update run: npm install -g [email protected] remote: 2024-10-22 22:31:41 npm notice remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 -----> Build remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 -----> Caching build remote: 2024-10-22 22:31:41 - npm cache remote: 2024-10-22 22:31:41 remote: 2024-10-22 22:31:41 -----> Pruning devDependencies remote: 2024-10-22 22:31:44 remote: 2024-10-22 22:31:44 up to date, audited 1435 packages in 4s remote: 2024-10-22 22:31:44 remote: 2024-10-22 22:31:44 184 packages are looking for funding remote: 2024-10-22 22:31:44 run `npm fund` for details remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 96 vulnerabilities (1 low, 38 moderate, 21 high, 36 critical) remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 To address issues that do not require attention, run: remote: 2024-10-22 22:31:45 npm audit fix remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 To address all issues possible (including breaking changes), run: remote: 2024-10-22 22:31:45 npm audit fix --force remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 Some issues need review, and may require choosing remote: 2024-10-22 22:31:45 a different dependency. remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 Run `npm audit` for details. remote: 2024-10-22 22:31:45 npm notice remote: 2024-10-22 22:31:45 npm notice New minor version of npm available! 10.8.2 -> 10.9.0 remote: 2024-10-22 22:31:45 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0 remote: 2024-10-22 22:31:45 npm notice To update run: npm install -g [email protected] remote: 2024-10-22 22:31:45 npm notice remote: 2024-10-22 22:31:45 remote: 2024-10-22 22:31:45 -----> Build succeeded! ...
Hi langutile nkarhi wa magoza lama landzelaka, ku fikela loko rungula Build succeeded
ekusuhi ni le makumu:
Installing dependencies
Build
Pruning devDependencies
Caching build
Hi ku angarhela, hi npm, ku aka loku ku teke 16 wa tisekoni.
Hi tsutsumise setup leyi fanaka eka phurojeke leyi lawuriwaka hi pnpm, hi tlhela hi tirhisa timings buildpack.
~/project-pnpm$ heroku apps:create --stack heroku-24 pnpm-timing ~/project-pnpm$ heroku buildpacks:add \ --index=1 \ https://github.com/edmorley/heroku-buildpack-timestamps.git \ --app pnpm-timing ~/project-pnpm$ heroku buildpacks:add \ --index=2 heroku/nodejs \ --app pnpm-timing ~/project-pnpm$ git push heroku main … remote: 2024-10-22 22:38:34 -----> Installing dependencies remote: 2024-10-22 22:38:34 Running 'pnpm install' with pnpm-lock.yaml … remote: 2024-10-22 22:38:49 remote: 2024-10-22 22:38:49 dependencies: remote: 2024-10-22 22:38:49 + animate.less 2.2.0 remote: 2024-10-22 22:38:49 + autoprefixer 10.4.20 remote: 2024-10-22 22:38:49 + babel-core 6.26.3 … remote: 2024-10-22 22:38:51 -----> Build succeeded!
Eka ku aka loku fanaka na pnpm, swi teke 7 wa tisekoni ntsena.
Ku hlayisiwa ka nkarhi, hi kumile, a hi ka ku vekiwa koloko ko sungula ntsena. Ku aka loku landzelaka, loku tirhisaka cache ya ku titshega, na kona ku hatlisa hi pnpm.
Loko ndzi sungula ku hluvukisa Node.js , ndzi tirhise npm. Malembe yo hlayanyana lama hundzeke, ndzi cince ndzi ya eka Yarn, naswona hi swona leswi a ndzi ri karhi ndzi swi tirhisa. . . ku fikela sweswinyana. Sweswi, ndzi endlile ku cinca eka pnpm. Eka muchini wa mina wa laha kaya, ndzi kota ku ntshunxa ndhawu leyikulu ya disk. Ku aka na swona swi hatlisa. Naswona sweswi, hi nseketelo wa Heroku wa pnpm, leswi swi pfala xirhendzevutani leswaku ndzi ta kota ku xi tirhisa ntsena ku suka eka nhluvukiso wa laha kaya ndlela hinkwayo ku ya eka ku tirhisiwa eka xigwitsirisi.
Ku khoda loku tsakisaka!