Setup a CoSpace
to link multiple (mono)repos together!
-
Install
create-cospace
, then runnpx cospace init
-
Clone all the repos you want to link together under the
repos
directory. You can use sparse checkouts to only clone the directories you need. -
Update the pnpm-workspace.yaml file with all the packages you want to add to your CoSpace.
-
Update the cospace.code-workspace file with all the repos you want to add to your VsCode multi root workspace.
-
(Optional) Run
pnpm setOverrides
to automatically update thepnpm.overrides
section of the CoSpace's package.json, to use the local package version from the workspace, disregarding semver. Useful for when you have pre-release versions of packages in your workspace. -
Run
pnpm install
to install all the packages you've added to your CoSpace. -
Run
pnpm build
to build all the packages you've added to your CoSpace using your monorepo task runner. I'm using lage, but turborepo should theoretically work.
git clone --filter=blob:none --no-checkout {repo}
cd {repo}
git checkout {branchName}
git sparse-checkout init --cone
git sparse-checkout set [...allSubDirs]
-
"If you need local packages to also be linked to subdependencies, you can use the
deep
setting""pnpm": { "link-workspace-packages": "deep" }
-
pros: don't have to explicitly list all packages in the
pnpm.overrides
section. -
cons: if you're linking a repo with HEAD pointing to pre-release packages, those won't be used/linked due to semver 😕
"pnpm": { "prefer-workspace-packages": true }