nbb

eval2020 2024-04-16T11:17:35.805259Z

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/bun

eval2020 2024-04-17T08:28:30.747209Z

Started 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 making

borkdude 2024-04-17T08:29:17.061299Z

I think bundle should always disable the config, I think? I don't see the need for a flag

eval2020 2024-04-17T08:31:08.370459Z

ah that makes sense

borkdude 2024-04-16T11:27:06.252469Z

👋

borkdude 2024-04-16T11:27:42.716799Z

I don't get the example, sorry

borkdude 2024-04-16T11:27:52.346039Z

oh there's a link

borkdude 2024-04-16T11:31:45.532799Z

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.js

eval2020 2024-04-16T11:32:39.076259Z

are you on the patch-1 branch?

eval2020 2024-04-16T11:32:47.477659Z

sorry, the bundle-deps branch?

borkdude 2024-04-16T11:33:11.466849Z

oh

borkdude 2024-04-16T11:33:37.959919Z

in which directory are you running this

eval2020 2024-04-16T11:33:40.846219Z

running from path examples/bun

eval2020 2024-04-16T11:33:48.386929Z

sorry for the confusion

borkdude 2024-04-16T11:33:54.982699Z

the sqlite.cljs file doesn't exist here

borkdude 2024-04-16T11:34:27.502649Z

oh it does

borkdude 2024-04-16T11:34:49.506009Z

needed to run bun install first

👍 1
borkdude 2024-04-16T11:35:33.713309Z

ok, at least this runs:

$ bun --bun out.mjs
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}

borkdude 2024-04-16T11:36:24.420989Z

$ 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 me

eval2020 2024-04-16T11:37:01.658399Z

yep 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

borkdude 2024-04-16T11:37:03.279949Z

$ 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"?

eval2020 2024-04-16T11:38:12.341329Z

yeah the --compile flag is needed for that to work

borkdude 2024-04-16T11:38:40.780989Z

file an issue with bun I'd say

borkdude 2024-04-16T11:46:21.410929Z

the weird thing is that nbb_deps.js isn't mentioned anywhere in out.mjs

borkdude 2024-04-16T11:48:19.810839Z

Ah it's something in nbb itself:

/lib/nbb_deps.js

borkdude 2024-04-16T11:50:38.171679Z

Ah I got it:

borkdude@m1-3 /tmp $ ./cli
["SELECT a, b, c FROM foo WHERE foo.a = ?" "baz"]
#js {:runtime "Bun"}

borkdude 2024-04-16T11:50:54.716519Z

the issue is that nbb tries to resolve dependencies when there is a relative nbb.edn file

borkdude 2024-04-16T11:51:15.739909Z

so if you move this binary to another place without nbb.edn, then it's not doing that

eval2020 2024-04-16T11:51:50.163229Z

ow, wow

eval2020 2024-04-16T11:51:56.675909Z

nice find!

eval2020 2024-04-16T11:53:27.311819Z

All in all a nice single executable for working with sqlite 🌟

borkdude 2024-04-16T11:53:50.982979Z

👍

borkdude 2024-04-16T11:59:43.953089Z

The startup of just hello world is around 100ms on my machine, quite ok

$ time ./cli
Hello world

eval2020 2024-04-16T12:01:55.443829Z

yep. The sqlite-example 200ms on my machine.

borkdude 2024-04-16T12:02:33.513069Z

same here. the 100ms is the loading/interpreting of honeysql

eval2020 2024-04-16T12:06:01.048439Z

ah, that adds a lot indeed. Is there any way to instruct nbb that it shouldn’t bother with nbb.edn?

eval2020 2024-04-16T12:06:55.729809Z

I mean: how would that look like, it’s not possible currently.

borkdude 2024-04-16T12:07:02.061289Z

I think nbb bundle should add something to disable that, probably

eval2020 2024-04-16T12:09:06.368239Z

…an extra flag to bundle (?)

borkdude 2024-04-16T12:14:34.050939Z

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