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

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.
@@ -12,12 +12,12 @@ import {
12
12
  presetNotInstalledYet,
13
13
  registerAdapters,
14
14
  resolve
15
- } from "../chunk-EETHWJBF.js";
15
+ } from "../chunk-F6ART7RH.js";
16
16
  import {
17
17
  resolveContext,
18
18
  separateToolArgs
19
- } from "../chunk-Z3JI7ZWX.js";
20
- import "../chunk-4UUL4SEW.js";
19
+ } from "../chunk-P6KTBQ2Q.js";
20
+ import "../chunk-ZFG6P27V.js";
21
21
  import {
22
22
  ensureWorkspacePrep,
23
23
  findWorkspaceRoot,
@@ -593,7 +593,7 @@ async function runMigrate(ctx) {
593
593
  );
594
594
  }
595
595
  if (!ctx.targets.includes("typescript")) return 1;
596
- const { migrateModule } = await import("../migrate-NI33SXZD.js");
596
+ const { migrateModule } = await import("../migrate-NWQ3LYER.js");
597
597
  const migration = migrateModule(module.root, {
598
598
  write: !ctx.dryRun,
599
599
  workspaceRoot: findWorkspaceRoot(module.root) ?? module.root
@@ -646,7 +646,7 @@ async function runValidate(ctx) {
646
646
  );
647
647
  }
648
648
  if (!ctx.targets.includes("test")) return 1;
649
- const { validateModuleTests } = await import("../validate-LRHF63AW.js");
649
+ const { validateModuleTests } = await import("../validate-4V3EGTXN.js");
650
650
  const outcomes = modules.flatMap(
651
651
  (module) => validateModuleTests(module.name, module.root)
652
652
  );
@@ -1,20 +1,12 @@
1
1
  import {
2
- ALWAYS_LOCAL_KEYS,
3
2
  BaseAdapter,
4
3
  ESLINT_CONFIG_FILES,
5
- FORMAT_CONFIG_FILE,
6
- FORMAT_DEFAULT_IGNORES,
7
- FORMAT_SCRIPT_NAME,
8
4
  LINT_BASELINE_FILE,
9
5
  LINT_BASELINE_SPECIFIER,
10
6
  LINT_CONFIG_FILE,
11
7
  LINT_MEASURE_FILE,
12
8
  LINT_PRESETS,
13
9
  LINT_SCRIPT_NAME,
14
- OWNED_WHEN_SET_KEYS,
15
- PERMITTED_LOCAL_KEYS,
16
- PRETTIER_CONFIG_FILES,
17
- PROVENANCE_KEY,
18
10
  RESOLVABLE_EXTENSIONS,
19
11
  VitestAdapter,
20
12
  adoptedPackageName,
@@ -26,9 +18,6 @@ import {
26
18
  downgradedFor,
27
19
  extendsWithBaseline,
28
20
  extendsWithPreset,
29
- formatPresetFor,
30
- formatPresetName,
31
- formatTargets,
32
21
  governedRules,
33
22
  hasLintPreset,
34
23
  heldRules,
@@ -42,7 +31,6 @@ import {
42
31
  moduleOwnBlocks,
43
32
  moduleScripts,
44
33
  nxTargetOperations,
45
- oxfmtRejects,
46
34
  oxlintPath,
47
35
  oxlintSearchPath,
48
36
  presetNameFromPath,
@@ -52,26 +40,38 @@ import {
52
40
  presetVariant,
53
41
  projectTargets,
54
42
  readAdoption,
55
- readFormatAdoption,
56
43
  readLintAdoption,
57
44
  readModuleAdditions,
58
45
  renderBaseline,
59
46
  resolveConfigTarget,
60
- resolveOxfmt,
61
47
  resolveOxlint,
62
48
  rewriteToolchainImports,
63
49
  selfCommand,
64
50
  splitToolArgs,
65
51
  uncoveredFor,
66
- walk,
67
- writtenFileFormatter
68
- } from "./chunk-Z3JI7ZWX.js";
52
+ walk
53
+ } from "./chunk-P6KTBQ2Q.js";
69
54
  import {
55
+ ALWAYS_LOCAL_KEYS,
56
+ FORMAT_CONFIG_FILE,
57
+ FORMAT_DEFAULT_IGNORES,
58
+ FORMAT_SCRIPT_NAME,
59
+ OWNED_WHEN_SET_KEYS,
60
+ PERMITTED_LOCAL_KEYS,
61
+ PRETTIER_CONFIG_FILES,
62
+ PROVENANCE_KEY,
70
63
  binFromOwnInstall,
71
64
  binSearchPath,
65
+ formatPresetFor,
66
+ formatPresetName,
67
+ formatTargets,
68
+ oxfmtRejects,
69
+ readFormatAdoption,
72
70
  resolveBin,
73
- scriptPath
74
- } from "./chunk-4UUL4SEW.js";
71
+ resolveOxfmt,
72
+ scriptPath,
73
+ writtenFileFormatter
74
+ } from "./chunk-ZFG6P27V.js";
75
75
  import {
76
76
  DEFAULT_MAX_DIAGNOSTICS,
77
77
  WORKSPACE_ROOT_MARKER,
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  binFromOwnInstall,
3
3
  binSearchPath,
4
- resolveBin
5
- } from "./chunk-4UUL4SEW.js";
4
+ resolveBin,
5
+ writtenFileFormatter
6
+ } from "./chunk-ZFG6P27V.js";
6
7
  import {
7
8
  DEFAULT_MAX_DIAGNOSTICS,
8
9
  WORKSPACE_ROOT_MARKER,
@@ -778,9 +779,9 @@ function resolveVitest(cwd) {
778
779
 
779
780
  // src/roles/test/adapters/vitest/vitest.adapter.ts
780
781
  import { spawnSync } from "node:child_process";
781
- import { existsSync as existsSync24, mkdtempSync as mkdtempSync3, readFileSync as readFileSync25, writeFileSync as writeFileSync2 } from "node:fs";
782
+ import { existsSync as existsSync22, mkdtempSync as mkdtempSync3, readFileSync as readFileSync23, writeFileSync as writeFileSync2 } from "node:fs";
782
783
  import { tmpdir as tmpdir3 } from "node:os";
783
- import { isAbsolute as isAbsolute2, join as join31, relative as relative7, resolve as resolve10 } from "node:path";
784
+ import { isAbsolute as isAbsolute2, join as join28, relative as relative7, resolve as resolve10 } from "node:path";
784
785
 
785
786
  // src/roles/test/ordering-is-a-permutation.ts
786
787
  function isAnImport(line) {
@@ -970,9 +971,9 @@ function rewriteToolchainImports(toolchain, source, fileName) {
970
971
  }
971
972
 
972
973
  // src/roles/test/jest-migration.ts
973
- import { existsSync as existsSync18, readFileSync as readFileSync20, readdirSync as readdirSync6 } from "node:fs";
974
- import { createRequire as createRequire4 } from "node:module";
975
- import { dirname as dirname11, join as join24, relative as relative6 } from "node:path";
974
+ import { existsSync as existsSync16, readFileSync as readFileSync18, readdirSync as readdirSync6 } from "node:fs";
975
+ import { createRequire as createRequire3 } from "node:module";
976
+ import { dirname as dirname9, join as join21, relative as relative6 } from "node:path";
976
977
 
977
978
  // src/roles/test/codemod/migrate-module.ts
978
979
  import { readdirSync as readdirSync4, readFileSync as readFileSync15, statSync as statSync5 } from "node:fs";
@@ -5134,260 +5135,16 @@ function runModes(cwd, fallback) {
5134
5135
  );
5135
5136
  }
5136
5137
 
5137
- // src/roles/test/written-file-formatter.ts
5138
- import { existsSync as existsSync17 } from "node:fs";
5139
- import { dirname as dirname10, join as join23 } from "node:path";
5140
-
5141
- // src/roles/format/read-adoption.ts
5142
- import { existsSync as existsSync16, readFileSync as readFileSync18 } from "node:fs";
5143
- import { join as join21 } from "node:path";
5144
-
5145
- // src/roles/format/config-policy.ts
5146
- var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
5147
- var FORMAT_SCRIPT_NAME = "format";
5148
- var PROVENANCE_KEY = "$sentinel";
5149
- var PERMITTED_LOCAL_KEYS = [
5150
- "useTabs",
5151
- "tabWidth",
5152
- "printWidth",
5153
- "semi",
5154
- "singleQuote",
5155
- "jsxSingleQuote",
5156
- "trailingComma",
5157
- "quoteProps",
5158
- "bracketSpacing",
5159
- "bracketSameLine",
5160
- "arrowParens",
5161
- "endOfLine",
5162
- "objectWrap",
5163
- "proseWrap",
5164
- "experimentalOperatorPosition"
5165
- ];
5166
- var ALWAYS_LOCAL_KEYS = ["ignorePatterns", "overrides"];
5167
- var OWNED_WHEN_SET_KEYS = ["sortImports"];
5168
- var FORMAT_DEFAULT_IGNORES = ["**/*.toml"];
5169
- var PRETTIER_CONFIG_FILES = [
5170
- ".prettierrc",
5171
- ".prettierrc.json",
5172
- ".prettierrc.json5",
5173
- ".prettierrc.yml",
5174
- ".prettierrc.yaml",
5175
- ".prettierrc.js",
5176
- ".prettierrc.cjs",
5177
- ".prettierrc.mjs",
5178
- "prettier.config.js",
5179
- "prettier.config.cjs",
5180
- "prettier.config.mjs"
5181
- ];
5182
- function formatTargets() {
5183
- return {
5184
- [FORMAT_SCRIPT_NAME]: {
5185
- cache: true,
5186
- inputs: ["default", `{projectRoot}/${FORMAT_CONFIG_FILE}`]
5187
- },
5188
- [`${FORMAT_SCRIPT_NAME}:fix`]: { cache: false }
5189
- };
5190
- }
5191
-
5192
- // src/roles/format/presets/base.json
5193
- var base_default = {
5194
- printWidth: 80,
5195
- semi: false,
5196
- singleQuote: true,
5197
- trailingComma: "all",
5198
- sortPackageJson: false,
5199
- sortImports: false
5200
- };
5201
-
5202
- // src/roles/format/presets/nest-imports.json
5203
- var nest_imports_default = {
5204
- customGroups: [
5205
- {
5206
- groupName: "workspace",
5207
- elementNamePattern: ["@hublo/**", "@shared/**", "@front/**", "@network/**"]
5208
- }
5209
- ],
5210
- groups: ["builtin", "external", "workspace", ["parent", "index"], "sibling"],
5211
- newlinesBetween: true,
5212
- order: "asc",
5213
- ignoreCase: false
5214
- };
5215
-
5216
- // src/roles/format/preset-data.ts
5217
- var FORMAT_PRESETS = ["base", "svelte", "nest"];
5218
- function hasFormatPreset(name) {
5219
- return FORMAT_PRESETS.includes(name);
5220
- }
5221
- function formatPresetName(declared) {
5222
- if (declared === "svelte") return "svelte";
5223
- if (declared === "nest") return "nest";
5224
- return "base";
5225
- }
5226
- function formatPresetFor(preset) {
5227
- const base = base_default;
5228
- const name = formatPresetName(preset);
5229
- if (name === "svelte") return { ...base, svelte: true };
5230
- if (name === "nest") return { ...base, sortImports: nest_imports_default };
5231
- return base;
5232
- }
5233
-
5234
- // src/roles/format/read-adoption.ts
5235
- var NOT_ADOPTED = (configFile, unreadable = null) => ({
5236
- configFile,
5237
- preset: null,
5238
- adopted: false,
5239
- conformant: false,
5240
- drift: [],
5241
- local: {},
5242
- presetVersion: null,
5243
- effective: {},
5244
- unreadable
5245
- });
5246
- function sameValue(a, b) {
5247
- return JSON.stringify(a) === JSON.stringify(b);
5248
- }
5249
- function readFormatAdoption(cwd) {
5250
- const path = join21(cwd, FORMAT_CONFIG_FILE);
5251
- if (!existsSync16(path)) return NOT_ADOPTED(null);
5252
- let parsed;
5253
- try {
5254
- parsed = parseJsonc(readFileSync18(path, "utf8"), FORMAT_CONFIG_FILE);
5255
- } catch (error) {
5256
- const reason = error instanceof Error ? error.message : String(error);
5257
- return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
5258
- }
5259
- const provenance = parsed[PROVENANCE_KEY];
5260
- if (!provenance || typeof provenance.preset !== "string") return NOT_ADOPTED(FORMAT_CONFIG_FILE);
5261
- if (!hasFormatPreset(provenance.preset)) {
5262
- return NOT_ADOPTED(
5263
- FORMAT_CONFIG_FILE,
5264
- `${FORMAT_CONFIG_FILE} declares the format preset "${provenance.preset}", which sentinel does not ship (shipped: ${FORMAT_PRESETS.join(", ")}). Re-run \`sentinel --init --format\`.`
5265
- );
5266
- }
5267
- const declaredLocal = Array.isArray(provenance.local) ? provenance.local : [];
5268
- const preset = formatPresetFor(provenance.preset);
5269
- const drift = [];
5270
- const local = {};
5271
- for (const [key, expected] of Object.entries(preset)) {
5272
- if (declaredLocal.includes(key)) {
5273
- local[key] = parsed[key];
5274
- continue;
5275
- }
5276
- if (!(key in parsed) || !sameValue(parsed[key], expected)) drift.push(key);
5277
- }
5278
- for (const key of declaredLocal) {
5279
- if (!(key in preset)) local[key] = parsed[key];
5280
- }
5281
- for (const key of ALWAYS_LOCAL_KEYS) {
5282
- if (key in parsed) local[key] = parsed[key];
5283
- }
5284
- return {
5285
- configFile: FORMAT_CONFIG_FILE,
5286
- preset: provenance.preset,
5287
- adopted: true,
5288
- conformant: drift.length === 0,
5289
- drift,
5290
- local,
5291
- presetVersion: typeof provenance.version === "string" ? provenance.version : null,
5292
- effective: parsed,
5293
- unreadable: null
5294
- };
5295
- }
5296
-
5297
- // src/roles/format/resolve-oxfmt.ts
5298
- import { readFileSync as readFileSync19 } from "node:fs";
5299
- import { createRequire as createRequire3 } from "node:module";
5300
- import { dirname as dirname9, join as join22 } from "node:path";
5301
- function resolveOxfmt(cwd) {
5302
- return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
5303
- }
5304
- function oxfmtRejects(key, value) {
5305
- const schema = configSchema();
5306
- const property = schema?.properties?.[key];
5307
- if (!property) return false;
5308
- const definition = resolveRef(schema, property);
5309
- if (Array.isArray(definition.enum)) return !definition.enum.includes(value);
5310
- if (definition.type === "boolean") return typeof value !== "boolean";
5311
- if (definition.type === "integer" || definition.type === "number")
5312
- return typeof value !== "number";
5313
- return false;
5314
- }
5315
- function resolveRef(schema, node) {
5316
- const ref = node.$ref ?? node.allOf?.[0]?.$ref;
5317
- const name = ref?.startsWith("#/definitions/") ? ref.slice("#/definitions/".length) : void 0;
5318
- return (name ? schema.definitions?.[name] : void 0) ?? node;
5319
- }
5320
- var cachedSchema;
5321
- function configSchema() {
5322
- if (cachedSchema !== void 0) return cachedSchema ?? void 0;
5323
- cachedSchema = readConfigSchema() ?? null;
5324
- return cachedSchema ?? void 0;
5325
- }
5326
- function readConfigSchema() {
5327
- try {
5328
- const manifest = createRequire3(import.meta.url).resolve("oxfmt/package.json");
5329
- const schemaPath = join22(dirname9(manifest), "configuration_schema.json");
5330
- return JSON.parse(readFileSync19(schemaPath, "utf8"));
5331
- } catch {
5332
- return void 0;
5333
- }
5334
- }
5335
-
5336
- // src/roles/test/written-file-formatter.ts
5337
- var PRETTIER_CONFIGS = [
5338
- ".prettierrc",
5339
- ".prettierrc.json",
5340
- ".prettierrc.json5",
5341
- ".prettierrc.yaml",
5342
- ".prettierrc.yml",
5343
- ".prettierrc.js",
5344
- ".prettierrc.cjs",
5345
- ".prettierrc.mjs",
5346
- ".prettierrc.toml",
5347
- "prettier.config.js",
5348
- "prettier.config.cjs",
5349
- "prettier.config.mjs"
5350
- ];
5351
- function prettierConfigFrom(cwd) {
5352
- let dir = cwd;
5353
- for (; ; ) {
5354
- for (const name of PRETTIER_CONFIGS) {
5355
- if (existsSync17(join23(dir, name))) return join23(dir, name);
5356
- }
5357
- const parent = dirname10(dir);
5358
- if (parent === dir) return void 0;
5359
- dir = parent;
5360
- }
5361
- }
5362
- function writtenFileFormatter(cwd) {
5363
- if (readFormatAdoption(cwd).configFile !== null) {
5364
- const oxfmt = resolveOxfmt(cwd);
5365
- if (oxfmt !== void 0) {
5366
- return { bin: oxfmt, args: ["--write"], origin: "this module's own oxfmt config" };
5367
- }
5368
- }
5369
- const config = prettierConfigFrom(cwd);
5370
- const prettier = resolveBin(cwd, "prettier");
5371
- if (config !== void 0 && prettier !== void 0) {
5372
- return {
5373
- bin: prettier,
5374
- args: ["--write", "--log-level", "warn"],
5375
- origin: `the workspace's Prettier`
5376
- };
5377
- }
5378
- return void 0;
5379
- }
5380
-
5381
5138
  // src/roles/test/jest-migration.ts
5382
5139
  var SPEC_TSCONFIG = "tsconfig.spec.json";
5383
5140
  var VITEST_GLOBAL_TYPES = "vitest/globals";
5384
5141
  function specTypesOperation(cwd) {
5385
- const path = join24(cwd, SPEC_TSCONFIG);
5386
- if (!existsSync18(path)) return void 0;
5142
+ const path = join21(cwd, SPEC_TSCONFIG);
5143
+ if (!existsSync16(path)) return void 0;
5387
5144
  let config;
5388
5145
  try {
5389
5146
  config = parseJsonc(
5390
- readFileSync20(path, "utf8"),
5147
+ readFileSync18(path, "utf8"),
5391
5148
  SPEC_TSCONFIG
5392
5149
  );
5393
5150
  } catch {
@@ -5406,12 +5163,12 @@ function specTypesOperation(cwd) {
5406
5163
  };
5407
5164
  }
5408
5165
  function specTypesCleanupOperation(cwd) {
5409
- const path = join24(cwd, SPEC_TSCONFIG);
5410
- if (!existsSync18(path)) return void 0;
5166
+ const path = join21(cwd, SPEC_TSCONFIG);
5167
+ if (!existsSync16(path)) return void 0;
5411
5168
  let config;
5412
5169
  try {
5413
5170
  config = parseJsonc(
5414
- readFileSync20(path, "utf8"),
5171
+ readFileSync18(path, "utf8"),
5415
5172
  SPEC_TSCONFIG
5416
5173
  );
5417
5174
  } catch {
@@ -5429,9 +5186,9 @@ function specTypesCleanupOperation(cwd) {
5429
5186
  }
5430
5187
  function shippedTypesPath(cwd, declaration) {
5431
5188
  try {
5432
- const manifest = createRequire4(join24(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
5433
- const file = join24(dirname11(manifest), declaration);
5434
- if (existsSync18(file)) {
5189
+ const manifest = createRequire3(join21(cwd, "noop.cjs")).resolve("@hublo/sentinel/package.json");
5190
+ const file = join21(dirname9(manifest), declaration);
5191
+ if (existsSync16(file)) {
5435
5192
  const path = relative6(cwd, file);
5436
5193
  return path.startsWith(".") ? path : `./${path}`;
5437
5194
  }
@@ -5450,7 +5207,7 @@ function helpersStillCallingJest(cwd) {
5450
5207
  return;
5451
5208
  }
5452
5209
  for (const entry of entries) {
5453
- const path = join24(dir, entry.name);
5210
+ const path = join21(dir, entry.name);
5454
5211
  if (entry.isDirectory()) {
5455
5212
  if (!skip.has(entry.name)) walk2(path);
5456
5213
  continue;
@@ -5460,7 +5217,7 @@ function helpersStillCallingJest(cwd) {
5460
5217
  if (/^(jest|vitest)\./.test(entry.name)) continue;
5461
5218
  let source;
5462
5219
  try {
5463
- source = readFileSync20(path, "utf8");
5220
+ source = readFileSync18(path, "utf8");
5464
5221
  } catch {
5465
5222
  continue;
5466
5223
  }
@@ -5497,7 +5254,7 @@ function tsconfigFileListOperations(cwd) {
5497
5254
  let config;
5498
5255
  try {
5499
5256
  config = parseJsonc(
5500
- readFileSync20(join24(cwd, name), "utf8"),
5257
+ readFileSync18(join21(cwd, name), "utf8"),
5501
5258
  name
5502
5259
  );
5503
5260
  } catch {
@@ -5912,12 +5669,12 @@ function plan(context) {
5912
5669
  }
5913
5670
 
5914
5671
  // src/roles/test/written-file-linter.ts
5915
- import { existsSync as existsSync23 } from "node:fs";
5916
- import { join as join30 } from "node:path";
5672
+ import { existsSync as existsSync21 } from "node:fs";
5673
+ import { join as join27 } from "node:path";
5917
5674
 
5918
5675
  // src/roles/lint/module-baseline.ts
5919
- import { existsSync as existsSync19, readFileSync as readFileSync21 } from "node:fs";
5920
- import { join as join25 } from "node:path";
5676
+ import { existsSync as existsSync17, readFileSync as readFileSync19 } from "node:fs";
5677
+ import { join as join22 } from "node:path";
5921
5678
 
5922
5679
  // src/roles/lint/oxlint-rule-owners.json
5923
5680
  var oxlint_rule_owners_default = {
@@ -6659,10 +6416,10 @@ function describeHolds(holds) {
6659
6416
  return `held ${holds.length} rule(s) at \`warn\` for this module, covering ${total} violation(s) that were already there: ${listed}${rest}. They are written to ${LINT_BASELINE_FILE}, they still report, and they return to \`error\` once fixed and re-initialized`;
6660
6417
  }
6661
6418
  function heldRules(cwd) {
6662
- const path = join25(cwd, LINT_BASELINE_FILE);
6663
- if (!existsSync19(path)) return [];
6419
+ const path = join22(cwd, LINT_BASELINE_FILE);
6420
+ if (!existsSync17(path)) return [];
6664
6421
  try {
6665
- const parsed = parseJsonc(readFileSync21(path, "utf8"), LINT_BASELINE_FILE);
6422
+ const parsed = parseJsonc(readFileSync19(path, "utf8"), LINT_BASELINE_FILE);
6666
6423
  const scoped = (parsed.overrides ?? []).flatMap((override) => Object.keys(override.rules ?? {}));
6667
6424
  return [.../* @__PURE__ */ new Set([...Object.keys(parsed.rules ?? {}), ...scoped])];
6668
6425
  } catch {
@@ -6698,7 +6455,7 @@ var SENTINEL_LINT_PRESET = /@hublo\/sentinel\/(?:lint|oxlint)\/([a-z-]+)\.json$/
6698
6455
  function presetNameFromPath(preset) {
6699
6456
  return preset ? SENTINEL_LINT_PRESET.exec(preset)?.[1] ?? void 0 : void 0;
6700
6457
  }
6701
- var PERMITTED_LOCAL_KEYS2 = ["extends", "ignorePatterns"];
6458
+ var PERMITTED_LOCAL_KEYS = ["extends", "ignorePatterns"];
6702
6459
  var ESLINT_CONFIG_FILES = [
6703
6460
  "eslint.config.js",
6704
6461
  "eslint.config.mjs",
@@ -6710,12 +6467,12 @@ function lintTarget() {
6710
6467
  }
6711
6468
 
6712
6469
  // src/roles/lint/read-adoption.ts
6713
- import { readFileSync as readFileSync24 } from "node:fs";
6714
- import { join as join28 } from "node:path";
6470
+ import { readFileSync as readFileSync22 } from "node:fs";
6471
+ import { join as join25 } from "node:path";
6715
6472
 
6716
6473
  // src/core/config/read-adoption.ts
6717
- import { existsSync as existsSync21, readFileSync as readFileSync23 } from "node:fs";
6718
- import { join as join27 } from "node:path";
6474
+ import { existsSync as existsSync19, readFileSync as readFileSync21 } from "node:fs";
6475
+ import { join as join24 } from "node:path";
6719
6476
 
6720
6477
  // src/core/config/owned-keys.ts
6721
6478
  function presetOwnedKeys(config, permitted, presetSets) {
@@ -6730,12 +6487,12 @@ function localOnlyKeys(config, permitted, presetSets) {
6730
6487
  }
6731
6488
 
6732
6489
  // src/core/config/resolve-config-target.ts
6733
- import { existsSync as existsSync20, readFileSync as readFileSync22 } from "node:fs";
6734
- import { join as join26 } from "node:path";
6490
+ import { existsSync as existsSync18, readFileSync as readFileSync20 } from "node:fs";
6491
+ import { join as join23 } from "node:path";
6735
6492
  function readExtends(absolutePath) {
6736
6493
  let parsed;
6737
6494
  try {
6738
- parsed = parseJsonc(readFileSync22(absolutePath, "utf8"), absolutePath);
6495
+ parsed = parseJsonc(readFileSync20(absolutePath, "utf8"), absolutePath);
6739
6496
  } catch {
6740
6497
  return [];
6741
6498
  }
@@ -6749,8 +6506,8 @@ function resolveConfigTarget(moduleDir, { candidates, markers, fallback }) {
6749
6506
  let existing;
6750
6507
  let existingExtendsSomething = false;
6751
6508
  for (const candidate of candidates) {
6752
- const absolutePath = join26(moduleDir, candidate);
6753
- if (!existsSync20(absolutePath)) continue;
6509
+ const absolutePath = join23(moduleDir, candidate);
6510
+ if (!existsSync18(absolutePath)) continue;
6754
6511
  const chain = readExtends(absolutePath);
6755
6512
  if (existing === void 0) {
6756
6513
  existing = candidate;
@@ -6773,7 +6530,7 @@ function normaliseExtends(value) {
6773
6530
  }
6774
6531
  return [];
6775
6532
  }
6776
- var NOT_ADOPTED2 = (configFile, unreadable = null) => ({
6533
+ var NOT_ADOPTED = (configFile, unreadable = null) => ({
6777
6534
  configFile,
6778
6535
  preset: null,
6779
6536
  adopted: false,
@@ -6783,18 +6540,18 @@ var NOT_ADOPTED2 = (configFile, unreadable = null) => ({
6783
6540
  });
6784
6541
  function readAdoption(cwd, options) {
6785
6542
  const target = resolveConfigTarget(cwd, options);
6786
- if (target.reason === "none" || !existsSync21(join27(cwd, target.path))) {
6787
- return NOT_ADOPTED2(target.reason === "none" ? null : target.path);
6543
+ if (target.reason === "none" || !existsSync19(join24(cwd, target.path))) {
6544
+ return NOT_ADOPTED(target.reason === "none" ? null : target.path);
6788
6545
  }
6789
6546
  let parsed;
6790
6547
  try {
6791
- parsed = parseJsonc(readFileSync23(join27(cwd, target.path), "utf8"), target.path);
6548
+ parsed = parseJsonc(readFileSync21(join24(cwd, target.path), "utf8"), target.path);
6792
6549
  } catch (error) {
6793
6550
  const reason = error instanceof Error ? error.message : String(error);
6794
- return NOT_ADOPTED2(target.path, `${target.path} could not be parsed (${reason})`);
6551
+ return NOT_ADOPTED(target.path, `${target.path} could not be parsed (${reason})`);
6795
6552
  }
6796
6553
  const preset = normaliseExtends(parsed.extends).find((entry) => options.presetPattern.test(entry)) ?? null;
6797
- if (preset === null) return NOT_ADOPTED2(target.path);
6554
+ if (preset === null) return NOT_ADOPTED(target.path);
6798
6555
  const settings = options.settingsKey === null ? parsed : parsed[options.settingsKey];
6799
6556
  const owned = presetOwnedKeys(settings, options.permitted, options.presetOwns?.(preset));
6800
6557
  const drift = options.refineDrift !== void 0 && settings !== void 0 ? options.refineDrift(owned, settings, preset) : owned;
@@ -9454,7 +9211,7 @@ function readLintAdoption(cwd) {
9454
9211
  // Drift for lint is read from the TOP-LEVEL keys beyond `extends`, so the settings the
9455
9212
  // shared reader inspects are the config's own root rather than a nested options object.
9456
9213
  settingsKey: null,
9457
- permitted: PERMITTED_LOCAL_KEYS2,
9214
+ permitted: PERMITTED_LOCAL_KEYS,
9458
9215
  // `rules` and `overrides` are drift only when they CONFLICT with the preset, by the
9459
9216
  // criterion a re-init keeps or drops them by: a rule the preset does not name is the
9460
9217
  // module's addition, kept and listed by `--inspect`, not drift. A preset sentinel does not
@@ -9472,7 +9229,7 @@ function readModuleAdditions(cwd) {
9472
9229
  if (preset === void 0 || adoption.configFile === null) return NO_ADDITIONS;
9473
9230
  try {
9474
9231
  const config = parseJsonc(
9475
- readFileSync24(join28(cwd, adoption.configFile), "utf8"),
9232
+ readFileSync22(join25(cwd, adoption.configFile), "utf8"),
9476
9233
  adoption.configFile
9477
9234
  );
9478
9235
  if (typeof config !== "object" || config === null || Array.isArray(config)) {
@@ -9489,15 +9246,15 @@ function readModuleAdditions(cwd) {
9489
9246
  }
9490
9247
 
9491
9248
  // src/roles/lint/resolve-oxlint.ts
9492
- import { existsSync as existsSync22 } from "node:fs";
9493
- import { createRequire as createRequire5 } from "node:module";
9494
- import { delimiter, dirname as dirname12, join as join29 } from "node:path";
9249
+ import { existsSync as existsSync20 } from "node:fs";
9250
+ import { createRequire as createRequire4 } from "node:module";
9251
+ import { delimiter, dirname as dirname10, join as join26 } from "node:path";
9495
9252
  import { fileURLToPath } from "node:url";
9496
9253
  var PACKAGE_OF = {
9497
9254
  oxlint: "oxlint",
9498
9255
  tsgolint: "oxlint-tsgolint"
9499
9256
  };
9500
- var require2 = createRequire5(import.meta.url);
9257
+ var require2 = createRequire4(import.meta.url);
9501
9258
  function resolveOxlint(cwd, name = "oxlint") {
9502
9259
  return resolveBin(cwd, name) ?? binFromOwnInstall(PACKAGE_OF[name], name);
9503
9260
  }
@@ -9507,7 +9264,7 @@ function canRunTypeAware(cwd) {
9507
9264
  function oxlintPath(cwd, env) {
9508
9265
  const shim = tsgolintShim(cwd);
9509
9266
  if (!shim) return env.PATH;
9510
- return [dirname12(shim), env.PATH].filter(Boolean).join(delimiter);
9267
+ return [dirname10(shim), env.PATH].filter(Boolean).join(delimiter);
9511
9268
  }
9512
9269
  function tsgolintShim(cwd) {
9513
9270
  const fromModule = resolveBin(cwd, "tsgolint");
@@ -9515,19 +9272,19 @@ function tsgolintShim(cwd) {
9515
9272
  const candidates = [];
9516
9273
  for (const owner of ["oxlint-tsgolint", "oxlint"]) {
9517
9274
  try {
9518
- const packageDir = dirname12(require2.resolve(`${owner}/package.json`));
9519
- candidates.push(join29(packageDir, "node_modules", ".bin", "tsgolint"));
9520
- candidates.push(join29(packageDir, "..", ".bin", "tsgolint"));
9275
+ const packageDir = dirname10(require2.resolve(`${owner}/package.json`));
9276
+ candidates.push(join26(packageDir, "node_modules", ".bin", "tsgolint"));
9277
+ candidates.push(join26(packageDir, "..", ".bin", "tsgolint"));
9521
9278
  } catch {
9522
9279
  }
9523
9280
  }
9524
9281
  try {
9525
- const ownRoot = dirname12(require2.resolve("@hublo/sentinel/package.json"));
9526
- candidates.push(join29(ownRoot, "node_modules", ".bin", "tsgolint"));
9282
+ const ownRoot = dirname10(require2.resolve("@hublo/sentinel/package.json"));
9283
+ candidates.push(join26(ownRoot, "node_modules", ".bin", "tsgolint"));
9527
9284
  } catch {
9528
- candidates.push(resolveBin(dirname12(fileURLToPath(import.meta.url)), "tsgolint") ?? "");
9285
+ candidates.push(resolveBin(dirname10(fileURLToPath(import.meta.url)), "tsgolint") ?? "");
9529
9286
  }
9530
- return candidates.find((candidate) => candidate !== "" && existsSync22(candidate));
9287
+ return candidates.find((candidate) => candidate !== "" && existsSync20(candidate));
9531
9288
  }
9532
9289
  function oxlintSearchPath(cwd) {
9533
9290
  return binSearchPath(cwd);
@@ -9541,7 +9298,7 @@ function writtenFileLinter(cwd) {
9541
9298
  return { bin: oxlint, args: ["--fix"], origin: "this module's own oxlint config" };
9542
9299
  }
9543
9300
  }
9544
- const config = ESLINT_CONFIG_FILES.map((name) => join30(cwd, name)).find((path) => existsSync23(path));
9301
+ const config = ESLINT_CONFIG_FILES.map((name) => join27(cwd, name)).find((path) => existsSync21(path));
9545
9302
  const eslint = resolveBin(cwd, "eslint");
9546
9303
  if (config !== void 0 && eslint !== void 0) {
9547
9304
  return {
@@ -9563,7 +9320,7 @@ var FORMATTABLE = /\.(m|c)?(j|t)sx?$|\.json$/;
9563
9320
  var FORMAT_BATCH = 25;
9564
9321
  function readIfPossible(path) {
9565
9322
  try {
9566
- return readFileSync25(path, "utf8");
9323
+ return readFileSync23(path, "utf8");
9567
9324
  } catch {
9568
9325
  return void 0;
9569
9326
  }
@@ -9689,12 +9446,12 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
9689
9446
  const linter = writtenFileLinter(ctx.cwd);
9690
9447
  if (linter === void 0) return;
9691
9448
  const workspaceRoot = findWorkspaceRoot(ctx.cwd) ?? ctx.cwd;
9692
- const fromRoot = (file) => relative7(workspaceRoot, join31(ctx.cwd, file));
9449
+ const fromRoot = (file) => relative7(workspaceRoot, join28(ctx.cwd, file));
9693
9450
  let unsettled = 0;
9694
9451
  const reverted = [];
9695
9452
  for (let at = 0; at < written.length; at += FORMAT_BATCH) {
9696
9453
  const batch = written.slice(at, at + FORMAT_BATCH);
9697
- const before = new Map(batch.map((file) => [file, readIfPossible(join31(ctx.cwd, file))]));
9454
+ const before = new Map(batch.map((file) => [file, readIfPossible(join28(ctx.cwd, file))]));
9698
9455
  const pass = spawnSync(linter.bin, [...linter.args, ...batch.map(fromRoot)], {
9699
9456
  cwd: workspaceRoot,
9700
9457
  encoding: "utf8"
@@ -9703,11 +9460,11 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
9703
9460
  for (const file of batch) {
9704
9461
  const was = before.get(file);
9705
9462
  if (was === void 0) continue;
9706
- const now = readIfPossible(join31(ctx.cwd, file));
9463
+ const now = readIfPossible(join28(ctx.cwd, file));
9707
9464
  if (now === void 0 || now === was) continue;
9708
9465
  const lost = lineLostByTheFixer(was, now);
9709
9466
  if (lost === void 0) continue;
9710
- writeFileSync2(join31(ctx.cwd, file), was);
9467
+ writeFileSync2(join28(ctx.cwd, file), was);
9711
9468
  reverted.push(`${file}: \`${lost.slice(0, 80)}\``);
9712
9469
  }
9713
9470
  }
@@ -9786,7 +9543,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
9786
9543
  metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: "vitest not available" }
9787
9544
  };
9788
9545
  }
9789
- const out = join31(mkdtempSync3(join31(tmpdir3(), "sentinel-test-report-")), "vitest.json");
9546
+ const out = join28(mkdtempSync3(join28(tmpdir3(), "sentinel-test-report-")), "vitest.json");
9790
9547
  const { cwd: runFrom, options, env } = fromWorkspaceRoot(ctx.cwd, [], []);
9791
9548
  const result = spawnSync(bin, ["run", ...options, "--reporter=json", `--outputFile=${out}`], {
9792
9549
  cwd: runFrom,
@@ -9801,7 +9558,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
9801
9558
  metrics: { ..._VitestAdapter.NOTHING_TO_REPORT, error: result.error.message }
9802
9559
  };
9803
9560
  }
9804
- if (!existsSync24(out)) {
9561
+ if (!existsSync22(out)) {
9805
9562
  return {
9806
9563
  ok: false,
9807
9564
  code: 1,
@@ -9810,7 +9567,7 @@ var VitestAdapter = class _VitestAdapter extends BaseAdapter {
9810
9567
  }
9811
9568
  let parsed;
9812
9569
  try {
9813
- parsed = JSON.parse(readFileSync25(out, "utf8"));
9570
+ parsed = JSON.parse(readFileSync23(out, "utf8"));
9814
9571
  } catch {
9815
9572
  return {
9816
9573
  ok: false,
@@ -9934,21 +9691,7 @@ export {
9934
9691
  splitToolArgs,
9935
9692
  separateToolArgs,
9936
9693
  nxTargetOperations,
9937
- FORMAT_CONFIG_FILE,
9938
- FORMAT_SCRIPT_NAME,
9939
- PROVENANCE_KEY,
9940
- PERMITTED_LOCAL_KEYS,
9941
- ALWAYS_LOCAL_KEYS,
9942
- OWNED_WHEN_SET_KEYS,
9943
- FORMAT_DEFAULT_IGNORES,
9944
- PRETTIER_CONFIG_FILES,
9945
- formatTargets,
9946
- formatPresetName,
9947
- formatPresetFor,
9948
- readFormatAdoption,
9949
9694
  rewriteToolchainImports,
9950
- resolveOxfmt,
9951
- oxfmtRejects,
9952
9695
  canonicalRuleName,
9953
9696
  describeRuleKey,
9954
9697
  LINT_BASELINE_FILE,
@@ -9989,7 +9732,6 @@ export {
9989
9732
  oxlintPath,
9990
9733
  oxlintSearchPath,
9991
9734
  walk,
9992
- writtenFileFormatter,
9993
9735
  RESOLVABLE_EXTENSIONS,
9994
9736
  readTestAdoption,
9995
9737
  resolveContext,
@@ -0,0 +1,313 @@
1
+ import {
2
+ parseJsonc
3
+ } from "./chunk-QXFCZON7.js";
4
+
5
+ // src/shared/resolve-bin.ts
6
+ import { existsSync } from "node:fs";
7
+ import { createRequire } from "node:module";
8
+ import { delimiter, dirname, join } from "node:path";
9
+ var require2 = createRequire(import.meta.url);
10
+ function resolveBin(fromDir, name) {
11
+ let dir = fromDir;
12
+ for (; ; ) {
13
+ const candidate = join(dir, "node_modules", ".bin", name);
14
+ if (existsSync(candidate)) return candidate;
15
+ const parent = dirname(dir);
16
+ if (parent === dir) return void 0;
17
+ dir = parent;
18
+ }
19
+ }
20
+ function binFromOwnInstall(packageName, binName) {
21
+ try {
22
+ const manifest = require2.resolve(`${packageName}/package.json`);
23
+ const bin = require2(manifest).bin;
24
+ const relative = typeof bin === "string" ? bin : bin?.[binName];
25
+ if (!relative) return void 0;
26
+ const executable = join(dirname(manifest), relative);
27
+ return existsSync(executable) ? executable : void 0;
28
+ } catch {
29
+ return void 0;
30
+ }
31
+ }
32
+ function binSearchPath(cwd) {
33
+ return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
34
+ " then "
35
+ );
36
+ }
37
+ function scriptPath(cwd, path) {
38
+ const bins = [];
39
+ let dir = cwd;
40
+ for (; ; ) {
41
+ bins.push(join(dir, "node_modules", ".bin"));
42
+ const parent = dirname(dir);
43
+ if (parent === dir) break;
44
+ dir = parent;
45
+ }
46
+ return [...bins, path].filter(Boolean).join(delimiter);
47
+ }
48
+
49
+ // src/roles/test/written-file-formatter.ts
50
+ import { existsSync as existsSync3 } from "node:fs";
51
+ import { dirname as dirname3, join as join4 } from "node:path";
52
+
53
+ // src/roles/format/read-adoption.ts
54
+ import { existsSync as existsSync2, readFileSync } from "node:fs";
55
+ import { join as join2 } from "node:path";
56
+
57
+ // src/roles/format/config-policy.ts
58
+ var FORMAT_CONFIG_FILE = ".oxfmtrc.json";
59
+ var FORMAT_SCRIPT_NAME = "format";
60
+ var PROVENANCE_KEY = "$sentinel";
61
+ var PERMITTED_LOCAL_KEYS = [
62
+ "useTabs",
63
+ "tabWidth",
64
+ "printWidth",
65
+ "semi",
66
+ "singleQuote",
67
+ "jsxSingleQuote",
68
+ "trailingComma",
69
+ "quoteProps",
70
+ "bracketSpacing",
71
+ "bracketSameLine",
72
+ "arrowParens",
73
+ "endOfLine",
74
+ "objectWrap",
75
+ "proseWrap",
76
+ "experimentalOperatorPosition"
77
+ ];
78
+ var ALWAYS_LOCAL_KEYS = ["ignorePatterns", "overrides"];
79
+ var OWNED_WHEN_SET_KEYS = ["sortImports"];
80
+ var FORMAT_DEFAULT_IGNORES = ["**/*.toml"];
81
+ var PRETTIER_CONFIG_FILES = [
82
+ ".prettierrc",
83
+ ".prettierrc.json",
84
+ ".prettierrc.json5",
85
+ ".prettierrc.yml",
86
+ ".prettierrc.yaml",
87
+ ".prettierrc.js",
88
+ ".prettierrc.cjs",
89
+ ".prettierrc.mjs",
90
+ "prettier.config.js",
91
+ "prettier.config.cjs",
92
+ "prettier.config.mjs"
93
+ ];
94
+ function formatTargets() {
95
+ return {
96
+ [FORMAT_SCRIPT_NAME]: {
97
+ cache: true,
98
+ inputs: ["default", `{projectRoot}/${FORMAT_CONFIG_FILE}`]
99
+ },
100
+ [`${FORMAT_SCRIPT_NAME}:fix`]: { cache: false }
101
+ };
102
+ }
103
+
104
+ // src/roles/format/presets/base.json
105
+ var base_default = {
106
+ printWidth: 80,
107
+ semi: false,
108
+ singleQuote: true,
109
+ trailingComma: "all",
110
+ sortPackageJson: false,
111
+ sortImports: false
112
+ };
113
+
114
+ // src/roles/format/presets/nest-imports.json
115
+ var nest_imports_default = {
116
+ customGroups: [
117
+ {
118
+ groupName: "workspace",
119
+ elementNamePattern: ["@hublo/**", "@shared/**", "@front/**", "@network/**"]
120
+ }
121
+ ],
122
+ groups: ["builtin", "external", "workspace", ["parent", "index"], "sibling"],
123
+ newlinesBetween: true,
124
+ order: "asc",
125
+ ignoreCase: false
126
+ };
127
+
128
+ // src/roles/format/preset-data.ts
129
+ var FORMAT_PRESETS = ["base", "svelte", "nest"];
130
+ function hasFormatPreset(name) {
131
+ return FORMAT_PRESETS.includes(name);
132
+ }
133
+ function formatPresetName(declared) {
134
+ if (declared === "svelte") return "svelte";
135
+ if (declared === "nest") return "nest";
136
+ return "base";
137
+ }
138
+ function formatPresetFor(preset) {
139
+ const base = base_default;
140
+ const name = formatPresetName(preset);
141
+ if (name === "svelte") return { ...base, svelte: true };
142
+ if (name === "nest") return { ...base, sortImports: nest_imports_default };
143
+ return base;
144
+ }
145
+
146
+ // src/roles/format/read-adoption.ts
147
+ var NOT_ADOPTED = (configFile, unreadable = null) => ({
148
+ configFile,
149
+ preset: null,
150
+ adopted: false,
151
+ conformant: false,
152
+ drift: [],
153
+ local: {},
154
+ presetVersion: null,
155
+ effective: {},
156
+ unreadable
157
+ });
158
+ function sameValue(a, b) {
159
+ return JSON.stringify(a) === JSON.stringify(b);
160
+ }
161
+ function readFormatAdoption(cwd) {
162
+ const path = join2(cwd, FORMAT_CONFIG_FILE);
163
+ if (!existsSync2(path)) return NOT_ADOPTED(null);
164
+ let parsed;
165
+ try {
166
+ parsed = parseJsonc(readFileSync(path, "utf8"), FORMAT_CONFIG_FILE);
167
+ } catch (error) {
168
+ const reason = error instanceof Error ? error.message : String(error);
169
+ return NOT_ADOPTED(FORMAT_CONFIG_FILE, `${FORMAT_CONFIG_FILE} could not be parsed (${reason})`);
170
+ }
171
+ const provenance = parsed[PROVENANCE_KEY];
172
+ if (!provenance || typeof provenance.preset !== "string") return NOT_ADOPTED(FORMAT_CONFIG_FILE);
173
+ if (!hasFormatPreset(provenance.preset)) {
174
+ return NOT_ADOPTED(
175
+ FORMAT_CONFIG_FILE,
176
+ `${FORMAT_CONFIG_FILE} declares the format preset "${provenance.preset}", which sentinel does not ship (shipped: ${FORMAT_PRESETS.join(", ")}). Re-run \`sentinel --init --format\`.`
177
+ );
178
+ }
179
+ const declaredLocal = Array.isArray(provenance.local) ? provenance.local : [];
180
+ const preset = formatPresetFor(provenance.preset);
181
+ const drift = [];
182
+ const local = {};
183
+ for (const [key, expected] of Object.entries(preset)) {
184
+ if (declaredLocal.includes(key)) {
185
+ local[key] = parsed[key];
186
+ continue;
187
+ }
188
+ if (!(key in parsed) || !sameValue(parsed[key], expected)) drift.push(key);
189
+ }
190
+ for (const key of declaredLocal) {
191
+ if (!(key in preset)) local[key] = parsed[key];
192
+ }
193
+ for (const key of ALWAYS_LOCAL_KEYS) {
194
+ if (key in parsed) local[key] = parsed[key];
195
+ }
196
+ return {
197
+ configFile: FORMAT_CONFIG_FILE,
198
+ preset: provenance.preset,
199
+ adopted: true,
200
+ conformant: drift.length === 0,
201
+ drift,
202
+ local,
203
+ presetVersion: typeof provenance.version === "string" ? provenance.version : null,
204
+ effective: parsed,
205
+ unreadable: null
206
+ };
207
+ }
208
+
209
+ // src/roles/format/resolve-oxfmt.ts
210
+ import { readFileSync as readFileSync2 } from "node:fs";
211
+ import { createRequire as createRequire2 } from "node:module";
212
+ import { dirname as dirname2, join as join3 } from "node:path";
213
+ function resolveOxfmt(cwd) {
214
+ return resolveBin(cwd, "oxfmt") ?? binFromOwnInstall("oxfmt", "oxfmt");
215
+ }
216
+ function oxfmtRejects(key, value) {
217
+ const schema = configSchema();
218
+ const property = schema?.properties?.[key];
219
+ if (!property) return false;
220
+ const definition = resolveRef(schema, property);
221
+ if (Array.isArray(definition.enum)) return !definition.enum.includes(value);
222
+ if (definition.type === "boolean") return typeof value !== "boolean";
223
+ if (definition.type === "integer" || definition.type === "number")
224
+ return typeof value !== "number";
225
+ return false;
226
+ }
227
+ function resolveRef(schema, node) {
228
+ const ref = node.$ref ?? node.allOf?.[0]?.$ref;
229
+ const name = ref?.startsWith("#/definitions/") ? ref.slice("#/definitions/".length) : void 0;
230
+ return (name ? schema.definitions?.[name] : void 0) ?? node;
231
+ }
232
+ var cachedSchema;
233
+ function configSchema() {
234
+ if (cachedSchema !== void 0) return cachedSchema ?? void 0;
235
+ cachedSchema = readConfigSchema() ?? null;
236
+ return cachedSchema ?? void 0;
237
+ }
238
+ function readConfigSchema() {
239
+ try {
240
+ const manifest = createRequire2(import.meta.url).resolve("oxfmt/package.json");
241
+ const schemaPath = join3(dirname2(manifest), "configuration_schema.json");
242
+ return JSON.parse(readFileSync2(schemaPath, "utf8"));
243
+ } catch {
244
+ return void 0;
245
+ }
246
+ }
247
+
248
+ // src/roles/test/written-file-formatter.ts
249
+ var PRETTIER_CONFIGS = [
250
+ ".prettierrc",
251
+ ".prettierrc.json",
252
+ ".prettierrc.json5",
253
+ ".prettierrc.yaml",
254
+ ".prettierrc.yml",
255
+ ".prettierrc.js",
256
+ ".prettierrc.cjs",
257
+ ".prettierrc.mjs",
258
+ ".prettierrc.toml",
259
+ "prettier.config.js",
260
+ "prettier.config.cjs",
261
+ "prettier.config.mjs"
262
+ ];
263
+ function prettierConfigFrom(cwd) {
264
+ let dir = cwd;
265
+ for (; ; ) {
266
+ for (const name of PRETTIER_CONFIGS) {
267
+ if (existsSync3(join4(dir, name))) return join4(dir, name);
268
+ }
269
+ const parent = dirname3(dir);
270
+ if (parent === dir) return void 0;
271
+ dir = parent;
272
+ }
273
+ }
274
+ function writtenFileFormatter(cwd) {
275
+ if (readFormatAdoption(cwd).configFile !== null) {
276
+ const oxfmt = resolveOxfmt(cwd);
277
+ if (oxfmt !== void 0) {
278
+ return { bin: oxfmt, args: ["--write"], origin: "this module's own oxfmt config" };
279
+ }
280
+ }
281
+ const config = prettierConfigFrom(cwd);
282
+ const prettier = resolveBin(cwd, "prettier");
283
+ if (config !== void 0 && prettier !== void 0) {
284
+ return {
285
+ bin: prettier,
286
+ args: ["--write", "--log-level", "warn"],
287
+ origin: `the workspace's Prettier`
288
+ };
289
+ }
290
+ return void 0;
291
+ }
292
+
293
+ export {
294
+ resolveBin,
295
+ binFromOwnInstall,
296
+ binSearchPath,
297
+ scriptPath,
298
+ FORMAT_CONFIG_FILE,
299
+ FORMAT_SCRIPT_NAME,
300
+ PROVENANCE_KEY,
301
+ PERMITTED_LOCAL_KEYS,
302
+ ALWAYS_LOCAL_KEYS,
303
+ OWNED_WHEN_SET_KEYS,
304
+ FORMAT_DEFAULT_IGNORES,
305
+ PRETTIER_CONFIG_FILES,
306
+ formatTargets,
307
+ formatPresetName,
308
+ formatPresetFor,
309
+ readFormatAdoption,
310
+ resolveOxfmt,
311
+ oxfmtRejects,
312
+ writtenFileFormatter
313
+ };
package/dist/index.js CHANGED
@@ -6,11 +6,11 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-EETHWJBF.js";
9
+ } from "./chunk-F6ART7RH.js";
10
10
  import {
11
11
  BaseAdapter
12
- } from "./chunk-Z3JI7ZWX.js";
13
- import "./chunk-4UUL4SEW.js";
12
+ } from "./chunk-P6KTBQ2Q.js";
13
+ import "./chunk-ZFG6P27V.js";
14
14
  import "./chunk-ZNANJEMK.js";
15
15
  import "./chunk-THTXP2QU.js";
16
16
  import "./chunk-4EIY7TTR.js";
@@ -1,13 +1,14 @@
1
1
  import {
2
2
  binFromOwnInstall,
3
- resolveBin
4
- } from "./chunk-4UUL4SEW.js";
3
+ resolveBin,
4
+ writtenFileFormatter
5
+ } from "./chunk-ZFG6P27V.js";
5
6
  import {
6
7
  parseJsonc
7
8
  } from "./chunk-QXFCZON7.js";
8
9
 
9
10
  // src/roles/typescript/migrate/migrate.ts
10
- import { execFileSync } from "node:child_process";
11
+ import { execFileSync, spawnSync } from "node:child_process";
11
12
  import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
12
13
  import { createRequire } from "node:module";
13
14
  import { dirname as dirname2, join, relative as relative2, resolve as resolve2 } from "node:path";
@@ -415,6 +416,31 @@ function restoreInterrupted(moduleRoot, tracked, notes, workspaceRoot) {
415
416
  }
416
417
  }
417
418
  }
419
+ function formatWritten(moduleRoot, files, notes, options) {
420
+ const proved = files.filter(
421
+ (one) => options.write ? one.kept : one.configDifferences?.length === 0 && one.resolutionDifferences?.length === 0
422
+ );
423
+ if (proved.length === 0) return;
424
+ const formatter = writtenFileFormatter(moduleRoot);
425
+ if (formatter === void 0) {
426
+ notes.push(
427
+ "no style is declared by this module or its workspace: run your formatter over the rewritten tsconfig before committing"
428
+ );
429
+ return;
430
+ }
431
+ if (!options.write) {
432
+ notes.push(`the rewritten tsconfig would be formatted with ${formatter.origin}`);
433
+ return;
434
+ }
435
+ const written = proved.map((one) => resolve2(options.workspaceRoot, one.file));
436
+ const pass = spawnSync(formatter.bin, [...formatter.args, ...written], {
437
+ cwd: moduleRoot,
438
+ encoding: "utf8"
439
+ });
440
+ notes.push(
441
+ pass.status === 0 ? `formatted the rewritten tsconfig with ${formatter.origin}` : `${formatter.origin} could not run over the rewritten tsconfig: run it before committing`
442
+ );
443
+ }
418
444
  function isOwnModule(folder) {
419
445
  return existsSync(join(folder, "package.json")) || existsSync(join(folder, "project.json"));
420
446
  }
@@ -481,6 +507,7 @@ function migrateModule(moduleRoot, options) {
481
507
  files.push(migrateTsconfig(folder, target, names, options));
482
508
  }
483
509
  }
510
+ formatWritten(moduleRoot, files, notes, options);
484
511
  const refused = files.filter((one) => !one.kept);
485
512
  const notAdopted = files.every((one) => one.reason?.includes("no sentinel preset") === true);
486
513
  if (notAdopted) {
@@ -7,8 +7,8 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-Z3JI7ZWX.js";
11
- import "./chunk-4UUL4SEW.js";
10
+ } from "./chunk-P6KTBQ2Q.js";
11
+ import "./chunk-ZFG6P27V.js";
12
12
  import "./chunk-ZNANJEMK.js";
13
13
  import "./chunk-O7REVMOC.js";
14
14
  import "./chunk-H4HAFJFZ.js";
@@ -81,6 +81,9 @@ It keeps nothing unless tsc agrees, and restores the file otherwise:
81
81
  (`src/roles/typescript/migrate/compare.ts`);
82
82
  - every module and type reference tsc resolves, file by file, lands on the same file.
83
83
 
84
+ A kept tsconfig is then formatted with the style the module states (its `.oxfmtrc.json`, else
85
+ the workspace's Prettier), the same rule `--init --test` follows: whitespace only, after tsc agreed.
86
+
84
87
  It refuses, and writes nothing, for a module not adopted yet (run `--init --typescript` first), a
85
88
  tsconfig with comments, and a module whose installed sentinel has no `legacy`. A nested folder
86
89
  that is a module of its own is named and left to its own run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.7.0-alpha.2",
3
+ "version": "1.7.0-alpha.3",
4
4
  "description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,50 +0,0 @@
1
- // src/shared/resolve-bin.ts
2
- import { existsSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
- import { delimiter, dirname, join } from "node:path";
5
- var require2 = createRequire(import.meta.url);
6
- function resolveBin(fromDir, name) {
7
- let dir = fromDir;
8
- for (; ; ) {
9
- const candidate = join(dir, "node_modules", ".bin", name);
10
- if (existsSync(candidate)) return candidate;
11
- const parent = dirname(dir);
12
- if (parent === dir) return void 0;
13
- dir = parent;
14
- }
15
- }
16
- function binFromOwnInstall(packageName, binName) {
17
- try {
18
- const manifest = require2.resolve(`${packageName}/package.json`);
19
- const bin = require2(manifest).bin;
20
- const relative = typeof bin === "string" ? bin : bin?.[binName];
21
- if (!relative) return void 0;
22
- const executable = join(dirname(manifest), relative);
23
- return existsSync(executable) ? executable : void 0;
24
- } catch {
25
- return void 0;
26
- }
27
- }
28
- function binSearchPath(cwd) {
29
- return [`${cwd}${delimiter}node_modules/.bin (and parents)`, "sentinel's own install"].join(
30
- " then "
31
- );
32
- }
33
- function scriptPath(cwd, path) {
34
- const bins = [];
35
- let dir = cwd;
36
- for (; ; ) {
37
- bins.push(join(dir, "node_modules", ".bin"));
38
- const parent = dirname(dir);
39
- if (parent === dir) break;
40
- dir = parent;
41
- }
42
- return [...bins, path].filter(Boolean).join(delimiter);
43
- }
44
-
45
- export {
46
- resolveBin,
47
- binFromOwnInstall,
48
- binSearchPath,
49
- scriptPath
50
- };