How to install bower component with git submodules as a dependency? - npm

I have a library which requires 2 dependencies to exist in the "vendor" directory. This library has these 2 dependencies installed as git submodules on Github, so to install my library from a Git clone you would do:
git clone --recursive https://github.com/MYLIBRARY.git
And to install it as another Git submodule, you would do:
git submodule add https://github.com/MYLIBRARY.git && git submodule update --init --recursive
The issue comes when trying to install it with Bower, as the Git submodules do not get downloaded with the bower package (the dependency folders exist, but are empty). The 2 dependencies exist separately on bower, but as they are required to be in the "vendor" directory of the main library, I cannot include them as bower dependencies. I also can't assume that any project installing my library will be a Git repo, so I can't do something like:
bower install MYLIBRARY && git submodule update --init --recursive
Which would work if the parent project you installed my library in was a Git repo, but would error if not.
I'm worried I may have to have an instruction similar to:
bower install MYLIBRARY && cd bower_componets/MYLIBRARY && git clone https://github.com/DEPENDENCY1.git vendor/DEPENDENCY1 && git clone https://github.com/DEPENDENCY2.git vendor/DEPENDENCY2
This can be tidied slightly by adding an npm run script in package.json:
"scripts": {
"bower_vendor": "git clone https://github.com/DEPENDENCY1.git vendor/DEPENDENCY1 && git clone https://github.com/DEPENDENCY2.git vendor/DEPENDENCY2"
}
Then the installation instruction would become:
bower install MYLIBRARY && cd bower_componets/MYLIBRARY && npm run bower_vendor
Which is a little neater, but again wouldn't work if the user has customised their bower_components directory (which is simple enough to change in the above command, but is still another concern).
I'm hoping I've just missed something somewhere which will solve my issue. I read that bower performs a git clone of the repo, so if there was a way to get it to perform git clone --recursive that would be amazing.
Thanks

Related

npm publish: with tag and kind?

We have a storybook / react component library, we have a master branch which is being published like so: make publish kind=patch
The Makefile command which works as expected:
.PHONY: publish
publish:
npm version $(kind)
tsc && cp ./package.json ./dist
(cd dist; npm publish) && rm -fr ./dist
git push && git push --tags
This takes the patch, applies a version then compiles to ./dist, and publishes, then deletes ./dist, pushes the git commit and git tags... great...
But we have a new development branch that needs to be published as well, how do you tag or label the development version without interfering with the master branch?

npm install not installing the packages on a git repo clone. (giving no-replace-object and cannot store pack file error)

trying to clone a git repo which has several npm dependencies, but it is failing with a pack error.enter image description here

How to get the sources of a npm package locally when developing?

I am very new to node and npm and I am wondering if it is possible to work on a application, but also work on a local git repository for some node modules.
Let's say I am starting a new project that uses chalk and I would like to develop both on my project and on chalk.
mkdir my-project && cd my-project
npm install
npm install --save chalk/chalk
With the above command I will the source of chalk into node_modules but I cannot contribute to it.
Is there a way to directly get the Git repository?
Asumming '~/projects' is your projects folder, first clone chalk:
cd ~/projects
git clone https://github.com/chalk/chalk.git
Then create your project:
mkdir my-project && cd my-project
npm init
And set your project to use your local chalk. Look for package.json file inside my-project and include chalk in dependencies:
"dependencies": {
"chalk": "file:../chalk"
....
....
Then install chalk in your project:
cd ~/my-project
npm install chalk
Or simply 'npm install' to install all your dependencies. Every time you need to include in your project changes you made on chalk type again 'npm install chalk'. It copies ~/chalk on ~/my-project/node_modules and uses it.
You can continue working on your project and on chalk.

Git dependency with npm keeping .git files

I am using a private GIT repository as dependency in npm:
"name": "git+ssh://git#git.domain.com:user/repo.git"
This is working and clones the repository inside node_modules when I do npm install.
The matter is it deletes .git folder and .gitignore file. I want to keep those file (to do commits later) ¿How to keep those files?
It's better to use npm link ../path-to-local-git after you git clone your dependency repo.
git clone <repo>
cd PROJECT
npm link ../<repo>
and you see the build process run.
It sounds like you would be better served keeping a local checkout of the project and specifying the dependency with a local path.
cd ..
git clone ssh://git#git.domain.com:user/repo.git
cd repo; npm install
cd ../PROJECT
npm i --save ../repo
That way you can make changes and commit them back.
npm treats the contents of node_modules as private, so you should not expect to be able to get into the node_modules directory and do anything useful. If you want to maintain a git checkout of a project which is a dependency, then do that, but don't combine it with the dependency-management that npm does.
Also check out npm link if the dependency is itself a npm-compatible package. https://docs.npmjs.com/cli/install

NPM dependency is not creating git submodule

I'm running grunt.js. One of its dependencies is node-jshint which has the actual jshint files added as a submodule. (I'm using my own fork of node-jshint so that I can do some modifications to the jshint source).
If you npm install in grunt, it'll install node-jshint and it will also build the jshint submodule.
However, my package.json file is pointing to the url of my node-jshint fork rather than the npm version, and the jshint submodule never gets created.
It seems like when npm grabs dependencies normally, it's internally running git submodule update, but when it grabs dependencies via a URL, it never runs that command.
Is there anyway to force npm to run git submodule update when it install a dependency, like via package.json?