@hublo/sentinel 1.4.3 → 1.5.0-alpha.2

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.
@@ -1,9 +1,3 @@
1
- import {
2
- matchesTsconfigPattern
3
- } from "./chunk-O7REVMOC.js";
4
- import {
5
- parseJsonc
6
- } from "./chunk-QXFCZON7.js";
7
1
  import {
8
2
  DEFAULT_MAX_DIAGNOSTICS,
9
3
  WORKSPACE_ROOT_MARKER,
@@ -13,6 +7,12 @@ import {
13
7
  readOwnPackage,
14
8
  readProjectPackageJson
15
9
  } from "./chunk-KMKQDGI6.js";
10
+ import {
11
+ matchesTsconfigPattern
12
+ } from "./chunk-O7REVMOC.js";
13
+ import {
14
+ parseJsonc
15
+ } from "./chunk-QXFCZON7.js";
16
16
 
17
17
  // src/core/base-adapter.ts
18
18
  var BaseAdapter = class {
@@ -5341,6 +5341,28 @@ function specTypesOperation(cwd) {
5341
5341
  }
5342
5342
  };
5343
5343
  }
5344
+ function specTypesCleanupOperation(cwd) {
5345
+ const path = join25(cwd, SPEC_TSCONFIG);
5346
+ if (!existsSync19(path)) return void 0;
5347
+ let config;
5348
+ try {
5349
+ config = parseJsonc(
5350
+ readFileSync21(path, "utf8"),
5351
+ SPEC_TSCONFIG
5352
+ );
5353
+ } catch {
5354
+ return void 0;
5355
+ }
5356
+ const types = config?.compilerOptions?.types;
5357
+ if (!Array.isArray(types) || !types.includes("jest")) return void 0;
5358
+ const remaining = types.filter((entry) => entry !== "jest");
5359
+ if (remaining.length === 0) return void 0;
5360
+ return {
5361
+ kind: "merge-json",
5362
+ path: SPEC_TSCONFIG,
5363
+ value: { compilerOptions: { types: remaining } }
5364
+ };
5365
+ }
5344
5366
  function shippedTypesPath(cwd, declaration) {
5345
5367
  try {
5346
5368
  const manifest = createRequire5(join25(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
@@ -5703,6 +5725,8 @@ function plan(context) {
5703
5725
  keys: [["targets", TEST_SCRIPT_NAME]]
5704
5726
  });
5705
5727
  }
5728
+ const specTypes = specTypesCleanupOperation(context.cwd);
5729
+ if (specTypes !== void 0) operations2.push(specTypes);
5706
5730
  if (operations2.length === 0) {
5707
5731
  return {
5708
5732
  operations: [],
@@ -5715,7 +5739,11 @@ function plan(context) {
5715
5739
  // Names what is actually removed, never a shape this module does not have: half of these
5716
5740
  // modules carry a config with no target behind it, and claiming otherwise would describe
5717
5741
  // an operation the plan never performs.
5718
- `this module has no test file, so this is a cleanup rather than an adoption: ${[...adoption.jestConfigs, ...hasTarget ? ["the jest target it feeds"] : []].join(" and ")} removed, so nothing here breaks the day jest leaves the workspace. No test config is written in exchange, because there is nothing to configure.`
5742
+ `this module has no test file, so this is a cleanup rather than an adoption: ${[
5743
+ ...adoption.jestConfigs,
5744
+ ...hasTarget ? ["the jest target it feeds"] : [],
5745
+ ...specTypes !== void 0 ? ["the jest entry in tsconfig.spec.json"] : []
5746
+ ].join(" and ")} removed, so nothing here breaks the day jest leaves the workspace. No test config is written in exchange, because there is nothing to configure.`
5719
5747
  ]
5720
5748
  };
5721
5749
  }
@@ -0,0 +1,92 @@
1
+ // src/shared/deep-merge.ts
2
+ function isPlainObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value);
4
+ }
5
+
6
+ // src/roles/static-analysis/presets/shared.json
7
+ var shared_default = {
8
+ entry: ["**/*.integration-spec.ts", "**/*.steps.ts"],
9
+ ignore: [
10
+ "**/node_modules/**",
11
+ "**/dist/**",
12
+ "**/build/**",
13
+ "**/coverage/**",
14
+ "**/.next/**",
15
+ "**/static-analysis-report/**",
16
+ "**/__mocks__/**",
17
+ "**/mocks/**",
18
+ "**/_mock_/**",
19
+ "**/**Mock**/**",
20
+ "**/__fixtures__/**",
21
+ "**/fixtures/**",
22
+ "**/public/**",
23
+ "**/.husky/**",
24
+ "**/.vscode/**",
25
+ "**/.idea/**",
26
+ "**/.github/**",
27
+ "**/*.d.ts",
28
+ "**/*.gen.ts",
29
+ "**/*.generated.ts"
30
+ ],
31
+ languages: ["javascript", "typescript", "jsx", "tsx", "css", "scss"],
32
+ journeys: {},
33
+ duplication: { minTokens: 50, minLines: 5, kinds: ["exact"] },
34
+ deadCode: {
35
+ minConfidence: 60,
36
+ categories: ["unused-file", "unused-export", "unused-symbol", "unused-import"]
37
+ },
38
+ thresholds: { duplicatedLinesPercent: 5, deadCodePercent: 5 },
39
+ tools: { jscpd: {} }
40
+ };
41
+
42
+ // src/roles/static-analysis/preset-data.ts
43
+ var REPORT_DIR = "static-analysis-report";
44
+ var defaults = shared_default;
45
+
46
+ // src/roles/static-analysis/configs/define.ts
47
+ function mergeInto(base, patch) {
48
+ if (!isPlainObject(patch)) return base;
49
+ if (!isPlainObject(base)) return patch;
50
+ const out = { ...base };
51
+ for (const [key, value] of Object.entries(patch)) {
52
+ out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value;
53
+ }
54
+ return out;
55
+ }
56
+ function leafPaths(patch, prefix = "") {
57
+ if (!isPlainObject(patch)) return prefix ? [prefix] : [];
58
+ return Object.entries(patch).flatMap(
59
+ ([key, value]) => leafPaths(value, prefix ? `${prefix}.${key}` : key)
60
+ );
61
+ }
62
+ function unique(values) {
63
+ return [...new Set(values)];
64
+ }
65
+ function withoutVendorKeys(overrides) {
66
+ if (!isPlainObject(overrides) || !("tools" in overrides)) return overrides;
67
+ const { tools: _vendor, ...rest } = overrides;
68
+ process.stderr.write(
69
+ "sentinel static-analysis: ignoring `overrides.tools` from this module. The tool underneath the role is not part of a module's surface; if a setting is missing, it needs a key of its own.\n"
70
+ );
71
+ return rest;
72
+ }
73
+ function defineStaticAnalysis(input = {}) {
74
+ const declared = {
75
+ ...defaults,
76
+ entry: unique([...defaults.entry, ...input.entry ?? []]),
77
+ journeys: { ...defaults.journeys, ...input.journeys ?? {} }
78
+ };
79
+ const overrides = withoutVendorKeys(input.overrides);
80
+ return {
81
+ ...mergeInto(declared, overrides),
82
+ root: input.root ?? null,
83
+ moved: leafPaths(overrides).sort()
84
+ };
85
+ }
86
+
87
+ export {
88
+ isPlainObject,
89
+ REPORT_DIR,
90
+ defineStaticAnalysis
91
+ };
92
+ //# sourceMappingURL=chunk-GJGZRXM3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/deep-merge.ts","../src/roles/static-analysis/presets/shared.json","../src/roles/static-analysis/preset-data.ts","../src/roles/static-analysis/configs/define.ts"],"sourcesContent":["/**\n * Is this a plain JSON object?\n *\n * The file is named for a `deepMerge` that no longer exists. It was written when the engine\n * merged JSON in memory and wrote the result; that approach was replaced by editing the\n * document IN PLACE with jsonc-parser, so a project's comments, key order and formatting\n * survive a `merge-json` op. Nothing has called `deepMerge` since, except its own recursion,\n * so it went.\n *\n * What remains is the predicate the in-place merge still needs, to decide whether a value is\n * a branch to walk into or a leaf to set.\n */\n\n/** True for a mergeable plain object (not null, not an array). */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","{\n \"entry\": [\"**/*.integration-spec.ts\", \"**/*.steps.ts\"],\n \"ignore\": [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/coverage/**\",\n \"**/.next/**\",\n \"**/static-analysis-report/**\",\n \"**/__mocks__/**\",\n \"**/mocks/**\",\n \"**/_mock_/**\",\n \"**/**Mock**/**\",\n \"**/__fixtures__/**\",\n \"**/fixtures/**\",\n \"**/public/**\",\n \"**/.husky/**\",\n \"**/.vscode/**\",\n \"**/.idea/**\",\n \"**/.github/**\",\n \"**/*.d.ts\",\n \"**/*.gen.ts\",\n \"**/*.generated.ts\"\n ],\n \"languages\": [\"javascript\", \"typescript\", \"jsx\", \"tsx\", \"css\", \"scss\"],\n \"journeys\": {},\n \"duplication\": { \"minTokens\": 50, \"minLines\": 5, \"kinds\": [\"exact\"] },\n \"deadCode\": {\n \"minConfidence\": 60,\n \"categories\": [\"unused-file\", \"unused-export\", \"unused-symbol\", \"unused-import\"]\n },\n \"thresholds\": { \"duplicatedLinesPercent\": 5, \"deadCodePercent\": 5 },\n \"tools\": { \"jscpd\": {} }\n}\n","/**\n * The static analysis preset: the role's settings, as data.\n *\n * One shared layer and no per-stack preset yet, because nothing measured so far varies by stack:\n * duplication, dead code and complexity are the same questions in Nest and in React. The split\n * that is already foreseen is `LCOM4`, which is meaningless on a functional front end and real on\n * nest's 16 568 classes; when it arrives it becomes `nest.json` beside this layer, which is why\n * the values live here as JSON rather than inline in the code.\n *\n * ## Why these values are the role's and not the module's\n *\n * A team declares FACTS about its own domain (which journeys exist, which files are entry points);\n * it does not declare the values a number is judged by. Two files with the same measurement\n * getting different verdicts in two modules would make every figure incomparable, and the first\n * thing this role has to be able to say is that a number means the same thing everywhere.\n *\n * That is a default, not a wall: a module CAN move any of them (see `configs/define.ts`), and when\n * it does the report prints `(module)` next to the value. The seam exists from the first commit\n * because retrofitting one later means rewriting every module's file.\n *\n * Both thresholds are a STARTING POINT and will be calibrated from the distribution the first full\n * run produces, the same commitment a preset rule carries in `CONTRIBUTING.md`. For scale,\n * sentinel's own package measures 1.4% duplicated lines and 1.3% dead code.\n *\n * ## Where each value comes from, so nobody has to guess later\n *\n * - `entry` is the single most consequential line in the file. Measured on\n * `apps/nest/microservices/network` with jscpd 5.4.0: with nothing declared the dead-code pass\n * reports **33.4%** of lines dead (79 657 lines, 232 files, 13 entry points); with these two\n * patterns declared it reports **1.0%** (2 462 lines, 207 entry points). The cause is a naming\n * convention and not a bug: our integration tests are `foo.integration-spec.ts` with a HYPHEN,\n * so they do not end in `.spec.ts` and the tool's own test-file detection never sees them, and\n * the 115 `.steps.ts` BDD definitions are tests by no convention it knows. A module ADDS to\n * this list rather than replacing it, precisely so no team can lose these two by declaring a\n * third.\n *\n * - `languages` is this role's name for what the tool calls `format`, a word that already names\n * another sentinel role and means something else there. Stating it has a measured cost either\n * way: on `apps/front/console`, naming `typescript` alone scans 300 of 523 files because `.tsx`\n * is a SEPARATE language to the tool, naming all four scans 522 (the one left out being\n * `styles.css`), and naming nothing scans every one of its 224 languages, json and markdown\n * included. Stylesheets are in deliberately: measured on `libs/front` they duplicate at 9.64%\n * against 3.50% for the code, a signal that only survives because the report is broken down per\n * language.\n *\n * - `duplication.minTokens` and `minLines` are the detection window, and the window decides what\n * is INVISIBLE: a fragment shorter than it is not reported at all, so a reader comparing two\n * runs has to know both values. They are the tool's own defaults, written out rather than\n * inherited for that reason.\n *\n * - `duplication.kinds` is `exact` alone, and that is a correctness constraint rather than\n * caution. Measured: with a second kind enabled, `duplicatedLines` adds up overlapping clones.\n * Two 9-line files reported 13 duplicated lines out of 18, 72%, because an `exact` clone of\n * lines 1-4 and a `similar` clone of lines 1-9 containing it were both counted; the real extent\n * is 9 of 18, 50%. The tool's own answer is to cap the display at 100%, which does not make a\n * threshold meaningful. Opening another kind therefore requires computing the share ourselves\n * from the UNION of the line ranges.\n *\n * - `deadCode.minConfidence` is the tool's own default of 60. It scores every finding and names\n * what lowered it (a file calling `eval`, an unrecognised decorator, a name appearing in a\n * string literal, a file in the scan that did not parse). Measured on sentinel: 60 yields 20\n * files, 10 exports and 22 symbols; 90 yields 18 files; 100 yields nothing.\n *\n * - `deadCode.categories` leaves out `unused-member` deliberately: without type information\n * `x.render()` could reach any `render` in the project, which the tool itself calls its least\n * certain rule.\n *\n * - `ignore` excludes generated, vendored and fixture code, which duplicates by nature and buries\n * the clones a developer can act on. It is load-bearing rather than tidy: measured on this\n * package, scanning the module root with no ignore list reports 18 186 files and 32 153 clones,\n * **31 969** of them touching `node_modules`; with the list, 408 files and zero.\n *\n * - `tools.jscpd` is passed to the tool verbatim, and it is **sentinel's own** escape hatch, not a\n * module's: `defineStaticAnalysis` excludes it from what a module can override. Everything above\n * uses OUR key names, translated on the way out, so that replacing the tool one day does not\n * oblige a single module to edit its config file, and a module only ever knows the ROLE. This\n * block is where that guarantee stops, which is why it stays on this side and why it is empty:\n * the first thing to put in it would be an option a single preset needs, not a workaround.\n */\nimport sharedData from './presets/shared.json'\n\n/**\n * Where the json and html reports are written, relative to the module.\n *\n * Named for the role rather than left on the tool's default `report/`, and added to `.gitignore`\n * by `--init`. Both halves matter: the format role once shipped a `lint/` directory that nothing\n * ignored, and every adopting module grew an untracked directory nobody could explain.\n */\nexport const REPORT_DIR = 'static-analysis-report'\n\nexport type StaticDefaults = {\n entry: string[]\n ignore: string[]\n languages: string[]\n journeys: Record<string, string[]>\n duplication: { minTokens: number; minLines: number; kinds: string[] }\n deadCode: { minConfidence: number; categories: string[] }\n thresholds: { duplicatedLinesPercent: number; deadCodePercent: number }\n tools: { jscpd: Record<string, unknown> }\n}\n\n/** The role's settings. Read-only here; `defineStaticAnalysis` resolves a module against them. */\nexport const defaults: StaticDefaults = sharedData as StaticDefaults\n","/**\n * `defineStaticAnalysis`: what a module imports to declare its own static analysis settings.\n *\n * ```js\n * // static-analysis.config.mjs\n * import { defineStaticAnalysis } from '@hublo/sentinel/static-analysis'\n *\n * export default defineStaticAnalysis({\n * root: import.meta.dirname,\n * entry: ['**\\/*.steps.ts'],\n * journeys: { planning: ['src/planning/**'] },\n * })\n * ```\n *\n * ## Why a function and not `{ ...baseConfig, ... }`\n *\n * A spread is SHALLOW, so a module writing `deadCode: { minConfidence: 80 }` would replace the\n * whole block and silently lose `categories`. And the flattening happens in the module's file,\n * before this package ever sees the object, so nothing here could tell \"set one key, keep the\n * rest\" from \"set one key, drop the rest\". A function receives the module's INTENT, the keys it\n * actually passed, and merges them here. Second reason: the defaults are never copied into a\n * module, so changing one reaches every module at the next release instead of leaving 108 stale\n * copies behind.\n *\n * Same shape as `reactTestConfig` in the test role, for the same reasons.\n *\n * ## Two semantics, one obvious and one deliberate\n *\n * `entry` and `journeys` are FACTS a team declares, and they ADD to what this role ships: no\n * module can lose `**\\/*.integration-spec.ts` by declaring a third pattern, which matters\n * because that one pattern is the difference between 33.4% and 1.0% of dead code on a real\n * service (see `defaults.ts`).\n *\n * `overrides` REPLACES, including those lists. It is the seam for the day a team has a real\n * reason, it is not documented anywhere a developer would meet it, and every path it sets is\n * recorded in `moved` so the report can print `(module)` next to the value. Without that trace\n * two modules stop being comparable and nobody knows. It reaches every setting EXCEPT the vendor\n * passthrough, for the reason stated on the field itself.\n */\nimport { isPlainObject } from '../../../shared/deep-merge.js'\nimport { defaults, type StaticDefaults } from '../preset-data.js'\n\ntype DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K] }\n\n/** What a module's config file passes. Everything is optional, including the file itself. */\nexport interface StaticAnalysisInput {\n /** The module's own directory, normally `import.meta.dirname`. */\n root?: string\n /** Files that run although nothing imports them. ADDED to the shipped patterns. */\n entry?: string[]\n /** Named journeys, as `{ name: [globs] }`. MERGED by name with any shipped ones. */\n journeys?: Record<string, string[]>\n /**\n * The seam. Replaces whatever it names, and every path it sets lands in `moved`.\n *\n * ⛔ `tools` is excluded, and the reason is the whole point of translating the vocabulary: a\n * module knows the ROLE, not the tool underneath it. A key named after the vendor would mean\n * nothing to the person reading their own config file, and showing it would invite them to learn\n * a name we are working to keep out of their world. The passthrough still exists, on sentinel's\n * side, for a preset that needs a vendor option; a module that genuinely needs one gets a key in\n * OUR vocabulary, which is the right friction because it goes through a review instead of\n * spreading silently.\n */\n overrides?: DeepPartial<Omit<StaticDefaults, 'tools'>>\n}\n\nexport interface ResolvedStaticConfig extends StaticDefaults {\n /** The module's directory, or null when its config file did not say. */\n root: string | null\n /**\n * Dotted paths the module set through `overrides`, so the report can mark them. Sorted, so\n * two runs on the same config produce the same report.\n */\n moved: string[]\n}\n\n/**\n * Merge `patch` into `base`, recursively, patch winning.\n *\n * Not the `deepMerge` this repo once had: that one existed for WRITING a module's json and was\n * replaced by an in-place jsonc edit, which is why only `isPlainObject` survived. This is the\n * read side, which has no file to preserve and only has to resolve two objects into one.\n *\n * Arrays are replaced, never concatenated. Additive behaviour is a decision about a specific\n * key, which `defineStaticAnalysis` makes explicitly for `entry`, rather than a property of the\n * merge: a merge that silently concatenates cannot express \"replace this list\", and a team\n * reaching for `overrides` is asking for exactly that.\n */\nfunction mergeInto<T>(base: T, patch: unknown): T {\n if (!isPlainObject(patch)) return base\n if (!isPlainObject(base)) return patch as T\n const out: Record<string, unknown> = { ...base }\n for (const [key, value] of Object.entries(patch)) {\n out[key] = isPlainObject(value) ? mergeInto(out[key], value) : value\n }\n return out as T\n}\n\n/** Every leaf path in `patch`, dotted, so a reader can be told what the module decided. */\nfunction leafPaths(patch: unknown, prefix = ''): string[] {\n if (!isPlainObject(patch)) return prefix ? [prefix] : []\n return Object.entries(patch).flatMap(([key, value]) =>\n leafPaths(value, prefix ? `${prefix}.${key}` : key),\n )\n}\n\n/** The same list with duplicates dropped, keeping the first occurrence's order. */\nfunction unique(values: string[]): string[] {\n return [...new Set(values)]\n}\n\n/**\n * Drop the vendor passthrough from what a module sent.\n *\n * ⚠️ Enforced here and not by the type, because the type cannot: a module's config file is `.mjs`,\n * so nothing type-checks it, and `Omit` on the input would be documentation that compiles away. A\n * `tools` key written there is dropped and NAMED on stderr rather than ignored, so a developer who\n * found the key somewhere learns why it did nothing instead of concluding the role is broken.\n */\nfunction withoutVendorKeys(overrides: unknown): unknown {\n if (!isPlainObject(overrides) || !('tools' in overrides)) return overrides\n const { tools: _vendor, ...rest } = overrides\n process.stderr.write(\n 'sentinel static-analysis: ignoring `overrides.tools` from this module. The tool underneath ' +\n \"the role is not part of a module's surface; if a setting is missing, it needs a key of \" +\n 'its own.\\n',\n )\n return rest\n}\n\n/** Resolve a module's declaration against this role's defaults. */\nexport function defineStaticAnalysis(input: StaticAnalysisInput = {}): ResolvedStaticConfig {\n const declared: StaticDefaults = {\n ...defaults,\n entry: unique([...defaults.entry, ...(input.entry ?? [])]),\n journeys: { ...defaults.journeys, ...(input.journeys ?? {}) },\n }\n const overrides = withoutVendorKeys(input.overrides)\n\n return {\n ...mergeInto(declared, overrides),\n root: input.root ?? null,\n moved: leafPaths(overrides).sort(),\n }\n}\n"],"mappings":";AAcO,SAAS,cAAc,OAAkD;AAC9E,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;AChBA;AAAA,EACE,OAAS,CAAC,4BAA4B,eAAe;AAAA,EACrD,QAAU;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,WAAa,CAAC,cAAc,cAAc,OAAO,OAAO,OAAO,MAAM;AAAA,EACrE,UAAY,CAAC;AAAA,EACb,aAAe,EAAE,WAAa,IAAI,UAAY,GAAG,OAAS,CAAC,OAAO,EAAE;AAAA,EACpE,UAAY;AAAA,IACV,eAAiB;AAAA,IACjB,YAAc,CAAC,eAAe,iBAAiB,iBAAiB,eAAe;AAAA,EACjF;AAAA,EACA,YAAc,EAAE,wBAA0B,GAAG,iBAAmB,EAAE;AAAA,EAClE,OAAS,EAAE,OAAS,CAAC,EAAE;AACzB;;;ACuDO,IAAM,aAAa;AAcnB,IAAM,WAA2B;;;ACdxC,SAAS,UAAa,MAAS,OAAmB;AAChD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO;AAClC,MAAI,CAAC,cAAc,IAAI,EAAG,QAAO;AACjC,QAAM,MAA+B,EAAE,GAAG,KAAK;AAC/C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,QAAI,GAAG,IAAI,cAAc,KAAK,IAAI,UAAU,IAAI,GAAG,GAAG,KAAK,IAAI;AAAA,EACjE;AACA,SAAO;AACT;AAGA,SAAS,UAAU,OAAgB,SAAS,IAAc;AACxD,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO,SAAS,CAAC,MAAM,IAAI,CAAC;AACvD,SAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,IAAQ,CAAC,CAAC,KAAK,KAAK,MAC/C,UAAU,OAAO,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK,GAAG;AAAA,EACpD;AACF;AAGA,SAAS,OAAO,QAA4B;AAC1C,SAAO,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;AAC5B;AAUA,SAAS,kBAAkB,WAA6B;AACtD,MAAI,CAAC,cAAc,SAAS,KAAK,EAAE,WAAW,WAAY,QAAO;AACjE,QAAM,EAAE,OAAO,SAAS,GAAG,KAAK,IAAI;AACpC,UAAQ,OAAO;AAAA,IACb;AAAA,EAGF;AACA,SAAO;AACT;AAGO,SAAS,qBAAqB,QAA6B,CAAC,GAAyB;AAC1F,QAAM,WAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,OAAO,OAAO,CAAC,GAAG,SAAS,OAAO,GAAI,MAAM,SAAS,CAAC,CAAE,CAAC;AAAA,IACzD,UAAU,EAAE,GAAG,SAAS,UAAU,GAAI,MAAM,YAAY,CAAC,EAAG;AAAA,EAC9D;AACA,QAAM,YAAY,kBAAkB,MAAM,SAAS;AAEnD,SAAO;AAAA,IACL,GAAG,UAAU,UAAU,SAAS;AAAA,IAChC,MAAM,MAAM,QAAQ;AAAA,IACpB,OAAO,UAAU,SAAS,EAAE,KAAK;AAAA,EACnC;AACF;","names":[]}
package/dist/index.d.ts CHANGED
@@ -111,6 +111,15 @@ interface RunContext {
111
111
  * calls. The engine echoes them on stderr and carries them in the `--json` envelope.
112
112
  */
113
113
  toolArgs?: readonly string[];
114
+ /**
115
+ * The output shape a caller asked for, from `--output`. A role that can produce more than a
116
+ * console summary reads it; every other role ignores it.
117
+ *
118
+ * Left a plain string rather than a union on purpose: which shapes exist is a property of the
119
+ * role that writes them, and the engine has no business holding a list it cannot validate.
120
+ * The role rejects a shape it does not know, by name.
121
+ */
122
+ output?: string;
114
123
  }
