shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
ghaskins 2021-06-09T12:53:45.423800Z

Hello all: im struggling to figure out how/when shadow-cljs may or may not automatically invoke npm install

ghaskins 2021-06-09T12:54:08.424400Z

i have two projects and I cant spy a difference in their config, yet one will implicitly install npm deps and the other doesnt

ghaskins 2021-06-09T12:54:40.424700Z

in the one that works, I observe this last line in the output

ghaskins 2021-06-09T12:54:42.425Z

$ lein dev
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
shadow-cljs - config: /Users/ghaskins/sandbox/git/mcp-login-ui/shadow-cljs.edn
shadow-cljs - running: lein run -m shadow.cljs.devtools.cli --npm watch app
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
running: npm install --no-save path@^0.12.7 chart.js@^2.9.4 react-chartjs-2@^2.11.1 react-sparklines@^1.7.0 react-password-strometer@^0.1.18 base64url@^3.0.1

ghaskins 2021-06-09T12:55:26.425500Z

I do not get that in the project that doesnt work…in that project, manually running npm install fixes it

ghaskins 2021-06-09T12:59:30.425800Z

im just looking for what triggers that difference in behavior

dpsutton 2021-06-09T13:58:58.426800Z

as far as I know shadow never does this. There's a lein plugin that you are likely using here that does this. To me that plugin is a mistake, making everything more complicated

ghaskins 2021-06-09T14:04:41.427700Z

That’s what I was wondering (and I agree) but I don’t seem to have a plug-in in either

ghaskins 2021-06-09T14:04:46.428Z

I’ll keep digging

dpsutton 2021-06-09T14:10:47.429400Z

in the project.clj file you should see a shadow config, and also a lein-shadow (i think this is the name) plugin. This plugin allows you to keep the config in project.clj, the aim being that everything in a single file is beneficial. It installs npm deps, copies the shadow part to the standard shadow-cljs.edn location and then runs shadow for you. I see zero benefit and only downsides

ghaskins 2021-06-09T14:13:57.429800Z

understood…i am not using lein-shadow in either project, afaict

ghaskins 2021-06-09T14:14:37.430500Z

i do use lein, but I have a distinct shadow-cljs.edn (with lein=true) and package.json for each

dpsutton 2021-06-09T14:15:00.431100Z

ah, sorry i went down the wrong path then

ghaskins 2021-06-09T14:15:02.431200Z

i cant discern what is different, but one project auto- npm-installs for me

thheller 2021-06-09T14:33:42.431800Z

@ghaskins installing npm dependencies is handled by libraries containing a deps.cljs file with :npm-deps listed

thheller 2021-06-09T14:34:47.432800Z

otherwise you can disable it in shadow-cljs.edn but thats about it. maybe the other project has older dependencies that didn't yet have deps.cljs?

thheller 2021-06-09T14:35:12.433300Z

@dpsutton shadow does install npm deps by default (for now, might make it optional at some point)

dpsutton 2021-06-09T14:35:33.433600Z

oh is that recent? or have i just totally missed it

thheller 2021-06-09T14:35:47.433900Z

no, that has been there for a very long time

dpsutton 2021-06-09T14:36:23.434700Z

huh. i could have sworn when i watch an project in the past it would fail until i killed it and npm installed the deps.

dpsutton 2021-06-09T14:36:29.435Z

oh well. sorry for the noise

thheller 2021-06-09T14:37:56.437Z

well it can only install npm deps if they are listed in deps.cljs. many libs didn't do that for a while but nowadays most do

zackteo 2021-06-09T14:39:00.437700Z

Hello, how do I do import 'leaflet/dist/leaflet.css'; from https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages I understand it should be (:require ["leaflet/dist/leaflet.css"]) ? But think I'm doing something wrong

thheller 2021-06-09T14:39:39.438300Z

@zackteo css is not supported, so you need to handle it separately. might be enough to just copy the node_modules/leaflet/dist/leaflet.css to your public folder and include it

zackteo 2021-06-09T14:40:45.438700Z

Right, how might I want to handle it actually?

thheller 2021-06-09T14:41:32.439600Z

really depends on what kind of css setup you have. if you don't have one then the manual copy is probably good enough. if you have something like postcss setup just use that.

zackteo 2021-06-09T14:44:06.440200Z

hmm okay will try

zackteo 2021-06-09T14:44:10.440400Z

thanks!

ghaskins 2021-06-09T15:29:14.441800Z

> installing npm dependencies is handled by libraries containing a `deps.cljs` file with `:npm-deps` listed @thheller thats what I figured…what I cant reconcile atm is that both projects include the same cljs lib with a deps.edn, and then locally declare additional npm deps (such as react) in their local packages.json

ghaskins 2021-06-09T15:29:35.442300Z

but for reasons I am still unsure about, one project implicitly runs npm install and the other does not

ghaskins 2021-06-09T15:29:51.442700Z

im sure i have some difference I am not yet seeing

ghaskins 2021-06-09T15:29:57.442900Z

ill keep digging

ghaskins 2021-06-09T15:30:27.443600Z

i just wasnt sure if there was something to look for, like “oh, check :foo-bar in shadow-cljs.edn”

thheller 2021-06-09T15:32:19.444300Z

@ghaskins shadow never runs an inital npm install for stuff listed in your package.json. that you have to do yourself

thheller 2021-06-09T15:32:46.444900Z

shadow will only install npm deps that aren't already listed in package.json, so if you have those in them but did not run npm install then they won't be installed

ghaskins 2021-06-09T15:33:03.445300Z

ah, that might be the hint I needed

ghaskins 2021-06-09T15:33:22.446Z

i think I know what is wrong, now

ghaskins 2021-06-09T15:33:23.446200Z

ty

ghaskins 2021-06-09T15:33:26.446500Z

ill report back

thheller 2021-06-09T15:33:32.446600Z

basically the deps.cljs install is just a way to get missing things into your package.json

ghaskins 2021-06-09T15:33:58.447400Z

yeah…the project that isnt working had previously been run with the defaults that creates packages-lock

thheller 2021-06-09T15:34:03.447800Z

but yeah one npm install you'll need at least

ghaskins 2021-06-09T15:34:26.448500Z

so the one that isnt working has a complete packages.json

ghaskins 2021-06-09T15:34:53.448900Z

where “isnt working” is probably functionally correct

ghaskins 2021-06-09T15:35:28.450Z

i.e. the project that runs npm install has inadvertent novelty in the dep

thheller 2021-06-09T15:35:28.450100Z

yeah unlike maven deps just listing the deps is not enough, need to actually run npm to install them

ghaskins 2021-06-09T15:36:30.450400Z

ty, this is very helpful