Fork me on GitHub
#shadow-cljs
<
2018-05-25
>
theeternalpulse03:05:13

I'm connected to the nrepl in emacs but can't seem to eval anything using js/. Is this only available during compilation.

grav06:05:12

@theeternalpulse Sounds like you have a Clj repl and not a CLJS repl. I usually invoke (shadow.cljs.devtools.api/nrepl-select :my-target) which drops me in the cljs-repl.

grav06:05:33

(where :my-target is from your shadow-cljs.edn)

bbss08:05:22

Since cider 17 my figwheel set-up for hot reloading chrome extension content script broke, so this seems like an excellent moment to try https://github.com/thheller/shadow-cljs/issues/279

bbss08:05:25

I must be missing something, I thought maybe it's not the latest version of shadow-cljs but that seems to be the latest

bbss08:05:34

Baruchs-MBP-2% shadow-cljs compile chrome-ext
shadow-cljs - config: /Users/baruchberger/stah/cljsc2/shadow-cljs.edn  cli version: 2.3.23  node: v8.9.4
shadow-cljs - starting ...
[:chrome-ext] Compiling ...
Target ":chrome-extension" for build :chrome-ext was not found. The built-in targets are:
  - :browser
  - :browser-test
  - :node-script
  - :node-library
  - :npm-module
  - :karma
  - :bootstrap

thheller08:05:49

@bbss that is still a WIP and currently only available in master

bbss08:05:16

I tried to find how to build from master, the version seems up-to-date.

thheller08:05:28

just git clone and lein install

bbss08:05:41

okay great, thanks.

thheller08:05:34

hope to get a release out today with basic support for :chrome-extension

bbss08:05:28

did you manage to get hot loading working on content-script pages?

bbss08:05:04

I've done it twice on projects with figwheel, but what I was doing felt like black magic and the blogs writing about it online also have trouble figuring it out.

bbss08:05:32

Awesome, my experience with shadow-cljs so far has been so streamlined, great work.

πŸ‘ 4
thheller08:05:56

nice to hear, thanks.

bbss08:05:58

I'm giving the same path to source-paths as in my project.clj with lein, but am getting The required namespace "cljsc2.cljs.content-script" is not available.. Any hints?

thheller08:05:31

Maybe you have a content-script.cljs? shadow-cljs is pretty strict about enforcing _ but the error message for that is still missing (or rather ends up in the wrong place)

bbss09:05:25

Hmm, I renamed everything to remove the dash/underscore

bbss09:05:44

Still getting The required namespace "cljsc2.cljs.contentscript" is not available..

thheller09:05:33

what is your source-path?

thheller09:05:54

assuming src you should have a src/cljsc2/cljs/contentscript.cljs correct?

bbss09:05:02

{:source-paths ["src/cljsc2/cljs"]
 :dependencies [[org.clojure/clojurescript "1.9.946"]
                [fulcrologic/fulcro "2.5.2"]
                [org.clojure/core.async  "0.3.443"]
                [com.cognitect/transit-cljs "0.8.243"]
                [cljsjs/d3 "4.12.0-0"]]
 :builds {:chrome-ext {:target :chrome-extension
                       :extension-dir "out/chrome-ext"}}}

thheller09:05:18

that is an incorrect source-path

thheller09:05:21

that is not how they work

thheller09:05:26

src would be correct

bbss09:05:08

Okay reading up.

bbss09:05:27

Now I'm getting namespace react not available but I can try to figure out how to solve that πŸ™‚

thheller09:05:36

npm install react react-dom

bbss09:05:30

that's cool. using npm for it. super clean πŸ™‚

bbss09:05:14

[:chrome-ext] Build completed. (257 files, 135 compiled, 0 warnings, 57.26s) Hooray. Let's see if it runs!

thheller10:05:12

@wilkerlucio @bbss just pushed an update for the chrome-ext stuff, still only on master though. https://github.com/thheller/shadow-cljs/issues/279#issuecomment-392007641

πŸŽ‰ 4
bbss10:05:45

Thanks, will check it out and update.

thheller10:05:00

@bbss did it run with the "older" config?

bbss10:05:37

Well I was still solving issues with dependencies, but I got a succesful print from the extension so yes

bbss10:05:20

Had one issue which I assume is because an earlier loaded file errored. Uncaught TypeError: cljsc2.cljs.contentscript.core.init_BANG_ is not a function

troglotit10:05:46

Did anyone faced Uncaught TypeError: $goog$string$$.format is not a function ? I thought Closure library is somewhat bulletproof to name munging

Geoffrey Gaillard11:05:25

To use goog.string.format you need to require the goog.string namespace and goog.string.format namespace, look at this example : https://github.com/reagent-project/reagent-utils/blob/master/src/reagent/format.cljs#L6

Geoffrey Gaillard11:05:30

Does it solve it?

