Fork me on GitHub
#shadow-cljs
<
2022-07-13
>
borkdude08:07:27

I have an awkward macro in SCI that attempts to do the following: When the macro is used from ClojureScript, it should load the cljs.analyzer.api and populate a var, so that I can use the var in another namespace (to resolve metadata about vars in CLJS). When the macro is used from outside of ClojureScript, it's a no-op. This approach works well, but has a problem with the analysis cache of CLJS. So when I change a dependency or so and restart the compiler/watch process, it crashes, unless I remove this cache, in shadow's case, the .shadow-cljs directory. What's the story with macro calls from .cljs namespaces - are these cached somehow?

borkdude08:07:56

When I put a logging statement in the macro which runs in the JVM:

(binding [*out* *err*] (println "Requiring cljs.analyzer.api!"))
I see the output on the first invocation of shadow-cljs, but not in the second one.

thheller08:07:30

yes, there code is compiled once and then cached

thheller08:07:22

I'm unsure that this is supposed to be doing though? looks like it tries to do a dynamic require?

borkdude08:07:58

It is doing it dynamically so CLJS doesn't become a dependency of SCI

thheller08:07:55

but wouldn't it be easier to make that sci.impl.cljs entirely unconditional and make it do whatever it needs to do for CLJS

thheller08:07:04

and then just conditionally load that namespace when building for CLJS?

thheller08:07:17

or I'm missing what this is supposed to be doing?

thheller08:07:28

I mean you can exclude this ns from the cache so your described problem goes away

borkdude08:07:54

Yes, if I could change things, I might have made a separate CLJS API namespace, but this would be kind of breaking. So I'm trying to solve the problem without doing this first. Thanks for the hints!

thheller08:07:20

btw that could would be much less gnarly if it wasn't .cljc ๐Ÿ˜‰

borkdude08:07:10

I know right ๐Ÿ˜‚

borkdude08:07:42

so what I'm trying now is on the first def, I have this:

#?(:clj (def cljs-ns-publics (resolve 'cljs.analyzer.api/ns-publics)))

borkdude08:07:28

This sometimes works and also after recompilation it works. But it hasn't always worked, probably due to the order of dependency loading: SCI first or CLJS first

thheller08:07:39

thinking about .cljc makes my head hurt. why do you do it as .cljc? it really doesn't need to me as far as I can tell?

borkdude08:07:51

I agree that it would be simpler. I think I've tried that before but I ran into different issues, possibly with self-hosted or so

thheller08:07:25

> so that I can use the var in another namespace (to resolve metadata about vars in CLJS).

thheller08:07:29

which ns would that be?

borkdude08:07:37

sci.core and sci.impl.namespaces

borkdude08:07:58

Note: I want to avoid a non-top level require

borkdude08:07:13

That doesn't play well with graalvm

thheller08:07:02

ok may I make the following suggestion. create or use a namespace that everything can import. sci.impl.env or so, which just has a (def resolve nil) which you'll call whenever you need to resolve something.

thheller08:07:34

in sci.core as your first require you do a conditional so #?(:cljs [sci.impl.cljs] :cljs [sci.impl.cli])

thheller08:07:49

(thats the only place loading these namespace)

thheller08:07:10

the cljs variants is just a regular CLJS requiring cljs.anylzer and whatever else it may need

thheller08:07:22

and then (set! env/resolve cljs.analyzer.api/resolve)

thheller08:07:34

the CLJ variant does the same but via (alter-var-root! ...) or so

thheller08:07:08

(all other requires for sci.impl.cljs need to go away of course)

thheller08:07:23

by doing it first in sci.core remove all other conditionals you may otherwise have

thheller08:07:46

any by putting it in a well known var that always exists things become much cleaner no?

thheller08:07:15

CLJ code never loads the sci.impl.sci so no graalvm issues should exist?

borkdude08:07:31

the well known var that always exists is inside sci.impl.cljs , it's called cljs-ns-publics

borkdude08:07:13

That is already the ns that everyone can import - trying to understand how your approach might work better

thheller08:07:15

but it exists in CLJ?

borkdude08:07:41

because I need to inspect information about CLJS vars in the JVM

thheller08:07:24

I assume that means you need it during macro expansion? or actually at JVM runtime, meaning in the final created binary?

