nbb

2023-11-04T12:11:45.732479Z

Hi everyone! I started to use nbb with Deno 😃 ( I like dinosaurs 🦕 😂 ) because I understand that bebo is not than mature that nbb but I have problems to use npm modules if I not use package.json and node_modules folder. What is the better approach to use nbb with deno? Can be use deno compile? The project that I started is a azure pipeline generator

2023-11-08T07:22:22.583589Z

Hi again! I updated the example repo with the compromise solution that I think that helps more to develop with Deno. The workflow will be like that: change deno.json with new dependencies, run the task update_cache and after that you can use the nbb task to run your code. If you want to distribute your code you can use the nbb_compile task to generate a self contained binary. You’ll need the jq utility to run the update_cache task

👍 1
borkdude 2023-11-04T12:12:40.180859Z

Hey :) I don't know exactly what your problem is but maybe a repro would help

borkdude 2023-11-04T12:13:08.754289Z

Perhaps using something like #squint would work better with deno, not sure

borkdude 2023-11-04T12:13:53.728849Z

The "bebo" project doesn't seem to be necessary anymore since nbb now works with deno

2023-11-04T12:17:53.626129Z

The problem is only that when I try to require a npm library nbb not found it if I don’t do before npm install library. I try to use a ts file when import nbb and all the npm libraries before loadfile nbb’s method

2023-11-04T12:18:11.770369Z

I’ll try to create a repo to show the example

borkdude 2023-11-04T12:18:56.695569Z

ah this is maybe because nbb used dynamic import which deno doesn't support that well? thanks, I'll look forward to the repro

2023-11-04T12:35:11.610769Z

I don’t know squint, it looks an interesting project 😃. I’m a noob of clojure and all the clojure’s ecosystem but I’ll try to use it in my new proyects for learning it. I like the concept of babashka and nbb because I can use it for a cli development this is the reason because I start my journey with nbb 😃

2023-11-04T12:36:33.908999Z

And nbb because I need a template engine and try to use nunjucks. I don’t know if exists something similar that I can use with bb

2023-11-04T12:36:59.343869Z

Jejeje I’m really noob in this world sorry if I don’t know something obvious

borkdude 2023-11-04T12:37:09.624159Z

can you maybe try

async function foo() {
  import('my-library');
}

await foo(); 
in a .js file in deno? without having my-library inside node_modules / package.json? I think this will fail in deno and this is similar to how nbb behaves. With squint however, it first generates source code and then that is executed by deno, which is more like:
import * as my_lib from 'my-library'

2023-11-04T12:38:32.697399Z

Ohhh thanks! I’ll try to use it and I’ll tell to you the result of the testing 😃

😃 1
2023-11-04T16:54:21.973499Z

Hi again! I finally found the way to my code works. This is the repo: https://github.com/ulthuan/test_nbb If you execute with deno run -A run_bb.ts don’t work but if you run with the —node-modules-dir flag deno itself create the node_module directory and all works 😃. I hope this example helps to others 😃

borkdude 2023-11-04T16:58:31.197859Z

It would be helpful if you could add to the README how to actually run it. I tried a bunch of different things like:

deno run —-node-modules-dir run_bb.ts

borkdude 2023-11-04T16:58:35.244979Z

but that doesn't work for me ;)

2023-11-04T17:20:07.208899Z

Sorry I suppose that I do something wrong 😑. I updated the repo with a Readme file and config file of deno that help to run the example easily

2023-11-04T17:20:37.745939Z

I try again to run my example to detect the errors

2023-11-04T17:29:08.593059Z

I updated a little bit the Readme for help to understand better the options and the example I hope that now works when you run it

borkdude 2023-11-04T18:22:00.873289Z

@ulthuan I'm seeing this now:

$ deno run -A --node-modules-dir --lock run_bb.ts
error: the following required arguments were not provided:
  [SCRIPT_ARG]...

Usage: deno run --allow-all --node-modules-dir[=<node-modules-dir>] --lock [<FILE>] [SCRIPT_ARG]...

For more information, try '--help'.

2023-11-04T18:22:40.618659Z

What is your deno version for try to reproduce it?

borkdude 2023-11-04T18:23:17.801109Z

It seems the output says that it expects a file after the --lock argument?

2023-11-04T18:23:21.671319Z

It’s strange because I try again cleaning cache before just in case

borkdude 2023-11-04T18:23:38.799139Z

$ deno --version
deno 1.37.2 (release, aarch64-apple-darwin)
v8 11.8.172.13
typescript 5.2.2

2023-11-04T18:23:45.030119Z

Try to run it without extra flags

2023-11-04T18:23:56.160329Z

And with the deno.json

2023-11-04T18:24:11.282199Z

deno run -A run_bb.ts

borkdude 2023-11-04T18:24:38.155589Z

$ deno run -A run_bb.ts
"Hello world!"

2023-11-04T18:24:48.250249Z

It’s works!!

2023-11-04T18:24:52.001939Z

😃

2023-11-04T18:26:41.726559Z

The configuration file use the lock file and the node_modules directory … it’s the same that the flags but I suppose that don’t work as I expected 😓

2023-11-04T18:28:25.684329Z

I’ll try again and fix the documentation with the use of the explicit name of the file in the lock parameter. Thanks for your time! I hope that this example help to more user of deno + nbb 😃

borkdude 2023-11-04T18:29:14.623129Z

ok, but I guess this only works because you added import "npm:nunjucks" to the start file right?

2023-11-04T18:51:38.818009Z

Yes I think so

2023-11-04T18:52:51.150439Z

Another option for that it’s a use of deps.ts file with all the dependencies and cache it before run nbb in the same folder

borkdude 2023-11-04T18:53:11.725939Z

you might as well just use npm install?

2023-11-04T18:53:55.392129Z

Yes it’s another option of course I try it before and works too

2023-11-04T18:57:46.779299Z

I think that a little “wrapper” for use deno with nbb it’s the load of deps.ts it’s a default convention in deno

borkdude 2023-11-04T18:59:06.452069Z

ok nice

2023-11-04T19:02:51.691179Z

I’ll try a little more because I don’t know all the options that the deno runtime provides but at this moment with my knowledge those are the best options that I know

borkdude 2023-11-04T19:04:09.190239Z

cool, perhaps we can document this in $nbb_repo/doc/deno.md or so

2023-11-04T19:13:23.318929Z

I’ll glad to write that .md when I finished a little bit more research and we’ll can discuss the content of the file through here or a direct message or after the first push in the PR