Fork me on GitHub
#shadow-cljs
<
2020-05-27
>
awb9904:05:14

I have a really weird issue with a npm dependency vega-embed. I have defined it in https://github.com/pink-gorilla/gorilla-ui and now https://github.com/pink-gorilla/shiny-clj uses gorilla-ui. In gorilla-ui I have defined deps.cljs When I compile cljs with shadow-cljs in shiny-clj it wants additional npm dependencies (buffer and process). This dependencies are not needed in gorilla-ui. And I think they are only needed when compiling for target :node and not for target :browser.

awb9905:05:22

base) [[email protected] shiny-clj]$ lein shadow-compile [:web] Compiling ... The required JS dependency "buffer" is not available, it was required by "node_modules/vega-loader/build/vega-loader.js". Search in: /home/andreas/Documents/gorilla/shiny-clj/node_modules You probably need to run: npm install buffer

awb9905:05:34

the even crazier thing is this:

awb9905:05:53

cat node_modules/vega-loader/build/vega-loader.js | grep buffer

awb9905:05:05

there is no buffer in this file

Helins07:05:38

Is there a way for testing an advanced compiled build? shadow-cljs release $test-build fails

thheller08:05:18

@adam678 fails how? you just run shadow-cljs release for the build and then run the tests normally?

thheller08:05:58

@hoertlehner you need to have shadow-cljs installed in your project. both buffer and process are polyfills packages that shadow-cljs will provide ...

awb9908:05:36

I have [thheller/shadow-cljs] [thheller/shadow-cljsjs "0.0.21"]

awb9908:05:42

and compile cljs with

awb9908:05:45

["with-profile" "+cljs" "run" "-m" "shadow.cljs.devtools.cli" "compile" ":web"]

thheller08:05:58

hmm? I mean the npm shadow-cljs package?

thheller09:05:07

just npm install shadow-cljs in the project?

awb9909:05:10

super! this fixed it!

awb9909:05:30

will the npm dependency bring th full compiler of shadow? or des it only bting this fixes?

awb9909:05:55

I am a little lost on undestanding what is going on behind the scenes...

thheller09:05:59

the npm package is mostly the for CLI stuff but also brings in some extra npm packages

thheller09:05:17

the compiler is from the CLJ dependency you have in project.clj.

thheller09:05:34

the npm stuff never does any actual compilation, just runs the java process

awb9910:05:16

thanks for the explaination!!!

Helins08:05:55

@thheller I get:

--- cljs_test_display/core.cljs:411
illegal initialization of @define variable cljs_test_display.core.root_node_id

thheller08:05:10

hmm is this :browser-test?

thheller08:05:18

hmm yeah I can reproduce that. cljs-test-display does a no-no for :advanced

thheller08:05:49

not allowed to set! goog-define constants

Helins09:05:19

Yes, :browser-test indeed. So I was not doing anything wrong. I am surprised no one has noticed this before, testing advanced builds is pretty useful.

thheller09:05:55

yeah indeed

thheller09:05:59

you can open an issue on the cljs-test-display repo. should be an easy fix. I can do that later too

thheller09:05:20

I have a custom test runner in my backlog too though. want something with a little more control over what it does on hot-reload so it doesn't always run all the tests

thheller09:05:28

dunno when I get to that though

Helins09:05:47

If it is an easy fix then I'll preferably someone else do it (well, you it seems 😄 ) since I have 0 knowledge about the codebase

plexus05:05:19

Would you consider trying out chui? It works under advanced and should be a richer UI experience than cljs-test-display https://github.com/lambdaisland/chui

dpsutton05:05:11

i'm getting the following error trying to cider-jack-in to this project: > Error building classpath. Manifest type not detected when finding deps for metosin/pohjavirta in coordinate #:local{:root "/System/Volumes/Data/home/arne/github/pohjavirta"}

dpsutton05:05:50

ah, this is in chui-remote's deps. need to clone and compile the java classes for that?

