Fork me on GitHub
#nbb
<
2022-06-21
>
genRaiy15:06:56

@borkdude I am having some trouble using goog.crypt

genRaiy15:06:12

Specifically

[goog.crypt :as crypt]
    [goog.crypt.Sha256 :as sha256]

genRaiy15:06:33

It's reporting Error: Could not find namespace: goog.crypt.Sha256

genRaiy15:06:52

so ok not goog.crypt 😂

genRaiy15:06:12

goog.crypt.Sha256 

genRaiy15:06:36

is it possible that these namespaces are not included within nbb ?

borkdude15:06:53

@raymcdermott Feel free to post an issue so that we can include that. Not included yet. But there is a workaround: https://clojurians.slack.com/archives/C029PTWD3HR/p1654207070552289

borkdude15:06:15

Also there might be other ways to get sha256 in node.js, maybe some built-in or so

borkdude15:06:34

const hash = crypto.createHash('sha256').update(input).digest('base64');

genRaiy15:06:55

there are ways to get sha256 ... I just thought I would avoid a dependency but depending google clojure is ok

genRaiy15:06:36

using the node crypto also works

borkdude15:06:00

@xander.carls Thanks for writing this awesome blog post and creating that project! https://www.alexandercarls.de/markdoc-nbb-clojure/

🎉 3
👍 2
🚀 2
Alexander Carls16:06:16

Thank you. This took me quite a while. Also learned Clojure along the way. The help from you with the "Prism" library imports was also greatly appreciated.

borkdude16:06:27

That's a pretty great way to learn you some Clojure :)

genRaiy15:06:19

dumb question ... how do I access crypto from nbb ? ... I tried js/crypto and it said Cannot find namespace node.crypto

borkdude15:06:19

Hmm, not sure what's up with that. Let me check

borkdude15:06:31

In Node:

globalThis.crypto.sign
In nbb:
user=> js/globalThis.crypto
nil
huh...?

genRaiy15:06:59

I was using v14 ... with v16 you get a different error

borkdude15:06:14

aaah

