shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
benny 2020-09-18T04:22:58.001100Z

any places to look when running with a release build, I get undefined is not an object (evaluating 'Z4.$l') but it works just fine when running dev builds?

p-himik 2020-09-18T04:31:34.001200Z

Issues with externs. Likely whatever Z4 was before, it shouldn't have been renamed. Or you have something different happening in the release build so that Z4 is a genuine variable that has a value of undefined.

thheller 2020-09-18T07:00:15.001900Z

@benny turn on externs inference if it isn't on (wasn't the default as of very recently) https://shadow-cljs.github.io/docs/UsersGuide.html#externs

thheller 2020-09-18T07:00:19.002100Z

looks like an externs renaming issue

Karol Wójcik 2020-09-18T10:14:08.003200Z

Is it possible to not start nrepl server when using shadow.cljs.devtools.server/start?

2020-09-18T10:47:20.005100Z

in shadow-cljs.edn: > The nREPL server can be disabled by setting :nrepl false.

1❤️
2020-09-18T10:47:33.005300Z

may be that works?

yenda 2020-09-18T14:46:03.006800Z

Is there some gotchas when hot-reloading a namespace that uses macros? Trying to use clara-rules defrule macro and every time I save the namespace shadow complains about undeclared vars, which are functions defined in the namespace and originally compiled fine

yenda 2020-09-18T14:46:19.007200Z

additionally when moving these functions to another namespace it also works fine

thheller 2020-09-18T14:47:04.007400Z

not enough information to comment

yenda 2020-09-18T14:48:29.008Z

(ns notifications.notifications
  (:require [clara.rules :as clara])
  (:require-macros [clara.macros :refer [defrule defsession]]))

(defsession session 'notifications.notifications
  :fact-type-fn :type)

(defn testz [user-id]
  {[:user/id user-id] [:user/id]})

(defrule follow
  "A rule which isd fired on every follow"
  [:context [env] (= ?env env)]
  [:follow [{followed-id :followed/id user-id :user/id}]
   (= ?followed-id followed-id)
   (= ?user-id user-id)]

  =>
  (testz ?user-id))

(defn handle-event [env event]
  (-> session
      (clara/insert (merge env {:type :context})
                    event)
      (clara/fire-rules)))

thheller 2020-09-18T14:49:49.008500Z

I don't know much about clara-rules so no clue what that code does

thheller 2020-09-18T14:50:15.009Z

I know that is uses a clojure side atom and does not play well with caching

thheller 2020-09-18T14:50:29.009400Z

so could be likely that it also doesn't play well with incremental compilation at all

yenda 2020-09-18T14:51:00.010Z

yeah it looks like it's something like that because rules that are deleted keep throwing undeclared-var compilation errors

yenda 2020-09-18T14:51:12.010300Z

so disabling caching could help?

thheller 2020-09-18T14:51:36.010700Z

if you want to completely obliterate recompile performance 😉

thheller 2020-09-18T14:52:13.011300Z

no clue to be honest. maybe there is something you can call to "reset" its state

thheller 2020-09-18T14:53:45.012100Z

cache is off by default for clara already

frozar 2020-09-18T15:04:55.015500Z

Hi, I'm wondering how to manage subproject through shadow-cljs. My situation is the following: I want to create a main project on a private repository and this project should use an "embedded" subproject which is public and should remain public. Both on them will use shadow-cljs.edn as build configuration file. Is there a convenient way to embed a subproject with shadow-cljs?

thheller 2020-09-18T15:06:11.016Z

you can use deps.edn or project.clj to do this

thheller 2020-09-18T15:06:16.016300Z

shadow-cljs.edn itself does not support this

thheller 2020-09-18T15:06:54.017300Z

well you can just add :sources-paths ["src/main" "../that-subproject/src/main"] if its just about source paths

yenda 2020-09-18T15:07:17.018100Z

interesting even after completely disable the cache the initial compilation works then I get undeclared variables 😕

thheller 2020-09-18T15:08:16.019800Z

@yenda diid you restart the shadow-cljs process? as I said the library keeps some CLJ side state that isn't part of any shadow-cljs cache or so you could reset

frozar 2020-09-18T15:08:36.020200Z

OK, thank you @thheller, always reactive, always amazing ! Yes, I can manage this with the classpath, but I don't want to duplicate the dependencies of the subproject in the main project. I'll try the deps.edn approach, thank again

yenda 2020-09-18T15:10:05.020300Z

yes I restarted it

thheller 2020-09-18T15:11:46.020500Z

sorry don't know enough about the lib to even guess

yenda 2020-09-18T15:13:22.020700Z

looks like there is a clear-ns-productions! function

yenda 2020-09-18T15:16:20.020900Z

so I should use it in

:before-load  <http://my.app/stop|my.app/stop>

thheller 2020-09-18T15:17:34.021100Z

you might also need ^:dev/always on the ns https://shadow-cljs.github.io/docs/UsersGuide.html#_lifecycle_hooks

thheller 2020-09-18T15:18:18.021300Z

for macros that access the analyzer state directly

thheller 2020-09-18T15:18:42.021500Z

can't remember if that was necessary or not

Stephen 2020-09-18T15:31:03.023500Z

Hi, I am just getting into clj/cljs dev. Is there a way to only use the shadow-cljs commandline tool for managing all deps (clj and cljs)? Or are deps.edn and/or lein always needed for the backend(clj) side?

Stephen 2020-09-18T15:34:24.024100Z

All this clj (deps.edn), lein, and shadow-cljs configs confuse me

