- 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
nx.json
and finish tagging the apps accordingly:"projects": { "store": { "tags": ["scope:store", "type:app"] }, .... <-- fill in the rest of the tags }
-
Open the root
.eslintrc.json
, find the"@nrwl/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/store-ui-shared.module.ts
- Try to
import { StoreFeatureGameDetailModule } from '@bg-hoard/store/feature-game-detail';
- In
-
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.- In
apps/api/src/app/app.service.ts
- Try to
import { formatRating } from '@bg-hoard/store/util-formatters';
- In
-
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