@hublo/sentinel 1.7.0-alpha.2 → 1.7.0-alpha.20

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 +2 -0
  2. package/dist/bin/sentinel.js +46 -113
  3. package/dist/{chunk-Z3JI7ZWX.js → chunk-AVT5FSPO.js} +232 -195
  4. package/dist/{chunk-EETHWJBF.js → chunk-B3Y7F7BA.js} +3533 -1074
  5. package/dist/{chunk-DLGBRLUU.js → chunk-EESVRILJ.js} +3 -16
  6. package/dist/chunk-EESVRILJ.js.map +1 -0
  7. package/dist/{chunk-ZNANJEMK.js → chunk-JT7ZMH44.js} +30 -16
  8. package/dist/chunk-JT7ZMH44.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-NGLEGAEN.js +190 -0
  12. package/dist/chunk-NGLEGAEN.js.map +1 -0
  13. package/dist/{chunk-4YQXLPJ5.js → chunk-PMRL4MH6.js} +2 -2
  14. package/dist/chunk-PXTU5MPW.js +9 -0
  15. package/dist/chunk-PXTU5MPW.js.map +1 -0
  16. package/dist/{chunk-LNFGVGLE.js → chunk-SWWQ7X7B.js} +11 -23
  17. package/dist/{chunk-LNFGVGLE.js.map → chunk-SWWQ7X7B.js.map} +1 -1
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +6 -6
  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-LRHF63AW.js → validate-B5567Z7X.js} +2 -4
  41. package/docs/build-adoption.md +0 -7
  42. package/docs/sql-adoption.md +552 -0
  43. package/docs/static-analysis-adoption.md +1 -1
  44. package/docs/test-adoption.md +1 -8
  45. package/docs/typescript-adoption.md +13 -52
  46. package/docs/typescript-traces.md +217 -3
  47. package/docs/using-sentinel.md +2 -1
  48. package/package.json +6 -4
  49. package/dist/chunk-4UUL4SEW.js +0 -50
  50. package/dist/chunk-DLGBRLUU.js.map +0 -1
  51. package/dist/chunk-H4HAFJFZ.js +0 -79
  52. package/dist/chunk-H4HAFJFZ.js.map +0 -1
  53. package/dist/chunk-THTXP2QU.js.map +0 -1
  54. package/dist/chunk-ZNANJEMK.js.map +0 -1
  55. package/dist/migrate-NI33SXZD.js +0 -517
  56. package/dist/tsconfig/legacy.json +0 -21
  57. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-PMRL4MH6.js.map} +0 -0
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,23 +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-EETHWJBF.js";
16
+ } from "../chunk-B3Y7F7BA.js";
16
17
  import {
17
18
  resolveContext,
18
19
  separateToolArgs
19
- } from "../chunk-Z3JI7ZWX.js";
20
- import "../chunk-4UUL4SEW.js";
20
+ } from "../chunk-AVT5FSPO.js";
21
21
  import {
22
22
  ensureWorkspacePrep,
23
23
  findWorkspaceRoot,
24
24
  inspectWorkspacePrep,
25
25
  readOwnVersion,
26
26
  readProjectPackageJson
27
- } from "../chunk-ZNANJEMK.js";
27
+ } from "../chunk-JT7ZMH44.js";
28
28
  import {
29
29
  DEFAULT_ENV_LEVEL,
30
30
  ENV_LEVELS,
@@ -35,10 +35,11 @@ import {
35
35
  SWEEPABLE_TARGETS,
36
36
  TARGETS,
37
37
  VERBS
38
- } from "../chunk-THTXP2QU.js";
38
+ } from "../chunk-LX7EG6PJ.js";
39
+ import "../chunk-NGLEGAEN.js";
40
+ import "../chunk-PXTU5MPW.js";
39
41
  import "../chunk-4EIY7TTR.js";
40
42
  import "../chunk-O7REVMOC.js";
41
- import "../chunk-H4HAFJFZ.js";
42
43
  import "../chunk-QXFCZON7.js";
43
44
 
44
45
  // bin/sentinel.ts
