nbb

borkdude 2022-11-17T10:07:03.066669Z

Load nbb in Github comments 🀩 https://twitter.com/borkdude/status/1593183576019070976

πŸ‘€ 1
πŸŽ‰ 1
borkdude 2022-11-17T12:05:02.644109Z

And another surprise today, apparently you can run nbb with deno now: https://twitter.com/borkdude/status/1593213424619917314

sparkofreason 2022-11-17T15:24:12.254989Z

Has anybody worked out how to import a TypeScript module into a nbb REPL?

borkdude 2022-11-17T15:26:10.249739Z

@dave.dixon Can you be more specific?

sparkofreason 2022-11-17T15:28:58.384159Z

I'm running nbb via calva. This is very handy for interactive development, but right now I'm building/running the TypeScript app externally and loading output through a file into nbb. It would be really nice if I could change the TypeScript, load that (presumably transpiled to JS) code into nbb, and call it to see the results interactively rather than doing a whole compile/run cycle.

borkdude 2022-11-17T15:30:03.818099Z

yes, you can do this, but without some sort of repro, it's hard to be specific on how to do this

borkdude 2022-11-17T15:30:28.955559Z

you can do (:require ["./foo.js"]) assuming that TS will spit out some .js file

πŸ‘πŸΌ 1
πŸ‘€ 1
sparkofreason 2022-11-27T17:57:56.408049Z

Found a possible workaround here. The core problem seems to be that we use ts-node, and that has issues with ESM imports. But if I make our server startup pure JS, and tell ts-node to not transpile files with the .js extension, it works: ts-node --ignore \.js src/server.js. That also explains the error, which I think occurred because ts-node was "helpfully" converting import to require behind the scenes.

borkdude 2022-11-27T17:59:53.847459Z

aha!

borkdude 2022-11-21T08:45:31.076489Z

@dave.dixon Here is how you do that:

async function nREPL() {
  const { loadString } = await import('nbb');
  await loadString(`
  (require '[nbb.nrepl-server :as nrepl])
  (nrepl/start-server! {:port 1337})
`);
}

nREPL();

sparkofreason 2022-11-21T13:56:04.387989Z

Thanks, but there's some issue with how we have our TypeScript project set up where it doesn't work. I either need to sneak in a pure JS script that avoids the TS transpiler, or get the right set of TS config options that won't break compilation on the rest of our codebase.

sparkofreason 2022-11-17T15:32:22.582199Z

Thanks. I'll work on this a bit. Pretty sure the above is possible, and maybe I can call the TypeScript API directly to compile/load from nbb. I'll research it.

borkdude 2022-11-24T16:53:50.941669Z

https://2ality.com/2021/06/typescript-esm-nodejs.html

🀘🏼 1
sparkofreason 2022-11-20T16:14:37.004969Z

How about coming at this from the other direction, and launching a REPL server from the JS end?

borkdude 2022-11-20T16:36:36.337699Z

perhaps make an issue for this, I don't think this is currently exposed

πŸ‘πŸΌ 1
borkdude 2022-11-20T20:06:33.809749Z

Ah there an issue for it here: https://github.com/babashka/nbb/issues/132

borkdude 2022-11-20T20:45:33.201939Z

@dave.dixon Publishing 1.1.145 now which should have this: https://github.com/babashka/nbb#nrepl-api

borkdude 2022-11-20T20:48:12.204729Z

crap, build failure on CI

borkdude 2022-11-20T21:16:29.752289Z

retrying a new publish

πŸ‘πŸΌ 1
borkdude 2022-11-20T21:38:24.979359Z

OK, this worked, version 1.1.146

sparkofreason 2022-11-21T00:49:31.329679Z

Thanks. I seem to be stuck in module incompatbility hell, Instead change the require of /Users/dave.dixon/Projects/de_flare/node_modules/nbb/index.mjs to a dynamic import() which is available in all CommonJS modules., so far haven't been able to try this out. I'll see if I can find a workaround.

borkdude 2022-11-21T06:54:54.394829Z

Yes, you could do this as a dynamic import in an async function if you’re using cjs