@hublo/sentinel 1.7.0-alpha.17 → 1.7.0-alpha.18

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.
package/README.md CHANGED
@@ -176,6 +176,7 @@ throwaway run wants. Once a module has adopted, nothing is fetched any more: the
176
176
  - [`docs/typescript-adoption.md`](docs/typescript-adoption.md) — the adoption cheat sheet: the two adoption steps, the command model (verb x type x location), options, reading a report, and troubleshooting.
177
177
  - [`docs/test-adoption.md`](docs/test-adoption.md) — migrating a module from jest to Vitest: the two steps, what the migration rewrites and what it refuses BY NAME, how the baseline gate proves nothing was lost, and the failures worth recognising.
178
178
  - [`docs/static-analysis-adoption.md`](docs/static-analysis-adoption.md) — running the static analysis role on a module: the two steps, the four output shapes, how to read each row and where its threshold comes from, declaring an entry point, and the two limits worth knowing before trusting a number.
179
+ - [`docs/sql-adoption.md`](docs/sql-adoption.md) — checking the migrations, the `Unsafe` calls and the `Prisma.raw` calls a branch adds or changes: the two steps, the 52 rules on by default and the 26 opt-in ones, the three levels in `sql.config.mjs` with an example, sentinel's two notes, and what the role does not read yet.
179
180
  - [`docs/env-adoption.md`](docs/env-adoption.md) — checking a whole repository's env files, contracts and Dockerfiles from its root: the ten rules and which block, the three levels of `SENTINEL_ENV_LEVEL`, the optional `env.config.mjs`, and what changed from the monorepo's `tools/repo-env`.
180
181
  - [`docs/typescript-traces.md`](docs/typescript-traces.md) — a **generated, versioned** reference of live command + output traces (every verb, option, config result and edge case) against the mock monorepo. Regenerate after CLI changes with `pnpm docs:traces`.
181
182
 
@@ -255,6 +256,7 @@ The rules live in `sentinel`. Each module keeps a **thin, generated stub** per t
255
256
  - **Rules in sentinel** — one source of truth, versioned.
256
257
  - **Thin stubs per module** — the stub is what keeps the **editor working** (VS Code discovers config by file, real-time lint/type/format stay live) and what **nx** uses to infer targets. Stubs are **generated by `sentinel --init`**, never hand-written; swapping a runner regenerates them.
257
258
  - **Drift guard** — sentinel validates that each stub is _only_ the sanctioned `extends`, with nothing of the preset's overridden. Unsanctioned drift is flagged in CI; a genuine exception must be **declared in an allowlist** (visible, reviewed), never silent. One addition is sanctioned, in lint: what the preset does not govern (a rule it does not name, a plugin, jsPlugin or setting it does not set) is the module's own, kept by `--init`, not drift, and listed by `--inspect`; a rule the preset names, set to another value, or an entry that collides with the preset's, is drift ([lint-adoption.md](docs/lint-adoption.md#what---inspect-calls-drift-and-what-it-lists-as-yours)).
259
+ - **Adopt first, then run the module's own** — every analysis tool starts with an adoption (`--init`: its config file, its scripts, the pinned devDependency); after it, the developer, the CI and an AI run the module's script, so all three use the same version. `static-analysis` and `sql` are the reference implementations ([CONTRIBUTING.md](CONTRIBUTING.md#an-analysis-role-adopt-first-then-everyone-runs-the-modules-own)).
258
260
  - **Per-module install** — `@hublo/sentinel` is added per module, so adoption is **gradual** (migrate lot by lot; a module can adopt sentinel while its neighbour still uses the old config). Root configs are removed only once the **last** module has migrated.
259
261
  - **Runner binaries** (`eslint`, `typescript`, `vite`, `vitest`, …) are **resolved from the adopting module** at run time (sentinel looks for the tool in the module, then falls back to `PATH`), so the editor and nx keep using the exact binary the project already installs. sentinel does **not** declare them as dependencies today, so it does not pin their versions: the module still owns its own `typescript`. Having sentinel dictate those versions (as peer dependencies, so the whole toolchain rides the sentinel version) is the intended end state, and it lands with the tool tickets that actually bundle a runner.
260
262
 
@@ -8,22 +8,23 @@ import {
8
8
  declaredPresetFor,
9
9
  describeFramework,
10
10
  dispatch,
11
+ locateRepository,
11
12
  palette,
12
13
  presetNotInstalledYet,
13
14
  registerAdapters,
14
15
  resolve
15
- } from "../chunk-CGPGCYVN.js";
16
+ } from "../chunk-3KOOIKKZ.js";
16
17
  import {
17
18
  resolveContext,
18
19
  separateToolArgs
19
- } from "../chunk-2LLRSWG2.js";
20
+ } from "../chunk-AVT5FSPO.js";
20
21
  import {
21
22
  ensureWorkspacePrep,
22
23
  findWorkspaceRoot,
23
24
  inspectWorkspacePrep,
24
25
  readOwnVersion,
25
26
  readProjectPackageJson
26
- } from "../chunk-ZNANJEMK.js";
27
+ } from "../chunk-JT7ZMH44.js";
27
28
  import {
28
29
  DEFAULT_ENV_LEVEL,
29
30
  ENV_LEVELS,
@@ -34,8 +35,8 @@ import {
34
35
  SWEEPABLE_TARGETS,
35
36
  TARGETS,
36
37
  VERBS
37
- } from "../chunk-5I6WUD2U.js";
38
- import "../chunk-TMVKYXZ3.js";
38
+ } from "../chunk-LX7EG6PJ.js";
39
+ import "../chunk-NGLEGAEN.js";
39
40
  import "../chunk-PXTU5MPW.js";
