Add support for mono-repos by specify packages as scoped #2082
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expected Behavior
I would expect to put the boilerplate in a yarn workspace, add another package in the workspace that requires babel compilation, and require that second package in the boilerplate package. Running
yarn dev
or packaging the component should properly build run the package.Current Behavior
Errors occur resolving dependencies from the secondary workspace package.
Steps to Reproduce (for bugs)
yarn install
in the project rootFor my example, i tried to make a simple sqlite database package. It simply consists of two files, within
packages/database/models
:Including this within
packages/electron-app/containers/App.js
asimport db from '@timing-export/database';
causes the following error in the renderer process:Now while it doesn't say what identifier is unexpected, I'm pretty sure it's the
import
statement. This all worked 100% when it didn't need babel compiling, and when I converted it to useimport
statements, the first thing that failed was the main process. By adding a config for@babel/register
to not ignore my packages:This instantly fixed my main renderer process. (
@timing-export
is the scope I put mydatabase
module under). Now my first thought was to try to accomplish the same thing in the webpack configuration.I tried setting the
exclude
to/node_modules\/(?!(@timing-export)\/?).*/
as well, but that made no effect. The next thing I tried was to remove my package as an external. That's when things really blew up. I got all kinds of errors regarding packages mydatabase
package depended on: log-outputSo then after a bit more digging, I realized not only did my other package have to be marked as not external, I also needed each and every dependency for every monorepo package to be marked as external. So that brings me to this PR.
I thought about the most non-intrusive, but simplest to implement way of getting workspaces setup, and I figured using the scoped package syntax would suffice. If any of you think of a better way to implement this, I'm all ears as I'm new to this whole monorepo/yarn workspaces mentality anyway.
My solution consists of setting up each package using a scoped name, such as
@monorepo/electron-app
and@monorepo/electron-app-dependency
. Using that logic, I scan the folders forpackage.json
files and read them in, whitelisting any scoped packages under the same scope as the electron boilerplate.If I did this all wrong in the first place, please let me know how I should have setup mono-repos with yarn workspaces. I spent hours debugging these issues having absolutely no direction.