I’m bundling a script using bun. But when using dependencies things go wrong:
$ bun run --bun nbb bundle sqlite.cljs -o out.mjs && bun build out.mjs --compile --outfile cli
[47ms] bundle 12 modules
[43ms] compile cli
~/src/nbb/examples/bun (patch-1 *=)
$ ./cli
error: Cannot find module "./nbb_deps.js" from "/$bunfs/root/cli"
Anyone an idea what’s going on?
Full rep(r)o: https://github.com/eval/nbb/tree/bundle-deps/examples/bunStarted some POC to do this via a flag for bundle:
nbb bundle sqlite.cljs -o out.mjs --disable-config
which emits await loadString(",,,," , {disableConfig: true}) . PR in the makingI think bundle should always disable the config, I think? I don't see the need for a flag
ah that makes sense
👋
I don't get the example, sorry
oh there's a link
when cloning your repo, I'm getting:
$ bun run --bun nbb bundle sqlite.cljs -o out.mjs
An error occurred when calling (nbb.impl.bundler/init)
----- Error --------------------------------------
Type: ENOENT
Message: No such file or directory
/private/tmp/nbb/examples/bun/node_modules/nbb/lib/nbb_main.jsare you on the patch-1 branch?
sorry, the bundle-deps branch?
oh
in which directory are you running this
running from path examples/bun
sorry for the confusion
the sqlite.cljs file doesn't exist here
oh it does
needed to run bun install first
ok, at least this runs:
$ bun --bun out.mjs
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}$ bun build out.mjs --compile --outfile cli
[74ms] bundle 12 modules
[153ms] compile cli
borkdude@m1-3 /tmp/nbb/examples/bun (bundle-deps?) $ ./cli
error: Cannot find module "./nbb_deps.js" from ""
Seems a bun error to meyep indeed. I also found that vendoring honey-sql works as well - bundled with bun that is:
$ cp -r .nbb/.cache/ab0dc41671be63d160b05b56f910fe19ba103da3/nbb-deps/honey vendor/
$ bun run --bun nbb -cp vendor bundle sqlite.cljs -o out.mjs && bun build out.mjs --compile --outfile cli$ bun build out.mjs --outfile cli
2 | import * as bun_COLON_sqlite from 'bun:sqlite'
^
error: Could not resolve: "bun:sqlite". Maybe you need to "bun install"?yeah the --compile flag is needed for that to work
file an issue with bun I'd say
the weird thing is that nbb_deps.js isn't mentioned anywhere in out.mjs
Ah it's something in nbb itself:
/lib/nbb_deps.jsAh I got it:
borkdude@m1-3 /tmp $ ./cli
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}
the issue is that nbb tries to resolve dependencies when there is a relative nbb.edn file
so if you move this binary to another place without nbb.edn, then it's not doing that
ow, wow
nice find!
All in all a nice single executable for working with sqlite 🌟
👍
The startup of just hello world is around 100ms on my machine, quite ok
$ time ./cli
Hello worldyep. The sqlite-example 200ms on my machine.
same here. the 100ms is the loading/interpreting of honeysql
ah, that adds a lot indeed. Is there any way to instruct nbb that it shouldn’t bother with nbb.edn?
I mean: how would that look like, it’s not possible currently.
I think nbb bundle should add something to disable that, probably
…an extra flag to bundle (?)
There is an initialize function in src/nbb/api.cljs which processes this nbb.edn stuff
Perhaps we can add another API function to disable this or an option to loadFile, something like:
import { loadFile } from 'nbb';
loadFile("foo.cljs", {disableConfig: true})
or whatever