Given a repo using yarn workspace and lerna. This workspace have two packages main-pack and sub-pack. The main-pack does reference sub-pack. I want to fork it and publish a patch on npm under my organisation name (ex: @myorg/main-pack and @myorg/sub-pack).
- I want to avoid having my @myorg/main-pack referencing the official sub-pack.
- I want to minimize code change and for example, I want the typescript files in main-pack to still import sub-pack and avoid changing them to @myorg/sub-pack.
I feel like I am missing something and it should be easy to patch and publish multiple packages with yarn workspace. Maybe something with Lerna or a special publish step?
I tried the npm alias "sub-pack": "npm:@myorg/sub-pack@*" but it seems to be conflicting with yarn workspace which usually expect "sub-pack": "*" as a workspace reference.
You should try with Yarn/pnpm
workspace:*protocol, when used, it will enforce the use of local code instead of trying to fetch it from npm (which is what*would do). I'm pretty sure that protocol was invented to solve issues similar to yours. For example take a look at pnpmworkspace:protocol docs. I just wrote 2min ago a similar answer in this other SO question, the question is different but the answer would be similar. This protocol is also supported by both newer versions of Lerna & Lerna-Lite (the latter is preferred if you're not using Nx, however if you are using Nx then probably best to stick with Lerna)