I'm trying to publish one (yarn) workspace from a monorepo to npm repository, and include root project's dependencies in the published package. The setup is as follows:
- package.json (contains shared dependencies, eg. single version of React to be used by all workspaces)
- library/ (this is the one I want to publish, for consumption outside of this monorepo, the published package.json should contain the root dependencies as well as library local)
- library/package.json (contains library specific dependencies)
- app1/ (application that uses library)
- app1/package.json (contains app local dependencies, and depends on library)
- app2/ (application that uses library)
- app2/package.json (contains app local dependencies, and depends on library)
So what I want to do, is to cd library and yarn publish. What I expect to happen is that the published package will work exactly the same way it works for my monorepo local apps. The problem is that yarn doesn't merge-in the dependencies from the monorepo's root package.json, and the published package's package.json only contains library local dependencies, from library/package.json. So when anyone installs this published library package, it will be broken because it imports modules from packages (dependencies) not listed in library/package.json.
Do I really need to write a custom publishing shell script that merges the root package.json's dependencies into library/package.json before running yarn publish?