Fork me on GitHub
#shadow-cljs
<
2022-06-20
>
isak18:06:48

I've been using a flush hook like this:

(defn flush-hook
  {:shadow.build/stage :flush}
  [build-state & args]
  (when (= :release (:shadow.build/mode build-state))
    ;; My logic
    )
  build-state)
Lately I see that it is getting called both with my normal build names (:shadow.build/build-id build-state), and with '-release-snapshot' appended to them. Is that new? What is that for?

hanDerPeder19:06:13

when building release artifacts on something like github actions. is it a good idea to cache .shadow-cljs? or will that just bite me in the ass at some point?

thheller19:06:51

@isak hmm I guess I didn't consider that. build reports just re-use the original build configs. I guess it should unset the build-hooks

1
thheller19:06:39

@peder.refsnes the intention is to maintain the cache (ie. .shadow-cljs) yes. it invalidates itself if something changes

πŸ‘ 1
CarnunMP20:06:54

Hellooo, Happy Monday! Ever since switching to a branch with some version bumps (`deps.edn` and package.json) I've been getting a bizarre build error running shadow-cljs ... watch appβ€”or shadow-cljs ... server then :Connecting (with https://github.com/tpope/vim-fireplace/blob/b6bef833b56632df917bcf33bc50b8a5d1e26139/doc/fireplace.txt#L19) and :CljEvaling (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :app) (shadow/nrepl-select :app)): see below ⬇️ I've tried a https://stackoverflow.com/a/70490790 of https://docs.npmjs.com/cli/v8/commands/npm-ci, up to and including updating my global shadow-cljs to the latest version, and using npx shadow-cljs... and fiddling with the :output-feature-set compiler option... and https://github.com/angular/clutz/issues/490#issuecomment-292236507 πŸ˜… ... and still nada. Seems like people have https://clojurians-log.clojureverse.org/shadow-cljs/2020-06-02 about similar https://clojurians-log.clojureverse.org/shadow-cljs/2020-08-25 before... and it was some kinda problem in/with the closure compiler? :thinking_face: Fwiw, this is the thing called in the last (i.e. most recent) line of the stacktrace below, afaict: https://github.com/google/closure-compiler/blob/dfa3226ec7b5197b2a1c11b4f0f4a3ee147919f4/src/com/google/javascript/jscomp/parsing/ParserRunner.java#L118 And this is the file where the stack-blowing is happening: https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/parsing/IRFactory.java The error:

$ shadow-cljs -d nrepl/nrepl:0.8.3 -d cider/piggieback:0.5.2 -d com.billpiel/sayid:0.1.0 -d refactor-nrepl:3.0.0 -d cider/cider-nrepl:0.27.2 watch app
shadow-cljs - config: /home/carnun/Documents/Nette/nette/shadow-cljs.edn
shadow-cljs - starting via "clojure"
shadow-cljs - HTTP server available at 
shadow-cljs - server version: 2.19.3 running at 
shadow-cljs - nREPL server started on port 8777
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
Failed to inspect file
  /home/carnun/Documents/Nette/nette/node_modules/highlight.js/lib/languages/gml.js

it was required from
  /home/carnun/Documents/Nette/nette/node_modules/highlight.js/lib/index.js

Errors encountered while trying to parse file
  /home/carnun/Documents/Nette/nette/node_modules/highlight.js/lib/languages/gml.js
  {:line 1, :column 1, :message "The file could not be parsed as JavaScript."}

