Fork me on GitHub
#shadow-cljs
<
2018-06-26
>
steveb8n02:06:01

HI all, I’m having trouble making the :node-library target work with the shadow CLI tool installed via npm i.e. not via a lein REPL

steveb8n02:06:14

has anybody else had success with this in the past?

steveb8n02:06:11

I’m using :exports with a map and I’m getting an error

steveb8n02:06:15

The required namespace "pages.handlers" is not available, it was required by "shadow/umd_helper.cljs".

steveb8n02:06:41

but that namespace is in the correct place under the “src” dir

steveb8n04:06:04

and it works ok when using lein to manage classpath i.e. server and build/watch commands invoked in REPL

thheller06:06:22

@lilactown exclusions are just the symols without versions. thats what it complains about. will add a spec for that.

thheller06:06:08

@steveb8n are you sure the :source-paths are the same?

steveb8n06:06:54

I tried without :source-paths and with. no change

thheller06:06:19

and what is your :source-paths now?

thheller06:06:46

it is required so you cannot take it out. unless using lein or deps or course

steveb8n06:06:11

what’s stranger is that it works for the :node-test target

steveb8n06:06:32

but since I have it working via the repl I am avoiding the CLI for now

thheller06:06:44

just check the source paths

thheller06:06:05

and then check <source-path>/pages/handlers.cljs

steveb8n06:06:14

ok. I’ll switch back. gimme a couple of mins

thheller06:06:34

:node-test discovers files so you may just have a typo in your namespace

thheller06:06:51

ie. the ns is page.handlers or pages.handler

thheller06:06:58

easy to overlook

steveb8n06:06:09

source paths is :source-paths ["src"]

steveb8n06:06:15

have reproduced now

steveb8n06:06:51

have confirmed correct ns is pages.handlers

steveb8n06:06:21

only other possible mistake is `:exports {:home pages.handlers/home-page :context pages.handlers/app-context-page}`

thheller06:06:56

and you have confirmed that you have a src/pages/handlers.cljs?

steveb8n06:06:00

maybe not “only” 🙂

steveb8n06:06:24

yes. must be ok since it works via repl

thheller06:06:40

could be src/pages/handlers.clj

steveb8n06:06:00

definitely .cljs

thheller06:06:21

