Fork me on GitHub
#shadow-cljs
<
2024-01-19
>
borkdude11:01:52

With target esm + node I'm getting this:

The required JS dependency "fs" is not available, it was required by "squint/embed.cljs".

Dependency Trace:
	squint/embed.cljs

Searched for npm packages in:
	/Users/borkdude/dev/squint/examples/cljs-embed/node_modules
fs is part of the node-libs-browser polyfill package to provide node-native package support
for none-node builds. You should install shadow-cljs in your project to provide that dependency.

	npm install --save-dev shadow-cljs

See: 
I already installed the shadow-cljs package and restarted, but it keeps coming up, what to do?
thheller/shadow-cljs {:mvn/version "2.26.5"}

thheller11:01:15

:js-options {:js-provider :import} controls how JS packages are bundled, or in case of :import not bundled and just imported at runtime

thheller11:01:25

or alternative :keep-as-import #{"fs"} to only import fs at runtime, but bundle others

borkdude11:01:41

thanks, the latter is what I need

borkdude11:01:04

no, this is not about the squint lib itself, it's an example project in which squint is used in a shadow project

borkdude11:01:22

where do I put that keep-as-import again? this didn't have any effect:

{:deps {:aliases [:shadow]}
 :builds
 {:squint.embed
  {:target :esm
   :keep-as-import #{"fs"}
   :runtime :node
   :output-dir "out"
   :modules {:eval {:init-fn squint.embed/init}}
   :build-hooks [(shadow.cljs.build-report/hook
                  {:output-to "report.html"})]}}}
also I don't see it mentioned in the manual

thheller11:01:32

:js-options

borkdude11:01:56

this did the trick, thanks!

thheller11:01:58

but if you are targetting node anyways I'd just use :js-provider :import

borkdude11:01:17

yeah maybe, I do think in this case, squint itself should be bundled

borkdude11:01:27

but that could be done by some JS tool as well probably

p-himik19:01:05

Just made my head a bit more barren by trying to understand what was going on. The original code from mousetrap:

(function(window, document, undefined) {
  [...]
  var _MAP = { ... };
  [...]
  for (var i = 1; i < 20; ++i) {
      _MAP[111 + i] = 'f' + i;
  }
  [...]
})(typeof window !== 'undefined' ? window : null, typeof  window !== 'undefined' ? document : null)
The corresponding code that the browser gets from module$node_modules$mousetrap$mousetrap.js:
(function(window, document, undefined) {
  [...]
  var _MAP = { ... };
  [...]
  for (undefined = 1; 0; ++undefined)
      _MAP[NaN] = "fundefined";
  [...]
})(typeof window !== 'undefined' ? window : null, typeof  window !== 'undefined' ? document : null)

thheller20:01:09

the fuck kinda code uses undefined as a variable name 😛

thheller20:01:38

I suspect that confuses the closure compiler. no clue though, so my only guess

p-himik20:01:25

Right. But it doesn't provide the "listen for this particular key press" functionality and seems to be mostly dealing with the quirks of ancient browsers or some very specific keys on Mac.

thheller20:01:50

I used it for the keyboard control in the shadow-cljs UI

thheller20:01:59

I hooked it up to emit the regular event style maps, so a handler for example can use a keyword for a specific key combo

p-himik20:01:55

