Fork me on GitHub
#shadow-cljs
<
2022-10-28
>
Shako Farhad00:10:15

Is it possible to import custom code from typescript files like this in shadow-cljs?

(def component (js/require "./typescript/component.tsx"))

Lone Ranger02:10:49

No, you need to compile them to JavaScript first

jaide04:10:19

Does shadow support bundling json files?

(ns my-project.my-ns
  (:require ["./assets.json" :as assets]))
or
(def assets (js/require "./assets.json"))

thheller05:10:34

not via require, but a macro

jaide06:10:18

That's fantastic. Thanks a ton!

jaide06:10:10

Having trouble getting it working though. I'm putting the code in a cljc file wrapped in a conditional as I need to target nbb and shadow-cljs

jaide06:10:59

#?(:org.babashka/nbb
   (do
     (ns crunchy.assets)
     
     (def assets (js/require "./assets.json")))
   :cljs
   (do
     (ns crunchy.assets
       (:require
         [shadow.resource :refer [inline]]))

     (def assets (inline "./assets.json"))))
       
(defn asset
  [rel-path]
  (let [actual-path (aget assets rel-path)]
    (when-not actual-path
      (throw (js/Error. (str "Could not lookup asset " rel-path))))
    actual-path))

Error:
[:app] Compiling ...
Closure compilation failed with 1 errors
--- crunchy/assets.cljc:8
Required namespace "shadow.resource" never defined.

thheller06:10:48

you cannot have do to define ns. ns must be its own top level form

thheller06:10:17

(ns crunchy.assets
  (:require
    #?@(:nbb []
        :cljs [[shadow.resource :refer [inline]]])))

(def assets
  #?(:nbb
     (js/require "./assets.json")
     :cljs
     (inline "./assets.json")))

thheller06:10:37

something like that I guess

thheller06:10:35

but note that inline just gives the the JSON string, not the object. so you'd need to parse that first

jaide07:10:58

Oh right, good catch

jaide07:10:18

That definitely works, thanks again!

J06:10:38

Hi guys! Do you have an idea how resolve this mistake:

thheller06:10:30

hmm no idea. never seen that. must be something npm related. definitely nothing from shadow-cljs.

thheller06:10:42

maybe you have a .npmrc or something setting some invalid config?

J06:10:16

You have right! There was a bad config in my npmrc.

👍 1
J06:10:12

Thanks @thheller. I will check that.

jaide06:10:10

Having trouble getting it working though. I'm putting the code in a cljc file wrapped in a conditional as I need to target nbb and shadow-cljs

juhoteperi10:10:58

https://gist.github.com/Deraen/a699de28866c117566e7d0d3f9088440 Any idea if these infer-warnings on Reagent test suite are real problems, and if there is way to clear up the warnings? All seem to be from deftype declaration, not even about calling those methods. Maybe the problem is that these "private" methods are just extending Object and they aren't declared on any protocols?

thheller15:10:20

which shadow-cljs/cljs version do you use? looks like warnings on an older version that should be fixed?

thheller15:10:14

you can also just set (set! *warn-on-infer* false) in the file to get rid of the warnings

erwinrooijakkers15:10:17

I have a shadow-cljs.edn config that moves a folder using a build-hook as follows:

:prod {:target :browser
       :output-dir "resources/public/js/compiled"
       :asset-path "/js/compiled"
       :build-hooks
       [(build/move-directory
         "node_modules/@fortawesome/fontawesome-pro/webfonts"
         "resources/public/webfonts")]
        ...}}}
and same for dev. When using shadow-cljs release prod this build hook does not seem to move the files… Should it?

erwinrooijakkers15:10:37

same hook does work for dev build via shadow-cljs compile dev

thheller15:10:46

@erwinrooijakkers why is this a build hook in the first place? wouldn't a simple cp node_modules/@fortawesome/fontawesome-pro/webfonts resources/public/webfonts solve the same problem in a much simpler way?

erwinrooijakkers17:12:19

it would. the reason it didn’t work was because the function was called copy-directory , not move. i do think it’s more logical to move this specific build step into a Makefile or so. thanks

thheller15:10:21

I can't see the implementation of your hook, I guess you are doing some dev filtering? shadow-cljs will call it for release the same way as dev

thheller15:10:46

shadow-cljs compile dev the build is called prod? which is not a recommended build separation. dev/prod should be the same build

Shako Farhad19:10:41

Is there any way to make shadow-cljs watch for file changes in a specific directory and have it call :after-load function? I tried this

:devtools {:watch-dir "public" :watch-path "/foo"}
But unfortunatly nothing happens. I have a folder with javascript files, and I am using (js/require "...") to require it in my react native project. I would like a change in the folder to trigger my :after-load function so that the changes become visible without having to reload the app.

thheller19:10:03

@shakof91 shadow only watches files relevant to the build. JS files provided by metro it doesn't watch and there is no way to make it watch that. there is also sort of no way to make it reload those unless you still have react-native hot-reload still active? which will interfere with shadow-cljs hot-reload, so kinda a tricky topic

Shako Farhad19:10:12

That is understandable. I will just activate "Fast refresh" when I am working in javascript world and disable it when I am in cljs world. This works, so not a blocker at all! 😄 Thank you for the quick answer!

Lone Ranger21:10:29

is there a way to connect the browser repl to an existing build (for use with nREPL)? stupid console.log isn't playing well with my nREPL, seeing if shadow does better for me

thheller04:10:29

I do not understand the question. yes, nrepl is supported. not a clue what you mean by console.log isn't playing with nrepl? the two are in no way related?

thheller04:10:46

npx shadow-cljs cljs-repl the-build or if you are connected to a CLJ nrepl already (shadow.cljs.devtools.api/repl :the-build)