shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
superstructor 2021-03-19T13:37:01.072700Z

If I want to rewrite cljs sources during compilation is there a way to use build hooks to get the result of reading the forms and manipulate the forms prior to macro expansion ? The only way I have figured out so far is hooking into compile-prepare and replacing every cljs file in build state with one at a different tmp path that has been modified. Thoughts ?

thheller 2021-03-19T13:56:19.073Z

what kind of "rewrite" are you thinking about?

thheller 2021-03-19T13:56:49.073500Z

currently there is no way to hook into the compiler at that level

pfeodrippe 2021-03-19T14:44:21.079200Z

Hi there o/ Is there any way that I could create standalone js files for each of the entries (or modules)? Or should I create a new build for each (could I watch them all at the same time, I guess it's doable from my part if this is the only way o/)? In the example below, it outputs a shared.js file, it's fine, but standalone would be good for now (I'm trying to use Cypress).

{:builds :....
 {:target :browser
  :output-dir "out/testtt"
  :compiler-options {:infer-externs :auto}
  :modules {:shared {:entries [cypress.core]}
            :cypress.blablabla.edit-test
            {:entries [cypress.blablabla.edit-test]
             :depends-on #{:shared}}

            :cypress.blablabla.add-test
            {:entries [cypress.blablabla.add-test]
             :depends-on #{:shared}}}}}
And thanks for this very awesome piece of software, Thomas o/

mauricio.szabo 2021-03-19T14:56:34.080Z

@pfeodrippe IFAIK, when you compile the release version, each module will be a single JS file

👍 1
thheller 2021-03-19T14:57:09.080600Z

I don't understand the question? the whole point of modules is creating multiple files? if you only want one file only use one module?

pfeodrippe 2021-03-19T15:01:40.084100Z

Oh sorry, I want to create a standalone file for each cypress.blablabla... namespace, right now it creates a thin js file for each, it gives me SHADOW_ENV is not defined error. The only way to do this is through a build (maybe any other dynamic way)?

thheller 2021-03-19T15:02:22.084800Z

I'm missing some basic information I guess. you are supposed to load the shared.js first before loading the other module

thheller 2021-03-19T15:02:33.085100Z

(that is where SHADOW_ENV comes from)

thheller 2021-03-19T15:03:08.085800Z

why does it have to be a standalone file?

thheller 2021-03-19T15:03:29.086200Z

I have never used cypress so I don't have a clue how it works

thheller 2021-03-19T15:03:56.087100Z

but to answer your question: no, there is no way to make modules standalone using shadow-cljs

thheller 2021-03-19T15:04:25.087800Z

you could do it yourself by just concatenating shared.js + the module file

thheller 2021-03-19T15:04:31.088100Z

but I don't get why you'd need to do that

pfeodrippe 2021-03-19T15:08:05.090800Z

Oh, thanks. Yes, to load shared.js before appears to be the best approach, I just wanted to check if there was another way. Thanks, @thheller and @mauricio.szabo o/

thheller 2021-03-19T15:09:56.091800Z

well technically the :target abstraction in shadow-cljs would allow for a :target :cypress and then just take the minimum amount of config to emit the output that fits best for cypress

thheller 2021-03-19T15:10:20.092300Z

but that is going to be a bit of work since none of the underlying code is documented 😉

pfeodrippe 2021-03-19T15:11:28.093400Z

Oh very nice! Well, I can check how karma (or some simpler one) works, thanks again o/