npm install package from github repo subfolder

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/

Leave a Comment