Fork me on GitHub
#nbb
<
2023-01-24
>
tbrooke03:01:36

This is a beginner question - I am basically just reading a file and I want to print it out. This is what I have: (defn get-concerto [concerto] (slurp (str local-dir concerto))) (p/let [concert (get-concerto “test.cto”)] (prn concert)) This is what I get: #<Promise[~]>

borkdude08:01:03

Define get: the return value is indeed a promise but does it also print a promise?

tbrooke14:01:06

This is super basic get-concerto returns a promise. I want to see the value - The contents of the file I am retreiving. I thought the let helped with this - Maybe I need an await in there (get-concerto “test.cto”) #<Promise[~]>

borkdude14:01:38

The let will get you a local that binds to the value but the let expression itself returns a promise. You can't break out of a promise. If you want, you can also use fs/readFileSync

borkdude14:01:01

It takes a bit getting used to working with promises, but you'll get the hang of it

zimablue09:01:01

any idea why I'm getting this? Error: Namespace name must be symbol, got: [object Object] my nbb nrepl via calva blows up with this error after running some promises, I'm not doing anything too interesting, require style is the same as cljs from the docs right, like ["fs" :as fs]

borkdude09:01:34

Doesn't ring a bell, full repro welcome

zimablue09:01:46

Kk thx I'll look more and come back if necessary I'm sorry just thought you might recognise it

borkdude09:01:15

No worries :)

borkdude09:01:41

Could it be that you are constructing a symbol with symbol yourself?

zimablue09:01:32

not using symbol

zimablue09:01:59

(ns release
  (:require
   ["child_process" :as child-process]
   [clojure.string :as string]
   [exec-nbb :as en :refer [ps-run w-kg-dir]]
   [promesa.core :as p]))

(defn release []
  (p/do
    (println 1)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "rm -r .shadow-cljs")
    (println 2)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "rm -r .\\public")
    (println 3)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "npx shadow-cljs release tab-app")
    (println 4)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "npx shadow-cljs release tab-backend")
    (println 5)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "cp assets\\index.html public\\index.html")
    (println 6)
    (ps-run {"cwd" "C:\\Users\\Administrator\\projects\\kangrok_build_dir\\kangrok-core"}
            "cp assets\\simple_main.js public\\assets\\app\\js\\simple_main.js")))

zimablue09:01:20

it's doing this, then the other ns header looks like this and is just some tiny wrappers around child process and promises

zimablue09:01:26

(ns exec-nbb (:require ["child_process" :as child-process] [promesa.core :as p]))

zimablue09:01:52

but don't worry it's not a real blocker was just hoping you might just recognize it, I will work around it and come back at some point and narrow down the source

zimablue09:01:05

I'm just using nbb to incrementally script my release process, so every time it's slightly more scripted instead of being manual commands or a shell script

borkdude10:01:13

cool. Normal bb might be an easier fit for this, but cool to see that you're using nbb for it

borkdude10:01:56

for removing files, you can avoid shelling out, with babashka fs, :

(fs/delete-tree ...)

borkdude10:01:07

and (fs/copy ...)

borkdude10:01:21

and for shelling out:

(shell {:dir ...} "command")

zimablue10:01:38

I don't use clj other than to compile my cljs and I've day insha'Allah I'll master self hosted

zimablue10:01:45

I've day I'll improve my java skills too

zimablue10:01:53

But for now

borkdude10:01:18

no worries, this approach should work too

zimablue10:01:39

Thx that's interesting, the code is ugly I'm just incrementally trying to migrate from the shell didn't know it had those built in

borkdude10:01:29

well, normal bb has babashka.fs - nbb doesn't. but "fs" from node has a lot of this stuff too

borkdude10:01:24

and by using that instead of shelling out, your code will become more cross platform too

tbrooke23:01:21

My npm list gives: npm list [email protected] /Users/tmb/Coding/Clojure/cljacc ├── @accordproject/[email protected] └── [email protected] I have: (ns concert (:require [“@accordproject/concerto-core” :as concerto] [nbb.core :refer [slurp]] [promesa.core :as p] [“readfilesync” :as fs] [clojure.string :as str]) ) I get: cljs꞉concert꞉> ; ENOENT: no such file or directory, scandir '/Users/tmb/Coding/Clojure/cljacc/node_modules/readfilesync/Users/tmb/Coding/Clojure/cljacc' It seems to have duplicated ‘Users/tmb/coding/Clojure’

borkdude09:01:02

This looks weird indeed

borkdude09:01:20

I'll try and repro it here locally or on Windows

borkdude14:01:24

I can reproduce the problem on Windows

borkdude14:01:02

Also on macos. It seems a problem specific with the "readfilesync" package

borkdude14:01:09

@U054219BT Did you intend to use this package? It seems to contain pure nonsense https://www.npmjs.com/package/readfilesync?activeTab=explore

borkdude14:01:28

I suppose you meant to write:

(:require ["fs" :as fs])

(fs/readFileSync ...)
to use Node's built-in fs package?