shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
thheller 2021-02-18T00:06:19.252800Z

when you require it from the ns :require it will become part of the shadow-cljs build

thheller 2021-02-18T00:06:33.253400Z

when you js/require it then it will just resolve at runtime and not be part of the build

bringe 2021-02-18T00:06:50.253800Z

Yes, that works. Whereas before I wasn't trying to make shadow bundle things, I later wanted to see if I could get shadow bundling everything as you mentioned in that ticket. I've been reading stuff you said there multiple times and understanding more and more 😄. > Just stick with :node-library. :esm will not give you any "new" features if it requires post-processing anyways. So until vscode can load ESM directly without further bundling :esm should not be used. I'm sticking to :node-library but was thinking I could still bundle things with shadow if I could make typescript ignore the goog:.. imports, as you mentioned, and then stop using webpack. But I see you mentioned potential issues with that, so I probably will stop this approach now.

thheller 2021-02-18T00:08:00.254500Z

yeah I'd recommend sticking with js/require until you get the amount of JS code down significantly

bringe 2021-02-18T00:08:32.255200Z

That makes sense

thheller 2021-02-18T00:08:44.255500Z

its fine for smaller bits of JS code or JS code that is fully advanced compatible

thheller 2021-02-18T00:09:05.256Z

but for the vast chunk of the vscode based code you probably won't have externs anyways

bringe 2021-02-18T00:09:38.256400Z

I see

thheller 2021-02-18T00:10:04.256900Z

I mean you can still go with this route and try it

thheller 2021-02-18T00:10:35.257500Z

but not many people do so there may be many issues with this that may require tinkering with shadow-cljs

thheller 2021-02-18T00:10:52.257900Z

it works ok-ish in the browser but node seems to have some problems

bringe 2021-02-18T00:12:29.258500Z

Yeah, I'd rather go the path of least resistance in this case

Kira McLean 2021-02-18T04:23:29.259300Z

Has anyone built a custom shadow-cljs build target before? Is this actually possible? I spotted this in the shadow-cljs docs: > The build target is an extensible feature of `shadow-cljs` but am still looking for details about how it might be done :thinking_face: .. wondering if there are any examples out there

Kira McLean 2021-02-18T04:25:20.260700Z

I would like to make a build target that combines devcards and karma (basically combine the current built-in :browser and :karma build targets), so I can use devcards as a test harness for UI-based cljs tests

thheller 2021-02-18T07:03:53.262500Z

@kiraemclean I guess as example you could look at the default provided targets, they all use the same mechanism a custom target would use. https://github.com/thheller/shadow-cljs/tree/master/src/main/shadow/build/targets

Kira McLean 2021-02-18T14:15:37.279Z

this is very helpful, thank you for the reply! I didn’t know the :karma target could take a runner-ns option, I think that would do it! I was looking at using a custom runner-ns for the existing browser-target then some karma hackery to get it to run in CI, but I think doing it the other way around (starting with the existing karma target and adding a custom runner) would be simpler.

Kira McLean 2021-02-18T14:15:40.279200Z

I was wading through the custom targets but didn’t figure out how to build a custom one that could hook in to the existing build chain.

thheller 2021-02-18T15:08:16.279600Z

they all function based on the same principle. when shadow-cljs finds :target :karma in the build config it'll "expand" :karma to shadow.build.targets.karma/process and call that function for every "stage" of the compilation. https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/targets/karma.clj#L114

thheller 2021-02-18T15:09:01.279900Z

so if you were to create a :target :kira you'd create that shadow.build.targets.kira/process function and do whatever you want to do

thheller 2021-02-18T15:09:55.280200Z

it it also valid to have :target kira.target which would call (kira.target/process build-state) or :target kira.target/do-stuff which would call (kira.target/do-stuff build-state)

thheller 2021-02-18T15:10:19.280400Z

so a keyword is just the shorter version of a symbol or qualified symbol

thheller 2021-02-18T15:11:01.280600Z

the function is call repeatedly and is supposed to look at the :shadow.build/stage etc keys to figure out what to do

thheller 2021-02-18T15:11:58.280800Z

explaining beyond that will get very technical and it would be best to look at what the current targets do to understand

thheller 2021-02-18T15:12:13.281Z

happy to help if you have specific questions but that should be the rough overview

Kira McLean 2021-02-18T19:29:32.285Z

This is very helpful! Thank you so much for the explanation. I suspect I can acheive what I’m after without needing a whole custom build target, but I see now how it’s done.. really really appreciate your guidance, thanks. And also shadow-cljs! It’s very cool.

thheller 2021-02-18T19:32:50.286700Z

yeah, I do think that a custom :runner-ns will probably be enough. the important bits there is just the exported init function

thheller 2021-02-18T19:33:37.286900Z

I vaguely remember someone doing something with devcards and shadow-cljs before but I can't find it

thheller 2021-02-18T19:34:56.287100Z

how you'd hook up devcards to the karma stuff I have absolutely no clue though 🙂

Kira McLean 2021-02-18T19:35:27.287300Z

nice.. if I ever get it running I’ll make sure to write it down somewhere 🙂 but yeah all the pieces are here — test harness, karma-compatible test js file, etc. but they don’t work together yet.