borkdude08:07:44

yes, during macro-expansion

thheller08:07:55

ok then you don't need it to be a var at all

thheller08:07:05

hang on, checking how you use cljs-ns-publics

borkdude08:07:30

btw, the workaround I pushed a minute ago, seems to work reliably after stopping and starting the compiler now...

thheller08:07:43

as far as I can tell my suggestion would remove a whole lot of conditional code and work in all environments. albeit being a little unclean when loading the sci.impl.cljs cljs/clj macro combi in CLJ environment

thheller08:07:02

but as far as I can tell that shouldn't happen. I mean you could even control via build config

thheller08:07:10

and consumers of sci as a lib probably never use sci.impl.* namespaces anyways right? only sci.core?

borkdude08:07:22

Exactly, impl means "internal, don't touch"

thheller08:07:43

but if your problem is solved then rewriting a bunch of stuff might not be necessary ๐Ÿ˜‰

thheller08:07:59

(as the caching problem will stay exactly the same)

borkdude08:07:04

I'll revisit this when the issue persists with your remarks in mind. Thanks a lot :)

borkdude08:07:51

If people can ensure the loading order CLJS and then SCI, then the issue won't happen anymore. But this order of loading isn't always guaranteed I think

Filipe Silva10:07:16

Is there a way to ignore :redef warnings from some namespaces? After cljs 1.11 I get a few of them on every rebuild:

[1] [:app] Build completed. (1684 files, 469 compiled, 5 warnings, 15.44s)
[1]
[1] ------ WARNING #1 - :redef -----------------------------------------------------
[1]  Resource: day8/re_frame_10x/inlined_deps/garden/v1v3v10/garden/color.cljc:390:1
[1]  abs already refers to: cljs.core/abs being replaced by: day8.re-frame-10x.inlined-deps.garden.v1v3v10.garden.color/abs
[1] --------------------------------------------------------------------------------
[1]
[1] ------ WARNING #2 - :redef -----------------------------------------------------
[1]  Resource: zprint/range.cljc:81:1
[1]  abs already refers to: cljs.core/abs being replaced by: zprint.range/abs
[1] --------------------------------------------------------------------------------
[1]
[1] ------ WARNING #3 - :redef -----------------------------------------------------
[1]  Resource: cljc/java_time/duration.cljc:33:1
[1]  abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
[1] --------------------------------------------------------------------------------
[1]
[1] ------ WARNING #4 - :redef -----------------------------------------------------
[1]  Resource: no/en/core.cljc:131:1
[1]  parse-long already refers to: cljs.core/parse-long being replaced by: no.en.core/parse-long
[1] --------------------------------------------------------------------------------
[1]
[1] ------ WARNING #5 - :redef -----------------------------------------------------
[1]  Resource: no/en/core.cljc:136:1
[1]  parse-double already refers to: cljs.core/parse-double being replaced by: no.en.core/parse-double
I get that they are a real thing and due to the new cljs fns, but I donโ€™t control these files, nor am I changing them. I know I can set :warnings {:redef false}} on compiler options, but then I donโ€™t get other real redef issues.

thheller10:07:14

I would assume that all these libs probably have new versions to address this for 1.11?

thheller10:07:41

but otherwise no there is no way to ignore these other than disabling them globally

Filipe Silva10:07:44

some might, some might not, but it only takes one of these warnings to make rebuilds very noisy, and updating them is a bit of a crapshoot (maybe new errors, maybe new api, etc)

Filipe Silva10:07:17

I think Iโ€™ll just remove the redef warning completely then

Filipe Silva10:07:23

thank you for taking a look

thheller10:07:52

but didn't I change it so warnings in files you don't control only appear once on the initial build for watch but not on recompile?

thheller10:07:01

can't actually remember ๐Ÿ˜›

Filipe Silva11:07:37

you know, thatโ€™s actually weird: two of these appear on startup, the rest appear on every reload

Filipe Silva11:07:12

they also show up differently

Filipe Silva11:07:20

startup

