Reputation: 20394
How can I update non-npm-package git-submodules in my npm package before install?
I'm using git and have a node.js module that depends on an external project also hosted in a git repository. I added the external project as a submodule and now I'm trying to make an npm package.
Since the external dependency is not an npm package (nor a node module), I think I can't use npm submodule
command, so I came up with this preinstall script in package.json
file:
"scripts": { "preinstall" : "git submodule update --init"}
When I execute npm install
in package directory, it works fine, but when I'm trying to install the package directly from my remote git repository or the tarball made with npm pack
, I get the following error:
You need to run this command from the toplevel of the working tree.
I also tried (as the error message said):
"scripts": { "preinstall" : "cd $(git rev-parse --show-toplevel) && git submodule update --init"}
This one doesn't show any errors but also doesn't update the submodule in package directory.
Any help would be appreciated.
Upvotes: 4
Views: 3450
Reputation: 11389
The npm
you download, once extracted, no longer contains the git information (no .git
directory).
So no git command will work this way, but works locally because you have the git information.
As for a solution, you may have to create a script that does what npm pack
does, but does not ignore submodules.
Not something I tried, but this script https://github.com/Kentzo/git-archive-all
may be work out of the box with something like
git-archive-all --prefix package/ module.tgz
May require some tweaks...
Upvotes: 3