Kira McLean 2021-02-18T19:36:28.287500Z

hah.. yeah I’m on the fence about using devcards as a ui actually.. most front-end browser tests work by appending and removing the component to be tested from the dom. with the dev-card ui I’d have to somehow click around to make sure the right one is showing for the right tests.

Kira McLean 2021-02-18T19:37:53.287700Z

anyway.. I’m optimistic about this 🙂 probably will pause to work on something else for a bit to give my brain a rest.. but I really would love to get it up and running! soon.

👍 1
Kira McLean 2021-02-18T19:38:03.287900Z

thanks again for the pointers.

thheller 2021-02-18T07:04:56.263500Z

it is however not exactly documented or easy to do since they can get rather involved in low level stuff (eg. :browser https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/targets/browser.clj)

thheller 2021-02-18T07:06:23.264400Z

:karma is much simpler and I think already allows what you are looking for via the :runner-ns option https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/build/targets/karma.clj

thheller 2021-02-18T07:07:14.265Z

defaults to this one https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/test/karma.cljs and I guess you could just create one that uses devcards instead

2021-02-18T07:16:25.270300Z

I'm trying to put my web-app into an app. I think http://capacitorjs.com looks pretty good so giving that a try. I've built and ran my app successfully, however firebase auth works a bit differently when running in apps (webview). I'm using the capacitor-firebase-auth plugin, but running into an error I haven't been able to solve yet and I think it's related to esModules stuff. The error I'm getting is: ️ TypeError: undefined is not an object (evaluating 'new q.auth.GoogleAuthProvider') Originating here: https://github.com/baumblatt/capacitor-firebase-auth/blob/master/src/facades.ts#L28 I've tried to shadow-cljs release with

:release {:compiler-options {:variable-renaming :off
                             :property-renaming :off
                             :pretty-print      true
                             :source-map        true
                             :infer-externs :auto
                             :output-feature-set :es6
                             :optimizations :simple}}
But to no avail.

2021-02-18T07:17:20.271200Z

Might it be there is a conflicting issue with typescript somehow? There is this comment in the readme:

1 import firebase from 'firebase/app';
         ~~~~~~~~
    8601 export = firebase;
         ~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
If you see the message above, please use `esModuleInterop=true` in your `tsconfig.json` file.

thheller 2021-02-18T07:17:26.271300Z

@bbss and how does the CLJS code looking doing this?

2021-02-18T07:18:20.272200Z

(ns kr.ui.firebase
  (:require ["firebase/auth"]
            ["firebase/analytics"]
            ["firebase/app" :default firebase]
            ["capacitor-firebase-auth" :refer [cfaSignIn]]
            ["firebaseui" :as fbui]))
...

(.subscribe (cfaSignIn "<http://google.com|google.com>") (fn [u] (js/console.log u :signed-in))) ;;offending line in my code

2021-02-18T07:19:15.272800Z

the library file on github does a require like this: import * as firebase from 'firebase/app';

thheller 2021-02-18T07:19:59.273500Z

so (cfaSignIn "<http://google.com|google.com>") this fails?

2021-02-18T07:20:04.273700Z

yes

thheller 2021-02-18T07:20:56.274300Z

did you verify that the firebase version you use matches EXACLTY the version capacitor-firebase-auth expects?

2021-02-18T07:21:09.274900Z

I did not, let me check.

thheller 2021-02-18T07:21:13.275Z

firebase is notorious for changing its API constantly

thheller 2021-02-18T07:21:26.275500Z

so I expect that you just use an incompatible version

2021-02-18T07:21:38.275700Z

could be! checking.

thheller 2021-02-18T07:23:27.276200Z

for example in the lib there is import * as firebase from 'firebase/app'; but you have ["firebase/app" :default firebase]

thheller 2021-02-18T07:23:37.276500Z

those are not the same thing and only one version is correct 😛

2021-02-18T07:24:37.276800Z

Ugh, they're not the same?

2021-02-18T07:24:59.277300Z

Yeah it's a major version mismatch, the plugin has peerdep 7.x.x and I use 8.x.x

2021-02-18T07:25:01.277500Z

downgrading..

2021-02-18T07:26:52.277700Z

https://github.com/baumblatt/capacitor-firebase-auth/issues/128 looks relevant..

2021-02-18T07:33:01.278300Z

great! updating to that alpha version mentioned in the issue seems to fix it!

👍 3
2021-02-18T07:33:16.278700Z

Thanks for the insight @thheller

lambduhhh 2021-02-18T18:59:35.284200Z

Does anybody know of an alternative to codox to auto generate documentation for a private cljs project? Codox looks great but seems like shadow w deps isn't officially supported.

lambduhhh 2021-02-18T19:00:19.284900Z

(hope I'm posting in the correct place, if anyone knows a better channel to post in just lmk 🙂 )

thheller 2021-02-18T19:30:47.286Z

you can just create a lein project.clj and use codox that way. as far as I know codox doesn't actually compile the code, just needs to be able to read it.

thheller 2021-02-18T19:31:24.286600Z

but it has been a while since I used and and only for CLJ at that