๐ก Lab 12 - Module boundaries
June 1, 2023 ยท View on GitHub
โฐ Estimated time: 10-15 minutes
๐ Learning outcomes:
- Understand how to assign scopes and type tags to your libraries
- How to specify boundaries around your tags and avoid circular dependencies in your repo
- How to use linting to trigger warnings or errors when you are not respecting these boundaries
๐๏ธโโ๏ธ Steps :
-
Open the
project.jsonfiles for each project and finish tagging the apps accordingly:// apps/store/project.json { "projectType": "application", "root": "apps/store", "sourceRoot": "apps/store/src", "prefix": "bg-hoard", "targets": { ... }, "tags": ["scope:store", "type:app"] } -
Open the root
.eslintrc.json, find the"@nx/enforce-module-boundaries"rule and set thedepConstraints:"depConstraints": [ { "sourceTag": "scope:store", "onlyDependOnLibsWithTags": ["scope:store", "scope:shared"] }, .... <-- finish adding constraints for the tags we defined in the previous step ] -
Run
nx run-many --target=lint --all --parallel๐ก
nx run-manyallows you run a specific target against a specific set of projects via the--projects=[..]option. However, you can also pass it the--alloption to run that target against all projects in your workspace.๐ก
--parallellaunches all thelintprocesses in parallel -
We talked about how importing a Feature lib should not be allowed from a UI lib. Let's test our lint rules by doing just that: - In
libs/store/ui-shared/src/lib/store-ui-shared.module.ts- Try toimport { StoreFeatureGameDetailModule } from '@bg-hoard/store/feature-game-detail'; -
Run linting against all the projects again.
-
You should see the expected error. Great! You can now delete the import above.
-
We also talked about the importance of setting boundaries between your workspace scopes. Let's try and import a
storelib from anapiscope. - Inapps/api/src/app/app.service.ts- Try toimport { formatRating } from '@bg-hoard/store/util-formatters'; -
Run linting on all projects - you should see another expected error.
-
You can now delete the import above.
-
Run linting again and check if all the errors went away.
-
Commit everything before moving on to the next lab
๐If you get stuck, check out the solution