[1] [:renderer] Configuring build.
[1] [:app] Configuring build.
[1] [:main] Configuring build.
[1] [:main] Compiling ...
[1] [:renderer] Compiling ...
[1] [:app] Compiling ...
[1] [:main] Build completed. (86 files, 85 compiled, 0 warnings, 4.00s)
[1] WARNING: abs already refers to: #'clojure.core/abs in namespace: day8.re-frame-10x.inlined-deps.garden.v1v3v10.garden.color, being replaced by: #'day8.re-frame-10x.inlined-deps.garden.v1v3v10.garden.color/abs
[1] WARNING: abs already refers to: #'clojure.core/abs in namespace: cljc.java-time.duration, being replaced by: #'cljc.java-time.duration/abs
[1] [:renderer] Build completed. (1684 files, 1683 compiled, 0 warnings, 33.24s)
[1] [:app] Build completed. (1684 files, 1683 compiled, 0 warnings, 33.35s)
[1] [:app] Configuring build.
[1] [:renderer] Configuring build.

Filipe Silva11:07:42

then on any file save, I get the previous set of warnings

thheller11:07:37

hmm maybe something is messed up and it logs the "noisy" warnings when it shouldn't?

thheller11:07:16

I don't use libs that produce warnings so not something I would never notice myself ๐Ÿ˜›

Filipe Silva11:07:39

lemme make a repro then, should be able to isolate it

Filipe Silva11:07:19

npm install
npm start

Filipe Silva11:07:40

on startup it shows

Filipe Silva11:07:41

[email protected] ~/s/repro-shadow-cljs-warnings (master)> npm start

> [email protected] start
> shadow-cljs watch app

shadow-cljs - config: /Users/filipesilva/sandbox/repro-shadow-cljs-warnings/shadow-cljs.edn
[2022-07-13 12:39:07.507 - WARNING] TCP Port 9630 in use.
shadow-cljs - server version: 2.19.5 running at 
shadow-cljs - nREPL server started on port 58223
shadow-cljs - watching build :app
[:app] Configuring build.
[:app] Compiling ...
WARNING: abs already refers to: #'clojure.core/abs in namespace: cljc.java-time.duration, being replaced by: #'cljc.java-time.duration/abs
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 1.77s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
--------------------------------------------------------------------------------
  30 | (clojure.core/defn of-nanos {:arglists (quote (["long"]))} (^js/JSJoda.Duration [^long long14686] (js-invoke java.time.Duration "ofNanos" long14686)))
  31 | (clojure.core/defn of-millis {:arglists (quote (["long"]))} (^js/JSJoda.Duration [^long long14687] (js-invoke java.time.Duration "ofMillis" long14687)))
  32 | (clojure.core/defn negated {:arglists (quote (["java.time.Duration"]))} (^js/JSJoda.Duration [^js/JSJoda.Duration this14688] (.negated this14688)))
  33 | (clojure.core/defn abs {:arglists (quote (["java.time.Duration"]))} (^js/JSJoda.Duration [^js/JSJoda.Duration this14689] (.abs this14689)))
-------^------------------------------------------------------------------------
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
  34 | (clojure.core/defn between {:arglists (quote (["java.time.temporal.Temporal" "java.time.temporal.Temporal"]))} (^js/JSJoda.Duration [^js/JSJoda.Temporal java-time-temporal-Temporal14690 ^js/JSJoda.Temporal java-time-temporal-Temporal14691] (js-invoke java.time.Duration "between" java-time-temporal-Temporal14690 java-time-temporal-Temporal14691)))
  35 | (clojure.core/defn get-seconds {:arglists (quote (["java.time.Duration"]))} (^long [^js/JSJoda.Duration this14692] (.seconds this14692)))
  36 | (clojure.core/defn from {:arglists (quote (["java.time.temporal.TemporalAmount"]))} (^js/JSJoda.Duration [^js/JSJoda.TemporalAmount java-time-temporal-TemporalAmount14693] (js-invoke java.time.Duration "from" java-time-temporal-TemporalAmount14693)))
  37 | (clojure.core/defn minus-nanos {:arglists (quote (["java.time.Duration" "long"]))} (^js/JSJoda.Duration [^js/JSJoda.Duration this14694 ^long long14695] (.minusNanos this14694 long14695)))
--------------------------------------------------------------------------------

Filipe Silva11:07:25

if you edit src/main/app.cljs, you get the warning

Filipe Silva11:07:27

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
[:app] Compiling ...
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 0.04s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
[:app] Compiling ...
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 0.05s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
[:app] Compiling ...
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 0.05s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
[:app] Compiling ...
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 0.04s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
[:app] Compiling ...
[:app] Build completed. (163 files, 1 compiled, 1 warnings, 0.04s)

