cherry

Stephan Renatus 2025-01-08T09:32:10.980409Z

has anyone succeeded in running a cherry project with go? I’ve tried using goja for this, but it doesn’t support import statements… 🧵

Stephan Renatus 2025-01-08T09:33:11.058869Z

…and I’m no JS expert by any means. tried using esbuild, but it won’t help: with format=esm, I still have import statements; with format=cjs, it gives a warning about import.meta.url and the resulting file fails to work with goja, too.

borkdude 2025-01-08T09:38:55.031999Z

squint and cherry don't use import.meta.url, perhaps you are using this in your own program?

borkdude 2025-01-08T09:39:19.962259Z

import and import.meta.url are ES6 constructs. it seems goja doesn't support ES6

borkdude 2025-01-08T09:39:48.977299Z

> ECMAScript 5.1

Stephan Renatus 2025-01-08T09:42:16.692479Z

yeah I saw that but they also claim to support some ES6 so I thought I’d give it a shot 😄

Stephan Renatus 2025-01-08T09:42:35.617539Z

npx esbuild cherry.mjs --bundle --platform=node --outfile=foo.mjs
▲ [WARNING] "import.meta" is not available with the "cjs" output format and will be empty [empty-import-meta]

    cherry.mjs:4:77:
      4 │ cherry_core.prn.call(null, fs.existsSync.call(null, fileURLToPath.call(null, import.meta.url)));
        ╵                                                                              ~~~~~~~~~~~

  You need to set the output format to "esm" for "import.meta" to work correctly.

Stephan Renatus 2025-01-08T09:43:06.796179Z

I don’t have any added code yet, cherry.mjs is the product of cherry run’ing

(ns example
  (:require ["fs" :as fs]
            ["url" :refer [fileURLToPath]]))

(prn (fs/existsSync (fileURLToPath js/import.meta.url)))

(defn foo [{:keys [a b c]}]
  (+ a b c))

(js/console.log (foo {:a 1 :b 2 :c 3}))

Stephan Renatus 2025-01-08T09:43:19.847439Z

oh wait. there it is 😳

Stephan Renatus 2025-01-08T09:45:20.295089Z

running the script without the import through the esbuild I get another error

panic: ReferenceError: module is not defined at cherry.mjs:24:1(37)

goroutine 1 [running]:
main.main()
        /Users/stephan/Sources/srenatus/cherry-go/main.go:14 +0x105
exit status 2
where line 24 is
module.exports = __toCommonJS(cherry_exports);

Stephan Renatus 2025-01-08T09:51:10.384599Z

hmm esbuild with --format=iife gives me console is not defined at ...

Stephan Renatus 2025-01-08T09:51:31.332829Z

there’s https://github.com/dop251/goja_nodejs for that

Stephan Renatus 2025-01-08T09:51:39.669969Z

(sorry for thinking out loud)

Stephan Renatus 2025-01-08T09:55:57.377309Z

huh I guess this kinda-sorta worked

srenatus/cherry-go % npx cherry run cherry.cljs
[cherry] Running cherry.cljs
6
srenatus/cherry-go % npx esbuild cherry.mjs --bundle --platform=node --outfile=foo.mjs --format=iife

  foo.mjs  473.9kb

⚡ Done in 50ms
srenatus/cherry-go % go run main.go
2025/01/08 10:55:21 6
2025/01/08 10:55:21 val: undefined goja.valueUndefined
srenatus/cherry-go %

jasalt 2025-03-04T04:35:11.948269Z

@stephan.renatus what was your experience with Goja so far, did you get things working to any extent? Found it's available in https://pocketbase.io/docs/js-overview/ and got curious about Cljs support.

Cora (she/her) 2025-01-09T23:14:44.261469Z

esbuild takes a target option, try --target=es5

1
Stephan Renatus 2025-03-06T08:57:09.361399Z

I haven't done anything beyond the quarter-hour hack above, sorry. no insights.

👍 1