Fork me on GitHub
#shadow-cljs
<
2023-01-05
>
Lucio Assis01:01:42

I'm using shadow.resource/inline so that I have access to the contents of a resource (a plain text file) in a browser setting. That means I had to https://github.com/luciolucio/holi/blob/99d59621d52b4a1193949143ab43dfb7cbf2adda/deps.edn#L6, i.e., it's now a runtime dependency for anyone that wants to use my library, which seems odd to me. Is this the way inline is supposed to be used?

Chris McCormick01:01:23

If you just want this one piece of functionality you could write a small macro that uses slurp like this: https://gist.github.com/noprompt/9086232

skylize03:01:25

The dependency issue should be mostly harmless. Shadow is written in JVM Clojure. and no CLJS build tool would try to stuff your whole Java dependency tree into a JavaScript bundle. The code in resource/internal does essentially the same thing as Chris McCormick's gist above, but adds logging to and lookup from a registry, to enable Shadow to cache those resources properly.

skylize03:01:07

If you wanted to remove the Shadow dep from release, while still benefiting from Shadow's caching behavior: You could add a build step for release that either swaps in your own version of the macro or fully inlines the contents of the resource files.

thheller06:01:00

@UUSQUGUF3 the point of s.r/inline is that shadow-cljs is aware of it and can trigger recompiles if the resource changes https://clojureverse.org/t/using-none-code-resources-in-cljs-builds/3745

πŸ‘ 2
thheller06:01:08

but yes otherwise just using slurp is the same

thheller06:01:22

@U028ZNM1S13 I could technically split out shadow.resource into its own separate lib but haven't done so yet. if you are worried about the extra dep you can put the code from it into one of your own namespaces and just use it that way.

Chris McCormick07:01:24

@U05224H0W every now and then I think about a PR for adding rc/inline to the Shadow user guide but then I get hung up figuring out where it would go. Maybe in "Usage" after "Running Clojure Code"?

thheller08:01:28

well as I said it would be fine as a separate lib. I just don't want to maintain 15 different one ns libs πŸ˜›

πŸ‘ 2
thheller08:01:20

probably a new "Utilities" section or so would be good

thheller08:01:30

posted those so you can at least google stuff πŸ˜›

πŸ™ 2
fabrao02:01:52

Hello all, I'm getting this error

; The result object failed to print. It is available via *1 if you want to interact with it.
; 
; The exception was: 
; 
; #error {:message "The limit of 1048576 bytes was reached while printing.", :data {:tag :shadow.remote.runtime.writer/limit-reached, :limit 1048576}}
What is it means?

wevrem02:01:24

It looks like whatever the result of the last expression evaluated, it was something rather large, too large to print.

Franklin05:01:30

Hello πŸ‘‹ I've been able to run my tests in the cljs repl before with shadow-cljs but recently(after updating to shadow-cljs version 2.20.15), I'm getting the following error when I try to call (run-tests) from the cljs.test ns. I wonder if I'm missing something

;  Execution error (TypeError) at (<cljs repl>:1).
; Cannot read properties of undefined (reading 'run_block')

Franklin06:01:07

here's how the tests I'm trying to run look like

(comment
  (deftest test-smart-search-form-fields
    (testing "If other fields list is truthy(not nil) then show dropdown"
      (re-frame-test/run-test-sync
       (js/console.log "does this work?")
       (let [other-field-temp (reagent/atom "")
             other-fields-focus (reagent/atom false)
             other-fields ["one" "two" "three" "four"]]
         (with-mounted-component
           [smart-search-form-fields other-field-temp other-fields-focus other-fields]
           (fn [_component]
             (js/console.log (.-innerText (js/document.querySelector
                                           "#smart-search-component")))))))))
  (run-tests))

thheller06:01:30

hard to say from that snippet alone. looks fine and should work. I didn't make any changes to how testing works. did you maybe upgrade shadow-cljs but not cljs or so?

jewiet14:01:21

Hello there, i have two builds. I am watching for the test and frontend build in one server. If I kill the watch that was started first, it kills the whole server.

{:dev-http {3449 "public"}
 :builds
 {:frontend
  {:target            :browser
   :output-dir        "public/js"
   :module-hash-names true
   :modules           {:main {:init-fn app.core/init}}
   :devtools          {:preloads [day8.re-frame-10x.preload]}
   :dev               {:compiler-options
                       {:closure-defines
                        {re-frame.trace.trace-enabled?        true
                         day8.re-frame.tracing.trace-enabled? true}}}}

  :test
  {:target    :node-test
   :output-to "out/node-tests.js"
   :ns-regexp "-test$"
   :autorun   true}}}
Is there a way to watch for the test and frontend build in separate servers?

dpsutton14:01:25

i suspect you should just start the server in its own process so that killing either watch doesn’t kill the server

dpsutton14:01:51

> Commands that do long-running things implicitly start a server instance (eg. watch) but it is often advisable to have a dedicated server process running.

jewiet14:01:32

Thanks a lot.

πŸ‘ 2
thheller06:01:04

yeah just npx shadow-cljs server and then you can toggle all builds via other commands or the UI at http://localhost:9630