New workspace
This documentation will explain how to setup a new workspace inside the monorepository.
-
Init a new project at the root. (or inside relevant folders).
-
Extend the
tsconfig.jsonwith the one at the root. In yourtsconfig.jsoncopy/paste this line:
"extends": "../../../../tsconfig.json",
It gives us access to aliases for using DTOs and libs:
"paths": {
"core/shared/dtos/*": ["core/shared/communication/dtos/*"],
"@wiotm-libs/*": ["core/shared/*"]
}
- Delete this line (still in your
tsconfig.json):
"baseUrl": "./"
⚠️ As you extend another configuration and we work as a monorepo way, if you don't delete this line it will override the root configuration.
- Add the new project as a workspace of the monorepository.
In the package.json at the root (
iotmanager/) add the path to your new workspace as in following examples:
"workspaces": [
"./core/apps/*",
"./core/apps/client/*",
],
-
In your new app delete the
node_modulesdirectory and at the root of the monorepo do anpm i. Now all packages will be shared across the monorepo through thenode_modulesdirectory at the root. -
Delete the
package-lock.jsonin your app is safer. Whenever you want to update a dependency in yourpackage.json, logically you would do anpm iin this directory to update your change. If you do that: as the workspace itself have no notions of the monorepository it is going to install all thenodes_modulesin this directory and that's not the goal of monorepo. So instead, you go to the root and do thatnpm ito upgrade the package. But, if you don't have deleted thepackage-lock.jsonof your new app before, it will only take in account this one and will not upgrade anything. Onlypackage-lock.jsonof monorepo root is useful. -
Finally, get rids of duplicates configurations that you can find on your tsconfig.json. As we extends the one at the root it is not necessary to have it both times.