@@ -484,6 +485,7 @@ async function runInit(ctx) {
484
485
  outcomes.push(outcome);
485
486
  };
486
487
  const planned = [];
488
+ const dependenciesBefore = declaredDependencies(module.root);
487
489
  let worst = 0;
488
490
  for (const type of toRun) {
489
491
  try {
@@ -549,18 +551,21 @@ sentinel (${type}): ${asMessage(error)}
549
551
  // Only when the FORMAT role actually adopted: a module still formatted by the root
550
552
  // must not be excluded from it.
551
553
  formattedModule: toRun.includes("format") ? module.root : void 0,
552
- // Same rule for the report directory: only when the STATIC ANALYSIS role adopted.
553
- analysedModule: toRun.includes("static-analysis")
554
+ // Same rule for the report directories: only for a role that writes reports and adopted.
555
+ adoptedRoles: toRun
554
556
  });
555
557
  workspace = changes;
556
558
  const prefix = ctx.dryRun ? " dry run: " : " ";
557
559
  for (const change of changes) process.stderr.write(`${prefix}${change}
558
560
  `);
559
- if (changes.length > 0 && !ctx.dryRun) {
560
- process.stderr.write(
561
- palette(process.stderr).dim(" run `pnpm install` to apply the workspace changes\n")
562
- );
563
- }
561
+ }
562
+ const hint = installHint(
563
+ workspace.length > 0,
564
+ declaredDependencies(module.root) !== dependenciesBefore
565
+ );
566
+ if (hint !== void 0 && !ctx.dryRun) {
567
+ process.stderr.write(palette(process.stderr).dim(` ${hint}
568
+ `));
564
569
  }
565
570
  }
566
571
  if (ctx.json) {
@@ -574,64 +579,18 @@ sentinel (${type}): ${asMessage(error)}
574
579
  }
575
580
  return worst;
576
581
  }
577
-
578
- // src/cli/run-migrate.ts
579
- async function runMigrate(ctx) {
580
- const { modules, scope } = resolveContext(ctx.cwd, { module: ctx.module, ci: false });
581
- const [module] = modules;
582
- if (scope === "all" || scope === "affected" || module === void 0) {
583
- ctx.fail(
584
- "--migrate writes files: target one module (run from its directory, or pass --module). Migrating every module at once is intentionally not allowed."
585
- );
586
- }
587
- const unsupported = ctx.targets.filter((target) => target !== "typescript");
588
- if (unsupported.length > 0) {
589
- const named = unsupported.map((target) => `--${target}`).join(", ");
590
- process.stdout.write(
591
- ` \xB7 ${named}: not available yet. \`--migrate\` answers \`--typescript\` today, by detaching the module from tsconfig.base.json. Nothing was migrated for ${named}.
592
- `
593
- );
594
- }
595
- if (!ctx.targets.includes("typescript")) return 1;
596
- const { migrateModule } = await import("../migrate-NI33SXZD.js");
597
- const migration = migrateModule(module.root, {
598
- write: !ctx.dryRun,
599
- workspaceRoot: findWorkspaceRoot(module.root) ?? module.root
600
- });
601
- if (ctx.json) {
602
- process.stdout.write(
603
- `${JSON.stringify({ module: module.name, target: "typescript", ...migration }, null, 2)}
604
- `
605
- );
606
- } else {
607
- const mark = migration.outcome === "migrated" || migration.outcome === "proved" ? "\u2713" : migration.outcome === "skipped" ? "\xB7" : "\u2717";
608
- process.stdout.write(` ${mark} ${module.name} \u2014 ${migration.message}
609
- `);
610
- for (const file of migration.files) {
611
- process.stdout.write(
612
- ` ${file.kept ? "\u2713" : "\xB7"} ${file.file}${file.reason ? `: ${file.reason}` : ""}
613
- `
614
- );
615
- if (file.aliases !== void 0) {
616
- process.stdout.write(
617
- ` ${file.legacy ? "extends legacy, " : ""}${file.aliases.kept} of ${file.aliases.of} aliases, ${file.resolutions ?? 0} resolutions compared${file.written && file.written.length > 0 ? `, wrote ${file.written.join(", ")}` : ""}
618
- `
619
- );
620
- }
621
- for (const line of [
622
- ...(file.configDifferences ?? []).map(
623
- (d) => `${d.key}: ${d.before ?? "unset"} -> ${d.after ?? "unset"}`
624
- ),
625
- ...file.resolutionDifferences ?? []
626
- ].slice(0, 20)) {
627
- process.stdout.write(` ${line}
628
- `);
629
- }
630
- }
631
- for (const note of migration.notes) process.stdout.write(` note: ${note}
632
- `);
633
- }
634
- return migration.outcome === "migrated" || migration.outcome === "proved" || migration.outcome === "skipped" ? 0 : 1;
582
+ function declaredDependencies(root) {
583
+ const { dependencies = {}, devDependencies = {} } = readProjectPackageJson(root);
584
+ const sorted = (map) => Object.entries(map).sort(([a], [b]) => a.localeCompare(b));
585
+ return JSON.stringify([sorted(dependencies), sorted(devDependencies)]);
586
+ }
587
+ function installHint(workspaceChanged, dependenciesChanged) {
588
+ if (!workspaceChanged && !dependenciesChanged) return void 0;
589
+ const what = [
590
+ workspaceChanged ? "the workspace changes" : void 0,
591
+ dependenciesChanged ? "this module's new dependencies" : void 0
592
+ ].filter((part) => part !== void 0);
593
+ return `run \`pnpm install\` to apply ${what.join(" and ")}, and commit pnpm-lock.yaml if it changed`;
635
594
  }
636
595
 
637
596
  // src/cli/run-validate.ts
@@ -646,7 +605,7 @@ async function runValidate(ctx) {
646
605
  );
647
606
  }