On the one hand, I really don't want to write all the necessary cruft so support stuff like "on Win/Linux Meta is Meta and Alt is Alt and undo is Ctrl+Z but on Mac, Command is Meta and Option is Alt and undo is Command+Z". On the other hand, I really don't want to study and introduce a new library that has a high chance of dealing with something in a crappy way (Mousetrap hasn't been maintained for years, and there are multiple issues). Damn programmers, they ruined programming. :D

thheller20:01:42

keep it simple I'd say 😉

p-himik20:01:28

I wish I could. But on top of proper cross-platform shortcuts, they also need to be assignable.

thheller20:01:26

I mean this is a tiny amount of code to get this event hookup thing I have in the UI

thheller20:01:41

I'm sure you can build something for your use case in about the same amount of code

thheller20:01:05

most of the complicated stuff is taken care of by KeyHandler

p-himik21:01:09

Maybe. But the amount of code that they have there, and how seemingly 90% of it is useless in modern browsers makes it daunting. Do you see anything wrong with this code BTW? Tried just js/document, but same thing - nothing's printed.

(let [listener (KeyHandler. (.-body js/document))]
  (.listen listener "keydown" (fn [evt]
                                (js/console.log "keydown" evt)))
  (.listen listener "keypress" (fn [evt]
                                 (js/console.log "keypress" evt)))
  (.listen listener "keyup" (fn [evt]
                              (js/console.log "keyup" evt))))

thheller21:01:21

the event is "key", no clue if any others are emitted or supported

p-himik21:01:22

Oh, that's bloody terrible for me then. :D I need to support shortcuts like Ctrl+Shift. Which can also be pressed as Shift+Ctrl. Which must not be confused by the app with e.g. Ctrl+Shift+x.

p-himik17:01:33

It seems that if I rely only on KeyboarEvent.code, I don't have to deal with any crap that pretty much all of the hotkeys libraries that I've seen are designed to deal with. So it all becomes much simpler. However, there's still that bullshit of "if e.g. Space is registered as a hotkey for action X, but the focus is in an input element that supports Space, the event should be handled by that input element". Doesn't seem like there's a proper and easy way around it.

thheller18:01:30

I usually handle it like this

thheller18:01:54

so it ignores the event when inside codemirror

thheller18:01:23

so its keybinds just work as normal. pretty simple to express it that way I think

p-himik18:01:52

Yeah, similarly I'm checking for the type of .-target and naively deciding whether a particular key combination is handled by the input. So e.g. if <input type="text> is in focus, pressing Space will emit a space character but pressing Ctrl+Space will check whether there's such a global binding.

thheller18:01:24

IIRC you shouldn't use .code though

thheller18:01:15

can't remember which one you are supposed to use, but one of them didn't respect keyboard layouts or remaps

thheller18:01:38

I have caps lock rebound to ctrl, and I think .code would still give you capslock

thheller18:01:52

and respecting chinese and other weird language that use code sequences for one character

thheller18:01:02

keyboards are really weird

p-himik18:01:11

What does "rebound" mean exactly? I have F14 on my Apple keyboard mapped to ScrollLock in the kernel module - that emits ScrollLock just fine.

p-himik18:01:08

> For example, the code returned is "`KeyQ`" for the Q key on a QWERTY layout keyboard, but the same code value also represents the ' key on Dvorak keyboards and the A key on AZERTY keyboards. Mm, OK. But shouldn't matter that much since truly special logic is only reserved for modifiers, and those are determined based on .-key. And I plan to make all of the predefined bindings adjustable, so since setting and using a keybinding will be done with the same keyboard and the same layout (presumably), I should be good.

p-himik18:01:22

There is one non-trivial problem where pressing Alt+Shift in Ubuntu generates exactly what you'd expect, but pressing Shift+Alt results in "keydown Shift, keydown Meta, [...keyups...]". But eh, I'll deal with it if anybody complains.

fabrao20:01:15

Hello all, I updated the version from 2.15.3 to 2.26.5 and this started to fail, executed with npx shadow-cljs run dev.build/build-release-static. I tested with version 2.22.2 and it works. Is there something that changed?

failed to run function: dev.build/build-release-static
{:tag :shadow.cljs.devtools.cli-actual/clj-run, :main-sym dev.build/build-release-static}
ExceptionInfo: failed to run function: dev.build/build-release-static
        shadow.cljs.devtools.cli-actual/do-clj-run (cli_actual.clj:110)
        shadow.cljs.devtools.cli-actual/do-clj-run (cli_actual.clj:65)
        shadow.cljs.devtools.cli-actual/blocking-action (cli_actual.clj:126)
        shadow.cljs.devtools.cli-actual/blocking-action (cli_actual.clj:116)
        shadow.cljs.devtools.cli-actual/main (cli_actual.clj:177)
        shadow.cljs.devtools.cli-actual/main (cli_actual.clj:132)
        clojure.core/apply (core.clj:671)
        clojure.core/apply (core.clj:662)
        shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:219)
        shadow.cljs.devtools.cli-actual/-main (cli_actual.clj:217)
        clojure.lang.Var.applyTo (Var.java:705)
        clojure.core/apply (core.clj:667)
        clojure.core/apply (core.clj:662)
        shadow.cljs.devtools.cli/-main (cli.clj:75)
        shadow.cljs.devtools.cli/-main (cli.clj:67)
        clojure.lang.Var.applyTo (Var.java:705)
        clojure.core/apply (core.clj:667)
        clojure.main/main-opt (main.clj:514)
        clojure.main/main-opt (main.clj:510)
        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:
