Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from git repo subfolder

I have a repo with various components and I want to be able to include the components as individual dependencies (but I don't want to create a repo per component).

Is it a way to use a subfolder of a github repo as the path for a dependency in npm ? (that will not involve creating separate branches per component)

Something like

dropdown: git+https://[email protected]/me/mycomponents.git/components/dropdown

like image 531
Avraam Mavridis Avatar asked Mar 22 '16 11:03

Avraam Mavridis


1 Answers

You kinda can.

Since version 1.7.0 git supports sparse checkouts, which is exactly what you want. Unfortunately npm doesn't have anything in set to support it, so you have to do it manually. Given you want to add Node/core from BotBuilder, add this to your package.json:

"scripts": {
  "postinstall": "mkdir BotBuilder; cd BotBuilder; git init; git remote add -f origin https://github.com/Microsoft/BotBuilder.git; git config core.sparseCheckout true; echo \"Node/core\" >> .git/info/sparse-checkout; git pull --depth=1 origin master; cd ..; npm i ./BotBuilder/Node/core/"
}
like image 167
Pedro Nascimento Avatar answered Nov 17 '22 18:11

Pedro Nascimento