plexus07:05:16

hmmm right, you don't need chui-remote, and chui-remote no longer needs pohjavirta. Let me clean that up

plexus07:05:00

thanks for trying it out!

plexus07:05:42

could you try a164d8ba32f48a632a3f285f41a52f93d7bd024d ? thanks!

plexus07:05:06

issues/questions can go to #lambdaisland

Helins09:05:15

Thanks Arne, this is perfect! I've already caught a nasty bug (r/w big ints with DataViews without type hinting)

thheller09:05:07

ok, I'll check it out later.

Helins09:05:50

If it turns out to be more involving, I can try to dive in the codebase and help, let me know. I opened an issue anyway https://github.com/bhauman/cljs-test-display/issues/7

Helins09:05:09

I'll close mine 😉

thheller09:05:05

hehe doh. almost hit close on mine 😛

Helins09:05:41

(by the way, thanks for shadow-cljs, I have been using more and more lately after a sabbatical from CLJS, and I keep being impressed with how drastically it simplifies the workflow 🚀)

❤️ 32
bhauman13:05:36

man I never thought about folks testing under advanced 🙂

Helins19:05:40

Well, you never know. I admit I became a bit paranoid regarding :advanced

thheller13:05:27

hehe yeah not many people do that with :browser-test I guess. first time this has come up. 🙂

bhauman13:05:33

devcards 0.2.7 realeased and should no longer depend on a global js/React

👍 12
bhauman13:05:59

but don’t use it in advanced mode 😉

Pavel Klavík14:05:19

Hi, I am trying to get puppeteer running with Shadow-cljs, by adapting this: https://gist.github.com/apeckham/ec1725b22642d9344e294c701de18fb2#file-puppeteer-cljs, so I got this code:

Pavel Klavík14:05:27

(-> (puppeteer/launch)
        (.then (fn [browser]
                 (-> (.newPage browser)
                     (.then (fn [page]
                              (.goto page url #js{:waitUntil "networkidle2"})
                              (.screenshot page #js {:path "screenshot.png"})
                              (.close page)))))))

Pavel Klavík14:05:55

and I am getting these error warnings:

(node:5068) ExperimentalWarning: The fs.promises API is experimental
(node:5068) UnhandledPromiseRejectionWarning: Error: Could not find browser revision 756035. Run "npm install" or "yarn install" to download a browser binary.
    at ChromeLauncher.launch (C:\Shared\orgpad\node_modules\puppeteer\lib\Launcher.js:59:23)
(node:5068) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5068) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Pavel Klavík14:05:29

What is the Clojurescript idiomatic way of rewritting this:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('', {waitUntil: 'networkidle2'});
  await page.pdf({path: 'hn.pdf', format: 'A4'});

  await browser.close();
})();

lilactown14:05:16

@pavel.klavik have you address the errors that you pasted at all?

lilactown14:05:29

it seems to be pretty clear in how to fix them

Pavel Klavík15:05:20

ya, I noticed the error there, got it working

Pavel Klavík15:05:42

thought at first that I am using promises in wrong way.

Pavel Klavík15:05:12

but I am still interested in idiomatic way of writing this in ClojureScript? core.async?

lilactown15:05:46

no, similar to the way you wrote it

lilactown15:05:53

but you can flatten it

Pavel Klavík15:05:07

I got this in the end while loading the browser in a different thread:

