Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install npm dependencies automatically #28

Open
cburgmer opened this issue Jul 23, 2015 · 9 comments
Open

Install npm dependencies automatically #28

cburgmer opened this issue Jul 23, 2015 · 9 comments

Comments

@cburgmer
Copy link
Contributor

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.

@RyanMcG
Copy link
Owner

RyanMcG commented Jul 23, 2015

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
Copy link
Owner

RyanMcG commented Jul 25, 2015

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
Copy link
Owner

RyanMcG commented Jul 25, 2015

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

@cburgmer
Copy link
Contributor Author

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 cburgmer/buildviz@2dce14a, 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
Copy link
Contributor Author

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.

@RyanMcG
Copy link
Owner

RyanMcG commented Jul 26, 2015

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.

@pupeno
Copy link

pupeno commented Sep 22, 2015

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.

@RyanMcG
Copy link
Owner

RyanMcG commented Sep 23, 2015

@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.

@pupeno
Copy link

pupeno commented Sep 23, 2015

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"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants