npm install package from github repo subfolder
Solution 1:
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:
- Make folder to clone repo:
mkdir BotBuilder
- enter to the folder:
cd BotBuilder
- init git repo:
git init
- set git origin to Microsoft/BotBuilder repo:
git remote add -f origin https://github.com/Microsoft/BotBuilder.git
- enable sparse checkout:
git config core.sparseCheckout true
- add
Node/core
to checkout list:echo "Node/core" >> .git/info/sparse-checkout
- pull part of repo:
git pull --depth=1 origin master
- enter to Your app folder:
cd ..
- install BotBuilder:
npm i ./BotBuilder/Node/core/
Solution 2:
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/
Solution 3:
If the package source is hosted on GitHub, you can use GitPkg like this:
# using npm:
npm install https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
# using yarn:
yarn add https://gitpkg.now.sh/<user>/<project>/<subdir>?<commit-ish>
For your particular case, the URL would be this:
https://gitpkg.now.sh/Microsoft/BotBuilder/Node/core?master
There is a nice wizard-like form at their site that helps build the URL, and the command to install it.