Fork me on GitHub
#shadow-cljs
<
2022-09-22
>
Drew Verlee03:09:41

Given a shadow-cljs.edn with :deps set to true, and a deps.edn with an :aliases of :shadow-cljs with the :extra dep of shadow and the main opt set to ["-m" "shadow.cljs.devtools.cli"] i would expect running the command line script clj -M:shadow-cljs pom to produce a pom (or do anything) instead i get "Unknown action" which is also what i get if i replace "pom" with "help" or "info", meanwhile "watch app" seems to work.

Drew Verlee03:09:51

i wonder if my shadow version is somehow ancient...

Drew Verlee03:09:59

nope its fairly recent 2.19.4.

Drew Verlee03:09:38

i would also be fine creating a release build another way, maybe i should just use the clojure shadow library directly?

thheller06:09:25

can you explain your intent? pom is a task by the shadow-cljs cli command, which you do not use? however you can ask clj to generate a pom file for you, since it is in charge of generating the classpath? -Spom I believe?

thheller06:09:43

I don't get what creating a pom has to do with creating a release build though?

thheller06:09:26

help, info are all things provided by the shadow-cljs command, which runs in node and doesn't execute java for those

thheller06:09:44

release watch compile are all done by the clojure parts

thheller06:09:34

note that you can just continue using the shadow-cljs command? it'll just call clj for you. you only lose features by going with clj

Drew Verlee15:09:54

@U05224H0W thanks thheller. I'm following the instructions as outlined here in the user guide. https://shadow-cljs.github.io/docs/UsersGuide.html#deps-edn > Example shadow-cljs.edn with :cljs alias >