frozar 2020-09-18T15:37:35.025100Z

@slack1781 as far as I know, shadow-cljs is dedicated to clojurescript project, or javascript aspect of a project.

yenda 2020-09-18T15:41:18.025200Z

ok works

yenda 2020-09-18T15:41:36.025400Z

(clara/clear-ns-productions!) needs to be put in the ns

yenda 2020-09-18T15:41:40.025600Z

nothing else required

wombawomba 2020-09-18T15:44:06.026800Z

So I have a shadow-cljs project, and I want to disable CORS (i.e. inject permissive CORS headers) for the shadow-cljs watch command. How can I make this happen?

wombawomba 2020-09-18T15:50:18.026900Z

FWIW I thought the :push-state/headers key as described in the docs (https://shadow-cljs.github.io/docs/UsersGuide.html#dev-http) seems promising for this, but adding it doesn’t seem to have any effect

wombawomba 2020-09-18T15:51:20.027200Z

Maybe I’m putting it in the wrong place?

frozar 2020-09-18T16:00:02.027400Z

As I use many npm package, it's finally easier to keep using shadow-cljs ^^

wombawomba 2020-09-18T16:04:04.027600Z

Nevermind, I figured it out 🙂

2020-09-18T16:49:43.029500Z

how can I set environment vars for development vs prod. I am reading this section of the docs (https://shadow-cljs.github.io/docs/UsersGuide.html#shadow-env), but I am used to starting shadow with Cider, so I am not even sure how I set the env vars there.

2020-09-18T16:50:22.030300Z

I just want to point the api endpoint to somewhere else, so it's something quite trivial

dpsutton 2020-09-18T16:55:16.031300Z

{...
 :builds
 {:app
  {:target :browser
   ...
   :modules {:app {:entries [<http://your.app|your.app>]}}
   ;; to enable in development only
   :dev {:closure-defines {<http://your.app/VERBOSE|your.app/VERBOSE> true}}
   ;; to enable always
   :closure-defines {<http://your.app/VERBOSE|your.app/VERBOSE> true}
   ;; you may also enable it for release as well
   :release {:closure-defines {<http://your.app/VERBOSE|your.app/VERBOSE> true}}
   }}
you could use :dev and :release to use hardcoded versions. or start shadow from the command line and then cider-connect-cljs to the already running instance with easily set env vars

2020-09-18T16:56:16.031500Z

thanks @dpsutton

dpsutton 2020-09-18T16:57:42.032200Z

you could also call (setenv VARIABLE VALUE). make a function that does this and then calls cider-jack-in-cljs and you might be good if you really wan to stay in emacs

2020-09-19T18:34:34.048900Z

Awesome, thanks

dpsutton 2020-09-18T16:58:58.032600Z

for work i use

(cider-connect-cljs (list :host "localhost"
                          :port 7888
                          :cljs-repl-type 'figwheel-connected
                          'project-dir "~/projects/aclaimant/acl"))
in a function. you could adjust that as needed with a call to set-env

zhuxun2 2020-09-18T18:32:44.033900Z

Has anyone seen npx shadow-cljs watch :main running forever? Like so:

[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.33s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.33s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.49s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.49s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.39s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.35s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.33s)
[:main] Compiling ...
[:main] Build completed. (286 files, 2 compiled, 0 warnings, 0.34s)
... (forever) ...

zhuxun2 2020-09-18T18:33:16.034500Z

I did not touch any code during this time..

zhuxun2 2020-09-18T18:33:55.034900Z

What triggers a re-compilation in watch mode?

zhuxun2 2020-09-18T18:37:23.035800Z

And if I delete the compiled folder, and restart the watch, the problem resolves ... weird

thheller 2020-09-18T18:38:15.036200Z

@zhuxun2 this can happen if your :output-dir is also on any of the :source-paths

zhuxun2 2020-09-18T18:41:43.037700Z

@thheller But isn't that usually the case? for example, I usually use "resources/public/js" as the output directory, but "resources" is usually one of the source-paths

thheller 2020-09-18T18:44:05.038300Z

yes, but that is filtered. the filter is very basic so it may not properly filter all the stuff

thheller 2020-09-18T18:44:29.038800Z

I thought I fixed most cases but maybe I didn't. not saying that this is the cause of your problem. just a guess.

thheller 2020-09-18T18:44:46.039300Z

if you have non-standard paths then it is more likely

zhuxun2 2020-09-18T18:45:24.040Z

Yes I do, I used a separate resources folder called "resources_dev" for the development compiles

zhuxun2 2020-09-18T18:45:33.040300Z

Is there any workaround in that case?

thheller 2020-09-18T18:46:18.040600Z

call it dev-resources 😛

thheller 2020-09-18T18:46:32.040900Z

paths ending in resources are filtered

thheller 2020-09-18T18:47:09.041500Z

which version is this? I though I fixed this in general but maybe I didn't

zhuxun2 2020-09-18T18:47:32.041700Z

LOL, okay. I am using 2.9.10

zhuxun2 2020-09-18T18:48:06.042Z

Oh actually 2.8.58

thheller 2020-09-18T18:48:38.042500Z

hmm yeah maybe try upgrading. or just renaming that should definitely work

zhuxun2 2020-09-18T18:50:14.043300Z

Okay I'll try. Why not make the filter an explicit setting?

thheller 2020-09-18T18:51:01.044200Z

it shouldn't be required at all anymore but that was definitely after 2.8.58

zhuxun2 2020-09-18T18:52:08.045100Z

I see, yeah maybe I was just using an out-dated version .. thanks!