------ WARNING #1 - :redef -----------------------------------------------------
 Resource: cljc/java_time/duration.cljs:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------

thheller11:07:04

hmm well yeah that does that is should be doing I guess

thheller11:07:24

it only shows the verbose warning once, after that it is shortened and doesn't show the code excerpt

thheller11:07:47

actually unsure where WARNING: abs already refers to: #'clojure.core/abs in namespace: cljc.java-time.duration, being replaced by: #'cljc.java-time.duration/abs that is coming from

thheller11:07:51

its not shadow-cljs generating that

thheller11:07:07

oh nevermind. thats clojure

thheller11:07:53

but instead of just shortening it could maybe just not show the warnings at all

Filipe Silva11:07:30

hmm also noticed that itโ€™s slightly different on a cljc file, which is what Iโ€™m using in the real code

Filipe Silva11:07:33

gonna update it

thheller11:07:20

well in case of a CLJC file it'll also be reloading the CLJ portion. can't do much about warnings coming from there I guess

Filipe Silva11:07:59

ah no, I donโ€™t think the difference is between cljs and cljc, I think it might be due to using deps or somethingโ€ฆ I donโ€™t get the full verbose on startup on my real code

Filipe Silva11:07:06

but itโ€™s not important

roman01la13:07:20

Interesting case with error and code location reporting. If I have :warnings-as-errors true set and a custom analyzer warning that is being emitted during macro expansion time, then code excerpt in the reported warning (as error) will be pointing at macro call site (which is expected given that the warning was thrown), but instead what I want is to point the code excerpt at the location that was provided to ana/warning. Not sure if that's also the default behaviour in cljs compiler itself, but I'm curious if there's something can be done to achieve desired behaviour

thheller13:07:15

the location is derived from the metadata on the emitted form most of the time. so you can influence what the error actually says

thheller13:07:18

look for with-loc uses in that file. of course if you manually call ana/warning it comes solely from the env arg passed to it, which you can also modify prior to calling

roman01la13:07:43

that's exactly what I'm doing, passing env with desired location to ana/warning, but the thrown warning during macroexpansion still points at the macro call site rather than a form within an expression that I'm interested in

(my-macro ... (inc) ...) ;; should report at `(inc)` location

thheller13:07:35

but works correctly when emitted as a regular warning? or is also wrong then?

roman01la13:07:07

yep, works correctly as a warning. I guess ex-info on a thrown error is not picked up

thheller13:07:43

do you have a repro for that? glancing at the code it should pickup the location properly from the warning? https://github.com/thheller/shadow-cljs/blob/f66ab9bb3945b75ee06f8397d14e5787ff045574/src/main/shadow/build/compiler.clj#L486-L490

roman01la13:07:38

let me put up a quick one

thheller13:07:31

hmm just tried locally with the fragments macro. error message is the same

thheller13:07:44

------ ERROR -------------------------------------------------------------------
 File: C:\Users\thheller\code\shadow-cljs\src\main\shadow\cljs\ui\components\inspect.cljs:310:13
