-
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 Bun's package manager from a built single-executable app #16262
Comments
To clarify: you want to use |
Bun is a single file, so installing it on a user's machine means downloading the right version and saving it somewhere. You don't need to have the user install bun globally, you can manage its installation yourself without too much difficulty. |
Well, this is quite a funny-sounding summary.
If I use Bun's single-executable builder, its result is almost the same single file. Duplicating it just because Bun didn't export its package manager logic is idiotic. I would like to avoid bloating my builds. |
Bun won't have a package management API in the near future, but bun could be modified to allow getting access to the main cli from a compiled binary diff --git a/src/StandaloneModuleGraph.zig b/src/StandaloneModuleGraph.zig
index aae3c32a1..14b4b9fdd 100644
--- a/src/StandaloneModuleGraph.zig
+++ b/src/StandaloneModuleGraph.zig
@@ -786,6 +786,12 @@ pub const StandaloneModuleGraph = struct {
const self_exe = openSelf() catch return null;
defer _ = Syscall.close(self_exe);
+ if (bun.getenvZ("BUN_SKIP_STANDALONE_MODULE_GRAPH")) |v| {
+ if (v.len > 0 and !(v.len == 1 and v[0] == '0')) {
+ return null;
+ }
+ }
+
var trailer_bytes: [4096]u8 = undefined;
std.posix.lseek_END(self_exe.cast(), -4096) catch return null; With this change, running a compiled binary with |
You can also be sus and name (or simlink) the executable I don't recommend this though |
I don't think I would like to pick the sussy baka route; @RiskyMH would it be possible to implement the env flag in the nearest releases? This would suit my needs and be roughly in-style with runners like execa that use |
What is the problem this feature would solve?
Ultimately I would like to use Bun's package manager in a single-executable Bun app without installing Bun globally, so my app manages npm packages automatically without additional downloads. It seems stupid to require node.js/Bun installed to install npm packages when an executable has all the needed APIs somewhere there, but not exported to Bun API. My target audience is only just partially overlaps with web developers so I would avoid making them download Bun as a dependency.
What is the feature you are proposing to solve the problem?
I would like Bun's package manager to be exposed in its
bun
import, maybe as apm
namespace (stands for Package Manager), or its CLI be accessible when calling a packaged single-executable app. For JS API, I would like it to have at least these methods that match their CLI versions:install
,add
,remove
,update
,pm ls
. I assume this is not a hard tasks as the implementation already exists.What alternatives have you considered?
Installing Bun/Node.js in end users' systems (and this sucks)
Having
npm
or an alternative as a package dependency in a Bun project 🤡The text was updated successfully, but these errors were encountered: