oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73k stars 2.66k forks source link

Package manager plugins #8062

Open wojtekmaj opened 8 months ago

wojtekmaj commented 8 months ago

What is the problem this feature would solve?

I think I don't need to explain that the fastest code is no code at all.

Unfortunately, the JavaScript ecosystem is polluted with loads of unnecessary polyfills for older versions of Node. This is especially true for extremely popular packages like eslint-plugin-import or eslint-plugin-react, and many others sharing its lead maintainer with the ones mentioned.

To counter this problem, without necessarily forking complex and often no longer maintained packages, nolyfill was born.

nolyfill replaces these heavy polyfills with "nolyfills", that look something like this:

https://github.com/SukkaW/nolyfill/blob/master/packages/manual/function-bind/index.js

I feel like it's the next best thing, performance-, disk usage-, installation speed-wise, to having no polyfills at all, which isn't gonna magically happen.

I found that the absolute easiest way to use nolyfill is via Yarn plugins. Yarn plugins allow, among many other things, changing installation behavior. I use that in my plugin to replace known polyfills with "nolyfills", automatically, transparently, during installation process:

https://github.com/wojtekmaj/yarn-plugin-nolyfill/

With Bun's focus on performance it feels to me like its package manager would be a perfect match for projects like nolyfill. However, I don't see a way of achieving what I was able to achieve with Yarn.

What is the feature you are proposing to solve the problem?

Bun package manager plugin system inspired by Yarn.

What alternatives have you considered?

Using Yarn as package manager, only using Bun at runtime.

Electroid commented 8 months ago

We could support yarn-like plugins, but it's not exactly clear if we should. If we need to execute JavaScript, that would make bun install slower.

wojtekmaj commented 8 months ago

Maybe, or maybe not! In my specific scenario, this removes tons of dependencies that consequently don't need to be resolved, downloaded… It also speed up runtime, so it might be a good tradeoff for many.

See example commit:

https://github.com/wojtekmaj/react-pdf/commit/147fa298032fae21badaae5e41fcc3dce167556e

instant -500 lines from yarn.lock!

Added packages:

