lein-npm icon indicating copy to clipboard operation
lein-npm copied to clipboard

Install npm dependencies automatically

Open cburgmer opened this issue 9 years ago • 9 comments

Is there a way to configure lein-npm to automagically install npm dependencies when running lein?

As stated in the "Clean code" book, there should be only one command to run the build. It would be nice if projects could include npm deps in their bootstrapping.

cburgmer avatar Jul 23 '15 15:07 cburgmer

What command are you running that you expect the hook to run on? It should already run lein npm install for lein run and lein deps. Generally, I think the deps hook is the only necessary one. We should fetch npm dependencies whenever leiningen would fetch other dependencies.

I'm not confident in this behaviour working perfectly, although I believe that is the intention.

RyanMcG avatar Jul 23 '15 21:07 RyanMcG

After looking into this some more it seems like we may be able to insert npm/install-depdencies at some lower-level points to do what you are hoping. I'm not sure how to do this yet though. A pull-request would be very welcome. :) I can help with ideas too.

RyanMcG avatar Jul 25 '15 19:07 RyanMcG

This hook exists right now, if you run deps or run, but not repl.

RyanMcG avatar Jul 25 '15 19:07 RyanMcG

Thanks for looking into this.

I have issues upgrading to 0.6.0, it looks like :npm { :root "..." } does not work anymore (the previous :npm-root). I pushed this (broken change) into https://github.com/cburgmer/buildviz/commit/2dce14a873ba52badd023b23454f9318a935a37f, I'll try to investigate.

npm deps installs node_modules, so this works, also lein ring uberjar. However it does not run on lein ring server-headless. I might need to dig in deeper to understand the different cycles for lein.

cburgmer avatar Jul 26 '15 10:07 cburgmer

Jumping a bit through the leiningen code it looks like dependencies are loaded via leiningen.core.classpath/resolve-dependencies. Even the deps command relies on it.

lein-npm seems to hook into leiningen.deps/deps, but I can't find any direct invocations of that in leiningen itself.

cburgmer avatar Jul 26 '15 16:07 cburgmer

Yeah, the only invocation of leiningen.deps/deps that I am aware of is when it is dispatched to via running lein deps on the command line.

When I changed the hook to be on resolve-depdencies it worked but the hook ran many times. I suppose I could continue using my only-execute-once hack.

RyanMcG avatar Jul 26 '15 18:07 RyanMcG

I am having this problem. Heroku run lein uberjar to build the project and the node modules are not being fetched. Running lein uberjar on my own machine has the same effect.

pupeno avatar Sep 22 '15 16:09 pupeno

@pupeno coudn't you just run lein npm install followed by lein uberjar? Even if you do run lein npm install first, I'm not sure the node_modules directory would make it into an uberjar.

RyanMcG avatar Sep 23 '15 00:09 RyanMcG

I don't need node_modules to be inside the uberjar, I just need it present in the server's copy of the sources. I don't know if Heroku allows me to run a custom command before lein uberjar. If it does, it's far from obvious. I ended up adding this to my uberjar: :prep-tasks ["deps" "javac" "compile"]

pupeno avatar Sep 23 '15 09:09 pupeno