Fork me on GitHub
#shadow-cljs
<
2023-12-09
>
nonrecursive00:12:30

hey y’all, i have use case that I’d love some help with. I’d like shadow-cljs to write a file to disk whose contents are the transformation of a cljs value:

;; source file contains this:
(def seq-1 [1 2 3])
(def seq-2 [3 4 5])

(def sequences
  [seq-1 seq-2])

;; i want shadow-cljs to write a file with this in it:
(def sequences [1 3])

;; in other words, transform the value of `sequences` and write it 
is this possible?

thheller06:12:19

no, there is no JS evaluation during compilation.

dvingo12:12:08

I had a similar problem when collecting malli schemas and wanting to write clj-kondo config for them during compilation - there is a demonstration of how to do that here https://github.com/metosin/malli/blob/master/src/malli/dev/cljs_kondo_preload.cljc

dvingo12:12:00

but this requires some "collection" mechanism, so not sure this will help with your use-case

nonrecursive16:12:15

this is helpful, thank you!

akis22:12:49

hi! 👋 I'm trying to load https://www.npmjs.com/package/@sqlite.org/sqlite-wasm

(:require
   ["@sqlite.org/sqlite-wasm" :as sqlite])
but getting
errors in file: {...}/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
{:js-str-offsets [], :js-esm false, :js-imports [], :js-invalid-requires [], :goog-provides [], :js-language "es9", :goog-module nil, :js-warnings [], :resource-name "node_modules/@sqlite_DOT_org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs", :js-requires [], :js-errors [{:line 2968, :column 7, :message "primary expression expected"}], :goog-requires [], :tag :shadow.build.npm/errors, :uses-global-buffer false, :uses-global-process false}
ExceptionInfo: errors in file: {...}/node_modules/@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
Is .mjs are ES modules supported by shadow? Thanks

thheller22:12:47

.mjs is just a file extension, it means absolutely nothing special

👍 1
thheller22:12:34

{:line 2968, :column 7, :message "primary expression expected"}

thheller22:12:51

this is the error. feel free to check what the syntax at that point is

thheller22:12:05

whatever it is is not supported by the closure compiler and thus not shadow-cljs

👍 1
akis22:12:00

couldn't figure out anything special about this line

createPreloadedFile: (
        parent,
        name,
        url,
        canRead,
        canWrite,
        onload,
        onerror,
        dontCreateFile,
        canOwn,
        preFinish,
      ) => { // line 2968
        var fullname = name
          ? PATH_FS.resolve(PATH.join2(parent, name))
          : parent;
  ...

akis22:12:12

> whatever it is is not supported by the closure compiler and thus not shadow-cljs good to know, thanks! Any workarounds or suggestions perhaps?