cherry

Chris McCormick 2022-07-27T07:51:04.881649Z

@chris358 has joined the channel

borkdude 2022-07-27T08:47:40.061539Z

I think we could make ES6 output vs .cjs or whatever else output configurable, so the compiler API gives you some options, for e.g. when you want to integrate the compiler in a REPL, browser, etc. Reloading ES6 modules is a bit painful so having some "dev" mode or "playground" mode vs "optimized build" mode could be a good idea.

💯 2
mkvlr 2022-07-27T08:52:42.745109Z

would love it if cherry wouldn’t inherit the closed world assumption of closure

borkdude 2022-07-27T08:58:53.752689Z

Well, es6 modules are closed for a reason, I think. It makes analyzing / caching / tree-shaking / etc a lot easier. So having the es6 module is good, but in some scenarios you might just want to get a JS snippet and js/eval that inside a browser, while not having the import and export stuff. There's also this: https://github.com/borkdude/cherry/issues/24

👀 1
borkdude 2022-07-27T09:00:04.043039Z

I opened an issue for the configurable output: https://github.com/borkdude/cherry/issues/23

mkvlr 2022-07-27T09:00:07.671339Z

I believe @jackrusher has some ideas about how it can be done with es6 modules.

borkdude 2022-07-27T09:01:12.849419Z

OK, opened an issue to discuss the reloading aspect: https://github.com/borkdude/cherry/issues/25

borkdude 2022-07-27T09:02:35.611939Z

Also opened an issue about the macro approach: https://github.com/borkdude/cherry/issues/4 I see two possible scenarios: • Macros are ran in SCI during compilation, no emission to .mjs for macros • Macro namespaces are transpiled first, then dynamically loaded in the compiler and then ran during compilation

borkdude 2022-07-27T09:03:58.521649Z

The first option would also allow cherry to be ran inside JVM / bb, etc. since macros aren't loaded from .js files in that case. But it would also force you to keep the macro sources around when you distribute a library

borkdude 2022-07-27T10:11:54.279149Z

So until google closure figures out how to produce ES6 module output, I think we're left with 300kb apps at minimum for cherry. See https://github.com/borkdude/cherry/issues/24

borkdude 2022-07-27T10:19:15.918819Z

Maybe not too bad and for multiple libs written with cherry, they'll still be able to interop with each other and other JS libs, so no extra kbs for those use cases

borkdude 2022-07-27T10:31:08.348839Z

Or... until cherry can transpile cljs.core itself to ES6 ;) loading

🤔 1
borkdude 2022-07-27T11:00:30.630129Z

I'm figuring out if google closure can do a pass over a cherry-compiled file which uses the (already advanced compiled) cherry module.

npx google-closure-compiler --js=index.mjs

borkdude 2022-07-27T11:11:00.004499Z

Alright, this worked!

npx google-closure-compiler --module_resolution NODE --compilation_level ADVANCED  --js=node_modules/cherry-cljs/lib/cljs_core.js --js=node_modules/cherry-cljs/cljs.core.js --js=index.mjs  --js_output_file=dist/out.js --language_in ECMASCRIPT_2020

3
borkdude 2022-07-27T11:11:03.629929Z

160kb

borkdude 2022-07-27T11:15:45.320779Z

And when adding a core function, like prn and assoc etc, it gets slightly bigger, like 10kb extra. But this seems to work :)

borkdude 2022-07-27T11:17:59.225559Z

This is the output for:

(ns index)

(prn (assoc {:a (+ 1 2 3)} :b 1)
     (range 20))
Does it run on your machine? partyparrot

borkdude 2022-07-27T11:20:50.802669Z

Seems to work in browser as well

mkvlr 2022-07-27T14:31:57.098879Z

what's your dev workflow like? In js land https://vitejs.dev/guide/why.html and https://vitest.dev/guide/why.html seem to be the choices du jour for es6 modules. I guess cherry should work well with those?

borkdude 2022-07-27T14:36:10.515599Z

I'm not so familiar with the existing JS tooling to be honest :) But I'll check it out. The two links you posted are identical

borkdude 2022-07-27T14:38:05.243749Z

Got vite dev thing up. Let's see :)

borkdude 2022-07-27T14:42:54.312449Z

Works :)

borkdude 2022-07-27T14:43:30.993269Z

(ns cherry)