648
607
  if (!ctx.targets.includes("test")) return 1;
649
- const { validateModuleTests } = await import("../validate-LRHF63AW.js");
608
+ const { validateModuleTests } = await import("../validate-B5567Z7X.js");
650
609
  const outcomes = modules.flatMap(
651
610
  (module) => validateModuleTests(module.name, module.root)
652
611
  );
@@ -916,35 +875,6 @@ async function runVerb(ctx) {
916
875
  return ctx.verb === "run" || ctx.ci ? worstCode : 0;
917
876
  }
918
877
 
919
- // src/core/repository-root.ts
920
- import { execFileSync } from "node:child_process";
921
- import { realpathSync as realpathSync2 } from "node:fs";
922
- function findRepositoryRoot(cwd2) {
923
- try {
924
- const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {
925
- cwd: cwd2,
926
- encoding: "utf8",
927
- stdio: ["ignore", "pipe", "ignore"]
928
- }).trim();
929
- return root === "" ? void 0 : realpathSync2(root);
930
- } catch {
931
- return void 0;
932
- }
933
- }
934
- function isRepositoryRoot(cwd2, root) {
935
- try {
936
- return realpathSync2(cwd2) === root;
937
- } catch {
938
- return false;
939
- }
940
- }
941
- function locateRepository(cwd2) {
942
- const root = findRepositoryRoot(cwd2);
943
- if (root === void 0) return { ok: false, reason: "not-a-repository" };
944
- if (!isRepositoryRoot(cwd2, root)) return { ok: false, reason: "not-the-root", root };
945
- return { ok: true, root };
946
- }
947
-
948
878
  // src/shared/node-version.ts
949
879
  var MIN_NODE = "24.15.0";
