microsoft/rushstack

[rush] Is Bun support planned?

EdwardDrapkin opened this issue ยท 7 comments

Just wondering if there was a plan to add bun's package manager as supported to rush alongside pnpm/npm/yarn?

Thanks for your time!

Probably not at this time. It seems that Bun implements the flawed NPM installation model.

For example, I tried converting the demo/sbs-3 branch to use a Bun workspace. Its dependency graph is supposed to look like this:

Running bun install produces:

  • doppelgangers: Duplicate copies of p@1.2.3 under b and c which PNPM would avoid using symlinks. Having two copies of the same package folder causes trouble such as singletons not being single, TypeScript having to process duplicate .d.ts files, etc.
  • a phantom dependency: The p@2.0.3 installation gets "hoisted" to the top-level node_modules folder. This is bad because other projects in the monorepo can accidentally import it without declaring a dependency in their own package.json file. PNPM avoids this problem by using symlinks.

These problems are tolerable in a small single-team repo (in fact much of the NPM community is entirely unaware of it), but it's too painful for a large scale monorepo, which is the focus of Rush. It's why the Rush community has largely abandoned the NPM+Rush configuration. If Bun is able to implement a more correct installation model, that would make bun install more attractive.

Apparently Bun only supports Windows Subsystem for Linux (WSL) not actual Windows/NTFS, which might be a blocker for companies that ship device apps that build using Windows. This is less common, although it's characteristic of large scale monorepos to eventually accumulate every possible requirement. ๐Ÿซ 

I can understand your hesitation but given that regular NPM is supported, am I right in assuming that the feature isn't unwelcome, just deprioritized? Bun is an attractive target to us, not necessarily because of the package manager, but the performance differences and other developer tooling. I can't promise a timeline, but would a contribution of this nature be accepted despite the package manager's flaws? Assuming it's acceptable conceptually, could you point me in the right direction to get started?

Of course, if someone from the community wants to contribute this feature, we would certainly support that.๐Ÿ‘

If I take one of the existing package manager classes, e.g. YarnPackageManager, and follow it through the codebase, will I miss anything that I need to do? Is there any sort of documentation I could refer to?

Well, the NPM and Yarn implementations predated workspaces, so they create a synthetic common/temp/package.json that depends on the union of all package.json files, and install that, then Rush creates symlinks for each project into that folder. This approach has benefits of preventing some phantom dependencies and enabling Rush-specific features such as preferred versions. Your other option would be to follow the approach of the PNPM implementation which uses a proper PNPM workspace, without Rush creating any symlinks. There are pros/cons to each approach.

The main thing I will say is that the world of node_modules folders is much more complicated than people assume, particularly for production monorepos. If you are serious about contributing we should do a community call where we can discuss it in detail.

Niek commented

With the bun 1.x releases, this looks more and more interesting. Full native Windows support has been added as well. Hopefully it's something that will be considered.