thheller / shadow-cljs

ClojureScript compilation made easy
https://github.com/thheller/shadow-cljs
Eclipse Public License 1.0
2.23k stars 173 forks source link

#shadow/env not working in ~/.config/shadow-cljs/config.edn? #1177

Closed glyh closed 3 months ago

glyh commented 3 months ago

For now I have to do:

{:maven
 {:local-repo "~/.cache/m2"}}  

Instead of

{:maven
 {:local-repo #shadow/env "$SHADOW_MVN_REPO"}}  

And I'll also have to set the envrionment variable SHADOW_MVN_REPO outside cause config.edn doesn't allow me to concat strings.

Is there a more ergonomic way to set m2 dir?

glyh commented 3 months ago

I saw this https://www.reddit.com/r/Clojure/comments/13vrrl0/leiningen_moving_the_maven_local_repository/ where people use #= to get work done but that doesn't seems to work with shadow-cljs.

glyh commented 3 months ago

I'm looking for information about #= but seems like github is broken and I can't find matches in discussion. Only refernce I got is 2 match on lein code base.

I think this might be somewhat overkill for configuration but I think we may at least have something like templates in bash?

thheller commented 3 months ago

#shadow/env should work fine, but note that it should likely be #shadow/env "SHADOW_MVN_REPO", so without the $.

And maybe you want to use a default value for cases where the env var isn't set?

{:maven
 {:local-repo #shadow/env ["SHADOW_MVN_REPO" :default "~/.cache/m2"]}}  
thheller commented 3 months ago

#= is the eval reader, it is generally advised to not use it. shadow-cljs also doesn't support it anywhere.

glyh commented 3 months ago

Yeah that looks like it. Also it's annoying that when using npm it cleans my environment variable and I have to use something like this:

$ cat .env
XDG_CONFIG_HOME="$HOME/.config"
SHADOW_MVN_REPO="$HOME/.cache/m2"
$ cat ~/.config/shadow-cljs/config.edn
{:maven
 {:mirrors 
  {"central" {:name "Aliyun"
              :url "https://maven.aliyun.com/nexus/content/groups/public/"}
   "clojars" {:name "USTC"
              :url "https://mirrors.ustc.edu.cn/clojars/"}}
  :local-repo #shadow/env ["SHADOW_MVN_REPO" :default "~/.cache/m2"]}} 

to get things working, is there a workaround?

thheller commented 3 months ago

I don't really understant the question. Workaround for what?

shadow-cljs on its own does not look at .env files, so I'm assuming you have some sort of shell support for that?

You might have more luck overall using deps.edn for this. It has a cleaner handling for all maven related configs as far as I know. Or if you have a solution for leiningen then you can just use that.

glyh commented 3 months ago

Sorry I should add another file here: package.json

{
  ...
  "scripts": {
    "dev": "source ./.env && shadow-cljs watch main renderer",
    "build": "shadow-cljs compile main renderer",
    "clean": "rm -rf resources/public/js/* && rm -rf target"
  },
  ...
}

npm script cleans my environment variables so I have to do source .env. I'll take a look at lein and deps.edn. Thanks for your paitience.