@hublo/sentinel 1.7.0-alpha.13 → 1.7.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/sentinel.js +15 -12
  3. package/dist/chunk-5NBNAIFJ.js +73 -0
  4. package/dist/chunk-5NBNAIFJ.js.map +1 -0
  5. package/dist/{chunk-5I6WUD2U.js → chunk-BBNABWZ6.js} +2 -1
  6. package/dist/chunk-BBNABWZ6.js.map +1 -0
  7. package/dist/{chunk-2LLRSWG2.js → chunk-FEDI4HHE.js} +5 -5
  8. package/dist/{chunk-4YQXLPJ5.js → chunk-J2RMARWP.js} +2 -2
  9. package/dist/{chunk-J7FBC7X7.js → chunk-TA4OTQMH.js} +4046 -5453
  10. package/dist/{chunk-ZNANJEMK.js → chunk-XTBHIKFG.js} +30 -16
  11. package/dist/chunk-XTBHIKFG.js.map +1 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +5 -5
  14. package/dist/roles/code-churn/config.d.ts +59 -0
  15. package/dist/roles/code-churn/config.js +8 -0
  16. package/dist/roles/static-analysis/config.js +1 -1
  17. package/dist/roles/test/setup/jest-parity.js +2 -2
  18. package/dist/roles/test/setup/workspace-entry.js +2 -2
  19. package/dist/{validate-S5I4Z7IO.js → validate-4VTJ7GMI.js} +2 -2
  20. package/docs/code-churn-adoption.md +150 -0
  21. package/docs/typescript-traces.md +142 -14
  22. package/docs/using-sentinel.md +2 -3
  23. package/package.json +4 -4
  24. package/dist/chunk-5I6WUD2U.js.map +0 -1
  25. package/dist/chunk-TMVKYXZ3.js +0 -18
  26. package/dist/chunk-TMVKYXZ3.js.map +0 -1
  27. package/dist/chunk-ZNANJEMK.js.map +0 -1
  28. package/dist/roles/arch/config.d.ts +0 -25
  29. package/dist/roles/arch/config.js +0 -8
  30. package/docs/arch-adoption.md +0 -191
  31. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-J2RMARWP.js.map} +0 -0
  32. /package/dist/roles/{arch → code-churn}/config.js.map +0 -0