950
880
  function parts(version) {
@@ -979,6 +909,7 @@ var TARGET_HELP = {
979
909
  dev: "dev server (long-running: never swept by an unqualified --run)",
980
910
  test: "tests",
981
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",
982
913
  env: "env files, contracts and Dockerfiles, for the whole repository (run from its root)",
983
914
  "runtime-analysis": "Lighthouse, web vitals",
984
915
  arch: "architecture boundaries"
@@ -987,16 +918,13 @@ program.name("sentinel").description("One CLI that guards code health: presets,
987
918
  "before",
988
919
  [
989
920
  "A check composes: verb + type + location.",
990
- " verb what to do: --run --inspect --report --status --init --migrate --validate",
921
+ " verb what to do: --run --inspect --report --status --init --validate (--migrate: planned)",
991
922
  " type which check: --lint --typescript ... (omit = all types; or --all)",
992
923
  " where run from a MODULE dir \u2192 that module; from the ROOT \u2192 --module <name>,",
993
924
  " --ci (affected), or all modules. --init targets one module only.",
994
925
  ""
995
926
  ].join("\n")
996
- ).option("--run", "execute the target tool").option("--inspect", "show the resolved configuration").option("--init", "set up a module: write its config stubs + the workspace prep it needs").option(
997
- "--migrate",
998
- "change an already-initialized setup: --typescript detaches the module from tsconfig.base.json"
999
- ).option(
927
+ ).option("--run", "execute the target tool").option("--inspect", "show the resolved configuration").option("--init", "set up a module: write its config stubs + the workspace prep it needs").option("--migrate", "planned: change an already-initialized setup (not available yet)").option(
1000
928
  "--validate",
1001
929
  "prove a migration kept the suite: record the reference, then compare against it"
1002
930
  ).option("--report", "deprecated: use --run --json").option("--status", "deprecated: use --inspect").option(
@@ -1164,10 +1092,12 @@ function parseEnvLevel(value) {
1164
1092
  var envLevel = targets.some((target) => REPOSITORY_TARGETS.includes(target)) ? parseEnvLevel(process.env.SENTINEL_ENV_LEVEL) : DEFAULT_ENV_LEVEL;
1165
1093
  var githubActions = process.env.GITHUB_ACTIONS === "true";
1166
1094
  var targetsExplicit = !(opts.all || namedTargets.length === 0);
1167
- if (namedTargets.includes("static-analysis") && (verb === "report" || verb === "run" && opts.json)) {
1168
- program.error(
1169
- `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.`
1170
- );
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
+ }
1171
1101
  }
1172
1102
  var maxDiagnostics = Number(opts.maxDiagnostics);
1173
1103
  if (!Number.isInteger(maxDiagnostics) || maxDiagnostics < 0) {
@@ -1175,8 +1105,8 @@ if (!Number.isInteger(maxDiagnostics) || maxDiagnostics < 0) {
1175
1105
  `--max-diagnostics must be a non-negative integer (0 = no cap); got ${JSON.stringify(opts.maxDiagnostics)}.`
1176
1106
  );
1177
1107
  }
1178
- if (opts.dryRun && verb !== "init" && verb !== "migrate") {
1179
- program.error("--dry-run only applies to --init and --migrate (the read verbs never write).");
1108
+ if (opts.dryRun && verb !== "init") {
1109
+ program.error("--dry-run only applies to --init (the read verbs never write).");
1180
1110
  }
1181
1111
  if (opts.rehearse && !opts.dryRun) {
1182
1112
  program.error(
@@ -1202,6 +1132,9 @@ async function exitWithoutTruncating(code) {
1202
1132
  await new Promise((resolve2) => stream.once("drain", () => resolve2()));
1203
1133
  }
1204
1134
  async function main() {
1135
+ if (verb === "migrate") {
1136
+ program.error("--migrate is planned and not available yet; use --init to set a module up.");
1137
+ }
1205
1138
  const context = {
1206
1139
  verb,
1207
1140
  cwd,
@@ -1226,7 +1159,7 @@ async function main() {
1226
1159
  githubActions,
1227
1160
  fail: (message) => program.error(message)
1228
1161
  };
1229
- const exitCode = verb === "init" ? await runInit(context) : verb === "validate" ? await runValidate(context) : verb === "migrate" ? await runMigrate(context) : await runVerb(context);
1162
+ const exitCode = verb === "init" ? await runInit(context) : verb === "validate" ? await runValidate(context) : await runVerb(context);
1230
1163
  await exitWithoutTruncating(exitCode);
1231
1164
  }
1232
1165
  main().catch((error) => {