user=> (require '["crypto" :as c])
nil
user=> c
#object[Object]
user=> c/sign
#object[signOneShot]

genRaiy15:06:42

It's always the version 🙂

borkdude15:06:51

This was in 17.8

genRaiy15:06:15

["crypto" :as c]
is also good in 16.x

genRaiy15:06:22

thanks dude

👍 1
genRaiy15:06:34

and I will get on to that blog post this week!

👍 1
borkdude15:06:04

In future versions they are moving to ["node:crypto"] - both work in 18

genRaiy16:06:00

I'll try and remember at some point in the future, I promise

1
genRaiy16:06:58

a good joke about how to lie and also tell the truth

cldwalker18:06:19

Has anyone tried building a nbb github action with ncc and with cljs files that contain npm dependencies? I don't think https://github.com/borkdude/nbb-action-example covers this scenario. When I https://github.com/logseq-cldwalker/graph-validator/commit/d8ebd1da4e550cfca34d5df3ca306d81bc58c7f4, the ncc build errors with Cannot find module 'import-meta-resolve'. I've tried this with two different cljs projects containing npm deps, https://github.com/logseq/logseq/tree/master/deps/graph-parser and https://github.com/chr15m/sitefox

borkdude18:06:02

There is an example nbb GitHub action repo under my account. Afk now

cldwalker18:06:15

No worries. When you're back, there's more info in my comment. I've tried the nbb-action example but my scenario is more complex. The cljs files I'm requiring have npm deps e.g. https://github.com/logseq/logseq/blob/59c0b9a83a13fb4d5d8b34599c0224796eb21acd/deps/graph-parser/src/logseq/graph_parser/mldoc.cljc#L5

borkdude20:06:51

@U08ALHZ2N yes, this is what the nbb github example works around by not doing that

👍 1
borkdude20:06:20

> All JS dependencies, including nbb, are compiled into a single file, dist/index.mjs, using https://github.com/vercel/ncc/. This is recommended in the Github docs as an alternative to commiting your node_modules into git. Because ncc needs to statically know which dependencies are required, this is done in the index.mjs wrapper and not inside the action.cljs script. The dependencies are then passed as parameters into a function defined in action.cljs.

👍 1
borkdude20:06:05

For including build-in cljs deps, you can pre-import them in the wrapper using import 'lib/nbb-promesa.js for example

borkdude20:06:22

such that ncc will see it and include it in the build

borkdude21:06:59

I am trying the repro locally, but I'm missing information on what to do exactly. Also npm install is failing on me

borkdude21:06:10

$ npm install
npm ERR! code 1
npm ERR! The git reference could not be found
npm ERR! command git --no-replace-objects checkout workspace=@logseq/db&head=dev/yarn-workspaces
npm ERR! error: pathspec 'workspace=@logseq/db&head=dev/yarn-workspaces' did not match any file(s) known to git

borkdude21:06:26

if you can add more info to the repro with very explicit steps on how to run without ncc and with ncc, etc, I can take another look tomorrow

cldwalker14:06:39

Ah. Missed the last couple sentences in that paragraph. For the graph-parser it'd be somewhat onerous for the ns to receive the js dependency as an arg because it sits about 3-4 namespace levels below the public api and is called by probably a dozen different fns across namespaces. All these caller fns are now coupled to an implementation detail in a child ns and if the implementation changes, all of the caller fns have to be updated. I'll probably try a different approach than ncc, starting with node_modules and then maybe docker. Was the https://clojurians.slack.com/archives/C029PTWD3HR/p1643724438954269?thread_ts=1643723841.896719&amp;cid=C029PTWD3HR approach you mentioned for use with docker?

cldwalker15:06:38

> if you can add more info to the repro with very explicit steps on how to run without ncc and with ncc, etc, I can take another look tomorrow If you're curious to try, yarn install should do it and then it's the same steps as the example for calling dev and release scripts. yarn -v should show up as 3.2.1. The install only works for yarn since I'm using https://yarnpkg.com/features/workspaces to pull a git dep from a non root directory

borkdude10:06:40

I tried fixing this error but I keep running into:

file:///private/tmp/graph-validator/dist/index.js:5049
aw(a){return a.toUtf16()}if(S.process&&S.process.cwd)var
                              ^

TypeError: Cannot read properties of undefined (reading 'process')

borkdude10:06:43

I give up for now

borkdude11:06:23

I tried once more. This error comes from:

import 'mldoc';
When I remove it, this error disappears

borkdude11:06:05

So I guess the error is within that lib then

cldwalker17:06:01

Thanks for taking a look. I found a viable approach with a composite github action

borkdude17:06:05

@U08ALHZ2N I'd be interested to hear how that works

cldwalker17:06:52

K. Will link to it when I have it at a good point

cldwalker19:06:02

https://github.com/logseq/graph-validator/blob/main/action.yml shows how it works. Basically downloads deps on every job run. Not great but at least deps are cached. Happy to add a link to this repo on the nbb-action-example or nbb repo if it it's helpful

borkdude19:06:33

Thanks! Yes, please!

borkdude19:06:00

Why does it have a 2MB JS file in the repo under .yarn/releases?

borkdude19:06:15

I think this is a much better approach than what I did. Cc @U04V4KLKC

cldwalker19:06:52

Afaik it's required to have a reproducible yarn 3. Was generated by yarn set version stable. I needed yarn 3 to use its workspaces feature

borkdude19:06:35

So where do I see an example run of this action? In the README it says that it's used in https://github.com/logseq/docs

cldwalker19:06:17

It's also running on 3 private repos but may soon be running on more public repos depending on how much the community embraces it

👍 1
borkdude19:06:15

Is such an approach also possible with npm or only with yarn?

cldwalker19:06:27

I used workspaces because I needed to make a gitlib of a subfolder, like a :deps/root for deps.edn. Afaik npm doesn't support this and only yarn's workspaces supports this. It's not well advertised and buried in git issues like https://github.com/yarnpkg/yarn/issues/4725#issuecomment-753416391. If someone doesn't have this requirement, then they should be able to use the composite action with either manager

borkdude21:06:16

@U08ALHZ2N Since the github actions distribution model is super ugly anyway, maybe one could also just work with a zipped node_modules file in the repo and unzip it in runs.pre

borkdude21:06:37

gonna try this

borkdude21:06:47

I don't know where to access the node_modules.zip when my action is running, when I do ls the directory appears to be empty

borkdude21:06:00

1 second to unzip the node_modules

borkdude21:06:56

screw those bundlers, just use .zip :)

🎉 1