@@ -1,191 +0,0 @@
1
- # Architecture check adoption cheat sheet
2
-
3
- `sentinel --arch` checks a module against an architecture decision of its repository: which
4
- folder may import which, which names a view may not import, which calls a view may not make. Only
5
- a violation a branch ADDS to a rule at `error` fails the run: what the module had where the branch
6
- left main never does, and nothing is recorded to get there.
7
-
8
- ## Adopt a module in two steps
9
-
10
- ```bash
11
- # 1. write the module's config, its scripts and the pinned devDependency
12
- cd apps/front/host-admin
13
- npx --yes @hublo/sentinel@<version> --init --arch
14
-
15
- # 2. fetch what step 1 declared, and commit pnpm-lock.yaml with the rest
16
- pnpm install
17
- ```
18
-
19
- Nothing to choose. The repository's `sentinel.arch.json` says which decision governs this module,
20
- and `--init` writes:
21
-
22
- | File | What it holds |
23
- | ----------------- | ---------------------------------------------------------------------------------------- |
24
- | `arch.config.mjs` | `defineArch`, and in comments each rule of the decision with its level in this module |
25
- | `package.json` | the `arch`, `arch:json` and `arch:html` scripts, the nx target, `@hublo/sentinel` pinned |
26
-
27
- The shape of `static-analysis.config.mjs` and `sql.config.mjs`. An existing `arch.config.mjs` is
28
- the team's and a re-init never rewrites it. If the map applies no decision to the module, `--init`
29
- says so and writes nothing. An `arch.config.json` or `arch.baseline.json` left by an earlier beta
30
- is removed: nothing reads them any more.
31
-
32
- ## Everyday use
33
-
34
- ```bash
35
- pnpm run arch # fails on a violation this branch adds at error
36
- pnpm run arch:json # arch-report/arch.json, for a machine
37
- pnpm run arch:html # arch-report/arch.html: each rule, its decision, its status, what to do
38
- sentinel --run --arch --output markdown # arch-report/arch.md, the pull-request section
39
- sentinel --inspect --arch # the rule set, and each rule's level here
40
- ```
41
-
42
- A run prints the files per role (a role with no file usually means a path with a typo in the
43
- rule set), what it compared with, then one line per rule, then each NEW violation with its file,
44
- what it reaches and the section of the decision that forbids it:
45
-
46
- ```
47
- architecture ADR 0050: the vertical feature slice is the unit of frontend architecture 5543 files
48
- compared with origin/main at 310bfc2: only what this branch adds can fail
49
- ✗ G1 A view or route never calls a query client: fetching goes through a hook. 1 new, 4 known
50
- src/modules/contracts/components/ArchProbeG1.tsx → @tanstack/react-query#useQuery
51
- why: RFC #19934, Governance readiness, G1
52
- ✓ G2a The api layer never imports a view, not even a type. 0 new, 3 known
53
- ```
54
-
55
- ## Compared with where the branch left main
56
-
57
- The module is analysed twice: on the branch (the working tree, uncommitted files included) and at
58
- the merge base, read from git without touching the checkout. The base is `NX_BASE` in CI and
59
- `origin/main` elsewhere, as for the sql role. When git cannot say what the base is (no
60
- `origin/main`, a shallow clone), the run fails and says which command fixes it: comparing with
61
- nothing would report every violation the module has as new.
62
-
63
- - A violation is compared by what it is: the rule, the file that breaks it, what it reaches. Not
64
- by a count, so fixing one and adding another in the same change still fails.
65
- - A file the branch only moves keeps its violations known, through git's rename detection: a pull
66
- request reorganising files into feature slices does what the decision asks. Locally, git sees the
67
- move only once it is staged: move with `git mv`, or `git add` both paths, or the moved file's
68
- violations read as new until then. CI always sees the commit.
69
- - A violation the branch removes is gone from the next run, and the report says how many were.
70
- There is nothing to commit for it.
71
- - A rule the decision adds is measured on both sides, so the module's existing violations of it
72
- are known on the day it lands.
73
- - A file the branch makes unparsable fails the run; one main could not parse either is said, and
74
- does not fail the branch.
75
-
76
- ## A rule's level in one module
77
-
78
- ```js
79
- // arch.config.mjs
80
- import { defineArch } from '@hublo/sentinel/arch'
81
-
82
- export default defineArch({
83
- root: import.meta.dirname,
84
- overrides: { severity: { G3: 'warn' } },
85
- })
86
- ```
87
-
88
- `warn` reports without failing, `off` skips the rule. A name that is not a rule of the set is
89
- refused, so a typo cannot leave a rule at `error` while you believe it is a warning. The level
90
- comes from the module's config, then the map, then the rule set.
91
-
92
- ## For the repository: the rules and the map
93
-
94
- The rules belong to the repository that took the decision, next to its ADR, so a decision and
95
- its check change in the same pull request and this package needs no release.
96
-
97
- A rule set (`docs/adr/0050-....rules.json`), in dependency-cruiser's vocabulary plus `roles`:
98
-
99
- ```json
100
- {
101
- "name": "ADR 0050: ...",
102
- "exclude": ["^(?!src/)", "\\.(test|spec|stories)\\.[cm]?[jt]sx?$"],
103
- "roles": [
104
- { "name": "route", "path": "^src/routes/" },
105
- { "name": "api", "path": ["(^|/)(services|queries|mutations)/"] },
106
- { "name": "view", "path": "\\.(tsx|svelte)$", "exports": "component" }
107
- ],
108
- "forbidden": [
109
- {
110
- "name": "G2a",
111
- "severity": "error",
112
- "comment": "The api layer never imports a view.",
113
- "from": { "role": "api" },
114
- "to": { "role": "view" }
115
- }
116
- ]
117
- }
118
- ```
119
-
120
- Roles are decided first match wins, by path (regular expressions relative to the module) and,
121
- for `exports: "component"`, by the file's default or same-named export. A file no role matches is
122
- `unclassified`: counted, never flagged. A role must have a `path` or `exports`.
123
-
124
- An import is followed to the file that DEFINES each imported name, through barrels
125
- (`export { x } from`, `export * from`), and that file's role is what a rule reads. Aliases come from
126
- the workspace's `tsconfig.base.json`, the module's own `tsconfig.json`, and SvelteKit's `$lib` and
127
- `kit.alias`. An alias that resolves to nothing is reported, not taken for a package.
128
-
129
- Which kind of rule a `to` makes:
130
-
131
- | `to` | Forbids |
132
- | ---------------------------------------------------------------- | ----------------------------------------------------------------------- |
133
- | `role` / `path` (`pathNot`, `dependencyTypesNot: ["type-only"]`) | importing a file of that side, inside the module or in a shared library |
134
- | `module` + `names` | importing those names from that package, as a value |
135
- | `calls` (+ `module`, a regular expression) | calling those globals, or importing a matching client as a value |
136
- | `role` / `path` + `slice: "other"` | the same import, only when it lands in another slice of the module |
137
- | `classNames` (a regular expression) | a class string written in a `className` or `class` attribute |
138
-
139
- A rule that states what a file, a class or a directory must BE uses one of these keys instead of
140
- `to`, one per rule:
141
-
142
- | Key | Requires | Example |
143
- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
144
- | `file` | `name` (a regex on its base name), `exportsItsName`, `exportStar: false`, `interfaceAndSymbol: true`, or `allowed: false` (it does not belong there) | `{ "exportsItsName": { "strip": "\\.controller\\.ts$", "case": "pascal", "append": "Controller" } }` |
145
- | `bindings` | `binds: "nothing"` (no `{ provide, useClass }`), or `"own-slice"` (only tokens of its own slice) | the application module binds no port |
146
- | `class` | `implements` / `injects` counted (`to`, `min`, `max`), or exactly these `publicMethods` | `{ "publicMethods": ["execute"] }` |
147
- | `imports` | `count` of distinct files of `to` (`min`, `max`), or `all`: it imports each kind at once | a route imports exactly one entry view |
148
- | `inbound` | `slices.min`: at least that many other slices import it | a file in `shared` used by two slices |
149
- | `directory` | `names` forbidden, `under: "slice"` (directly under a slice root), `withSibling` | no `domain/` beside an `infrastructure/` |
150
-
151
- A slice is what the rule set's `slices` says: regular expressions with one capture group, the slice
152
- root, first match wins. Only a file of the same module has a slice; a shared library has none, so it
153
- is never "another slice". A rule that reads slices in a set that declares none is refused.
154
-
155
- A violation of these rules names what is wrong in words that stay the same while the violation
156
- does (`class FooAdapter`, `directory domain`), so a moved count is not a new violation; the count
157
- is shown beside it.
158
-
159
- The map (`sentinel.arch.json`, at the workspace root), first match wins:
160
-
161
- ```json
162
- {
163
- "decisions": [
164
- {
165
- "modules": ["apps/front/hr-management"],
166
- "rules": "docs/adr/0050-....rules.json",
167
- "severity": { "G3": "warn" }
168
- },
169
- {
170
- "modules": ["apps/front/*", "libs/front/*"],
171
- "rules": "docs/adr/0050-....rules.json"
172
- }
173
- ],
174
- "notices": [{ "modules": ["apps/nest/backends-for-frontends/planning"], "text": "..." }]
175
- }
176
- ```
177
-
178
- A decision's `severity` is read on every run and never copied into a module, so moving it for a
179
- family of modules is one reviewed change of the map; a module's own `arch.config.mjs` overrides
180
- it. Notices are said at adoption and change nothing.
181
-
182
- A rule set, a map or a module config with a defect is refused before anything runs.
183
-
184
- ## What the role will not do
185
-
186
- - Analyse a module whose files did not change: in CI, the modules analysed are those whose own
187
- files a pull request touches. A shared library that changes can create a violation in a module
188
- downstream that is not analysed then.
189
- - Read markup: a `.svelte` file is checked through its `<script>` blocks.
190
- - Decide a design question no file and import can answer (is this the right boundary for a
191
- feature). Those stay with the reviewers, as the decisions themselves say.
File without changes