codereviewanskquestions
codereviewanskquestions

Reputation: 13998

npm install update git submodule

I have a Node JS lib with git submodule. When I clone the git repository of my lib, I had to do submodule update --init --recursive something like this to pull the actual stuff from the submodule. After I released the lib and I did npm install my-lib and noticed it's not pulling the git submodule. How do I configure it so it pulls the git submodule? is that even possible?

Upvotes: 0

Views: 7068

Answers (2)

Norman Pellet
Norman Pellet

Reputation: 414

Indeed, there's not git environment that's installed with npm i, but you could be explicit and in the scripts entry of package.json, add:

 "scripts": {
    "preinstall": "git init && git submodule add -f YOUR_REPO_URL LOCAL_PATH"
  }

Edit: That's however not the best option, because you won't be install to re-install your package. Prefer a simple git clone.

Upvotes: 0

pixeldesu
pixeldesu

Reputation: 642

I don't think that is possible, as the submodule is, outside of git, just a simple file.

What you can do, however, is using the submodule only in development, compile your library and publish the compiled version in a dist/ folder inside the package.

Then just point main in the package.json to the compiled library script and you can include it in your other projects.

Upvotes: 1

Related Questions