DEV Community

Ivan Starkov
Ivan Starkov

Posted on

Local Development with Public and Private monorepos

In the project I'm working on now webstudio.is, we have 2 mono repositories.

One open and fully public and one closed source.

Projects from the closed repository use libraries from the open one.

So usually working on a closed repository looks like this

  • we publish libraries from public repository into npm
  • we update libraries in a closed repository pnpm up -r -L '@webstudio-is/*'

Local development becomes terribly messy with this approach.
Each iteration takes an awful lot of time (15 minutes to 30 minutes on average).
Create PR wait for all checks to be done, wait for all checks to be done and publish.

To avoid all this I tried.

Link protocol

in package.json of the closed packages I replaced all

"dependency": {
  "@webstudio-is/form-handlers": "^0.75.0",
  ...
}
Enter fullscreen mode Exit fullscreen mode

to

"dependency": {
  "@webstudio-is/form-handlers": "link:/Users/User/webstudio-is/webstudio-builder/packages/form-handlers",
  ...
}
Enter fullscreen mode Exit fullscreen mode

This worked for some of the packages in the closed repository. But some packages got runtime errors like TypeError: Cannot read properties of null (reading 'useContext').
It seemed like some dependencies were duplicated and I didn't manage to get rid of this error.

Soft link packages from one monorepo into another

I plugged the open repository as a workspace into a closed repo. ln -s /Users/ice/webstudio-is/webstudio-designer/packages packages and added into workspaces. The result is the same as with 1.

I guess it's possible to fix it but I failed.

Verdaccio

Valentin Semirulnik gave me an idea to use verdaccio
The idea to use private proxy registry for local development

And it worked.

Briefly how I use it.
Everytime I need to check how an open library will work with a closed one, I do.

# Run verdaccio locally
verdaccio
# build all libs
pnpm run build
# change version of all public libraries from current to exprimental like "0.75.0" => "0.75.1-qawqisps.0" etc
pnpm -r exec pnpm version prepatch --preid $(cat /dev/urandom | LC_ALL=C tr -dc 'a-z' | fold -w 8 | head -n 1)
# Publish all to verdaccio registry
pnpm -r publish --access public --no-git-checks --registry http://localhost:4873
# Reset version changes I made to package.json (DANGEROUS! as can remove changes you made)
git restore --source=$(git branch --show-current) '**/*/package.json
Enter fullscreen mode Exit fullscreen mode

And now in a closed project I can just run

pnpm up -r -L '@webstudio-is/*' --registry http://localhost:4873
Enter fullscreen mode Exit fullscreen mode

Now it takes me 1-2 minutes to check something. This is still a lot but I have not found a better solution.

Top comments (0)