{:deps {:aliases [:cljs]}
>  :builds ...}
> Example deps.edn >
{:paths [...]
>  :deps {...}
>  :aliases
>  {:cljs
>   {:extra-deps {thheller/shadow-cljs {:mvn/version <latest>}}}}
> Running with clj directly. >
{:paths [...]
>  :deps {...}
>  :aliases
>  {:shadow-cljs
>   {:extra-deps {thheller/shadow-cljs {:mvn/version <latest>}}
>    :main-opts ["-m" "shadow.cljs.devtools.cli"]}}}
> clj -A:shadow-cljs watch app
a pom has nothing to do with creating a release build, i didn't mean to imply it did. Build the following command fails: >
clj -A:shadow-cljs pom
And reports Unknown action As where >
clj -A:shadow-cljs watch app
Correctly watches the app. Similarly, >
clj -A:shadow-cljs release app
fails with "unknown action" just like pom, which is why i pointed out that more "actions" then the one i wanted to run were failing. The readme implies this should work. If i just use shadow-cljs i get a very different complaint about missing devtools:
shadow-cljs release app
shadow-cljs - config: /home/drewverlee/Centriq/centriq-web/frontend/shadow-cljs.edn
shadow-cljs - starting via "clojure"
Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.

Full report at:
/tmp/clojure-5691110849954872601.edn
My best guess this is because shadow doesn't know about binaryage/devtools because it's a hidden behind a deps.edn aliase as an extra dep. But that guess doesn't seem great because the path is shadow/cljs/devtools/cli and nothing about binaryage. My only other thought is that my package.json has shadow as a devDependency as well, though thats what i feel i have done in all my projects and i don't recall running into this.

Drew Verlee15:09:29

Yea, if i add shadow-cljs as a dep (not behind an alias) to my deps.edn then i can run shadow-cljs release

thheller15:09:03

you add :deps {:aliases [:cljs]} to shadow-cljs.edn

thheller15:09:33

and add the thheller/shadow-cljs dependency to your deps.edn :cljs alias (or :shadow-cljs, or whatever alias you want)

thheller15:09:42

you do NOT add the main opts

thheller15:09:09

those you only add if you do NOT use the shadow-cljs command

thheller15:09:56

if you do not use the shadow-cljs command I think you must use clj -M:shadow-cljs release app?

thheller15:09:52

package.json is not relevant in this stage

thheller15:09:17

> My best guess this is because shadow doesn't know about binaryage/devtools because it's a hidden behind a deps.edn aliase as an extra dep.

thheller15:09:20

I don't follow

thheller15:09:25

create one alias for CLJS and use that

thheller15:09:42

or is your intent really to run everything via clj and no longer use the shadow-cljs command

thheller15:09:49

the setups are different. what do you want?

Drew Verlee15:09:08

i'm running some different combinations to see if i can answer my own question...

Drew Verlee15:09:26

I understand now, the shadow-cljs.edn :deps :aliases are picked up when you run shadow-cljs at the command line, and so the deps.edn aliases by the same name as the one i gave shadow-cljs.edn shouldn't have a main-opt that calls out to shadow command line as well. That makes sense.

Drew Verlee16:09:25

@U05224H0W For my own education, i wrote up a short explanation of how i understand the topic now that i have had a chance to review it. If you like, i can try to clean it up more and and it could be used in the docs, or not 🙂 The following is pulled from a markdown file, so the formatting is a tad off: # 3.2.2. integration with deps.edn and clj tool Shadow can pull dependencies from deps.edn and Shadow can be called from the clj tool. In the section below will break down both. ## Integration with deps.edn In order to tell Shadow that you want to use a deps.edn you have to add the :deps key to your shadow-cljs.edn. The :deps value is going to Shadow where to look for the theller/shadow-cljs dependency in your deps.edn. If you want to place that in your deps.edn :deps directly then set your shadow-cljs.edn :deps to true Which looks like this: shadow-cljs.edn

{:deps true}
deps.edn
{:deps {theller/shadow-cljs ...}}
Now when you run bash
shadow-cljs some-shadow-action
the command line tool will find theller/shadow-cljs in the deps.edn through the shadow-cljs.edn file. If you want to move the shadow depency under a deps.edn :aliases, then you will have to tell shadow about that aliase (or aliases) that you want to use when the shadow is invoked. You do this by changing the deps.edn :deps value to a list of keywords that shadow will use to look up in the deps.edn and use there extra-deps from. for example shadow-cljs.edn
{:deps {:aliases [:shadow-cljs]} }
deps.edn
{:aliases {:shadow-cljs {:extra-deps {theller/shadow-cljs ...}} }
Here shadow finds theller/shadow-cljs through the :shadow-cljs keyword, but you can use any :keyword as long as it matches. ## Having the clj command line call through to Shadow If for some reason you want to use the clj command line tool to call out to Shadow, you will need to tell the clj command line how to do that by updating your deps.edn to have an alias with a :main-opts and a value of exactly ["--main" "shadow.cljs.devtools.cli"]. "--main" is a function that takes the string representation of the clojure namespace that has a -main function that you want to pass arguments from the command line to. A full example might look like this: shadow-cljs.edn
{:deps {:aliases [:shadow-cljs]} }
deps.edn
{:aliases {:shadow-cljs {:extra-deps {theller/shadow-cljs ...}
                         :main-opts ["--main" "shadow.cljs.devtools.cli"]}}
bash
clj -M:shadow-cljs pom
Of course, clj -M can pass through arguments to any namespace with a main function. Shadow isn't special in this regard.

thheller16:09:23

clj -M:shadow-cljs pom this won't work so doesn't make for a good example in the last section

thheller16:09:32

otherwise seems accurate

thheller16:09:55

> the command line tool will find theller/shadow-cljs in the deps.edn through the shadow-cljs.edn file.

thheller16:09:26

this isn't entirely accurate. it won't find anything. the clj tool constructs the classpath with shadow-cljs in it, when the process it started it can then be loaded

Drew Verlee17:09:40

> clj -M:shadow-cljs pom this won't work so doesn't make for a good example in the last section Oh you right (big surprise 🙂 ) Why does clj -M:shadow-cljs watch app work then? I guess the main function of shadow-cljs.devtools.cli doesn't take the same arguments as the command line then? as shadow-cljs pom would work right?

thheller19:09:17

no, this is not true for all command

thheller19:09:50

as I said yesterday. some commands are provided by the shadow-cljs node script and never execute any java to do that

thheller19:09:00

pom just generates a xml file, it doesn't need java for that

thheller19:09:21

all build related commands require clojure, so they launch java and are available via shadow.cljs.devtools.cli

👍 1
Logan Powell15:09:38

I'm back, with hopefully just one more question and I'll be out of your hair. Currently, Shadow is importing a dep (using :esm target) like this:

import * as esm_import$node_fetch from "node-fetch";
How can I get it to do
import esm_import$node_fetch from "node-fetch";

thheller15:09:36

(:require ["node-fetch$default" :as node-fetch]), see translation table provided here https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages

🙏 1
❤️ 1
Logan Powell15:09:17

Thank you! Sorry for not seeing that!