8

I've run into this scenario quite a few times and still haven't found the answer. I'm starting a new Node.js project, and this project will be dependent on some other libraries. For sake of argument, let's say that some are purely JS libraries that could be added as git submodules in the new project, but some have pieces that need some extra effort (such as system dependencies that npm installs, or C libraries that must be compiled).

What's the best way to start this project and add it to git, with the following two requirements:

  • Other people's libraries aren't committed to our own repo, and are instead submodules or are pulled in dynamically and installed by npm.
  • Not needing to have a big list of instructions that have to be followed just to clone the repo and have a working environment. Running git submodules update --init --recursive is fine, running an npm command to read package.json and install the dependencies is fine (does such a command exist?), but forcing everyone to run through an "npm install __" of every single dependency isn't ok, and I'd rather not use 'make' or 'ant' to do that if I don't have to.

Any thoughts of the best way to do this? It seems like such a simple, basic thing, but I couldn't find a single example of what I'm trying to do.

Edit: Grammar

1
  • By the way, you can use git clone --recursive ... foo which is the same as git clone ... foo && cd foo && git submodule update --init --recursive Commented Dec 26, 2012 at 10:24

1 Answer 1

10

edit Ignore below, but left for reference. Sometimes I don't think clearly in the morning :)

make a package.json file, add your dependencies and your install simply becomes:

npm install

from your project directory. git ignore all the added projects.


npm submodule foo

It installs the packages into node_modules via git submodule so github, etc will recognize that they're link. This works whenever the npm package has a git URI included. Unfortunately a good number don't, so you're out of luck on those.

Also, note that when you do this, npm won't work on the module any longer, e.g. you can't update via npm, you have to do it via git


Or you could just do something like:

./modules.js

modules.exports = [ '[email protected]', '[email protected]', '[email protected]' ];

./make

#!/usr/bin/env node
var modules = require( './modules' )
  ,   spawn = require('child_process').spawn;

for( var i=0, l=modules.length; i<l; i++ ){
    spawn( 'npm', [ 'install', modules[i] ] );
}
Sign up to request clarification or add additional context in comments.

2 Comments

Sheezus -- it seems so silly that I didn't know about 'npm install' with no arguments! That's exactly what I needed... though your custom solution is pretty slick as well! Thanks for the assist :).
Thanks for not removing your original anwser, it was just what I needed. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.