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?
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.
By default, npm install will install all modules listed as dependencies in package. json .
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.
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:
mkdir BotBuilder cd BotBuilder git init git remote add -f origin https://github.com/Microsoft/BotBuilder.git git config core.sparseCheckout true Node/core to checkout list: echo "Node/core" >> .git/info/sparse-checkout git pull --depth=1 origin master cd .. npm i ./BotBuilder/Node/core/ 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With