-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the "engines"
field to automatically replace node with bun in the shebang
#9346
Comments
I like this proposal, but I don't like that it will force every CLI that is compatible to bun to add this field. It should not be required for packages to alter any of their code for I think this shebang replacement Also, it should be noted that this specific case is not an issue on Windows, as the shim does what I describe when As a first step, we should document this and make |
an alternative solution would maybe to allow running scripts without a shebang at all? currently it fails with |
i didn't realize that is even allowed. this feels more like a separate bug to me, and it should be implemented in addition to the other ideas. |
This would be handy for
Linking this issue also vercel/turborepo#7688 |
@Jarred-Sumner should we expect for |
Great idea! I will wait it |
Currently, it is difficult to publish CLIs to npm which can transparently run in either node or bun.
Thus far, Bun has attempted to address that in two ways:
node
is not in path,bun <any-executable>
andbun run <any-executable>
automatically adds a temporarynode
to path symlinked to Bun, which makes#!/usr/bin/env node
still work when Node is not installed--bun
flag forces the behavior of ^ even whennode
is in path -bun --bun <any-executable>
This doesn't fix the case where
<any-executable>
is installed globally, you don't havenode
installed and you want to run it without prefixingbun
.While some packages are happy to be bun-only, for many packages it doesn't make sense today to limit their potential users to only bun.
tsc
andturbo
both seem to work in bun, there's no reason it doesn't run them using bun when bun is installedThis proposal suggests the following:
When using
bun install
and"bun"
exists in the"engines"
field inpackage.json
in an installed dependency, we automatically inject and replace the#!/usr/bin/env node
shebang with#!/usr/bin/env bun
in all bins with a javascript-like file extension.This would let package authors publish packages for both node and bun that lets the user choose which runtime to use (implicitly by choosing bun with bun install, or node with other package managers). This has the downside that yarn v1 will report a warning about an unknown engine (only yarn v1 as far as I can tell), but that's probably okay (the
"vscode"
engine used by vscode extensions has the same issue)Another approach involves the
"exports"
field, but the npm registry api does not expose that information in the abbreviated version object (nor should it, imo)Fixes #9334
Blocked on #5846
The text was updated successfully, but these errors were encountered: