@hublo/sentinel 1.7.0-alpha.6 → 1.7.0-alpha.8

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 (57) hide show
  1. package/README.md +1 -0
  2. package/dist/bin/sentinel.js +25 -87
  3. package/dist/{chunk-DLGBRLUU.js → chunk-EESVRILJ.js} +3 -16
  4. package/dist/chunk-EESVRILJ.js.map +1 -0
  5. package/dist/{chunk-ZNANJEMK.js → chunk-JT7ZMH44.js} +30 -16
  6. package/dist/chunk-JT7ZMH44.js.map +1 -0
  7. package/dist/chunk-LU4E4TVD.js +183 -0
  8. package/dist/chunk-LU4E4TVD.js.map +1 -0
  9. package/dist/{chunk-THTXP2QU.js → chunk-LX7EG6PJ.js} +5 -6
  10. package/dist/chunk-LX7EG6PJ.js.map +1 -0
  11. package/dist/{chunk-4YQXLPJ5.js → chunk-PMRL4MH6.js} +2 -2
  12. package/dist/chunk-PXTU5MPW.js +9 -0
  13. package/dist/chunk-PXTU5MPW.js.map +1 -0
  14. package/dist/{chunk-LNFGVGLE.js → chunk-SWWQ7X7B.js} +11 -23
  15. package/dist/{chunk-LNFGVGLE.js.map → chunk-SWWQ7X7B.js.map} +1 -1
  16. package/dist/{chunk-YRBFCQQI.js → chunk-VZZ3DOC3.js} +2954 -1219
  17. package/dist/{chunk-P6KTBQ2Q.js → chunk-ZASD5YPF.js} +480 -186
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +6 -7
  20. package/dist/roles/build/nest/toolchain.d.ts +1 -1
  21. package/dist/roles/build/nest/toolchain.js +2 -6
  22. package/dist/roles/build/nest/toolchain.js.map +1 -1
  23. package/dist/roles/sql/config.d.ts +68 -0
  24. package/dist/roles/sql/config.js +8 -0
  25. package/dist/roles/sql/config.js.map +1 -0
  26. package/dist/roles/static-analysis/config.js +2 -1
  27. package/dist/roles/test/nest/toolchain.d.ts +1 -1
  28. package/dist/roles/test/nest/toolchain.js +2 -3
  29. package/dist/roles/test/nest/toolchain.js.map +1 -1
  30. package/dist/roles/test/react/toolchain.js +2 -3
  31. package/dist/roles/test/react/toolchain.js.map +1 -1
  32. package/dist/roles/test/setup/jest-parity.js +2 -2
  33. package/dist/roles/test/setup/workspace-entry.js +2 -2
  34. package/dist/roles/test/shared-test-config.d.ts +1 -1
  35. package/dist/roles/test/shared-test-config.js +2 -3
  36. package/dist/tsconfig/nest.json +1 -10
  37. package/dist/tsconfig/node.json +1 -11
  38. package/dist/tsconfig/react.json +0 -3
  39. package/dist/{tsconfig-aliases-C_PxuZni.d.ts → tsconfig-aliases-Ce6axdJ4.d.ts} +2 -17
  40. package/dist/{validate-4V3EGTXN.js → validate-QYP7HFSY.js} +2 -4
  41. package/docs/build-adoption.md +0 -7
  42. package/docs/sql-adoption.md +282 -0
  43. package/docs/test-adoption.md +1 -8
  44. package/docs/typescript-adoption.md +13 -96
  45. package/docs/typescript-traces.md +217 -3
  46. package/docs/using-sentinel.md +2 -1
  47. package/package.json +6 -4
  48. package/dist/chunk-DLGBRLUU.js.map +0 -1
  49. package/dist/chunk-H4HAFJFZ.js +0 -79
  50. package/dist/chunk-H4HAFJFZ.js.map +0 -1
  51. package/dist/chunk-THTXP2QU.js.map +0 -1
  52. package/dist/chunk-ZFG6P27V.js +0 -313
  53. package/dist/chunk-ZNANJEMK.js.map +0 -1
  54. package/dist/chunk-ZZMYV576.js +0 -297
  55. package/dist/migrate-X7PB2X7R.js +0 -553
  56. package/dist/tsconfig/legacy.json +0 -21
  57. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-PMRL4MH6.js.map} +0 -0
