cherry

2022-07-23T13:39:44.047269Z

@jackrusher has joined the channel

2022-07-23T14:06:57.336349Z

https://twitter.com/jackrusher/status/1550844847245885440

🍒 2
😎 1
borkdude 2022-07-23T14:17:43.809479Z

So quickjs resolves stuff from node_modules while compiling?

borkdude 2022-07-23T14:17:55.668639Z

Awesome btw :)

2022-07-23T16:10:34.333459Z

I edited out a few ls results for clarity. The compile was done with cherry-cljs directory in the same dir. qjsc resolves modules but expects them to be in subdirectories of the current dir. (One could also do the compile in the node_modules directory.)

2022-07-23T16:13:28.160169Z

Btw, if I disable a bunch of the advanced features that aren't needed in this example the binary comes in at ~750K.

$ qjsc -flto -fno-date -fno-eval -fno-string-normalize -fno-regexp -fno-json -fno-proxy -fno-map -fno-typedarray -fno-promise -fno-module-loader -fno-bigint test.mjs
$ ls -la
-rwxr-xr-x  1 jack  staff   746K Jul 23 18:11 a.out

borkdude 2022-07-23T16:15:31.964399Z

cool. you could also try to assemble a single js file first:

npx @vercel/ncc build -m test.mjs

👍 1
borkdude 2022-07-23T16:15:46.004539Z

and then feed that into qjsc, if for some reason this makes it easier for that tool

borkdude 2022-07-23T16:15:55.655029Z

the output is in dist/index.mjs

borkdude 2022-07-23T20:42:12.893409Z

I'm also able to compile SCI with quickjs, although I'm getting some weird output sometimes:

$ qjs lib/cli.mjs -e '(+ 1 2 3)'
Unbound: #'clojure.core/*print-fn*
Unbound: #'clojure.core/*print-err-fn*
6
and qjsc does finish, the resulting binary is around 1.8mb but when I run it I get:
$ ./a.out -e '1'
Unbound: #'clojure.core/*print-fn*
Unbound: #'clojure.core/*print-err-fn*
TypeError: not a function
    at <anonymous> (/Users/borkdude/dev/quickjs/lib/cli.mjs:1639)

borkdude 2022-07-23T20:43:47.417309Z

If you're interested, this is what I tried:

code:

(ns qjsci.core
  (:require
   [babashka.cli :as cli]
   [sci.core :as sci]))

(defn init []
  (sci/alter-var-root sci/print-fn js/print)
  (sci/alter-var-root sci/print-err-fn js/print)
  (let [expr (:e (cli/parse-opts (.slice js/scriptArgs 1)))
        ctx (sci/init {:classes {'js js/globalThis
                                 :allow :all}})]
    (js/print
     (str (sci/eval-string* ctx expr)))))

shadow-cljs.edn:

{:deps {:aliases [:cljs]}
 :builds
 {:qjsci
  {:js-options {;; don't bundle any npm libs
                :js-provider :import}
   :compiler-options {:infer-externs :auto}
   :target :esm
   :runtime :node
   :output-dir "lib"
   :modules
   ;; note: this is overriden in bb build-cherry
   {:cli {:init-fn qjsci.core/init}}
   :build-hooks [(shadow.cljs.build-report/hook
                  {:output-to "report.html"})]}}}

deps.edn:

{:paths ["src" "resources"]
 :deps {borkdude/edamame {:mvn/version "1.0.0"}
        babashka/process {:mvn/version "0.1.7"}
        org.babashka/cli {:mvn/version "0.3.32"}
        org.babashka/sci {:mvn/version "0.3.32"}
        }
 :aliases
 {:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.19.6"}}}
  :test ;; added by neil
  {:extra-paths ["test"]
   :extra-deps {io.github.cognitect-labs/test-runner
                {:git/tag "v0.5.0" :git/sha "b3fd0d2"}
                babashka/fs {:mvn/version "0.1.6"}}
   :main-opts ["-m" "cognitect.test-runner"]
   :exec-fn cognitect.test-runner.api/test}}

 }