(index) file diff
0 '.yarn/cache/@nolyfill-array-includes-npm-1.0.24-172cbb7bac-7e8d1572d0.zip' '+3.73 KB'
1 '.yarn/cache/@nolyfill-array.prototype.flatmap-npm-1.0.24-4a58a00f99-38f8fb9c70.zip' '+3.9 KB'
2 '.yarn/cache/@nolyfill-array.prototype.tosorted-npm-1.0.24-e4b9c4a506-f57f72fbeb.zip' '+4.05 KB'
3 '.yarn/cache/@nolyfill-has-npm-1.0.25-17da4b602b-18bd4e96b0.zip' '+2.57 KB'
4 '.yarn/cache/@nolyfill-isarray-npm-1.0.25-5830e53f58-459678ac2e.zip' '+2.56 KB'
5 '.yarn/cache/@nolyfill-object.assign-npm-1.0.24-7a09d57b60-ac138cd171.zip' '+3.7 KB'
6 '.yarn/cache/@nolyfill-object.entries-npm-1.0.24-2494beda6f-2ee6d72f9e.zip' '+3.72 KB'
7 '.yarn/cache/@nolyfill-object.fromentries-npm-1.0.24-4bad6756e2-f862accb7d.zip' '+3.8 KB'
8 '.yarn/cache/@nolyfill-object.hasown-npm-1.0.24-ef7589114b-c822af885b.zip' '+3.75 KB'
9 '.yarn/cache/@nolyfill-object.values-npm-1.0.24-3a3198fde4-fd3955ed65.zip' '+3.7 KB'
10 '.yarn/cache/@nolyfill-shared-npm-1.0.24-6b54ea6d39-d523d2d0d6.zip' '+6.35 KB'
11 '.yarn/cache/@nolyfill-side-channel-npm-1.0.24-901786c109-42c3386588.zip' '+3.04 KB'
12 '.yarn/cache/@nolyfill-string.prototype.matchall-npm-1.0.24-9130188cc7-7e442591d0.zip' '+3.94 KB'
Removed packages: (index) file diff
0 '.yarn/cache/array-buffer-byte-length-npm-1.0.0-331671f28a-12f84f6418.zip' '-9.98 KB'
1 '.yarn/cache/array-includes-npm-3.1.6-d0ff9d248b-d0caeaa57b.zip' '-27.5 KB'
2 '.yarn/cache/array.prototype.flatmap-npm-1.3.1-c65186ca34-2bd58a0e79.zip' '-21.6 KB'
3 '.yarn/cache/array.prototype.tosorted-npm-1.1.1-1be94ad4a7-fd5f57aca3.zip' '-21 KB'
4 '.yarn/cache/available-typed-arrays-npm-1.0.5-88f321e4d3-c4df567ca7.zip' '-16 KB'
5 '.yarn/cache/call-bind-npm-1.0.2-c957124861-74ba3f31e7.zip' '-16.6 KB'
6 '.yarn/cache/define-properties-npm-1.2.0-3547cd0fd2-34b58cae46.zip' '-14 KB'
7 '.yarn/cache/es-abstract-npm-1.21.2-f4ebace1ab-7dc2c882ba.zip' '-1.74 MB'
8 '.yarn/cache/es-set-tostringtag-npm-2.0.1-c87b5de872-9af096365e.zip' '-10.2 KB'
9 '.yarn/cache/es-shim-unscopables-npm-1.0.0-06186593f1-d54a66239f.zip' '-11.9 KB'
10 '.yarn/cache/es-to-primitive-npm-1.2.1-b7a7eac6c5-0886572b8d.zip' '-42.8 KB'
11 '.yarn/cache/for-each-npm-0.3.3-0010ca8cdd-22330d8a2d.zip' '-14.3 KB'
12 '.yarn/cache/function-bind-npm-1.1.1-b56b322ae9-60b74b2407.zip' '-26.7 KB'
13 '.yarn/cache/function.prototype.name-npm-1.1.5-e776a642bb-b75fb8c526.zip' '-20.8 KB'
14 '.yarn/cache/functions-have-names-npm-1.2.3-e5cf1e2208-33e77fd29b.zip' '-18.5 KB'
15 '.yarn/cache/get-intrinsic-npm-1.2.0-eb08ea9b1d-7c564f6b10.zip' '-39.7 KB'
16 '.yarn/cache/get-symbol-description-npm-1.0.0-9c95a4bc1f-23bc3b44c2.zip' '-12.4 KB'
17 '.yarn/cache/globalthis-npm-1.0.3-96cd56020d-0db6e9af10.zip' '-24.7 KB'
18 '.yarn/cache/gopd-npm-1.0.1-10c1d0b534-505c05487f.zip' '-9.05 KB'
19 '.yarn/cache/has-bigints-npm-1.0.2-52732e614d-724eb1485b.zip' '-14.3 KB'
20 '.yarn/cache/has-npm-1.0.4-0dc267d5e0-82c1220573.zip' '-4.06 KB'
21 '.yarn/cache/has-property-descriptors-npm-1.0.0-56289b918d-d4ca882b69.zip' '-11.2 KB'
22 '.yarn/cache/has-proto-npm-1.0.1-631ea9d820-c8a8fe411f.zip' '-8.66 KB'
23 '.yarn/cache/has-symbols-npm-1.0.3-1986bff2c4-e6922b4345.zip' '-22.7 KB'
24 '.yarn/cache/has-tostringtag-npm-1.0.0-b1fcf3ab55-1cdba76b7d.zip' '-13.2 KB'
25 '.yarn/cache/internal-slot-npm-1.0.5-a2241f3e66-66d8a66b4b.zip' '-21.2 KB'
26 '.yarn/cache/is-array-buffer-npm-3.0.2-0dec897785-40ed13a5f5.zip' '-13.5 KB'
27 '.yarn/cache/is-bigint-npm-1.0.4-31c2eecbc9-eb9c88e418.zip' '-16.3 KB'
28 '.yarn/cache/is-boolean-object-npm-1.1.2-ecbd575e6a-6090587f8a.zip' '-23.9 KB'
29 '.yarn/cache/is-callable-npm-1.2.7-808a303e61-ceebaeb9d9.zip' '-30.2 KB'
30 '.yarn/cache/is-date-object-npm-1.0.5-88f3d08b5e-eed21e5dcc.zip' '-22.5 KB'
31 '.yarn/cache/is-negative-zero-npm-2.0.2-0adac91f15-eda024c158.zip' '-23.7 KB'
32 '.yarn/cache/is-number-object-npm-1.0.7-539d0e274d-aad266da1e.zip' '-23.8 KB'
33 '.yarn/cache/is-regex-npm-1.1.4-cca193ef11-bb72aae604.zip' '-31.2 KB'
34 '.yarn/cache/is-shared-array-buffer-npm-1.0.2-32e4181fcd-cfeee6f171.zip' '-13.8 KB'
35 '.yarn/cache/is-string-npm-1.0.7-9f7066daed-905f805cbc.zip' '-20.6 KB'
36 '.yarn/cache/is-symbol-npm-1.0.4-eb9baac703-9381dd015f.zip' '-23.6 KB'
37 '.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-9863e9cc72.zip' '-19.3 KB'
38 '.yarn/cache/is-weakref-npm-1.0.2-ff80e8c314-1545c5d172.zip' '-13.7 KB'
39 '.yarn/cache/isarray-npm-1.0.0-db4f547720-18b5be6669.zip' '-5.11 KB'
40 '.yarn/cache/object-inspect-npm-1.12.3-1e7d20f5ff-752bb5f4dc.zip' '-98.5 KB'
41 '.yarn/cache/object-keys-npm-1.1.1-1bf2f1be93-b11f7ccdbc.zip' '-27.9 KB'
42 '.yarn/cache/object.assign-npm-4.1.4-fb3deb1c3a-2f286118c0.zip' '-1.12 MB'
43 '.yarn/cache/object.entries-npm-1.1.6-5f9ba14b46-8782c71db3.zip' '-33.2 KB'
44 '.yarn/cache/object.fromentries-npm-2.0.6-424cf4cd3c-db6759ea68.zip' '-17.7 KB'
45 '.yarn/cache/object.hasown-npm-1.1.2-db9bbc7f97-419fc1c74a.zip' '-18.5 KB'
46 '.yarn/cache/object.values-npm-1.1.6-ab9b67ccd3-3381204390.zip' '-32.7 KB'
47 '.yarn/cache/regexp.prototype.flags-npm-1.5.0-5623b9e07f-312b7966c5.zip' '-40.7 KB'
48 '.yarn/cache/safe-regex-test-npm-1.0.0-e94a09b84e-14a81a7e68.zip' '-8.92 KB'
49 '.yarn/cache/side-channel-npm-1.0.4-e1f38b9e06-054a5d23ee.zip' '-16.2 KB'
50 '.yarn/cache/string.prototype.matchall-npm-4.0.8-1feb1531b6-644523d05c.zip' '-38.8 KB'
51 '.yarn/cache/string.prototype.trim-npm-1.2.7-3fbaf3b9d2-31698f6d71.zip' '-34 KB'
52 '.yarn/cache/string.prototype.trimend-npm-1.0.6-304246ecc1-51b663e319.zip' '-23.9 KB'
53 '.yarn/cache/string.prototype.trimstart-npm-1.0.6-0926caea6c-13b9970d4e.zip' '-24.2 KB'
54 '.yarn/cache/typed-array-length-npm-1.0.4-92771b81fc-c5163c0103.zip' '-20.1 KB'
55 '.yarn/cache/unbox-primitive-npm-1.0.2-cb56a05066-81ca2e8113.zip' '-16.6 KB'
56 '.yarn/cache/which-boxed-primitive-npm-1.0.2-e214f9ae5a-0a62a03c00.zip' '-17.1 KB'
57 '.yarn/cache/which-typed-array-npm-1.1.11-f37f0cefe2-2cf4ce417b.zip' '-35.1 KB'
Jarred-Sumner commented 8 months ago

I think a version of this is a good idea

like a better alternative to patching