Fork me on GitHub
#nbb
<
2021-08-24
>
borkdude13:08:34

I have a little dilemma (again) regarding ecmascript modules. E.g. the term-size package now only offers an ESM module

borkdude13:08:02

while other libraries only offer a CommonJS module, this is what nbb currently defaults to

borkdude13:08:38

but it's probably not a good idea to mix and match those. And the ESM stuff is a superset of the CommonJS stuff: dynamic import also supports loading those

borkdude13:08:46

But then it would make scripts look like:

$ cat test-scripts/esm-test/script.cljs
(ns esm-test.script
  (:require ["path$default" :as path]
            ["term-size$default" :as term-size]))

(prn (path/resolve "."))
(prn (term-size))

borkdude13:08:00

$ node out/nbb_main.js test-scripts/esm-test/script.cljs
"/Users/borkdude/Dropbox/dev/clojure/nbb"
#js {:columns 209, :rows 52}

borkdude13:08:38

the $default thing is a bit of an ugliness in my taste, but perhaps it's better to just support this style going forward so all libs can be required in one style

borkdude13:08:01

and it seems ESM is the future... no?

borkdude15:08:09

ok, I went with ESM module imports again

borkdude15:08:04

so, for example this works now (`zx` is an ESM module):

(ns script
  (:require ["csv-parse/lib/sync$default" :as csv-parse]
            ["fs" :as fs]
            ["shelljs$default" :as sh]
            ["zx$fs" :as zxfs]
            [nbb.core :refer [*file*]]))

(println (count (str (fs/readFileSync "script.cljs"))))

(prn (sh/ls "."))

(prn (csv-parse "foo,bar"))

(prn (zxfs/existsSync *file*))

borkdude15:08:20

This is a breaking change, take note everyone.