40
41
  import "../chunk-4EIY7TTR.js";
41
42
  import "../chunk-O7REVMOC.js";
@@ -550,8 +551,8 @@ sentinel (${type}): ${asMessage(error)}
550
551
  // Only when the FORMAT role actually adopted: a module still formatted by the root
551
552
  // must not be excluded from it.
552
553
  formattedModule: toRun.includes("format") ? module.root : void 0,
553
- // Same rule for the report directory: only when the STATIC ANALYSIS role adopted.
554
- analysedModule: toRun.includes("static-analysis")
554
+ // Same rule for the report directories: only for a role that writes reports and adopted.
555
+ adoptedRoles: toRun
555
556
  });
556
557
  workspace = changes;
557
558
  const prefix = ctx.dryRun ? " dry run: " : " ";
@@ -604,7 +605,7 @@ async function runValidate(ctx) {
604
605
  );
605
606
  }
606
607
  if (!ctx.targets.includes("test")) return 1;
607
- const { validateModuleTests } = await import("../validate-S5I4Z7IO.js");
608
+ const { validateModuleTests } = await import("../validate-B5567Z7X.js");
608
609
  const outcomes = modules.flatMap(
609
610
  (module) => validateModuleTests(module.name, module.root)
610
611
  );
@@ -874,35 +875,6 @@ async function runVerb(ctx) {
874
875
  return ctx.verb === "run" || ctx.ci ? worstCode : 0;
875
876
  }
876
877
 
877
- // src/core/repository-root.ts
878
- import { execFileSync } from "node:child_process";
879
- import { realpathSync as realpathSync2 } from "node:fs";
880
- function findRepositoryRoot(cwd2) {
881
- try {
882
- const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
883
- cwd: cwd2,
884
- encoding: "utf8",
885
- stdio: ["ignore", "pipe", "ignore"]
886
- }).trim();
887
- return root === "" ? void 0 : realpathSync2(root);
888
- } catch {
889
- return void 0;
890
- }
891
- }
892
- function isRepositoryRoot(cwd2, root) {
893
- try {
894
- return realpathSync2(cwd2) === root;
895
- } catch {
896
- return false;
897
- }
898
- }
899
- function locateRepository(cwd2) {
900
- const root = findRepositoryRoot(cwd2);
901
- if (root === void 0) return { ok: false, reason: "not-a-repository" };
902
- if (!isRepositoryRoot(cwd2, root)) return { ok: false, reason: "not-the-root", root };
903
- return { ok: true, root };
904
- }
905
-
906
878
  // src/shared/node-version.ts
907
879
  var MIN_NODE = "24.15.0";
908
880
  function parts(version) {
@@ -937,6 +909,7 @@ var TARGET_HELP = {
937
909
  dev: "dev server (long-running: never swept by an unqualified --run)",
938
910
  test: "tests",
939
911
  "static-analysis": "duplication, dead code, complexity, import graph, file size, bundle weight",
912
+ sql: "migrations and Unsafe raw SQL calls, in the modules that hold them",
940
913
  env: "env files, contracts and Dockerfiles, for the whole repository (run from its root)",
941
914
  "runtime-analysis": "Lighthouse, web vitals",
942
915
  arch: "architecture boundaries"
@@ -1119,10 +1092,12 @@ function parseEnvLevel(value) {
1119
1092
  var envLevel = targets.some((target) => REPOSITORY_TARGETS.includes(target)) ? parseEnvLevel(process.env.SENTINEL_ENV_LEVEL) : DEFAULT_ENV_LEVEL;
1120
1093
  var githubActions = process.env.GITHUB_ACTIONS === "true";
1121
1094
  var targetsExplicit = !(opts.all || namedTargets.length === 0);
1122
- if (namedTargets.includes("static-analysis") && (verb === "report" || verb === "run" && opts.json)) {
1123
- program.error(
1124
- `sentinel: --static-analysis writes its own report, so ${verb === "report" ? "--report" : "--json"} has nothing to add to it. Run it bare for the console report, or with --output json|html|markdown for the files.`
1125
- );
1095
+ for (const reporting of ["static-analysis", "sql"]) {
1096
+ if (namedTargets.includes(reporting) && (verb === "report" || verb === "run" && opts.json)) {
1097
+ program.error(
1098
+ `sentinel: --${reporting} writes its own report, so ${verb === "report" ? "--report" : "--json"} has nothing to add to it. Run it bare for the console report, or with --output json|html|markdown for the files.`
1099
+ );
1100
+ }
1126
1101
  }
1127
1102
  var maxDiagnostics = Number(opts.maxDiagnostics);
1128
1103
  if (!Number.isInteger(maxDiagnostics) || maxDiagnostics < 0) {