Popular Javascript package managers compared:.

Popular Javascript package managers compared:

(npm vs yarn vs pnpm)

npm, yarn, and pnpm are the popular package
managers from the Javascript world.

There are new entrants in the market (bun and
deno), we will discuss them later.

Why is there a need for a package manager?

A packager manager is a tool that automates publishing,
installing, upgrading, and removing software programs.

Now, the next question.

Which one should you choose and why?

This question needs a deeper understanding and
comparison between the available options.

Let’s understand them one by one.

1- npm (Node Package Manager)

npm is the default package manager of Node.js.
As it is the default option, it has the
biggest community.

It does comes with its disadvantages.

Sequential installation is one of the main disadvantages
of npm. It increases the package install time.

npm duplicates packages for every project affecting
disk size.

npm audit is broken by default. There is no
graceful way to fix or update vulnerabilities.

2- yarn (created by Meta)
yarn solved the download problem with parallel
downloads.

It also came with an out-of-the-box offline mode.

Yarn came up with a new approach to manage
packages.

Instead of duplicating package code for every project,
it hoists the common packages further up the tree.

However, hoisting comes with its challenges.

You might end up importing something from a subpackage
which you did not install.

Another downside to hoisting is that it uses semver
(semantic versioning).

So if a package does not use semver consistently,
You might end up with problems that you
did not cause.

To solve these, yarn added Plug’n’Play (PnP).

It stores all the packages in a global directory
eliminating the need for a node_modules folder.

PnP uses symlinks (native file links in OS) to link
packages.

If you have 10 Next.js projects (with the same version),
yarn PnP will only install it once in the global directory.

3- pnpm (Performant NPM)
pnpm is the fastest of the three.

It works quite similarly to Yarn’s PnP and, it also
uses symlinks.

The cool thing is that it does not download the whole
packages for new versions, only the changes.

If I were building a project today, I would choose pnpm.

For me, pnpm > yarn > npm.

There are also other alternatives in the market like bun
and deno.

They are not simple package managers. They also include
JS runtime to compile and execute JS and TS.

However, in terms of speed bun is 100x faster than pnpm.

Deno is a relatively new entrant in the market, aiming to evolve
the Node.js ecosystem.

Let me know in the comments:
Which package manager do you regularly?

If you are interested in the JS ecosystem:
Follow for more content

#javascript


ترجمه:

مدیران بسته بندی JavaScript محبوب مقایسه شده:

(NPM در مقابل نخ در مقابل PNPM)

NPM ، نخ و PNPM بسته محبوب هستند
مدیران دنیای جاوا اسکریپت.

ورودی های جدیدی در بازار وجود دارد (Bun و
دنو) ، ما بعداً در مورد آنها بحث خواهیم کرد.

چرا نیاز به مدیر بسته وجود دارد؟

مدیر Packager ابزاری است که انتشارات را خودکار می کند ،
نصب ، به روزرسانی و حذف برنامه های نرم افزاری.

حال ، سوال بعدی.

کدام یک را باید انتخاب کنید و چرا؟

این سوال به درک عمیق تری نیاز دارد و
مقایسه بین گزینه های موجود.

بیایید آنها را یکی یکی درک کنیم.

1- NPM (مدیر بسته گره)

NPM مدیر بسته پیش فرض Node.js. است.
همانطور که گزینه پیش فرض است ، دارای آن است
بزرگترین جامعه

این با مضرات آن همراه است.

نصب متوالی یکی از معایب اصلی است
از NPM زمان نصب بسته را افزایش می دهد.

NPM بسته هایی را برای هر پروژه تأثیر می گذارد
اندازه دیسک

حسابرسی NPM به طور پیش فرض شکسته می شود. هیچ وجود ندارد
روش برازنده برای رفع یا به روزرسانی آسیب پذیری ها.

2- نخ (ایجاد شده توسط متا)
نخ مشکل بارگیری را با موازی حل کرد
بارگیری

همچنین با یک حالت آفلاین خارج از جعبه همراه بود.

نخ با یک رویکرد جدید برای مدیریت به وجود آمد
بسته ها

به جای کپی کردن کد بسته برای هر پروژه ،
این بسته های مشترک را بیشتر از درخت بالا می برد.

با این حال ، بالابر با چالش های خود همراه است.

ممکن است در نهایت واردات چیزی را از یک زیرمجموعه وارد کنید
که نصب نکردید

نکته منفی دیگر برای بلند کردن این است که از Semver استفاده می کند
(نسخه معنایی).

بنابراین اگر یک بسته به طور مداوم از semver استفاده نمی کند ،
ممکن است در نهایت با مشکلاتی که در آن هستید به پایان برسید
ایجاد نکرد

برای حل این موارد ، نخ اضافه شده پلاگین (PNP).

تمام بسته ها را در یک فهرست جهانی ذخیره می کند
رفع نیاز به پوشه Node_Modules.

PNP از Symlinks (پیوندهای فایل بومی در سیستم عامل) برای پیوند استفاده می کند
بسته ها

اگر 10 پروژه Next.js دارید (با همان نسخه) ،
نخ PNP فقط یک بار آن را در فهرست جهانی نصب می کند.

3- PNPM (NPM اجرا)
PNPM سریعترین سه نفر است.

کاملاً مشابه PNP نخ کار می کند و نیز
از Symlinks استفاده می کند.

نکته جالب این است که کل را بارگیری نمی کند
بسته های نسخه های جدید ، فقط تغییرات.

اگر امروز در حال ساخت یک پروژه بودم ، PNPM را انتخاب می کردم.

برای من ، pnpm> نخ> npm.

گزینه های دیگری نیز در بازار مانند Bun وجود دارد
و دنو

آنها مدیران بسته ساده نیستند. آنها همچنین شامل می شوند
JS زمان اجرا برای کامپایل و اجرای JS و Ts.

با این حال ، از نظر سرعت Bun 100 برابر سریعتر از PNPM است.

دنو یک شرکت کننده نسبتاً جدید در بازار است ، با هدف تکامل
اکوسیستم Node.js.

در نظرات به من اطلاع دهید:
به طور مرتب کدام مدیر بسته را دارید؟

اگر به اکوسیستم JS علاقه دارید:
برای محتوای بیشتر دنبال کنید

#JavaScript