troglotit11:05:15

Yeah, it works. Thanks!

bbss11:05:50

I have some JavaScript that I need to manually include, is there an easy way to include some js file? I would include it in the html but the content-script has no access to the window.

bbss11:05:56

@thheller I'm getting `At least one js or css file is required for 'content_scripts[0]'. Could not load manifest.` when loading the extension using the latest push.

bbss11:05:33

Maybe I forgot to include something, hold on.

thheller11:05:29

@bbss you probably need to remove the :content-scripts entry from manifest.edn since that will now be generated from :shadow/outputs

bbss11:05:53

Yeah, sorry I was being stupid. Working in the wrong buffer..

thheller11:05:55

:shadow/entry there is no longer correct

bbss11:05:19

It works now, just need to include some manual JS. Will use yarn add file:// for it.

thheller11:05:32

what do you mean by manual js?

bbss11:05:07

err, well non-compiled JS. I have some horrible unoptimized for loops for running through image data.

bbss11:05:44

And normally I manually include these in a script tag of the page. But since the content-script has limited access to that it's saying those are undefined.

thheller11:05:12

you can just (:require ["./some-script.js" :as x]) and its exports will be available via CLJS

bbss11:05:28

I wouldn't even need to yarn add, great. Thanks.

thheller11:05:29

(this assumes in the the same directory as your .cljs file

bbss11:05:41

Okay. Makes sense.

thheller11:05:57

you can put it anywhere on the classpath and include it via "/somewhere/some-script.js" as well

thheller11:05:20

but must be on the classpath, so in one of your :source-paths

bbss12:05:19

okay, getting close. Jacking in with cider but now the manifest.json is invalid:

"out/cljs-runtime/cljs.pprint.js", ...],

thheller12:05:03

cider sets *print-length* which messes with things in pretty annoying ways

thheller12:05:01

@bbss master should fix that

bbss12:05:28

It did! Thanks @thheller. I have my trusty in IDE cljs eval back, now with new shadow-cljs flavor.

bbss12:05:01

However my screen is now full of build warnings after refreshing. I guess I should use proper reflection instead of the regular . syntax.

bbss12:05:26

Yes, I included that with auto.

thheller12:05:56

yeah those are the things that might break in :advanced

thheller12:05:27

(fn [^js cell] ...) would fix one of them

bbss12:05:59

You can see the image I posted? Slack said it's only visible to me.

thheller12:05:17

but yeah might need to turn off the externs inference if you get too many warnings

thheller12:05:43

I can see the image yes. I think the slack message is just info about them not storing it due to lack of premium

bbss12:05:51

I turned it on because I thought I'd need it for d3/react

thheller12:05:18

funny thing is that you probably don't need it for those

thheller12:05:50

. is native interop and the compiler sometimes needs a hint to figure out if you are working with a JS object which it shouldn't rename

thheller12:05:01

or something else which would be fine to rename

thheller12:05:26

the fulcro thing is odd since I thought that was fixed

bbss12:05:08

It's a version that's already a couple weeks old though.

thheller12:05:30

that actually looks like invalid code (generated by the fulcro macro)

bbss12:05:06

Thank you so much for helping me out so quickly.

bbss12:05:42

I'm so happy I got my set-up back with a recent cider.

bbss12:05:35

I'll probably be using it quite a bunch more now.

bbss12:05:21

Got my set-up back + the code is simplified a bunch. It's cool to integrate so naturally with JS, I thought cljs<->JS interop was already decent but shadow-cljs really takes it up a notch.

bbss12:05:36

with my approach before I had to include react and d3 from external sources as cljsjs deps didn't work. Now don't even need them πŸ™‚!

parrot 4
bbss14:05:11

figwheel has a on-js-reload. I think :devtools {:after-load ns/fn} is the analog. But I get can't find fn cljsc2.cljs.contentscript/on-js-reload. Funnily enough it also reports that when I remove that from the shadow-cljs.edn and add ^:dev/after-load as function meta.

thheller14:05:57

odd. will check. it might be related due to the weird scoping in content-scripts. it probably tries to look up window.cljsc2....

πŸ‘ 4
thheller14:05:31

@bbss fixed in master

bbss14:05:34

@thheller confirmed, you're the best πŸ™‚

thheller14:05:16

I doubt that given that I added the bug that prevented that from working πŸ˜‰

bbss14:05:00

Well, being able to write a module system that works on so many platforms with such a consistent api is πŸ’―

bbss14:05:42

All the exceptions, hidden config options and rules with almost no error reporting of the extension ecosystem... Ugh. So much trouble saved in this approach πŸ™‚

thheller14:05:47

btw I just pushed 2.3.24 which has the latest version of the chrome stuff as well

thheller14:05:03

might need to bump your dep if you do another lein install later

πŸ‘Œ 4
thheller14:05:39