RuntimeException: Exception parsing "/home/carnun/Documents/Nette/nette/node_modules/highlight.js/lib/languages/gml.js"
	com.google.javascript.jscomp.parsing.ParserRunner.parse (ParserRunner.java:148)
	com.google.javascript.jscomp.JsAst.parse (JsAst.java:156)
	com.google.javascript.jscomp.JsAst.getAstRoot (JsAst.java:62)
	shadow.build.closure.JsInspector.getFileInfo (JsInspector.java:180)
	shadow.build.closure.JsInspector.getFileInfoMap (JsInspector.java:194)
	shadow.build.npm/get-file-info*/fn--12316 (npm.clj:452)
	shadow.build.npm/get-file-info* (npm.clj:451)
	shadow.build.npm/get-file-info* (npm.clj:401)
	shadow.build.npm/get-file-info (npm.clj:512)
	shadow.build.npm/get-file-info (npm.clj:509)
	shadow.build.npm/find-resource-in-package (npm.clj:726)
	shadow.build.npm/find-resource-in-package (npm.clj:686)
	shadow.build.npm/find-resource (npm.clj:776)
	shadow.build.npm/find-resource (npm.clj:739)
	shadow.build.resolve/find-npm-resource (resolve.clj:122)
	shadow.build.resolve/find-npm-resource (resolve.clj:93)
	shadow.build.resolve/eval14445/fn--14448 (resolve.clj:262)
	clojure.lang.MultiFn.invoke (MultiFn.java:244)
	shadow.build.resolve/find-resource-for-string (resolve.clj:80)
	shadow.build.resolve/find-resource-for-string (resolve.clj:69)
	shadow.build.resolve/resolve-string-require (resolve.clj:453)
	shadow.build.resolve/resolve-string-require (resolve.clj:436)
	shadow.build.resolve/resolve-require (resolve.clj:669)
	shadow.build.resolve/resolve-require (resolve.clj:662)
	shadow.build.resolve/resolve-deps/fn--14394 (resolve.clj:51)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:45)
	shadow.cljs.util/reduce-> (util.clj:44)
	shadow.build.resolve/resolve-deps (resolve.clj:49)
	shadow.build.resolve/resolve-deps (resolve.clj:33)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:656)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:615)
	shadow.build.resolve/resolve-require (resolve.clj:666)
	shadow.build.resolve/resolve-require (resolve.clj:662)
	shadow.build.resolve/resolve-deps/fn--14394 (resolve.clj:51)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:45)
	shadow.cljs.util/reduce-> (util.clj:44)
	shadow.build.resolve/resolve-deps (resolve.clj:49)
	shadow.build.resolve/resolve-deps (resolve.clj:33)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:656)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:615)
	shadow.build.resolve/resolve-require (resolve.clj:666)
	shadow.build.resolve/resolve-require (resolve.clj:662)
	shadow.build.resolve/resolve-deps/fn--14394 (resolve.clj:51)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:45)
	shadow.cljs.util/reduce-> (util.clj:44)
	shadow.build.resolve/resolve-deps (resolve.clj:49)
	shadow.build.resolve/resolve-deps (resolve.clj:33)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:656)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:615)
	shadow.build.resolve/resolve-require (resolve.clj:666)
	shadow.build.resolve/resolve-require (resolve.clj:662)
	shadow.build.resolve/resolve-deps/fn--14394 (resolve.clj:51)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:45)
	shadow.cljs.util/reduce-> (util.clj:44)
	shadow.build.resolve/resolve-deps (resolve.clj:49)
	shadow.build.resolve/resolve-deps (resolve.clj:33)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:656)
	shadow.build.resolve/resolve-symbol-require (resolve.clj:615)
	shadow.build.resolve/resolve-require (resolve.clj:666)
	shadow.build.resolve/resolve-require (resolve.clj:662)
	shadow.build.resolve/resolve-deps/fn--14394 (resolve.clj:51)
	clojure.lang.PersistentVector.reduce (PersistentVector.java:343)
	clojure.core/reduce (core.clj:6885)
	clojure.core/reduce (core.clj:6868)
	shadow.cljs.util/reduce-> (util.clj:45)
	shadow.cljs.util/reduce-> (util.clj:44)
	shadow.build.resolve/resolve-deps (resolve.clj:49)
	shadow.build.resolve/resolve-deps (resolve.clj:33)
Caused by:
StackOverflowError: 
	com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processBinaryExpression (IRFactory.java:1743)
	com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process (IRFactory.java:2780)
	com.google.javascript.jscomp.parsing.IRFactory.transform (IRFactory.java:737)
	com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.processBinaryExpression (IRFactory.java:1748)
	com.google.javascript.jscomp.parsing.IRFactory$TransformDispatcher.process (IRFactory.java:2780)
	com.google.javascript.jscomp.parsing.IRFactory.transform (IRFactory.java:737)
	...
Any pointers would be much appreciated! πŸ˜„

thheller21:06:03

dunno how you are using highlight.js. if its via re-frame-10x you should upgrade that

CarnunMP21:06:36

Oh wow... so throwing (even) more stack at it really is the answer? πŸ™ƒ

thheller21:06:35

well imho the answer is not including these files in the first place. I doubt very much you need gml support? whatever that even is πŸ˜›

CarnunMP21:06:39

re-frame-10x aye... and lowlight, via https://tiptap.dev iirc

CarnunMP21:06:48