Exception: No files matched regex /js/compiled/.*\.js\.map
        optimus.assets.creation/realize-regex-paths (creation.clj:106)
        optimus.assets.creation/realize-regex-paths (creation.clj:98)
        optimus.assets.creation/load-assets/fn--6324 (creation.clj:112)

thheller20:01:43

the code seems to be failing in your code, so you tell you what you are doing there and I tell you what might have changed 😛

thheller20:01:20

I mean thats a lot of versions inbetween, so there are likely things that have changed

thheller20:01:31

(I'm assuming here optimus is your code. I have no idea what that is)

thheller20:01:41

it is not code from shadow-cljs

thheller20:01:29

could also be that you turned off source maps? and it is expecting to find some? no clue really

fabrao20:01:23

I'll tell you it was working before 😅 . I'll will investigate it. But the basic is

(clean-compiled-resources)
  (export-image-assets-and-replace-paths)
  (export-deeplinking-assets)
  (shadow/release environment {:verbose true})
  (compile-sass)
  (export-assets)
But it seems that is not creating the /js/compiled/.*\.js\.map

fabrao20:01:16

:compiler-options  {:optimizations                      :advanced
                                   :source-map                         true
                                   :source-map-include-sources-content true}

thheller20:01:00

which :target is the build using?

thheller20:01:50

I mean /js/compiled doesn't look like a valid output-dir to me? unless you are actually putting them at your fs root?

thheller20:01:11

so many questions ...

thheller20:01:31

source map emission has not changed, well that is unless they are empty. in that case there are no longer generated

fabrao20:01:58

I'm checking with version 2.22.2

thheller20:01:12

so maybe try 2.26.2 to see if it still works

thheller20:01:27

or you know look at what that optimus code is doing and go from there

thheller20:01:39

much faster than me guessing randomly

fabrao21:01:07

yes, so what is your advice about the map?

thheller21:01:40

there is no advice to give. I don't know what the problem is this tool I don't know has.

thheller21:01:50

I don't know enough about what you are building

thheller21:01:53

I know basically nothing

thheller21:01:17

files that have actual JS code in them still have source maps

thheller21:01:25

so their functionality has not changed in any way

thheller21:01:59

and this mostly only affected :target :npm-module, so is you build using that

thheller21:01:08

or is you build generating empty output files in the first place

thheller21:01:41

look at what your :output-dir looks like, I don't have enough information to provide any tips

fabrao21:01:47

well, I'm using the :modules to split into many .js

thheller21:01:11

that is fine. if one of them very tiny or empty?

thheller21:01:18

you know less than 100 bytes?

fabrao21:01:18

no, higher than 100 bytes

thheller21:01:31

I'm still on the vague guess that this is related to this change at all

thheller21:01:40

so, instead dig into optimus

thheller21:01:03

this is not code shadow-cljs uses or provides, so I'm completely in the dark

fabrao21:01:44

great thank your help effort, I'll investigate it.

fabrao21:01:59

to give more details

thheller21:01:37

I mean are the .map files in the :output-dir or not?

thheller21:01:50

totally possible that the change had unintended consequences

fabrao21:01:28

I couldn't see even the compiled files over there

fabrao21:01:03

so, no .map into output

thheller21:01:54

so the build fails?

fabrao21:01:13

fails in that part

thheller21:01:19

I see you are using (shadow/release environment {:verbose true}) which will not throw an exception if it fails

fabrao21:01:24

Caused by:
Exception: No files matched regex /js/compiled/.*\.js\.map

thheller21:01:28

you likely want to use release! instead

thheller21:01:59

that error is not a message from shadow-cljs. and not related to a shadow-cljs build failure at all. it just happens to run after shadow-cljs completes or maybe fails in this case

thheller21:01:24

just run npx shadow-cljs release your-build without all this additional stuff

thheller21:01:37

and see if it completes properly or not

fabrao21:01:09

yes, but I reached here because I couldn't see the compiled *.js

thheller21:01:22

yes, then run the above command and tell me why

thheller21:01:48

all your additional extra stuff I cannot comment on or help with

thheller21:01:20

with actual shadow-cljs stuff I can help. I suspect now that the build is just failing and your setup not correctly identifying it and trying to continue as if everything was fine

fabrao21:01:49

I think I got the error:

switch (a) {
            case V.types.logCustomEvent:
              import("./log-custom-event.js").then(
                ({ logCustomEvent: logCustomEvent }) => {
                  e.so()
                    ? ((i = Array.prototype.slice.call(s)),
                      logCustomEvent(...i))
                    : r.error(_);
                },
              );
Dynamic import expressions cannot be transpiled.

thheller21:01:47

ok. that is an error from the closure compiler and it never actually worked. could be that it was just ignored before.

fabrao21:01:54

now is it not?

thheller21:01:03

yes. this is not something shadow-cljs can do anything about. it is entirely within the closure compiler.

thheller21:01:05

if you need code like this then you can use a different JS bundler via https://shadow-cljs.github.io/docs/UsersGuide.html#js-provider-external

thheller21:01:46

I don't know what this code is and if it was ever actually used or if you can avoid it

fabrao21:01:04

this was cause by introducing a new npm package

thheller21:01:20

then remove it 😉

fabrao21:01:45

😅 if I could

fabrao21:01:46

dammit 😱

thheller21:01:01

which npm package is this?

fabrao14:01:56

So, @U05224H0W I'll try to use js-provider-external, but what about the problem with module split? I have 5 splitting modules.

fabrao14:01:26

is there a problem with it? Using with webpack.

thheller14:01:44

depends. CLJS modules is fine and doesn't change. however the JS code will all end up in that single external file, which may not be ideal. https://github.com/thheller/shadow-cljs/issues/1162

fabrao14:01:15

you mean, at the end, all split files will be joint to a single .js ?

thheller15:01:32

:external creates an :external-index file which you process with webpack

thheller15:01:56

the file it generates contains ALL JS dependencies

thheller15:01:05

the CLJS output is still just the 5 modules you configured

thheller15:01:15

so you have a total of 6 .js files

fabrao15:01:28

oh ok, understood

thheller13:01:20

note that I just added support for this style of import that JS package is trying to do

thheller13:01:00

so if you try 2.26.6 it may just work, couldn't try the actual package since I didn't find it. https://www.npmjs.com/package/braze didn't seem to be it

fabrao13:01:19

oh great !!!

fabrao13:01:48

but should I run it normally?

thheller13:01:03

yes, as before

fabrao13:01:20

I'd appreciate your effort

fabrao13:01:33

and the Closure error compiler gone too?

thheller14:01:02

I don't know if the error is gone. It might be. I didn't try the package but the problematic snippet you posted above should now be fine and not produce an error

thheller14:01:46

just tried the package. doesn't work. I mean it compiles fine now, but produces a runtime error

thheller15:01:00

I'm guessing some kind of other code pattern the closure compiler doesn't like

thheller15:01:06

no time to look into that one now

fabrao15:01:08

Yes, I got this error too:

thheller15:01:33

yeah that one

fabrao22:01:30

Hello, do you think is it worth to work with that fixes?