(-> (.newPage @browser/browser)
        (.then (fn [page]
                 (log/info "Openning page" url "...")
                 (-> (.goto page url #js{:waitUntil "networkidle2"})
                     (.then #(.screenshot page #js {:path "screenshot.png"}))
                     (.then #(do (log/info "Screenshot of " id "with token" token "generated.")
                               (.close page)))))))
How would you do flattening?

lilactown15:05:43

promise .then always returns another promise

lilactown15:05:53

you don’t need to nest inside of the function you pass to .then

lilactown15:05:12

(-> (puppeteer/launch)
    (.then (fn [browser]
             (.newPage browser)))
    (.then (fn [page]
             (.goto page url #js{:waitUntil "networkidle2"})
             page))
    (.then (fn [page]
             (.screenshot page #js {:path "screenshot.png"})
             page))
    (.then (fn [page]
             (.close page))))

Pavel Klavík15:05:38

I see, that looks better.

Alex Porter17:05:17

Hi, working on setting up shadow-cljs for our project, and I'm getting the following error when I attempt to generate the shadow build report. Everything else is working fine in terms of creating my release build. Any ideas?

Alex Porter17:05:54

I'm not sure if this is affecting anything, but we have a shared project used between our different cljs apps in a monorepo, and so we're adding the source-path from here like ../shared/src/client and then getting a lot of these warnings as well

[2020-05-27 12:32:24.902 - INFO] filename violation for ns shcl.core.c.dropzone, got: client/shcl/core/c/dropzone.cljs expected: shcl/core/c/dropzone.cljs (or .cljc)
These didn't seem to affect anything with the release build though.

thheller18:05:42

just a guess but do you also have ../shared/src as a classpath/source-path?

Alex Porter18:05:37

No, just these

"src/server"
"src/client"
"src/shared"
"../shared/src/app"
"../shared/src/server"
"../shared/src/client"
"../shared/src/shared"

Alex Porter18:05:28

We use the same ns convention / folder structure inside src/client and it doesn't have any issues with that.

thheller18:05:19

yeah but somehow client/shcl/core/c/dropzone.cljs exists on the classpath. try ( "client/shcl/core/c/dropzone.cljs") from a clojure REPL. shadow-cljs clj-repl or so

thheller18:05:27

see what the full path for that is

Alex Porter19:05:28

#object[.URL 0x5a069486 "jar:file:/Users/alex.porter/.m2/repository/fullcontact/redboat.shared/latest/redboat.shared-latest.jar!/client/shcl/core/c/dropzone.cljs"]

thheller19:05:41

ok so that jar seems to contain a file that is maybe shouldn't contain? 😛

Alex Porter19:05:07

ok, yeah, I'll get that figured out

Alex Porter19:05:58

Thinking this is maybe the cause of the build report issue as well?

thheller19:05:18

I doubt it. the error is deep in the closure compiler code so I'm not exactly sure what it means

thheller19:05:06

it has something to do with source maps which are required for the build report

thheller19:05:11

but I never had that error before so I'm not exactly sure what the problem is

Alex Porter19:05:36

ok, no worries. Thanks for the help.

Alex Porter17:05:17

failed to run function: shadow.cljs.build-report/-main
{:tag :shadow.cljs.devtools.cli/clj-run, :main-sym shadow.cljs.build-report/-main}
ExceptionInfo: failed to run function: shadow.cljs.build-report/-main
	shadow.cljs.devtools.cli/do-clj-run (cli.clj:112)
	shadow.cljs.devtools.cli/do-clj-run (cli.clj:67)
	shadow.cljs.devtools.cli/blocking-action (cli.clj:128)
	shadow.cljs.devtools.cli/blocking-action (cli.clj:118)
	shadow.cljs.devtools.cli/main (cli.clj:179)
	shadow.cljs.devtools.cli/main (cli.clj:134)
	clojure.core/apply (core.clj:669)
	clojure.core/apply (core.clj:660)
	shadow.cljs.devtools.cli/-main (cli.clj:221)
	shadow.cljs.devtools.cli/-main (cli.clj:219)
	clojure.lang.Var.invoke (Var.java:399)
	user/eval152 (form-init209812503692384868.clj:1)
	user/eval152 (form-init209812503692384868.clj:1)
	clojure.lang.Compiler.eval (Compiler.java:7177)
	clojure.lang.Compiler.eval (Compiler.java:7167)
	clojure.lang.Compiler.load (Compiler.java:7636)
	clojure.lang.Compiler.loadFile (Compiler.java:7574)
	clojure.main/load-script (main.clj:475)
	clojure.main/init-opt (main.clj:477)
	clojure.main/init-opt (main.clj:477)
	clojure.main/initialize (main.clj:508)
	clojure.main/null-opt (main.clj:542)
	clojure.main/null-opt (main.clj:539)
	clojure.main/main (main.clj:664)
	clojure.main/main (main.clj:616)
	clojure.lang.Var.applyTo (Var.java:705)
	clojure.main.main (main.java:40)
Caused by:
NullPointerException:
	com.google.debugging.sourcemap.SourceMapObjectParser.parse (SourceMapObjectParser.java:44)
	com.google.debugging.sourcemap.SourceMapConsumerV3.parse (SourceMapConsumerV3.java:68)
	com.google.javascript.jscomp.SourceMapInput.getSourceMap (SourceMapInput.java:58)
	com.google.javascript.jscomp.Compiler.addSourceMapSourceFiles (Compiler.java:2828)
	com.google.javascript.jscomp.Compiler.initBasedOnOptions (Compiler.java:553)
	com.google.javascript.jscomp.Compiler.initModules (Compiler.java:533)
	com.google.javascript.jscomp.Compiler.compileModules (Compiler.java:729)
	sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
	sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke (Method.java:498)
	clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167)
	clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102)
	shadow.build.closure/compile-js-modules (closure.clj:1008)
	shadow.build.closure/compile-js-modules (closure.clj:997)
	shadow.build.closure/optimize/fn--3682 (closure.clj:1195)
	shadow.build.closure/optimize (closure.clj:1181)
	shadow.build.closure/optimize (closure.clj:1172)
	shadow.build.api/optimize (api.clj:267)
	shadow.build.api/optimize (api.clj:261)
	shadow.build/optimize (build.clj:419)
	shadow.build/optimize (build.clj:411)
	shadow.cljs.build-report/generate/body-fn--8571--auto----9378 (build_report.clj:219)
	shadow.cljs.build-report/generate (build_report.clj:195)
	shadow.cljs.build-report/generate (build_report.clj:190)
	shadow.cljs.build-report/-main (build_report.clj:261)
	shadow.cljs.build-report/-main (build_report.clj:260)
	clojure.lang.Var.applyTo (Var.java:705)
	clojure.core/apply (core.clj:665)
	clojure.core/apply (core.clj:660)
	shadow.cljs.devtools.cli/do-clj-run/body-fn--8571--auto----9150 (cli.clj:110)
	shadow.cljs.devtools.cli/do-clj-run (cli.clj:109)
	shadow.cljs.devtools.cli/do-clj-run (cli.clj:67)
	shadow.cljs.devtools.cli/blocking-action (cli.clj:128)
	shadow.cljs.devtools.cli/blocking-action (cli.clj:118)
	shadow.cljs.devtools.cli/main (cli.clj:179)
	shadow.cljs.devtools.cli/main (cli.clj:134)
	clojure.core/apply (core.clj:669)
	clojure.core/apply (core.clj:660)
	shadow.cljs.devtools.cli/-main (cli.clj:221)
	shadow.cljs.devtools.cli/-main (cli.clj:219)
	clojure.lang.Var.invoke (Var.java:399)
	user/eval152 (form-init209812503692384868.clj:1)
	user/eval152 (form-init209812503692384868.clj:1)
	clojure.lang.Compiler.eval (Compiler.java:7177)
	clojure.lang.Compiler.eval (Compiler.java:7167)
	clojure.lang.Compiler.load (Compiler.java:7636)
	clojure.lang.Compiler.loadFile (Compiler.java:7574)
	clojure.main/load-script (main.clj:475)
	clojure.main/init-opt (main.clj:477)
	clojure.main/init-opt (main.clj:477)
	clojure.main/initialize (main.clj:508)
	clojure.main/null-opt (main.clj:542)
	clojure.main/null-opt (main.clj:539)
	clojure.main/main (main.clj:664)
	clojure.main/main (main.clj:616)
	clojure.lang.Var.applyTo (Var.java:705)
	clojure.main.main (main.java:40)

thheller18:05:07

@ajporter2011 is this for a :browser build? build-report currently has issues with other targets?

Alex Porter18:05:05

Here's my :shadow-cljs config in my project.clj

{:nrepl  {:port 8777}
                :builds {:app {:target     :browser
                               :output-dir "resources/public/js/compiled"
                               :asset-path "/js/compiled"
                               :modules    {:app {:init-fn  plcl.main/init
                                                  :preloads [devtools.preload
                                                             day8.re-frame-10x.preload]}}
                               :dev        {:compiler-options {:closure-defines
                                                               {goog.DEBUG                           true
                                                                re-frame.trace.trace-enabled?        true
                                                                day8.re-frame.tracing.trace-enabled? true}}}
                               :release    {:compiler-options
                                            {:infer-externs :auto
                                             :optimizations :advanced}
                                            :build-options
                                            {:ns-aliases
                                             {day8.re-frame.tracing day8.re-frame.tracing-stubs}}}
                               :devtools   {:http-root "resources/public"
                                            :http-port 9222}}}}

thheller18:05:07

looks fine. this only fails for the build report or does release also fail?

Alex Porter18:05:47

Only the build report

thheller18:05:47

hmm not sure

Johnson19:05:22

Hey all, wondering if someone has some advice. I want to pass an api key as a command line argument. I understand that you can use --config-merge to pass command line arguments to the shadow-cljs.edn file. My question is, how do I then use that argument in my application? Thanks in advance for your help

thheller19:05:45

what is your application? browser/node-script?

Johnson19:05:06

At the moment it’s browser

thheller19:05:40

then don't make it part of the build at all. this is runtime configuration. I really need to write the blog post about this ... 😛

thheller19:05:44

basically set it via HTML

thheller19:05:59

<script>_API_KEY = "foo";</script> or so

thheller19:05:16

then load it in your code :init-fn via js/MY_API_KEY

thheller19:05:40

or add it into your <body data-api-key="foo"> and load it from there

thheller19:05:45

lots of options

thheller19:05:02

making it part of the build would be my last choice but you can do it if you want

thheller19:05:17

look at the docs for closure-defines and set that via --config-merge

Johnson19:05:41

Ah okay, thanks for explaining the options 🙂 I was hoping to pass the api key to a docker container at runtime, using a secret in my CI pipeline, rather than having stored in the html file. Do you tend to inject it into the html file? echo >> … etc?

thheller19:05:33

anything that makes it to the client is NOT a secret

thheller19:05:32

I typically have a server that generates my HTML but if you just have a static file you can use a placeholder and replace that via some command line tool

Johnson19:05:52

Yeah, I get your point about it not being a secret when it gets to the client, I’ll have at node target as well and consider options. Thanks for your time and pointing me in the right direction 🙂 I listened to the podcast you were on with @jacek.schae, it’s an excellent tool you’ve built!

thheller20:05:01

thanks 🙂

mruzekw21:05:38

If I was using shadow-cljs for a fulcro project, and I'd like to use a local version of fulcro (to change and test some fulcro code), how would I do that? Thanks!

thheller21:05:01

easiest way is probably via deps.edn

mruzekw21:05:17

Okay, yes, I'm only using :dependencies now

mruzekw21:05:23

Would you do something like?

{:deps
 {time-lib {:local/root "/path/to/time-lib"}}}

mruzekw21:05:31

(with fulcro of course)

mruzekw21:05:32

Or maybe with an alias?

thheller21:05:33

move all your dependencies to deps.edn and configure shadow-cljs to use it. see the user-guide

mruzekw22:05:34

Kk, thanks

plexus05:05:19

Would you consider trying out chui? It works under advanced and should be a richer UI experience than cljs-test-display https://github.com/lambdaisland/chui