Here are some development notes that may be useful to you if you decide to contribute to the project.
No examples in workspaces
The LeanJs monorepo has different workspaces; as you can see here, the examples folder is not one of them. The reason is that when we install dependencies at the root of the monorepo it could take a lot of time if there are a lot of workspaces with many different dependencies, which slows down CI, our local dev, etc. When we run yarn in the root directory, yarn installs the dependencies, and if a local package depends on some LeanJS package (e.g. e2e/test-subjects/package-leanjs-react-18) then yarn will create a symlink in the node_modules to the local LeanJS package.
Experimenting with packages
If you want to experiment with some LeanJS packages by making changes and running them in an app, the easiest way is to use any of the e2e/test-subjects apps because they are part of the workspaces. This is what I normally do. Heads up! because we export the output of the build in the dist folder, we need to run yarn build in the LeanJS package that you are changing so you can use those changes in the e2e test app.
If you want to make changes in a LeanJS package and use that in an example folder, then you have to create a symlink to replicate the above functionality. You have two options of that:
In my experience using yarn link I had sometimes issues when a linked dependency had a dependency on another package that was also local and it was also linked, e.g. @leanjs/react depends on @leanjs/core. So I prefer to use yalc which has worked always fine for me. Bear in mind that in either case, yarn link or yalc, you’ll have to do yarn build every time that you make changes in the local @leanjs package to be able to execute those changes in your “linked” app.
yarn global add yalc
- if you want experiment with the vue-router package:
- make your changes, then build and publish the package @leanjs/vue-router locally in a local store in the folder ~/.yalc/
- now to use this local package in our dependant example (eg. the coolest-todos)
- install the local package in the example
yalc add @firstname.lastname@example.org
- add yalc local repo in workspaces
NOTE form yalc documentation:
using yarn workspaces, --pure option will be used by default, so package.json and modules folder will not be touched. Then you add yalc'ed package folder to workspaces in package.json (you may just add .yalc/ and .yalc/@/* patterns). While update (or push) operation, packages content will be updated automatically and yarn will care about everything else. If you want to override default pure behavior use --no-pure flag.
.yalc/@*/* as workpackages in the example root package.json
- so, run the example
- when you're done to roll back the changes yalc made, remove all installed packages from yalc
yalc remove --all
- remove previously added yalc repo from workspaces
When working on a monorepo, the peerDependencies should point to an asterisk (*) as version in each package except the root package. Then we can bump a given dependency in all the packages by changing the version in one place. This is an implementation of something called single-version policy, which is something most monorepo tools recommend. All the packages in the monorepo use the same version. This is to avoid a dependency hell.