oven-sh / bun

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

Fix installing bun via `yarn` #9389

Open anchan828 opened 6 months ago

anchan828 commented 6 months ago

This question was initially posted on Discord: https://discord.com/channels/876711213126520882/1217331919507951688


What version of Bun is running?

1.0.30+1424a196f

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

$ yarn add bun

➤ YN0000: · Yarn 4.1.1
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + bun@npm:1.0.30, @oven/bun-darwin-aarch64@npm:1.0.30, @oven/bun-darwin-x64-baseline@npm:1.0.30, @oven/bun-darwin-x64@npm:1.0.30, @oven/bun-linux-aarch64@npm:1.0.30, @oven/bun-linux-x64-baseline@npm:1.0.30, and 1 more.
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0007: │ bun@npm:1.0.30 must be built because it never has been before or the last one failed
➤ YN0009: │ bun@npm:1.0.30 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/b3/x2d5gh_j2kbdgwk675vvw__c0000gn/T/xfs-355727ec/build.log)
➤ YN0000: └ Completed in 1s 298ms
➤ YN0000: · Failed with errors in 1s 462ms

build.log

# This file contains the result of Yarn building a package (bun@npm:1.0.30)
# Script name: postinstall

Error: Yarn does not support bun, because it does not allow linking to binaries. To use bun, install using the following command: curl -fsSL https://bun.sh/install | bash
    at optimizeBun (node_modules/bun/install.js:408:11)
    at node_modules/bun/install.js:425:3

What is the expected behavior?

yarn add bun installs bun in node_modules/.bin without error.

What do you see instead?

No response

Additional information

Hi :wave: , I am trying to introduce bun:test only to a project using yarn@4.1.1. But the installation fails due to this code: https://github.com/oven-sh/bun/blob/e45ece05d9b8ee014901a4e89145d51b6eb843db/packages/bun-release/src/npm/install.ts#L129-L134

I removed the code that throws the error and installed it, and yarn bin recognizes the bun.

$ yarn bin
➤ YN0000: bun
➤ YN0000: bunx

I installed yarn add bun@1.0.28 in project, and globally with curl -fsSL https://bun.sh/install | bash.

$ yarn exec bun -v
1.0.28
$ bun -v
1.0.30

Is this error being addressed due to a problem with yarn@1.x or yarn dlx?

paperdave commented 6 months ago

i want to note that running npm, yarn, pnpm, and bun; all with their respective version of --ignore-scripts does not cause issues. therefore, i am skeptical of the need of the postinstall script in bun.

platform checks are already supported by package managers, and instead of using a wrapper JS script to start the bin, the bin could just be the bun binary. (i tested this using a local tarball on all relevant package managers)

surely the status quo is not the best approach to this problem.

Jarred-Sumner commented 6 months ago

The postinstall script is necessary to move the symlink from the optional dependency to the bin/bun executable

We’d like for Yarn Berry to work but haven’t figured out a way without making node call bun, which would negate the start time benefits of Bun.

Also if using the Yarn PnP feature it definitely won’t work ( that doesn’t support non-JS executables unless they’ve fixed that since I last checked)

There’s unfortunately not much we can do about this, it’s mostly up to Yarn Berry to address these issues

If you have any ideas though please share

paperdave commented 6 months ago

okay so my earlier comment missed some things so the postinstall is likely neccecary (there are alot of edge cases).

we agree that yarn v1 has to work.

when this is fixed i also want to document all of the reasons for this script and make it very clear what is going on, because without such knowledge it is very very easy to discard this script.