@@ -0,0 +1,282 @@
1
+ # SQL adoption cheat sheet
2
+
3
+ A quick reference for adopting the sentinel `sql` role on a module, for knowing what it checks, and
4
+ for moving a rule's level in `sql.config.mjs`. Why the role exists, and the measurements behind
5
+ its scope, are in [`sql-verification-study.md`](sql-verification-study.md); this page is what you
6
+ need to run it.
7
+
8
+ The role reads what a branch adds or changes:
9
+
10
+ - **the Prisma migrations** (`**/migrations/*/migration.sql`), checked by
11
+ [squawk](https://squawkhq.com) 2.72.0 against PostgreSQL 16.8;
12
+ - **the calls to `$queryRawUnsafe` / `$executeRawUnsafe`** in the module's TypeScript, checked by
13
+ sentinel's own rule, `unsafe-sql-pasted-value`;
14
+ - **the calls to `Prisma.raw`**, checked the same way under a rule of their own,
15
+ `unsafe-sql-raw-fragment`.
16
+
17
+ **Every finding is a warning until the module decides otherwise.** Nothing fails a run by default,
18
+ so adopting the role, or a sentinel upgrade that brings a new squawk rule, never turns a module red.
19
+ A module that wants a rule to block sets it to `error` (see [Rule levels](#rule-levels)).
20
+
21
+ ## Adopt a module in two steps
22
+
23
+ Run from the **module's own directory**, the one that holds `prisma/migrations` or the raw SQL
24
+ calls. You do not need to install sentinel first: use `npx --yes` for a one-off.
25
+
26
+ ```bash
27
+ # 1. write the module's config + the pinned devDependency
28
+ cd apps/.../<module>
29
+ npx --yes @hublo/sentinel@<version> --init --sql
30
+
31
+ # 2. fetch what step 1 declared
32
+ pnpm install
33
+ ```
34
+
35
+ `--init` writes `sql.config.mjs`, adds the three scripts below and the `sql` nx target to the
36
+ module's `package.json`, and pins `@hublo/sentinel` into its `devDependencies`. It prints:
37
+
38
+ ```
39
+ wrote sql.config.mjs
40
+ wrote package.json
41
+ added sql.config.mjs; added the 3 `sql` scripts; every finding is a warning while the role is being adopted
42
+ ```
43
+
44
+ A module that holds no migration and no `Unsafe` or `Prisma.raw` call is skipped by name: there is nothing for the
45
+ role to read. An existing `sql.config.mjs` is the team's and is never rewritten by a re-init.
46
+
47
+ ## Everyday use
48
+
49
+ ```bash
50
+ pnpm run sql # the summary, in your terminal. Writes nothing
51
+ pnpm run sql:json # sql-report/sql.json, for a machine
52
+ pnpm run sql:html # sql-report/sql.html, for a reader
53
+ ```
54
+
55
+ Or without the scripts:
56
+
57
+ ```bash
58
+ sentinel --run --sql # same as the first script
59
+ sentinel --run --sql --output markdown # sql-report/sql.md, the pull-request recap
60
+ sentinel --inspect --sql --json # every setting and every rule's level, without running
61
+ ```
62
+
63
+ ## What it reads: only what the branch adds or changes
64
+
65
+ The role compares the branch with `origin/main` and reads the migrations and the TypeScript files
66
+ the branch **adds or modifies**. An old migration has already run in production; reporting it again
67
+ on every pull request would bury the one that has not. The console says what was read and what
68
+ was not:
69
+
70
+ ```
71
+ read 1 migration(s) this branch adds or changes, compared with origin/main at 63d1ee7. The 1 other(s) in this module are unchanged and not read.
72
+ checked 1 call(s) to $queryRawUnsafe / $executeRawUnsafe and 2 to Prisma.raw in the 2 file(s) this branch adds or changes.
73
+ ```
74
+
75
+ This is how the role reads, not a setting.
76
+
77
+ ## What is checked, out of the box
78
+
79
+ | Source | Rules | On by default |
80
+ | ----------------------------------------------------------------- | ----- | --------------------------------------------- |
81
+ | squawk 2.72.0, its default rules | 50 | **yes**, at `warn` |
82
+ | squawk 2.72.0, its opt-in rules | 26 | no: one runs once the module gives it a level |
83
+ | sentinel, `unsafe-sql-pasted-value` and `unsafe-sql-raw-fragment` | 2 | **yes**, at `warn` |
84
+
85
+ **52 rules run on every module**, the set squawk itself runs, plus sentinel's two. sentinel turns
86
+ no squawk rule off and turns no opt-in rule on: the choice of what runs by default is squawk's, and
87
+ a module moves it in its own config. `pnpm exec sentinel --inspect --sql --json` lists all 78 rules
88
+ with the level each has in this module.
89
+
90
+ <details>
91
+ <summary>The 50 squawk rules on by default</summary>
92
+
93
+ `adding-field-with-default`, `adding-foreign-key-constraint`, `adding-not-nullable-field`,
94
+ `adding-required-field`, `adding-serial-primary-key-field`, `ban-alter-domain-with-add-constraint`,
95
+ `ban-alter-identity`, `ban-char-field`, `ban-concurrent-index-creation-in-transaction`,
96
+ `ban-create-domain-with-constraint`, `ban-drop-column`, `ban-drop-constraint`, `ban-drop-database`,
97
+ `ban-drop-default`, `ban-drop-domain`, `ban-drop-extension`, `ban-drop-function`,
98
+ `ban-drop-generated-expression`, `ban-drop-not-null`, `ban-drop-schema`, `ban-drop-sequence`,
99
+ `ban-drop-table`, `ban-drop-type`, `ban-drop-view`, `ban-duplicate-column-assignments`,
100
+ `ban-set-schema`, `ban-truncate-cascade`, `ban-uncommitted-transaction`, `changing-column-type`,
101
+ `constraint-missing-not-valid`, `disallowed-unique-constraint`, `identifier-too-long`,
102
+ `prefer-bigint-over-int`, `prefer-bigint-over-smallint`, `prefer-identity`, `prefer-repack`,
103
+ `prefer-robust-stmts`, `prefer-text-field`, `prefer-timestamp-tz`, `renaming-column`,
104
+ `renaming-object`, `renaming-table`, `require-concurrent-index-creation`,
105
+ `require-concurrent-index-deletion`, `require-concurrent-partition-detach`,
106
+ `require-concurrent-reindex`, `require-enum-value-ordering`, `require-lock-timeout`,
107
+ `require-statement-timeout`, `transaction-nesting`.
108
+
109
+ </details>
110
+
111
+ <details>
112
+ <summary>The 26 opt-in squawk rules, off until given a level</summary>
113
+
114
+ `ban-add-column`, `ban-add-composite-attribute`, `ban-add-enum-value`, `ban-alter-database-options`,
115
+ `ban-alter-extension`, `ban-alter-function-options`, `ban-alter-generated-expression`,
116
+ `ban-alter-policy-condition`, `ban-alter-policy-roles`, `ban-alter-role-options`,
117
+ `ban-alter-row-level-security`, `ban-alter-sequence-values`, `ban-alter-system-options`,
118
+ `ban-alter-view-options`, `ban-create-policy`, `ban-detach-inheritance`, `ban-disable-trigger`,
119
+ `ban-drop-index`, `ban-drop-policy`, `ban-drop-trigger`, `ban-new-write-restriction`,
120
+ `ban-replace-view-function`, `ban-replica-identity`, `ban-revoke`, `ban-set-default`,
121
+ `require-table-schema`.
122
+
123
+ </details>
124
+
125
+ The rule pages are squawk's: `https://squawkhq.com/docs/<rule>`.
126
+
127
+ ## Rule levels
128
+
129
+ A rule has one of three levels, the meanings lint already uses:
130
+
131
+ | Level | The rule runs? | A finding fails the run? | In the report |
132
+ | ---------------- | -------------- | ------------------------ | ---------------------------------------------------------------- |
133
+ | `warn` (default) | yes | no | listed |
134
+ | `error` | yes | **yes**, exit code 1 | listed first, marked `error` |
135
+ | `off` | no | no | named in a line of its own, so a reviewer sees it was turned off |
136
+
137
+ ## The config file, `sql.config.mjs`
138
+
139
+ The one file a module writes, the shape of `static-analysis.config.mjs`. `--init` writes it with
140
+ every setting the module can move and the role's value today, generated from the defaults so it
141
+ cannot drift from them. A setting the module leaves out keeps the role's value; a setting it writes
142
+ **replaces** it, including inside a list, and the html report shows it as overridden by this module.
143
+
144
+ | Setting | Default | What it moves |
145
+ | --------------------- | ------------------------------------------ | ------------------------------------------------------ |
146
+ | `migrations.include` | `["**/migrations/*/migration.sql"]` | which files are migrations |
147
+ | `migrations.exclude` | `[]` | migrations never read |
148
+ | `unsafe.includeTests` | `true` | whether calls in test files are checked, by both rules |
149
+ | `unsafe.tests` | test folders and `*.spec`/`*.test`/… files | what counts as a test file |
150
+ | `ignore` | `node_modules`, `dist`, `coverage` | never read, by either check |
151
+ | `pgVersion` | `"16.8"` | the PostgreSQL version squawk checks against |
152
+ | `rules` | `{}`, every rule at its default | a level per rule, by its name |
153
+
154
+ An example that blocks two rules, silences one and turns an opt-in rule on:
155
+
156
+ ```js
157
+ // sql.config.mjs
158
+ import { defineSql } from '@hublo/sentinel/sql'
159
+
160
+ export default defineSql({
161
+ root: import.meta.dirname,
162
+ overrides: {
163
+ rules: {
164
+ 'require-concurrent-index-creation': 'error',
165
+ 'unsafe-sql-pasted-value': 'error',
166
+ 'prefer-robust-stmts': 'off',
167
+ 'ban-drop-index': 'warn',
168
+ },
169
+ },
170
+ })
171
+ ```
172
+
173
+ What the run prints with it:
174
+
175
+ ```
176
+ this module turns off 1 rule(s) in sql.config.mjs, so squawk does not check them: prefer-robust-stmts.
177
+ ✗ 6 finding(s): 2 error(s), from the rule(s) this module sets to "error" in sql.config.mjs, which fail this run, and 4 warning(s):
178
+ require-concurrent-index-creation 1 error
179
+ sentinel's note: Prisma runs a multi-statement file in a transaction, where CONCURRENTLY fails: give the statement its own migration.
180
+ unsafe-sql-pasted-value 1 error
181
+ changing-column-type 1
182
+ ...
183
+ ```
184
+
185
+ `rules` names a rule by **squawk's name for it**, the name the report prints. A name that is not a
186
+ rule is refused in the module's own file, before anything runs, with the closest name:
187
+
188
+ ```
189
+ sql.config.mjs: `rules['prefer-robust-stmt']` is not a rule of squawk 2.72.0 or of sentinel. Did you mean 'prefer-robust-stmts'? The names are listed by `pnpm exec sentinel --inspect --sql --json`.
190
+ ```
191
+
192
+ An older name squawk still accepts, such as `prefer-timestamptz`, is refused too, with the name to
193
+ write: squawk reports the rule under its new name, so a level on the old one would never apply.
194
+
195
+ ## sentinel's notes
196
+
197
+ squawk's advice is written for PostgreSQL in general. Under two rules, sentinel adds a note where
198
+ that advice meets the way Prisma runs a migration, each proven on PostgreSQL 16.8 with Prisma
199
+ 6.19.3. **A note is added beside a finding; it never removes or changes one.**
200
+
201
+ - **`require-concurrent-index-creation` / `-deletion`.** Prisma runs a file of several statements
202
+ inside a transaction, where `CONCURRENTLY` fails (`25001`), nothing is applied and the next deploy
203
+ is refused (`P3009`). The note says to give the statement a migration of its own, alone in its
204
+ file, which applies.
205
+ - **`changing-column-type`, to `varchar` or `text`.** Widening a `varchar`, or changing it to
206
+ `text`, rewrites neither the table nor its index (under 4 ms on 2 million rows), but still waits
207
+ for the table's lock and makes every query behind it wait. The note says to put
208
+ `SET lock_timeout` before the `ALTER`. The statement does not say the type before it, so the
209
+ finding stays for every type change: narrowing a `varchar`, or leaving a `uuid`, does rewrite the
210
+ table.
211
+
212
+ ## The `Unsafe` rule, `unsafe-sql-pasted-value`
213
+
214
+ Prisma's tagged `` $queryRaw`…${value}…` `` sends each `${}` as a parameter. `$queryRawUnsafe` and
215
+ `$executeRawUnsafe` take a plain string: whatever is pasted into it runs as SQL. The rule reports a
216
+ call whose SQL text holds a part sentinel **cannot show** is a constant.
217
+
218
+ It clears what cannot carry text a caller chose:
219
+
220
+ - a string literal, or a template without a value;
221
+ - a template, `+`, ternary, `??`, `||` or `&&` built only of safe parts;
222
+ - arithmetic and comparisons, whose result is a number or a boolean;
223
+ - a `const` of the file, declared once under that name, whose value is safe;
224
+ - a name imported from a relative path, from a file that says `export const NAME = <safe>`;
225
+ - generated placeholders, ``list.map((_, index) => `$${index + 1}`).join(', ')``.
226
+
227
+ It reports everything else, and names the part it could not see:
228
+
229
+ ```
230
+ `table` is pasted into the SQL text of $queryRawUnsafe, and sentinel cannot show it is constant: a quote in it would end the string and run the rest as SQL
231
+ ```
232
+
233
+ That includes a function parameter (the SQL arrives from a caller, unchecked where it is used), a
234
+ `let`, an object property, an enum member, a call, a name declared twice in the file, and an import
235
+ from a package. The rule never guesses: when it cannot see, it reports. The fix it prints is a
236
+ parameter (`$1` in the text, the value after it), or the tagged form; a table or column name cannot
237
+ be a parameter, so take it from a `const` of the file.
238
+
239
+ Measured on the monorepo's 219 calls before the rule was written: the 23 production calls match a
240
+ classification made by hand, one of them a real injection pasting data into a `VALUES` list.
241
+
242
+ ## The `Prisma.raw` rule, `unsafe-sql-raw-fragment`
243
+
244
+ `Prisma.raw(text)` puts its text into a tagged query **as SQL, never as a parameter**: the same
245
+ hazard as the `Unsafe` methods, inside the safe form. Its argument is checked exactly like theirs,
246
+ with the same list of what is cleared, and reported under its own rule, so a module can set the two
247
+ levels apart. `Prisma` is recognised by its import from a `@prisma/` package, under any name
248
+ (`import { Prisma as AgencyPrisma }` included); a `raw` of anything else, `String.raw` among them,
249
+ is not read.
250
+
251
+ ```
252
+ the SQL text of Prisma.raw is `sortOrder`, which sentinel cannot show is a constant: whatever was pasted into it, wherever it was built, runs as SQL
253
+ ```
254
+
255
+ The fix it prints: a value goes into `` Prisma.sql`…` `` as `${value}`, which binds it. A keyword or
256
+ a column name cannot be bound, so write each choice as a literal, which the rule clears:
257
+
258
+ ```ts
259
+ Prisma.sql`ORDER BY "lastName" ${order === 'DESC' ? Prisma.raw('DESC') : Prisma.raw('ASC')}`
260
+ ```
261
+
262
+ Measured on `main` (f12da701121): 97 calls, 20 cleared (all literals or ternaries of literals) and 77
263
+ reported. None of the 77 was found injectable, and none can be proven safe where it is written:
264
+
265
+ | What the call receives | Calls | Why the rule cannot clear it |
266
+ | --------------------------------------------------------------------------------------------------------------- | ----: | ------------------------------------------------------------ |
267
+ | a value validated elsewhere: an enum checked by the HTTP DTO, a key of a column map, a filtered list of numbers | 37 | the proof is a type or a validator, files away from the call |
268
+ | an alias or a column name, a parameter of a SQL helper | 19 | the callers pass literals, in other files |
269
+ | a fragment of SQL built elsewhere, by a query builder or a helper | 21 | the text is made in another function |
270
+
271
+ That is the rule's purpose: on a branch that changes one of these files, the reviewer is told that
272
+ the safety of the text rests on code the call does not show.
273
+
274
+ ## What the role does not read yet
275
+
276
+ Said here so that a clean report is not read as more than it is:
277
+
278
+ - **The SQL text itself** of a raw query is not parsed: a tagged `$queryRaw` with only parameters is
279
+ safe from injection, and its SQL is not checked against any rule.
280
+ - **Files outside a module.** The role runs on a module; a script at the repository's root that
281
+ belongs to no module is read by no role.
282
+ - **What the ORM generates** (`findMany`, `update`, …) is not seen: there is no SQL text to read.
@@ -138,17 +138,10 @@ The wall is decorator metadata: Nest resolves a constructor's parameters from
138
138
  ```ts
139
139
  plugins: [decoratorMetadata({ root: here })],
140
140
  resolve: { alias: [{ find: /^jest-mock-extended$/, replacement: 'vitest-mock-extended' },
141
- ...tsconfigAliases(workspaceRoot, { moduleRoot: here })] },
141
+ ...tsconfigAliases(workspaceRoot)] },
142
142
  test: { globals: true, environment: 'node', isolate: true },
143
143
  ```
144
144
 
145
- **The aliases are the module's, read the way tsc reads them.** `tsconfigAliases` follows the
146
- module's own tsconfig chain (`tsconfig.spec.json`, then `tsconfig.app.json`, then `tsconfig.json`), so a module that declares
147
- its own `paths` is tested with the aliases it type-checks with. When the chain declares no `paths`,
148
- it falls back to `tsconfig.base.json`, which is what it always read: a module that still extends
149
- the base sees no change. That fallback is a transition. Once no module extends the base, a module
150
- without `paths` has no aliases, as in tsc. The rules are in `src/shared/tsconfig-paths.ts`. One difference with tsc 7 is deliberate: a `baseUrl` in the chain is honoured, as ts-jest, Vite and TypeScript 5 and 6 read it, so a chain whose `baseUrl` is not the directory of the file declaring `paths` resolves differently at runtime than in the typecheck. None exists in the monorepo today.
151
-
152
145
  **`isolate` stays `true`**, whatever the performance note in Vitest's docs suggests. Jest gives each
153
146
  test file a fresh module registry and `isolate: true` reproduces that. Nest registers metadata as an
154
147
  import SIDE EFFECT, a decorator writing into a catalog when its module loads, so a shared registry
@@ -33,7 +33,7 @@ pnpm install
33
33
  | `--run` | dev, everyday | **yes** (tsc) | executes the check, pass/fail. This is your `typecheck` script. |
34
34
  | `--inspect` | dev, everyday | no (reads config) | the resolved config: preset, target, and which rules are deferred |
35
35
  | `--init` | dev, once to adopt | writes files | the tsconfig stub, the `typecheck` script, the pinned dep, + workspace prep |
36
- | `--migrate` | dev, once per role | writes files | changes an adopted module's setup: `--typescript` detaches it from the base |
36
+ | `--migrate` | planned | not available yet | reserved for changing an already-initialized setup (later ticket) |
37
37
  | `--report` | **deprecated** | — | use `--run --json`: same work, same envelope |
38
38
  | `--status` | **deprecated** | — | use `--inspect`, which absorbed it |
39
39
 
@@ -43,87 +43,13 @@ pnpm install
43
43
  > the two above, because they answered the same two questions in a different shape. Both still
44
44
  > run and print a notice telling you what to use instead.
45
45
 
46
- **Location** (any verb): from a module dir → that module; from the root → `--module <name>`, `--ci` (affected), or all modules. `--init` and `--migrate` write, so they target one module only.
46
+ **Location** (any verb): from a module dir → that module; from the root → `--module <name>`, `--ci` (affected), or all modules. `--init` writes, so it targets one module only.
47
47
 
48
48
  **Your tsconfig extends exactly one preset.** The options every stack shares are flattened into
49
49
  each published preset at build time, so `@hublo/sentinel/tsconfig/react` is self-contained and
50
50
  there is nothing to stack under it. The shared layer lives in the repo as
51
51
  `src/roles/typescript/presets/shared.json`; it is ours and is never published on its own.
52
52
 
53
- The one addition is `@hublo/sentinel/typescript/legacy`, and it is not a preset: it is the debt
54
- a module carried through `tsconfig.base.json` (the six strict opt-outs, `ignoreDeprecations`,
55
- and for react the decorator flags, `declaration: false` and `types`). Only `--migrate
56
- --typescript` adds it, LEFT of the stack preset where the base was, so the stack preset keeps
57
- winning; `--init` never does, so a new module is born with the full strict set.
58
-
59
- ## Detach a module from `tsconfig.base.json`
60
-
61
- Run from an **adopted** module's directory (its tsconfig extends a sentinel preset), once its
62
- `@hublo/sentinel` is the version that ships `legacy`:
63
-
64
- ```bash
65
- sentinel --migrate --typescript --dry-run # prove it and write nothing
66
- sentinel --migrate --typescript # prove it and keep the result
67
- ```
68
-
69
- It replaces the base in `extends` with `legacy` (when the module has those compromises), keeps
70
- the stack preset, and writes only what depends on the module: `outDir`, `rootDir`, `exclude`,
71
- and the `paths` entries tsc reports having MATCHED (`--traceResolution`), the setup and config
72
- files no tsconfig compiles included. Measured on 113 modules (sentinel#147), that is all that is
73
- left once the presets carry the base's standards.
74
-
75
- It is all or nothing. Every tsconfig of the module that extends the base is proved first, each
76
- rewritten and put back in turn, and the module's files are written only when tsc agrees on every
77
- one of them, on both:
78
-
79
- - `--showConfig` of every tsconfig of the folder applies the same options, `paths` aside. Applied,
80
- not printed: the base printed `alwaysStrict`, `allowJs: false` and `isolatedModules`, and the
81
- presets leave them to `strict`, the default and `verbatimModuleSyntax`. Same compilation,
82
- different output, so the comparison derives those options the way tsc does
83
- (`src/roles/typescript/compare.ts`);
84
- - every module and type reference tsc resolves, file by file, lands on the same file.
85
-
86
- A kept tsconfig is then formatted with the style the module states (its `.oxfmtrc.json`, else
87
- the workspace's Prettier), the same rule `--init --test` follows: whitespace only, after tsc agreed.
88
-
89
- It refuses, and writes nothing, for:
90
-
91
- - a module not adopted yet (run `--init --typescript` first);
92
- - a module with one tsconfig that extends the base without a sentinel preset, even when the others
93
- are proved (`partly-adopted`). On the monorepo that is `tsconfig.acceptance.json` in `contract`
94
- and `network`. Detaching the rest would leave the module compiling two ways, still on the base.
95
- `--init` adopts the main tsconfig only, so the fix is to add the stack preset to that file's
96
- `extends`, or to make it extend the adopted tsconfig;
97
- - a tsconfig with comments;
98
- - a module whose installed sentinel has no `legacy`, or resolves it from another install than its
99
- stack preset;
100
- - a tsconfig tsc cannot read (`error`, naming what tsc said), or a program that compiles files and
101
- whose trace yields no resolution at all (`no-trace`): every program resolves at least its type
102
- references, the smallest of the monorepo's 111 traces 447, so none means the trace was not read.
103
- A solution file (`files: []`, `include` absent or `[]`) compiles nothing and is not traced: its
104
- programs are, through the tsconfigs that extend it. A program tsc lists no file for (a spec
105
- tsconfig in a library with no tests) is not a `no-trace` either: its trace must stay empty
106
- after the rewrite.
107
-
108
- A nested folder that is a module of its own is named and left to its own run. Each refusal carries a
109
- `refusal` code in `--json` (`not-adopted`, `partly-adopted`, `comments`, `no-legacy`,
110
- `several-installs`, `no-trace`, `disagrees`, `error`).
111
-
112
- `--dry-run` writes nothing either, but each tsconfig is rewritten on disk for the time of its proof.
113
- A watcher (the Nx daemon, tsserver, a dev server) can see it come and go.
114
-
115
- Once migrated, `--inspect` lists the compromises the module takes from `legacy` under
116
- `inherited compromises (debt to remove)`: the options the stack preset does not set and the module
117
- does not set itself, the ones that apply, each against the value the standard would apply
118
- (`noImplicitAny — false, where the standard says true, inherited from …/legacy`). `--json` carries
119
- the same lists as data: `standardOverrides` and `legacyCompromises`, each item with `rule`,
120
- `value` and `standard`. The debt left the base, and stays
121
- visible module by module until the module removes the `legacy` line.
122
-
123
- What it does not prove is tsc's view only: the Nx project graph still reads the root base's
124
- `paths`, and esbuild and Vite resolve each file through its nearest tsconfig. The base stays
125
- until every module is detached, and the module's own build, test and lint are its proof.
126
-
127
53
  ## Everyday use (developers)
128
54
 
129
55
  ```bash
@@ -142,17 +68,17 @@ sentinel --inspect --typescript # adoption + conformity coverage
142
68
 
143
69
  ## Options
144
70
 
145
- | Option | What it does |
146
- | ----------------------- | ------------------------------------------------------------------------------------- |
147
- | `--preset <name>` | override detection (`react` / `nest` / `svelte` / `node`); recommended for `--init` |
148
- | `--module <name>` | from the root, scope to one module |
149
- | `--ci` | from the root, only affected modules; non-zero exit on failure |
150
- | `--json` | machine-readable envelope on stdout, for every verb; progress goes to stderr |
151
- | `--max-diagnostics <n>` | cap the diagnostics embedded per module in `--run --json` (`0` = no cap) |
152
- | `--dry-run` | preview what `--init` would write, or prove `--migrate` and write nothing (see above) |
153
- | `--rehearse` | with `--dry-run`: run the autofix passes in a copy and name the source they rewrite |
154
- | `--runner <tool>` | override the default runner |
155
- | `-- <tool options>` | `--run` only, one type named: everything after `--` goes to tsc itself (see below) |
71
+ | Option | What it does |
72
+ | ----------------------- | ----------------------------------------------------------------------------------- |
73
+ | `--preset <name>` | override detection (`react` / `nest` / `svelte` / `node`); recommended for `--init` |
74
+ | `--module <name>` | from the root, scope to one module |
75
+ | `--ci` | from the root, only affected modules; non-zero exit on failure |
76
+ | `--json` | machine-readable envelope on stdout, for every verb; progress goes to stderr |
77
+ | `--max-diagnostics <n>` | cap the diagnostics embedded per module in `--run --json` (`0` = no cap) |
78
+ | `--dry-run` | preview what `--init` would write, changing nothing |
79
+ | `--rehearse` | with `--dry-run`: run the autofix passes in a copy and name the source they rewrite |
80
+ | `--runner <tool>` | override the default runner |
81
+ | `-- <tool options>` | `--run` only, one type named: everything after `--` goes to tsc itself (see below) |
156
82
 
157
83
  ## Measuring a deferred rule
158
84
 
@@ -257,12 +183,3 @@ it would hand it to the workspace tsconfig this module extends
257
183
  ```
258
184
 
259
185
  It is not reported as drift by `--inspect` either, so a module that legitimately overrides the base does not read as non-conformant forever.
260
-
261
- Not drift, but not hidden either: `--inspect` lists it under `differs from the repo standard`,
262
- with both values. An option a preset took over from the base (`fromBase`) and that the module
263
- sets to another value is this module departing from the standard, and that is worth seeing:
264
-
265
- ```
266
- differs from the repo standard (kept by --init, not drift):
267
- • verbatimModuleSyntax — false, where the nest preset says true
268
- ```