and what does shadow-cljs browser-repl then (require '[pages.handlers :as x]) give you? without lein?

steveb8n06:06:10

the repl starts but the require fails

steveb8n06:06:57

here’s my shadow file contents

steveb8n06:06:00

`{;:lein true ; let lein/project.clj manage source-paths and deps :dependencies [] :builds {:pages {:target :node-library :source-paths [“src”] :js-options {:js-provider :shadow} ; include deps in single resource :output-to “out/pages/handlers.js” ; where does compilation output go :exports {:home pages.handlers/home-page :context pages.handlers/app-context-page} :release {:output-to “out/release/handlers.js”}} :test {:target :node-test :source-paths [“src” “test”] :output-to “out/tests/node-tests.js” :ns-regexp “-spec$” :autorun true}}} `

steveb8n06:06:15

I’m using the :pages build

thheller06:06:27

:source-paths is only at the top level. it is not per build.

steveb8n06:06:44

I tried that also. will retry again to check my sanity

thheller06:06:05

:js-options {:js-provider :shadow} ; include deps in single resource this doesn't work for node

steveb8n06:06:49

that was going to be my next question. I’m hoping for a way to generate 1 big js artifact for node. this is destined for AWS lambda

steveb8n06:06:55

I’ll comment it out for now

steveb8n06:06:55

ok, with :source-paths at top level, same error when required in repl

thheller06:06:32

did you restart the server properly?

steveb8n06:06:54

no! restarting…

steveb8n06:06:14

so it was the top level key in that case. thank you - again!

steveb8n06:06:57

since you are here. the webpack workaround for the single file bundle. is there an example of that somewhere?

steveb8n06:06:20

I’ve recently used webpack/umd so I can work it out but an example will be faster

thheller06:06:39

no idea, I never did that

steveb8n06:06:52

ok. I’ll dig into it. thanks

steveb8n06:06:33

when deploying a node module to AWS lambda, a single file is much easier to manage

steveb8n06:06:13

FYI : this is for a sample project using Datomic Ion so might get a little more support for shadow once we have it working

thheller06:06:42

I have not used any of the cloud stuff. all my projects are too small to justify cloud stuff. I'm open to adding support for it just don't have the time to look into it currently.

steveb8n06:06:08

no worries. we’ve got your back on the cloud stuff

thheller06:06:09

it is definitely possible to do one-file but needs some special treatment since everything is currently meant for the browser

thheller06:06:24

and some of the node emulation stuff needs to be adjusted to not emulate but rather use the real thing

steveb8n06:06:47

cool. it’s not urgent since there is a workaround. I’ll try it out and report back

steveb8n06:06:09

BTW : I’m going to ClojuTre. will you attend that?

steveb8n06:06:23

shame. would be nice to shake hands one day

steveb8n06:06:35

ok I’ll get back to it. thanks again

thheller07:06:44

one day I'll go to a conference 😉 they are usually too far away and I hate travelling

mhuebert09:06:55

I’ve created a small PR for an issue with watch* - https://github.com/thheller/shadow-cljs/pull/326 - it is currently throwing away the config map it is passed, re-reading the config from its build-id.

thheller09:06:31

@mhuebert oops. the if check should just be removed since it always expects a build-config map. passing a keyword would break the destructure above

4
thheller10:06:39

fixed in master

grounded_sage13:06:21

I know this is very side effecty but I can't seem to run this in my clj-run (map #(spit (str % ".txt") "test") ["one" "two"])

grounded_sage13:06:40

I probably need a recursive function but I'm still curious why it doesn't run but the spit on it's own works and doing this function in a repl works as well.

thheller16:06:43

@grounded_sage clj-run is for calling fully qualified functions, ie. your.thing/foo

thheller16:06:27

if you are doing that inside your function then note that map is lazy and doesnt do anything unless consumed (wrap in doallor use doseq)

pez16:06:55

Can the :node-test target be made to generate tests from the :test functions inside function attribute maps?

thheller16:06:17

@pez maybe? it currently relies in cljs.test/deftest but since cljs.test doesn't look for anything besides that the change would really need to be in cljs.test

thheller16:06:26

I also sort of tried to avoid macros since they make everything harder

thheller16:06:44

and since you need a macro to get the metadata it doesn't seems like a good idea

pez16:06:39

Hmmm, I wonder why it is not part of cljs.test already…

thheller16:06:33

whats wrong with deftest? having lots of metadata on defns makes them sort of unreadable no?

thheller16:06:33

and all your namespaces need to import cljs.test for the is assertions? it is generally best practice to have separate your.thing and your.thing-test namespaces

pez16:06:34

I think it is very readable to have the tests embedded in the function tested. I like to “document” my functions that way.

pez16:06:02

I have decided not to use CLJC for the ClojureScript parts of my extensions. It makes it a bit less easy to access the node ecosystem. But at the same time cuts me out of my embedded tests. I was hoping I could eat the cake and have it. 😃

thheller16:06:49

well you can write your own macro to do this. there just isn't anything built-in

pez16:06:43

You mean a macro that creates the deftest as well as the defn for me?

pez16:06:35

This might be a silly example, but I think it is readable:

(defn- split
  "Splits text at idx"
  {:test (fn []
           (is= [" " " "]
                (split "  " 1))
           (is= ["(foo\n " "\n bar)"]
                (split "(foo\n  \n bar)" 6)))}
  [text idx]
  [(subs text 0 idx) (subs text idx)])

pez16:06:28

It helps me use the REPL to create the function TDD-style. And then I can leave some of the “exploration” code as unit tests where they help both with testing and explaining what the function does.

pez16:06:28

Anyway, I probably will write any macro helping me keep this style of coding. Just not sure what kind of macro is needed. 😃

pez21:06:24

Is there a way to get the tests to automatically run when they are built using watch?

thheller22:06:32

:autorun true