npm install forked git with submodule

2019-04-21 12:41发布

问题:

I'm trying to get npm to install node-gitteh as a dependency via npm install which reads from package.json. Unfortunately this npm package is broken in node 0.6.x, but no problem as there's a forked repo that fixes the issues (https://github.com/hughsk/node-gitteh.git).

Now the issue is that this forked repo has a submodule, so if I try to download the tar from github in the package.json:

, "dependencies" : {
    "gitteh" : "https://github.com/hughsk/node-gitteh/tarball/master"
}

I get an error that equates to "submodule folder not found". If I clone the same repo manually and do a recursive submodule update and an npm install from the node-gitteh folder, it works fine, but I can't figure out how to get npm to do this.

回答1:

I've had the same problem and so far have just relied on cloning my module into node_modules and doing a submodule update manually. It would be nice to have npm handle this automatically.

In package.json there's a scripts field (see npm docs) So could do

"scripts":{"preinstall": "git submodule update -i -r"}

See https://github.com/isaacs/octave-test for an example of this.



回答2:

According to the docs, you need to supply the git url in a special format. Also, it needs to point to git repo (same address you would use for git clone), not the tarball provided by github.

In your case (git over https), it would be:

, "dependencies" : {
  "gitteh" : "git+https://github.com/hughsk/node-gitteh"
}

Using this, npm will default to the master branch.