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:
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
If you are using npm , you need to run npm dedupe . If the installer cannot find a common version, then you will need to specify which version should be used. In your package. json add a resolutions field to specify the dependency and the version that should used.
NPM installs devDependencies within the package. json file. The 'npm install' command should add all the dependencies and devDependencies automatically during installation.
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
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] ] );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With