(defn myCoolFn []
  #js {:payload "Hello from Cherry"})
import { myCoolFn } from './cherry.mjs'

borkdude 2022-07-27T14:45:45.521869Z

It's amazing :)

🙌 1
borkdude 2022-07-27T14:46:02.708899Z

Now only hook up cherry recompilation to this vite watcher

borkdude 2022-07-27T14:46:10.301449Z

and then you have an instant experience

borkdude 2022-07-27T14:47:14.295899Z

yeah, a vite plugin seems feasible

mkvlr 2022-07-27T16:17:12.927089Z

the links are almost identical, but not quite, the second one is vite test 👀

mkvlr 2022-07-27T16:17:54.882689Z

vite stole the ideas and users of snowpack btw

borkdude 2022-07-27T16:18:25.545059Z

ah I'll check it out after dinner. check main channel for tweet

borkdude 2022-07-27T15:05:34.837589Z

cherry + vite.js https://twitter.com/borkdude/status/1552308825310494721 😎

3
borkdude 2022-07-27T18:46:45.815919Z

Pushed the vite code example so you can play around locally: https://github.com/borkdude/cherry/blob/main/examples/vite/README.md

borkdude 2022-07-27T19:05:42.388229Z

vitest: https://twitter.com/borkdude/status/1552369264866230275 (cc @mkvlr)

mkvlr 2022-07-27T19:06:51.236039Z

@borkdude nice, looks pretty snappy as well

borkdude 2022-07-27T19:07:48.175149Z

could become even snappier when cherry exposes an API to be used in Node, currently I'm launching node on every change to recompile .cljs

borkdude 2022-07-27T19:08:31.191409Z

and with source map support, perhaps this tool will also show the right .cljs location

mkvlr 2022-07-27T19:10:14.330869Z

could the compilation also run in the browser without node?

borkdude 2022-07-27T19:10:38.504409Z

it could yes, the compiler is pretty simple, just a string -> string translation

mkvlr 2022-07-27T19:10:45.407169Z

and wondering if this could be useful for self-hosted tests

borkdude 2022-07-27T19:11:55.063569Z

what do you mean self-hosted tests?

mkvlr 2022-07-27T20:04:14.017389Z

the tests running as es6 modules, compiled by 🍒

borkdude 2022-07-27T20:10:31.506169Z

@mkvlr that's what I'm also doing in the cherry repo, but then with node:test (node 18)

borkdude 2022-07-27T20:10:49.635479Z

(not fully worked out)

mkvlr 2022-07-27T20:16:37.654279Z

I guess since vite test can reuse vite transformers / plugins you should be able to use vite test if we made it independent of node

mkvlr 2022-07-27T20:17:01.113679Z

the parallel test running sounds nice, does node also do that?

borkdude 2022-07-27T20:17:04.449419Z

yes, but I don't see why I would want to do this in a browser :)

😂 1
borkdude 2022-07-27T20:17:51.116949Z

I think so yes, https://nodejs.org/api/test.html

mkvlr 2022-07-27T20:18:24.293539Z

ah and same syntax it seems

mkvlr 2022-07-27T20:18:52.794229Z

need to take a closer look at how you do this currently

borkdude 2022-07-27T20:19:42.532859Z

I only have one small test here: https://github.com/borkdude/cherry/blob/main/test/node_test.cljs and nothing automated in CI. I do have more tests with cljs.test which currently only run in a REPL

mkvlr 2022-07-27T20:19:50.520509Z

and I guess for browser dev it's nice for the tests to run in the target runtime

mkvlr 2022-07-27T20:21:10.013239Z

could the cljs.tests compile to a node test?

borkdude 2022-07-27T20:21:41.470659Z

you mean an automatic translation?

borkdude 2022-07-27T20:21:50.977059Z

that would seem a little bit too much magic to me :)

mkvlr 2022-07-27T20:22:37.244309Z

how do you run them, in what repl?

borkdude 2022-07-27T20:22:46.252759Z

the cljs.test tests?

mkvlr 2022-07-27T20:25:39.955549Z

so then you have clojure, clojurescript and cherry in the mix

borkdude 2022-07-27T20:25:49.744799Z

yes

borkdude 2022-07-27T20:26:05.896929Z

similar to how I test SCI

mkvlr 2022-07-27T20:26:37.492099Z

what's missing for cherry to be able to transpile cljs.test? 😜

borkdude 2022-07-27T20:27:22.625479Z

the most important ones currently: 1 varargs support 2 macro support

mkvlr 2022-07-27T20:28:00.796559Z

cool, not so long a list

borkdude 2022-07-27T20:45:14.188219Z

not sure what else I'll come across, but adding features goes faster than I expected

3
1
borkdude 2022-07-27T20:45:23.716589Z

the macro thing comes with trade-offs though

borkdude 2022-07-27T19:11:02.928339Z

right now it's coupled with node.js fs to read files but that has to be split out from the compiler core thing to make it work with browsers

👍 2