--------------------------------------------------------------------------------
 307 |                  (when label
 308 |                    (str " - " label)))]
 309 |            [:div.truncate
 310 |             (foo.bar)
-------------------^------------------------------------------------------------
null
Use of undeclared Var shadow.cljs.ui.components.inspect/foo
{:warning :undeclared-var, :line 310, :column 14, :msg "Use of undeclared Var shadow.cljs.ui.components.inspect/foo"}
ExceptionInfo: Use of undeclared Var shadow.cljs.ui.components.inspect/foo
	shadow.build.compiler/warning-collector (compiler.clj:493)

thheller13:07:05

but this is not calling ana/warning directly so I guess that isn't really comparable

roman01la13:07:42

not sure if the problem is the fact that I'm not passing entire env, but only location data, but that's enough for the warning to be printed correctly

roman01la13:07:16

how did you get correct location printing? I'd use it for now

thheller13:07:33

the with-loc function I linked above

roman01la13:07:48

Perhaps I misunderstood this > but this is not calling ana/warning directly so I guess that isn't really comparable

thheller13:07:12

ah well, you are trying to get metadata from a number which doesn't have metadata ๐Ÿ˜›

roman01la13:07:44

well that's fair ๐Ÿ˜„ but it doesn't work with IMeta's as well

thheller13:07:07

eh, keyword I mean

roman01la13:07:45

the actual app code that I'm testing takes location from meta in a hashmap

roman01la13:07:51

here's the same warning with and w/o :warnings-as-errors true

roman01la13:07:36

Maybe in your example with undeclared var it works fine because the erroring location matches analyzed location. In my case with the macro, analyzed location is the callsite of a macro.

thheller13:07:55

hmm yeah I can reproduce it. checking

thheller13:07:44

hmm so I guess this happens due to the cljs.analyzer macroexpansion code try/catching the error and throwing a new one with its own location data added. which it takes from the source form.

thheller13:07:41

dunno if I can get to the info easily without breaking other errors

roman01la13:07:41

I guess I can include my own excerpt into the error message then

thheller13:07:09

nah, I think I can address this

roman01la13:07:24

Cool! I wonder if cljs analyzer itself could use thing change, unless it breaks other errors

roman01la13:07:12

Are you gonna read location from the re-thrown error e? (throw (ex-info nil (error-data env :macroexpansion (var->sym mac-var)) e))

thheller13:07:41

so that could check the data if its a macroexpansion error and then get the data from the (.getCause e) instead

thheller13:07:52

but I'm unsure that this will always be correct. meaning pointing to the correct location if it has line/column.

thheller14:07:28

there might be cases where that location is actually worse than showing the location of the macro

roman01la14:07:59

do you have an example?

thheller14:07:27

no, just thinking about it

roman01la14:07:12

I'll have to patch shadow on my side to have meaningful error messages in the meantime, but that's a good point.

thheller14:07:13

I mean this only happens because of :warnings-as-errors so it is isolated to shadow-cljs. so I guess I could add a marker of sorts

๐Ÿ‘ 1
thheller14:07:57

needs some more testing before I make a release but seems to be ok for your repro

๐Ÿ™ 1
thheller14:07:36

(although modified your repro since keywords can't take meta and won't have location data)

๐Ÿ‘ 1
roman01la14:07:48

On that note: I think shadow's ERROR reporting browser UI could use more love, the warning reporting screen is much easier to read because of formatting (bold text, marings, etc)

thheller15:07:30

yeah but its a lot of work since errors are captured as text for the terminal. wiring the whole error reporting again to capture html is meh

roman01la15:07:15

I just made it nice looking with a bunch of regexes ๐Ÿ˜„

thheller15:07:49

hehe I guess that works too ๐Ÿ˜›

roman01la11:07:36

@U05224H0W Just noticed that code location pointing is also wrong for "undeclared var" warnings with :warnings-as-errors true

thheller11:07:30

hmm, probably the exception being wrapped multiple times. feel free to open issue, can't look into it currently

๐Ÿ‘ 1
richiardiandrea17:07:16

Hi there, I am trying to get a runtime against wrangler (Cloudflare worker) up However, when I start it I get:

[mf:err] Error: Failed to construct 'WebSocket': the constructor is not implemented.
    at Object.construct (/home/cokap/git/arudik-website/cloudflare-workers/backblaze-download-token-to-secrets/node_modules/@miniflare/web-sockets/src/plugin.ts:37:19)
    at shadow$cljs$devtools$client$websocket$start (/home/cokap/git/arudik-website/cloudflare-workers/.cljs/cljs-runtime/shadow/cljs/devtools/client/websocket.cljs:12:16)
    at shadow.cljs.devtools.client.shared.Runtime.attempt_connect_BANG_ (/home/cokap/git/arudik-website/cloudflare-workers/.cljs/cljs-runtime/shadow/cljs/devtools/client/shared.cljs:324:25)
    at Object.shadow$cljs$devtools$client$shared$init_runtime_BANG_ [as init_runtime_BANG_] (/home/cokap/git/arudik-website/cloudflare-workers/.cljs/cljs-runtime/shadow/cljs/devtools/client/shared.cljs:509:24)
    at ../.cljs/cljs-runtime/shadow.cljs.devtools.client.browser.js (/home/cokap/git/arudik-website/cloudflare-workers/.cljs/cljs-runtime/shadow/cljs/devtools/client/browser.cljs:337:3)
Is there a way to avoid compiling the browser dev tools in a module?

richiardiandrea17:07:07

import "./cljs-runtime/shadow.cljs.devtools.client.browser.js";
SHADOW_ENV.setLoaded("shadow.cljs.devtools.client.browser.js");
If I remove the two lines up it seems to work

thheller17:07:58

:devtools {:enabled false} in the build config

richiardiandrea17:07:46

@U05224H0W oh thanks you, will try that out

richiardiandrea17:07:20

I am experimenting with the new js-await macro I did this

(ns cloudflare.workers
  (:require [shadow.cljs.modern :refer (js-await)]))

(defn backblaze-download-token-to-secrets
  [controller env ctx]
  (js-await [result (js/Promise.resolve #js {"foo" "bar"})]
   (js/console.log "environment" env)
   #js {:response "response"}))
but I don't see any compiled file...the module contains only
import "./cljs_env.js";

thheller17:07:12

hmm? what does one have to do with the other?

thheller17:07:26

what is your build config? which file did you look at?

richiardiandrea17:07:55

{:target :esm
            :output-to "target/cloudflare-workers.js"
            :output-dir ".cljs"
            :modules {:backblaze-download-token-to-secrets
                      {:exports {default cloudflare.workers/backblaze-download-token-to-secrets}}}
            :compiler-options {:output-feature-set :es-next}
            :js-options {:entry-keys ["module" "browser" "main"]}
            :devtools {:enabled false}
            :release {:compiler-options {:source-map true}}}

richiardiandrea17:07:33

I am looking at both this two guys

$ cat .cljs/cljs-runtime/shadow.module.backblaze-download-token-to-secrets.
shadow.module.backblaze-download-token-to-secrets.append.js
shadow.module.backblaze-download-token-to-secrets.prepend.js

thheller17:07:50

thats not the correct file to be looking at

thheller17:07:03

.cljs/cljs-runtime/cloudflare.workers.js will have the source from cloudflare.workers ns

richiardiandrea17:07:51

yeah that contains the right code..sorry for the newbie question, but would that match the expected format here? https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/#syntax-module-worker ?

richiardiandrea17:07:45

basically I am not sure I am producing the expected async scheduled function

thheller17:07:14

which part? I mean your code is doing something else entirely?

thheller17:07:28

the export default would be correct yes

richiardiandrea17:07:08

well yeah, I am trying stuff ๐Ÿ˜„ basically I need to export this

export default {
  async scheduled(event, env, ctx) {

  },
};
an export list with scheduled in it

thheller17:07:48

hehe I'm blind. didn't even see the extra object

๐Ÿ˜„ 1
thheller17:07:44

(def thing
  #js {:scheduled
       (fn [event env ctx]
         ...)})

richiardiandrea17:07:47

oh I think I just saw how to do that sorry

(def exports #js {:g f
                  ...})

thheller17:07:55

thing being the thing referenced in the build config

richiardiandrea17:07:58

thank you Thomas

thheller18:07:29

does that runtime just accept the watch output as is or do only release builds work?

richiardiandrea18:07:16

I am still trying to get the watch - haven't tried release yet

richiardiandrea18:07:56

but I might cause I get this error now

[mf:err] TypeError: Cannot read properties of undefined (reading 'module_loaded')
    at /home/cokap/git/arudik-website/cloudflare-workers/.cljs/backblaze-download-token-to-secrets.js:92:33
as shadow.cljs.devtools.client.env is undefined

richiardiandrea18:07:50

trying :console-support false`

thheller18:07:55

try a release build

thheller18:07:12

:console-support has nothing to do with the module stuff

๐Ÿ‘ 1
thheller18:07:30

I'm guessing that it doesn't actually support the globalThis hacks the watch/compile builds do

thheller18:07:38

release might work though

richiardiandrea18:07:46

oki, trying that as we speak

richiardiandrea18:07:28

seems good apart from one little warning

npx wrangler dev --local
 โ›…๏ธ wrangler 2.0.17 (update available 2.0.19)
-------------------------------------------------------
Your worker has access to the following bindings:
- Vars:
  - B2_APPLICATION_KEY_ID: "foo"
  - B2_APPLICATION_KEY: "bar"
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit         โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ–ฒ [WARNING] Source maps with "sections" are not supported [sections-in-source-map]

    ../.cljs/backblaze-download-token-to-secrets.js.map:1:61:
โŽ” Starting a local server...
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit         โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
[mf:inf] Worker reloaded! (0.54KiB)
[mf:inf] Listening on localhost:43843
[mf:inf] - 
[mf:inf] Updated `` object cache!
SCHD /cdn-cgi/mf/scheduled 200 OK (0.75ms)

thheller18:07:48

pff who doesn't support sections these days

thheller18:07:59

all browsers do so they should too ๐Ÿ˜‰

richiardiandrea18:07:59

it is weird though, I am calling the code but nothing is printed out, I will debug further

richiardiandrea18:07:40

@U05224H0W can I watch a release configuration?

thheller18:07:24

no

๐Ÿ‘ 1
richiardiandrea21:07:46

Sorry to come back on this, but is shadow.cljs.devtools.client.env/ globalThis an issue can be solved with an additional bundler? Working against the release code is a bit slow (7s every run before I can try new code)

richiardiandrea21:07:06

if I comment out // shadow.cljs.devtools.client.env.module_loaded("backblaze-download-token-to-secrets"); Things seem to work - having a REPL is nice maybe I'll just go with that ๐Ÿ˜„

richiardiandrea21:07:31

Well ok, the JS runtime also needs to be hooked up here and I see ๐Ÿ‰s there as well

richiardiandrea21:07:54

Ok I guess I read this document and now at least I know more about the problem(s) https://github.com/thheller/shadow-cljs/blob/master/doc/esm.md

thheller05:07:49

well as always. I cannot comment much without seeing actual code and actual errors. slack descriptions do not have enough information to make accurate guesses

thheller05:07:13

I would assume watch is possible, but I'm unsure about what the actual issue is

thheller05:07:26

shadow.cljs.devtools.client.env.module_loaded("backblaze-download-token-to-secrets"); should be find and I'm unsure why it wouldn't be

thheller05:07:48

feel free to setup a repro and I can probably tell you more

โค๏ธ 1
richiardiandrea16:07:49

ok I'll create a repo with some code

richiardiandrea16:07:29

@U05224H0W here it is, I hope things are going to work there, let me know if you find any issue https://github.com/arichiardi/cloudflare-workers

richiardiandrea16:07:30

it's working with a bundler now and it all seems good, I could go for one module per worker and get rid of main.js but I am in the middle of something else now

thheller18:07:37

I guess I'm missing what I'm supposed to do once wrangler is running?

thheller18:07:51

after adjusting your config to eliminate all the esbuild etc stuff

thheller18:07:01

I can run wrangler dev --local

thheller18:07:26

backblaze-download-token-to-secrets$ wrangler dev --local
 :partly_sunny:๏ธ wrangler 2.0.21
--------------------
Your worker has access to the following bindings:
- Vars:
  - B2_APPLICATION_KEY_ID: "foo"
  - B2_APPLICATION_KEY: "bar"
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit                                                                                                                           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
โ–ฒ [WARNING] Using direct eval with a bundler is not recommended and may cause problems [direct-eval]

    out/cljs-runtime/cljs.core.js:37984:63:
      37984 โ”‚ return cljs.core.find_ns_obj_STAR_((function (){try{var ctxt = eval(cljs.core.first(segs));
            โ•ต                                                                ~~~~
โŽ” Starting a local server...
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [l] turn off local mode, [c] clear console, [x] to exit                                                                                                                           โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Debugger listening on 
For help, see: 
Debugger attached.
[mf:inf] Worker reloaded! (2.40MiB)
[mf:wrn] Worker's uncompressed size exceeds the 1MiB limit! Note that your worker will be compressed during upload so you may still be able to deploy it.
[mf:inf] Listening on localhost:8787

thheller18:07:38

so so me this looks like its working but no clue whats next

thheller18:07:24

I mean is supposed to show something? all I get is a white page?

thheller18:07:55

(ns cloudflare.workers
  (:require [cloudflare.workers.backblaze :as backblaze]))

(def exports
  #js {:fetch (fn [request]
                (js/Promise.resolve (js/Response. "Hello World.")))
       :scheduled backblaze/upload-download-token-to-secrets})

thheller18:07:10

I get the expected Hello World. on http://localhost:8787/

thheller18:07:29

dunno why you are doing all the esbuild stuff. I'm not gonna look at that

thheller18:07:59

;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 []

 :builds
 {:workers {:target :esm
            :output-dir "backblaze-download-token-to-secrets/out"
            :modules {:main
                      {:preloads [shadow.cljs.devtools.client.env]
                       :exports {default cloudflare.workers/exports}}}
            :compiler-options {:output-feature-set :es-next}
            :js-options {:entry-keys ["main" "module"]}
            :devtools {:enabled false}
            :release {:compiler-options {:source-map true}}}}}

thheller18:07:18

thats the build config. I guess the :preloads is needed because of a bug

thheller18:07:36

(which would be the module_loaded being emitted when it shouldn't be, due to :enabled false)

thheller18:07:33

watch and release both work just fine then

richiardiandrea19:07:51

Ok cool, don't worry about the esbuild stuff, it was there because I was fiddling with cljs.main as well

richiardiandrea19:07:19

I think what I was missing was the :preloads then

thheller19:07:47

well thats not required if you have :runtime :node but effectively that also does nothing

thheller19:07:57

it just happens to include the env namespace but nothing else

thheller19:07:17

REPL however I didn't get working

๐Ÿ‘ 1
richiardiandrea19:07:21

Ok I am fine with watch only for now, thanks for your help, if you want me to try any build to get the REPL working I can also definitely do that

richiardiandrea19:07:02

with cljs.main too there was no way to get the REPL running and I was only getting watch working with -O advanced

thheller19:07:06

I have the wrangler thing working. just too tired to dive deeper into the REPL support now

thheller19:07:35

but the wrangler command also always seems to restart everything when you make a change

thheller19:07:44

so REPL doesn't really seem necessary or useful

thheller19:07:07

I mean could always just run a browser-repl or node-repl I guess

richiardiandrea19:07:11

> I have the wrangler thing working. just too tired to dive deeper into the REPL support now Of course no worries > I mean could always just run a browser-repl or node-repl I guess right, that probably would suffice, I'll try to see if it "sees" the wrangler runtime, probably now that will work

thheller19:07:01

who sees what?

richiardiandrea19:07:27

ah I see what you mean now, the node-repl would not need wrangler at all

richiardiandrea19:07:47

(sorry it's been a while since I last used shadow-cljs)

NickName19:07:42

When I quit from npx shadow-cljs browser-repl, I get this really long error report:

Failed to read: java.io.IOException: Input/output error
cljs.user=> Failed to read: java.io.IOException: Input/output error
cljs.user=> Failed to read: java.io.IOException: Input/output error
cljs.user=> Failed to read: java.io.IOException: Input/output error
โ€ฆ
cljs.user=> Failed to read: java.io.IOException: Input/output error
cljs.user=> Failed to read: java.io.IOException: Input/output error
cljs.user=> Worker shutdown.
I'm wondering if there is something wrong with my setup. Or is it possible to disable this output? It is not critical, just annoying that terminal gets spammed with 50+ lines.

thheller07:07:04

how did you quit it? which OS is this? which shadow-cljs version? which java version? I've never seen this so dunno what would be causing it

NickName12:07:24

Sorry for not providing all the info from the beginning. > how did you quit it? Ctrl + C > which OS is this? macOS Big Sur 11.6.1 > which shadow-cljs version? 2.19.6 > which java version? openjdk 17.0.1 2021-10-19 OpenJDK Runtime Environment (build 17.0.1+12-39) OpenJDK 64-Bit Server VM (build 17.0.1+12-39, mixed mode, sharing)

thheller16:07:02

hmm yeah dunno. I dont have a mac available with that version. versions all seem fine. I have no guesses as to what that may be

thheller16:07:11

does it also happen if you exit with CTRL+D?

NickName19:07:48

It doesn't happend with CTRL+D, though CTRL+D in itself works somewhat strange โ€” I have to press them a few times to exit (no reaction on single pressing)

NickName19:07:19

Another thing I noticed โ€” this behavior is only produced when I start shadow server from scratch i.e. when there is no running server at the time I do shadow-cljs watch โ€ฆ In such a case it is not so annoying as I think Iโ€™m going to keep the server always on.