- 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
-
Open the
project.json
files 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-many
allows you run a specific target against a specific set of projects via the--projects=[..]
option. However, you can also pass it the--all
option to run that target against all projects in your workspace.💡
--parallel
launches all thelint
processes 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/header/header.tsx
- Try toimport { StoreFeatureGameDetail } 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
store
lib from anapi
scope. - Inapps/api/src/main.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.
💡 Pass the suggested --only-failed
option, so it doesn't relint everything.
- Commit everything before moving on to the next lab
🎓 If you get stuck, check out the solution