Important
In this pnpm monorepo, we imported a remote package through git submodule without the need of publishing/installing it through a package registry like npm!
Project structure:
+ root (pnpm monorepo)
+ apps
+ packages
+ (git submodule)
Accompanying blog: https://boda.sh/blog/pnpm-workspace-git-submodules/
Isn't this just git clone and build a package yourself?
Sort of, with the super power and convenience of pnpm monorepo features.
As long as we have access to the source code of the dependency, we can build and import the library however we like, but
I do believe managing them as part of a pnpm monorepo will make a smoother experience than manual duct tape solutions.
What are the tradeoffs?
This blog article explains it, but tldr: this setup is ideal for repos where you can modify and use pnpm with.
After updating the nested git submodule content, we can perform git updates in the remote repo directly by cd into the nested folder:
cd packages/<git-submodule-folder>
# perform git commands as normal
git add .
git commit -m "update"
git pushNow, to sync the submodule from the root folder, do:
cd ../../
git submodule update --remote
# commit as normal