@jackrusher has joined the channel
So quickjs resolves stuff from node_modules while compiling?
Awesome btw :)
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.)
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.outcool. you could also try to assemble a single js file first:
npx @vercel/ncc build -m test.mjsand then feed that into qjsc, if for some reason this makes it easier for that tool
the output is in dist/index.mjs
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)
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}}
}