lein-npm
lein-npm copied to clipboard
Install npm dependencies automatically
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.
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.
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.
This hook exists right now, if you run deps
or run
, but not repl
.
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.
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.
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.
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 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.
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"]