115
124
  /**
116
125
  * A single, DECLARATIVE file operation an `--init` wants to happen. Adapters
package/dist/index.js CHANGED
@@ -6,13 +6,14 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-DYK6UEMO.js";
9
+ } from "./chunk-AHA7LGGA.js";
10
10
  import {
11
11
  BaseAdapter
12
- } from "./chunk-TDNPPNGK.js";
12
+ } from "./chunk-E3MYVYEZ.js";
13
+ import "./chunk-KMKQDGI6.js";
14
+ import "./chunk-GJGZRXM3.js";
13
15
  import "./chunk-O7REVMOC.js";
14
16
  import "./chunk-QXFCZON7.js";
15
- import "./chunk-KMKQDGI6.js";
16
17
  export {
17
18
  BaseAdapter,
18
19
  all,
@@ -0,0 +1,60 @@
1
+ type StaticDefaults = {
2
+ entry: string[];
3
+ ignore: string[];
4
+ languages: string[];
5
+ journeys: Record<string, string[]>;
6
+ duplication: {
7
+ minTokens: number;
8
+ minLines: number;
9
+ kinds: string[];
10
+ };
11
+ deadCode: {
12
+ minConfidence: number;
13
+ categories: string[];
14
+ };
15
+ thresholds: {
16
+ duplicatedLinesPercent: number;
17
+ deadCodePercent: number;
18
+ };
19
+ tools: {
20
+ jscpd: Record<string, unknown>;
21
+ };
22
+ };
23
+
24
+ type DeepPartial<T> = {
25
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
26
+ };
27
+ /** What a module's config file passes. Everything is optional, including the file itself. */
28
+ interface StaticAnalysisInput {
29
+ /** The module's own directory, normally `import.meta.dirname`. */
30
+ root?: string;
31
+ /** Files that run although nothing imports them. ADDED to the shipped patterns. */
32
+ entry?: string[];
33
+ /** Named journeys, as `{ name: [globs] }`. MERGED by name with any shipped ones. */
34
+ journeys?: Record<string, string[]>;
35
+ /**
36
+ * The seam. Replaces whatever it names, and every path it sets lands in `moved`.
37
+ *
38
+ * ⛔ `tools` is excluded, and the reason is the whole point of translating the vocabulary: a
39
+ * module knows the ROLE, not the tool underneath it. A key named after the vendor would mean
40
+ * nothing to the person reading their own config file, and showing it would invite them to learn
41
+ * a name we are working to keep out of their world. The passthrough still exists, on sentinel's
42
+ * side, for a preset that needs a vendor option; a module that genuinely needs one gets a key in
43
+ * OUR vocabulary, which is the right friction because it goes through a review instead of
44
+ * spreading silently.
45
+ */
46
+ overrides?: DeepPartial<Omit<StaticDefaults, 'tools'>>;
47
+ }
48
+ interface ResolvedStaticConfig extends StaticDefaults {
49
+ /** The module's directory, or null when its config file did not say. */
50
+ root: string | null;
51
+ /**
52
+ * Dotted paths the module set through `overrides`, so the report can mark them. Sorted, so
53
+ * two runs on the same config produce the same report.
54
+ */
55
+ moved: string[];
56
+ }
57
+ /** Resolve a module's declaration against this role's defaults. */
58
+ declare function defineStaticAnalysis(input?: StaticAnalysisInput): ResolvedStaticConfig;
59
+
60
+ export { type ResolvedStaticConfig, type StaticAnalysisInput, defineStaticAnalysis };
@@ -0,0 +1,7 @@
1
+ import {
2
+ defineStaticAnalysis
3
+ } from "../../chunk-GJGZRXM3.js";
4
+ export {
5
+ defineStaticAnalysis
6
+ };
7
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,11 +1,11 @@
1
+ import {
2
+ alreadyInstalled
3
+ } from "../../../chunk-NUOQXAYR.js";
1
4
  import {
2
5
  CURRENT_FILE_MOCKS,
3
6
  PHASE,
4
7
  SHARED_WORKER
5
8
  } from "../../../chunk-H3GSGAX2.js";
6
- import {
7
- alreadyInstalled
8
- } from "../../../chunk-NUOQXAYR.js";
9
9
  import {
10
10
  fromModule
11
11
  } from "../../../chunk-ELZHIN6E.js";
@@ -7,10 +7,10 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-TDNPPNGK.js";
10
+ } from "./chunk-E3MYVYEZ.js";
11
+ import "./chunk-KMKQDGI6.js";
11
12
  import "./chunk-O7REVMOC.js";
12
13
  import "./chunk-QXFCZON7.js";
13
- import "./chunk-KMKQDGI6.js";
14
14
 
15
15
  // src/roles/test/validate.ts
16
16
  import { execFileSync } from "node:child_process";