shadow-cljs icon indicating copy to clipboard operation
shadow-cljs copied to clipboard

Allow :npm-deps to be specified per-build or per-target

Open aiba opened this issue 1 year ago • 2 comments

I have a project that has both a browser frontend and also a react-native frontend, and they share clojurescript code and a single deps.edn file and a single shadow-cljs.edn file. But they need to have separate node_modules directories.

I'd like to be able to specify different :npm-deps for different targets, e.g.:

 :target-defaults
 {:browser {:js-options {:js-package-dirs ["web/node_modules"]
                          :npm-deps {:install-dir "web"}}}
  :react-native {:js-options {:js-package-dirs ["mobile/node_modules"]
                              :npm-deps {:install-dir "mobile"}}}}

But it seems that :npm-deps is only accepted at the top level of the config.

aiba avatar Jul 27 '22 03:07 aiba

Currently, this is tricky since the :npm-deps install runs once when shadow-cljs first starts. This is far before any actual builds are looked at or started. See https://github.com/thheller/shadow-cljs/issues/998

Most likely I will be removing the automatic install of :npm-deps entirely at some point. It has been nothing but a nuisance and has lots of quirks. Instead it'll probably become manual command, which you could then pass a directory to I guess.

So, something like npx shadow-cljs install-npm-deps --dir mobile or so.

Would that be a suitable fix? I mean its not impossible to look at build configs and running the install multiple times, I'm just skeptical of the automatic install given the problems it has.

thheller avatar Jul 27 '22 07:07 thheller

Yes, that would work great for my use case. If it's not too much trouble, it would also be handy to get a message or warning when running watch or compile, indicating that it may be necessary to re-run install-npm-deps command.

aiba avatar Jul 27 '22 13:07 aiba