shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
yqrashawn 2021-03-16T04:01:00.001500Z

Hi all, Is it possible to export macros to js context with the :esm target like this?

(ns core
  (:require [cljs.spec.alpha :as s :include-macros true]))

(def exports #js
  {:and s/and})

thheller 2021-03-16T07:55:17.002900Z

@namy.19 no. macros run at compile-time. you cannot use them dynamically at runtime unless you go full self-hosted. even then you couldn't use them from JS though.

yqrashawn 2021-03-16T08:03:37.003400Z

is it possible to use annotation to skip the check? @thheller

thheller 2021-03-16T08:04:40.004100Z

which check? s/or is a macro. you cannot call it dynamically from a function. what you are trying is simply not possible without eval

yqrashawn 2021-03-16T08:05:44.004400Z

but this works

yqrashawn 2021-03-16T08:06:36.005Z

the s/and and s/def are both macros

thheller 2021-03-16T08:07:21.005200Z

it does not work. not in the sense of actually using spec correctly.

yqrashawn 2021-03-16T08:11:51.005500Z

ok so it’s not possible..

thheller 2021-03-16T08:12:39.005700Z

macros are function that take CLJS syntax forms and return new CLJS syntax forms that the compiler will then compile. fundamentally you cannot call them from javascript without eval

thheller 2021-03-16T08:13:04.005900Z

and even with eval you'd be constructing the CLJS forms from JS and then compile them. not just call them as functions.

yqrashawn 2021-03-16T08:13:51.006100Z

ok so if I want to use spec in js, i have to implement one in js

thheller 2021-03-16T08:17:54.006300Z

kind of yeah

🥲 1
yqrashawn 2021-03-16T08:26:22.006600Z

really thanks for your super fast reply

wombawomba 2021-03-16T10:10:07.006800Z

@namy.19 you might find https://github.com/metosin/malli or https://github.com/plumatic/schema useful for these kinds of things

👍 1
wombawomba 2021-03-16T10:46:34.007500Z

Any recommendations on how to handle environment-specific configuration? (e.g. hostnames that need to be different for dev vs different prod envs)

thheller 2021-03-16T10:49:11.008Z

if you are talking about a browser build I recommend putting it into the HTML when this is dynamically generated HTML from a server

thheller 2021-03-16T10:50:04.008700Z

otherwise the typical answer is :closure-defines

wombawomba 2021-03-16T11:11:37.009Z

Good idea, thanks

Alexis Vincent 2021-03-16T12:50:24.010200Z

@thheller You once shared a neat code snippet to sidestep the closure “namespace has already been declared” thing. Can’t find it or remember where it was from. Are you able to reshare?

Alexis Vincent 2021-03-16T14:56:59.011Z

Thanks!

2021-03-16T23:20:23.012500Z

Hi all. I was wondering if there was a way to make the cljs-runtime directory concatenate to a single file when we release? Using a Vercel and having the 1000 odd files on upload for every deploy kills thier hobby limit.

thheller 2021-03-17T08:29:51.024500Z

watch or compile produce the cljs-runtime dir. release does not and does not need it. it also doesn't clear it though. you can just rm -rf the-output-dir && shadow-cljs release app or so yourself

wilkerlucio 2021-03-16T23:23:47.012800Z

the release build does that

2021-03-16T23:26:56.013Z

hmm... so it does... I wonder where all those other files came from? thanks for you help!