not confident that I covered everything for :chrome-extension yet so I still consider that a WIP

bbss14:05:23

Yes, I feel lucky googleing for "shadow-cljs chrome extension" this morning and seeing your 7 day your old issue with a proof of concept!

kurt-o-sys14:05:31

just wondering @thheller: I really like your way of thinking and how to pass configs from index.html... but here's the thing: how to pass different configs read from a config file. I mean: if I have 2 index.html files (one for prod and one for dev) that seems fine. However, whenever I need to add some lines (script, css) to index.html, I need to do it in 2 places. So I'd prefer to be able to have a kind of templating/preprocessing of index.html, so it reads the config from a file. How d'you do that usually?

thheller14:05:32

I have been planning a chrome extension for shadow-cljs for years now so it was about time πŸ˜‰

thheller14:05:21

@kurt-o-sys my server-side is always clojure so the html is generated by the server which makes adding dynamic stuff pretty easy

kurt-o-sys14:05:23

no static html file there, right πŸ˜›

thheller14:05:26

generating an index.html could be done via clj-run

kurt-o-sys14:05:44

that will certainly do!

thheller14:05:51

I want to add a webpack-ish html thing eventually

πŸ‘ 4
mhuebert15:05:02

@thheller this is not a big deal, but is there a reason why shadow.loader can’t be used immediately when a page loads? one must have it called later (or after a 0ms timeout) otherwise an β€œUnknown module: …” error pops up

mhuebert15:05:16

i was also looking at the builtin cljs.loader. I actually can’t get it to work at all, it shows a warning about source maps not being found and just prints my callback function to the console

theeternalpulse15:05:41

anyone having issues accessing the documentaiton?

theeternalpulse15:05:16

odd, it times out on my work or home laptop. I'm on the west coast of north america.

mhuebert15:05:58

i’m in berlin so we are probably hitting different endpoints

thheller15:05:08

hmm yeah I kind of torn about supporting this. I could make it work ... BUT the idea is that loading should be triggered by a user event

thheller15:05:36

if you are loading one script which then immediately loads another you should just be loading one combined version

thheller15:05:43

since that would be faster

mhuebert15:05:43

I mean as long as it is predictable, and isn’t a variable amount of time delay

mhuebert15:05:08

but in a SPA i may check the route and then load the appropriate module

thheller15:05:09

currently a shadow.loader.setup function call is added to the end of the base module

thheller15:05:44

@mhuebert yeah there are valid arguments for loading modules directly. no doubt about that.

thheller15:05:14

the problem goes away when you go full async

mhuebert15:05:31

what do you mean by full async?

thheller15:05:42

how is your app initialized/started?

mhuebert15:05:49

i am figuring out how i will do that now. I don’t think this is going to be an issue at all because i will be resolving this in a callback anyway

mhuebert15:05:12

it was just the first thing i hit trying to test out modules and was wondering if there was something weird going on

thheller15:05:20

<script async src="/js/base.js"></script>

mhuebert15:05:38

(defn init []
  (routing/listen
   (fn [{:keys [path] :as location}]
     (try-module-load))))

(-> js/document
    (.addEventListener "DOMContentLoaded" init))

mhuebert15:05:43

^^this works

thheller15:05:45

I'm assuming that you have a ns that simply calls (init) or so

thheller15:05:13

yeah that works as well

thheller15:05:05

ie. embed a <script type="shadow/run" data-fn="my.app/init">["some" "args"]</script> which basically invokes (my.app/init "some" "args") when the JS is loaded

thheller15:05:40

but technically that could still have the same problem with the loader

thheller15:05:31

I can change the setup sequence

thheller15:05:37

I probably should just to get rid of this problem

mhuebert15:05:09

I like how that looks on the server side

mhuebert15:05:28

along the lines of (cljs 'some.ns/fn & args)

mhuebert15:05:54

which i guess is just hiccup for the script tag

thheller16:05:21

yep exactly

thheller17:05:01

@mhuebert just pushed [email protected] which changes the shadow.loader init so it should be immediately available

mhuebert17:05:19

Cool, thanks!

justinlee18:05:21

i need a cron job that updates my shadow-cljs every morning πŸ˜›

4
Logan Powell22:05:03

I'm getting this error when trying to eval the code above:

utils.async_fetch._GT__BANG__BANG_.call(null,c,"hello");
                                   ^

TypeError: Cannot read property 'call' of undefined

thheller22:05:07

>!! does not exist in CLJS

thheller22:05:46

when inside a go

Logan Powell22:05:30

is there one for cljs.core.async?

thheller22:05:33

no that is intended for clojure

thheller22:05:08

hey πŸ˜‰

Logan Powell23:05:57

Alrighty! I think I'm finally all set up with SHADOW BABY!

Logan Powell23:05:33

just had to get used to the new error messages πŸ˜‰