Fork me on GitHub
#clojurescript
<
2021-09-03
>
qv11103:09:29

how do I run clojurescript tests with clj? I have tests set up but dont understand how to run them

Steve Pegoraro04:09:29

Hi all, what is the preferred way of working with CLJS and node.js? I’m currently using shadow-cljs and CIDER, I select shadow and node-repl when prompted which gives me a working REPL. However I encounter this issue: • I create some namespace that has an error in it (e.g. I forgot to require a var from another namespace) • Then I try to require it from the REPL • It correctly notifies me of my mistake: WARNING - :undeclared-var • I then go and fix the error and save the source file • I try to require it again but the warning appears again • This happens no matter what I do to the original source file until I restart the REPL

Steve Pegoraro04:09:26

Is there some caching happening that I’m not aware of maybe?

thheller05:09:20

looks like a bug. feel free to open an issue, can't investigate more right now

kirill.salykin09:09:20

Hi, is there a way speed up cljs compilation on ci by reusing some caches from prev compilation? if so - which folders i need to reuse?

kirill.salykin09:09:41

or to be more precise - what is path for the :aot-cache ?

p-himik09:09:36

Can't say for the vanilla compiler, but shadow-cljs uses .shadow-cljs dir within the project. Regarding :aot-cache - this function from cljs.analyzer seems relevant:

(defn ^File cache-base-path
     ([path]
      (cache-base-path path nil))
     ([path opts]
      (io/file (System/getProperty "user.home")
        ".cljs" ".aot_cache" (util/clojurescript-version)
        (build-affecting-options-sha path opts))))

kirill.salykin10:09:04

thank you so much! so ~/.cljs/aot_cache , roger regarding the .shadow-cljs - is it safe to reuse/share it?

p-himik10:09:21

No clue. I'm trying to reuse it across Heroku dyno builds and I think it works.

p-himik10:09:13

Also, not ~/.cljs/aot_cache but ~/.cljs/.aot_cache - notice the extra dot.

kirill.salykin11:09:57

thanks too bad it is in the home dir, gitlab ci doesnt like it

p-himik11:09:26

You should be able to override the user.home property. But it might affect other things.

p-himik11:09:03

Although if your CI doesn't like ~ in general, then it's probably fine to override that property.

kirill.salykin11:09:46

I’ll try first to cache .shadow-cljs

kirill.salykin12:09:49

caching .shadow-cljs removed about 1 minute for me thank you!

👍 2
zendevil.eth11:09:14

I have the following inside let […]:

contract-deploy
          (.. contract
              (deploy (clj->js 
                         {:arguments [ipfs 
                                      (:percentage db) 
                                      (:min-to-raise db)
                                      (:bid-start db) 
                                      (:bid-end db) 
                                      (:payments-start db)
                                      (:payments-end db)
                                      (:payments-interval db)]
                          :data (.-bytecode (js/JSON.parse resp))})))
_
(.. contract-deploy
              (send (clj->js {:from ego}) 
                    (fn [err tx-hash] 
                      (prn "err is " err
                           "tx hash is " tx-hash))))
coverted from the following js from web3 docs:
myContract.deploy({
    data: '0x12345...',
    arguments: [123, 'My String']
})
.send({
    from: '0x1234567890123456789012345678901234567891',
    gas: 1500000,
    gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
but I’m getting this error for the second expression
Uncaught TypeError: Cannot read property 'length' of null
    at require.formatParam (index.js:224)
    at eval (index.js:100)
    at Array.map (<anonymous>)
    at require.encodeParameters (index.js:94)
    at eval (index.js:439)
    at Array.map (<anonymous>)
    at Object.global._encodeMethodABI (index.js:438)
    at Object.global._processExecuteArguments (index.js:701)
    at Object.global._executeMethod (index.js:720)
    at switch__60994__auto__ (events.cljs:157)

p-himik12:09:38

Is your environment browser or Node?

p-himik12:09:27

Then just enable breaking on every exception and debug it.

zendevil.eth12:09:04

the js land code makes no sense in relation to the cljs world

p-himik12:09:35

You mean the existing JS code or the JS code into which your CLJS was compiled?

zendevil.eth12:09:00

the js code that’s throwing the exception. It’s the code from the web3js library

zendevil.eth12:09:22

called from cljs

p-himik12:09:44

Well, that's something you have to learn to deal with then. But something that's passed into encodeParameters is not right. Might be your :data above is wrong.

tianshu13:09:51

Hi, how can I call a javascript function with varargs in ClojureScript, like:

Uint8Array.of(1, ...data)

tianshu13:09:32

I know in Clojure, I can pass last argument as array.

p-himik13:09:39

Regular apply should also work, I think.

tianshu13:09:48

It's seems regular apply won't work, because (.-foo obj) doesn't have a binding with obj. I just tried js-invoke it works. I'll try this prototype.apply, thanks for your help!

ingesol13:09:57

Hi! I’m experimenting with storybook, struggling to get a non-trivial example up and running. If I make a story with basically just reagent in it it works fine. But as soon as I require namespaces that pull in large third party namespaces, storybook takes forever to compile (webpack/babel) and often just crashes with out of memory. Using the approach outlined here https://github.com/DavidVujic/clojurescript-amplified. Anyone with pointers? First thing that comes to mind for me is that i really don’t need babel to transpile anything, but not sure if that’s what causes this. I have tried several different things to skip files on webpack and babel, no luck so far

thheller15:09:11

@ingesol "large third party" CLJS lib or JS lib?

ingesol15:09:15

@thheller CLJS. Like specter.js

p-himik15:09:23

Just in case (and sorry if I have mentioned it to you before, I don't recall) - beware of Specter usage in the browser since it increases the bundle size significantly.

ingesol15:09:20

Thanks, but I confirmed this isn't specifically about specter

👍 2
thheller17:09:49

in the past there were issues with code becoming too large for webpack. in react-native I worked around it by effectively hiding it so it doesn't get processes at all

thheller17:09:02

the same might be possible for storybook too

ingesol09:09:40

Sounds like the sensible solution, yes. I really should learn more about how webpack and babel works. In this case it seems like the value of processing all files with those tools is pretty minimal for a lot of storybook users, but it is included by default anyway.

ingesol15:09:51

Or actually I’m not 100% sure. But specter is one that triggers the warning The code generator has deoptimised the styling .

dnolen17:09:16

@ingesol that all seems very strange to me - ideally any usage of Storybook would just avoid needing to look at the CloureScript

lilactown17:09:23

I think they're writing stories & components in CLJS

dnolen17:09:30

it still shouldn't matter in dev? I don't think any CLJS should get processed by Webpack

lilactown18:09:19

if the storybook site is built via webpack at dev time, it needs to load the compiled JS of your stories and components right?

dnolen21:09:11

well the API of the whole thing is dynamic, I don't see how Webpack has anything to do w/ it

dnolen21:09:10

(I could be missing some other details but it seems to me this should work w/o processing CLJS)

sun-one21:09:52

Curious if this is a known issue but escaping forward slash on literal regex appears to be giving me an exception (I'm assuming the compiled JS code is invalid)?

#"\/"
#object[SyntaxError SyntaxError: Unexpected token ';']
Is there a way to get the generated JS code without evaling it in CLJS? (I'm on version "1.10.866" ).

sun-one21:09:01

Unrelated but is there a way to get what would be outputted JS code from a CLJS expression in REPL? I would in essence want the JS code as a string (or some other form that hasn't been eval'd).

p-himik05:09:38

Not sure about REPL but you can use http://app.klipse.tech/ for that.

👍 2