Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install package from github repo subfolder

Tags:

git

github

npm

Is it possible to install npm package from github when the package located inside subfolder?

For example, we have Microsoft BotBuilder repository: https://github.com/Microsoft/BotBuilder

But I need to install package inside subfolder "Node/core/": https://github.com/Microsoft/BotBuilder/tree/master/Node/core/

So how can I install it with npm?

like image 995
Ceridan Avatar asked Aug 28 '16 18:08

Ceridan


People also ask

How do I add a Git repo to a NPM package?

To npm install a public project that is hosted on Github, and not the NPM registry, add the Github repo to package. json dependencies using the username/repo#branch-name format. Run npm install and npm will download the project and save it into your /node_modules/ folder.

Does npm install sub dependencies?

By default, npm install will install all modules listed as dependencies in package. json .

How do I push a subfolder to GitHub?

move everything from the subdirectory of the parent repo work tree to the child repo work tree. commit the child repo. replace the subdirectory in the parent repo with a submodule reference.


2 Answers

Add to 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/"   ... }, ... 

postinstall script is running after the package is installed.

And step by step:

  1. Make folder to clone repo: mkdir BotBuilder
  2. enter to the folder: cd BotBuilder
  3. init git repo: git init
  4. set git origin to Microsoft/BotBuilder repo: git remote add -f origin https://github.com/Microsoft/BotBuilder.git
  5. enable sparse checkout: git config core.sparseCheckout true
  6. add Node/core to checkout list: echo "Node/core" >> .git/info/sparse-checkout
  7. pull part of repo: git pull --depth=1 origin master
  8. enter to Your app folder: cd ..
  9. install BotBuilder: npm i ./BotBuilder/Node/core/
like image 92
Tomasz Jakub Rup Avatar answered Sep 17 '22 18:09

Tomasz Jakub Rup


Paste the github link to the subfolder into gitpkg. You can then use this along with yarn or npm to install the package from a github sub folder.

https://gitpkg.now.sh/

like image 24
MrBlenny Avatar answered Sep 21 '22 18:09

MrBlenny