reHi!
Here's the deal, we have a monorepo. We're using Lerna & Yarn with a bunch of Angular Libraries.
In every package.json for the packages/libraries, we have something like:
"prepublishOnly": "yarn build <library name goes here>"
The way Yarn works for workspaces is yarn install, does what it does. Because we use workspaces, it creates symlinks to the packages. For example, if we have a package called @foo/bar, in the top-level node_modules, we would have node_modules/@foo/bar be a symlink to libs/foo-bar.
Yarn Workspaces is all fine and dandy, except the stuff in node_modules/@foo/bar isn't ready to be published. First, we need to build the package using Angular CLI's compiler.
We accomplish that with the already mentioned prepublishOnly script in package.json.
What works is when all the packages need are to be built. The flow goes:
yarn install- Does the symlink/workspace magic.lerna publish --contents dist- Does the monorepo magic. Lerna will see that all the packages have had modifications, and run theprepublishOnlyacross all the packages. This way, what's innode_modules/@foowill be "legit" NPM packages (the output of Angular CLI building the libraries)
The problem is when a single library has a modification.
yarn install- Does the symlink/workspace magic. All the things innode_modules/@foowill be symlinks tolibs/<package-name>which, at this point, are source files. Not NPM packageslerna publish --contents dist- Starts... and goes "Oh, only Package A has changed. So let me run against it." Lerna will fail due to the other packages insidenode_modulesNOT being legit NPM packages.
I need to figure out how to either:
- Always build all the packages when doing a publish OR
- Somehow use packages from the NPM registry during the build process
I feel like I'm missing something simple somewhere.
If there are examples I can give to help explain, please ask.