GameMaker Language πŸ˜› just one of many that highlight.js ships with in its node_modules

thheller21:06:07

well its fine to include it if you actually need it

thheller21:06:23

including it when you don't need it just makes everything larger and slower (to build, load, etc)

CarnunMP21:06:00

agreed! but it's very likely a keeper (unfortunately?)

CarnunMP21:06:35

I just mean I agree in general that larger and slower is worse πŸ˜›

thheller21:06:25

I mean another option is just editing this file in your node_modules folder

thheller21:06:40

just remove all the registerLanguage calls you don't need

thheller21:06:53

bit manual but might be worth

CarnunMP21:06:49

Throwing more more stack at it seemed to do the trick. Thanks @thheller! :))

CarnunMP21:06:53

> I mean another option is just editing this file in your node_modules folder Hmm... would this mean checking that into source control? deep_thinking

thheller21:06:41

well I would just automate the edit in some way so it always runs after the package is installed

thheller21:06:08

I mean all of this only applies if you don't control how highlight.js is used yourself

thheller21:06:13

but I assume that is the case here

thheller21:06:59

you can also use :js-options {:resolve {"highlight.js" {:target :npm :require "highlight.js/core"}}

thheller21:06:30

that would only give you the basic highlight.js

thheller21:06:42

you can then add all the languages you actually need manually in your code somewhere

thheller21:06:49

or just live with the high stack size

πŸ˜… 1
CarnunMP21:06:10

Really appreciate these ideas. I'll have to chew them over tomorrow. Thanks again!

Tiago Dall'Oca21:06:07

possible bug report (more in the thread)

Tiago Dall'Oca21:06:38

deps.edn

{:paths ["src" "tests"]
 :deps {
        ;; ...
 }
 :aliases
 {:shadow-cljs
  {:extra-deps {thheller/shadow-cljs {:mvn/version "2.19.3"}}
   :main-opts ["-m" "shadow.cljs.devtools.cli"]}}}

Tiago Dall'Oca21:06:01

shadow-cljs.edn

{:deps true

 :builds
 {;; ...

  :prod
  {:target :npm-module
   :output-dir "dist"
   ;; ...
   }}}

Tiago Dall'Oca21:06:46

running clj -M:shadow-cljs compile prod works as expected

Tiago Dall'Oca21:06:45

shadow-cljs compile prod, on the other hand, outputs

Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.

Full report at:
/tmp/clojure-15396811791392763534.edn

Tiago Dall'Oca21:06:21

Adding thheller/shadow-cljs {:mvn/version "2.19.3"} to :deps solves it

thheller21:06:33

not a bug. working as expected.

Tiago Dall'Oca21:06:50

It seems to me that shadow-cljs is not calling clj with the right alias

thheller21:06:01

with :deps true you tell shadow-cljs to use no aliases

thheller21:06:11

so it won't have shadow-cljs available when starting

thheller21:06:26

so you use :deps {:aliases [:shadow-cljs]} instead to activate it

thheller21:06:44

but need to take out :main-opts since that is redundant

Tiago Dall'Oca21:06:45

I must have missed it in the user guide

Drew Verlee23:06:47

will shadow use a cljsjs dependency? [edit] nope. clearly not. e.g :dependencies [[cljsjs/something "xyz version" ]] or is it ignored and i need to use npm install something and create a cljsjs shim as per the migration docs. I'm asking because i got errors about missing libs unless i did an npm install but my worry is that the cljsjs wrapper for some libs is doing more then a 1 to 1 translation to cljs. I don't have a specific example of this happening but it would be nice to be aware i need to tackle it.

sansarip01:06:26

shadow-cljs does not support cljsjs packages πŸ™… src: https://clojurians.slack.com/archives/C6N245JGG/p1655013153124169

Drew Verlee02:06:09

so yea, it just ignores them. That's reasonable, i just had magically hoping that the migration strategy was accounting for them somehow. https://shadow-cljs.github.io/docs/UsersGuide.html#cljsjs

thheller05:06:38

as I said before. if you are the one requiring cljsjs packages you should change that to use npm packages directly.

thheller05:06:13

most popular libraries that use cljsjs packages have been updated to also declare :npm-deps so the npm packages should be isntalled and used automatically

thheller05:06:44

some are not so you need to install manually

thheller05:06:04

note that using npm packages directly is also what you need to be doing for :target :bundle and most cljsjs packages have also been updated to support that.

Drew Verlee10:06:33

Thanks theller.