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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ import {
16
16
  registerAdapters,
17
17
  resolve,
18
18
  resolveBin
19
- } from "../chunk-B73S4RZP.js";
19
+ } from "../chunk-QP37G2HO.js";
20
20
  import {
21
21
  WORKSPACE_ROOT_MARKER,
22
22
  ensureWorkspacePrep,
@@ -5404,7 +5404,7 @@ function registerLint() {
5404
5404
  import { spawnSync as spawnSync5 } from "child_process";
5405
5405
  import { mkdtempSync as mkdtempSync2, readFileSync as readFileSync30 } from "fs";
5406
5406
  import { tmpdir as tmpdir2 } from "os";
5407
- import { join as join37 } from "path";
5407
+ import { isAbsolute as isAbsolute3, join as join37, resolve as resolve6 } from "path";
5408
5408
 
5409
5409
  // src/roles/test/presets/toolchain.json
5410
5410
  var toolchain_default2 = {
@@ -5481,7 +5481,7 @@ function testTarget(options) {
5481
5481
  }
5482
5482
 
5483
5483
  // src/roles/test/jest-migration.ts
5484
- import { existsSync as existsSync29, readFileSync as readFileSync28 } from "fs";
5484
+ import { existsSync as existsSync29, readFileSync as readFileSync28, readdirSync as readdirSync8 } from "fs";
5485
5485
  import { join as join35 } from "path";
5486
5486
 
5487
5487
  // src/roles/test/codemod/migrate-module.ts
@@ -8188,31 +8188,56 @@ function specTypesOperation(cwd) {
8188
8188
  return void 0;
8189
8189
  }
8190
8190
  const types = config?.compilerOptions?.types;
8191
- const include = config?.include;
8192
- const rewrittenInclude = Array.isArray(include) ? rewriteSpecInclude(include) : void 0;
8193
- const typesChanged = Array.isArray(types) && types.includes("jest");
8194
- if (!typesChanged && rewrittenInclude === void 0) return void 0;
8191
+ if (!Array.isArray(types) || !types.includes("jest")) return void 0;
8195
8192
  return {
8196
8193
  kind: "merge-json",
8197
8194
  path: SPEC_TSCONFIG,
8198
8195
  value: {
8199
- ...typesChanged ? {
8200
- compilerOptions: {
8201
- types: types.map(
8202
- (entry) => entry === "jest" ? VITEST_GLOBAL_TYPES : entry
8203
- )
8204
- }
8205
- } : {},
8206
- ...rewrittenInclude === void 0 ? {} : { include: rewrittenInclude }
8196
+ compilerOptions: {
8197
+ types: types.map((entry) => entry === "jest" ? VITEST_GLOBAL_TYPES : entry)
8198
+ }
8207
8199
  }
8208
8200
  };
8209
8201
  }
8210
- function rewriteSpecInclude(include) {
8211
- const rewritten = include.filter((entry) => typeof entry !== "string" || !JEST_CONFIG_ENTRY.test(entry)).map((entry) => typeof entry === "string" ? vitestSupportName(entry) : entry);
8212
- const unchanged = rewritten.length === include.length && rewritten.every((entry, index) => entry === include[index]);
8202
+ function tsconfigFileListOperations(cwd) {
8203
+ const operations = [];
8204
+ let names;
8205
+ try {
8206
+ names = readdirSync8(cwd).filter((name) => TSCONFIG_FILE.test(name));
8207
+ } catch {
8208
+ return operations;
8209
+ }
8210
+ for (const name of names) {
8211
+ let config;
8212
+ try {
8213
+ config = parseJsonc(
8214
+ readFileSync28(join35(cwd, name), "utf8"),
8215
+ name
8216
+ );
8217
+ } catch {
8218
+ continue;
8219
+ }
8220
+ const include = Array.isArray(config?.include) ? rewriteFileList(config.include) : void 0;
8221
+ const exclude = Array.isArray(config?.exclude) ? rewriteFileList(config.exclude) : void 0;
8222
+ if (include === void 0 && exclude === void 0) continue;
8223
+ operations.push({
8224
+ kind: "merge-json",
8225
+ path: name,
8226
+ value: {
8227
+ ...include === void 0 ? {} : { include },
8228
+ ...exclude === void 0 ? {} : { exclude }
8229
+ }
8230
+ });
8231
+ }
8232
+ return operations;
8233
+ }
8234
+ function rewriteFileList(entries) {
8235
+ const rewritten = entries.filter((entry) => typeof entry !== "string" || !JEST_CONFIG_ENTRY.test(entry)).map((entry) => typeof entry === "string" ? vitestSupportName(entry) : entry);
8236
+ const unchanged = rewritten.length === entries.length && rewritten.every((entry, index) => entry === entries[index]);
8213
8237
  return unchanged ? void 0 : rewritten;
8214
8238
  }
8215
8239
  var JEST_CONFIG_ENTRY = /(^|\/)jest\.[\w.-]*config\.[cm]?[jt]s$/;
8240
+ var TSCONFIG_FILE = /^tsconfig[\w.-]*\.json$/;
8216
8241
  function siblingScriptRewrites(cwd) {
8217
8242
  const rewrites = {};
8218
8243
  for (const [name, command] of Object.entries(moduleScripts(cwd))) {
@@ -8278,6 +8303,7 @@ function planJestMigration(context, adoption) {
8278
8303
  })),
8279
8304
  ...migration.operations,
8280
8305
  ...specTypes === void 0 ? [] : [specTypes],
8306
+ ...tsconfigFileListOperations(context.cwd),
8281
8307
  manifestOperation(context.cwd, { ...scripts, ...siblings }),
8282
8308
  ...prepared.flatMap(
8283
8309
  ({ mode }) => nxTargetOperations({
@@ -8847,13 +8873,16 @@ var VitestAdapter = class extends BaseAdapter {
8847
8873
  `using the MODULE's vitest, not sentinel's. An adopted config gets its plugins from sentinel, and two copies fail in ways that never mention a version. Remove vitest from this module's package.json.`
8848
8874
  );
8849
8875
  }
8850
- const { options, paths } = splitToolArgs(ctx.cwd, ctx.toolArgs, { valueFlags: [] });
8876
+ const { options: typedOptions, paths: typedPaths } = splitToolArgs(ctx.cwd, ctx.toolArgs, {
8877
+ valueFlags: ["--config", "-c"]
8878
+ });
8879
+ const { cwd: runFrom, options, paths } = fromWorkspaceRoot(ctx.cwd, typedOptions, typedPaths);
8851
8880
  const watching = options.includes("--watch") || options.includes("-w");
8852
8881
  const proving = !watching && hasReference(ctx.cwd);
8853
8882
  const reportFile = proving ? join37(mkdtempSync2(join37(tmpdir2(), "sentinel-run-")), "vitest.json") : void 0;
8854
8883
  const reporters = reportFile === void 0 ? [] : ["--reporter=default", "--reporter=json", `--outputFile=${reportFile}`];
8855
8884
  const argv = watching ? [...options, ...paths] : ["run", ...reporters, ...options, ...paths];
8856
- const result = spawnSync5(bin, argv, { cwd: ctx.cwd, stdio: "inherit" });
8885
+ const result = spawnSync5(bin, argv, { cwd: runFrom, stdio: "inherit" });
8857
8886
  if (result.error) {
8858
8887
  this.say(`could not run vitest (${result.error.message})`);
8859
8888
  return Promise.resolve({ ok: false, code: 1 });
@@ -8881,6 +8910,31 @@ var VitestAdapter = class extends BaseAdapter {
8881
8910
  `);
8882
8911
  }
8883
8912
  };
8913
+ function fromWorkspaceRoot(moduleDir, options, paths) {
8914
+ const root = findWorkspaceRoot(moduleDir);
8915
+ if (root === void 0 || root === moduleDir) {
8916
+ return { cwd: moduleDir, options: [...options], paths: [...paths] };
8917
+ }
8918
+ const absolute = (value) => isAbsolute3(value) ? value : resolve6(moduleDir, value);
8919
+ const moved = [];
8920
+ let previousWasConfig = false;
8921
+ for (const option of options) {
8922
+ if (previousWasConfig) {
8923
+ moved.push(absolute(option));
8924
+ previousWasConfig = false;
8925
+ continue;
8926
+ }
8927
+ if (option.startsWith("--config=")) moved.push(`--config=${absolute(option.slice(9))}`);
8928
+ else moved.push(option);
8929
+ previousWasConfig = option === "--config" || option === "-c";
8930
+ }
8931
+ return {
8932
+ cwd: root,
8933
+ // `--root` LAST, so a caller cannot be silently overridden by our own flag.
8934
+ options: [...moved, "--root", moduleDir],
8935
+ paths: paths.map((path) => absolute(path))
8936
+ };
8937
+ }
8884
8938
 
8885
8939
  // src/roles/test/register.ts
8886
8940
  function registerTest() {
@@ -9636,7 +9690,7 @@ function replaceLines(current, replacements) {
9636
9690
 
9637
9691
  // src/core/apply-plan.ts
9638
9692
  import { existsSync as existsSync32, readFileSync as readFileSync33, renameSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
9639
- import { resolve as resolve6, sep } from "path";
9693
+ import { resolve as resolve7, sep } from "path";
9640
9694
  import { applyEdits as applyEdits3, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
9641
9695
 
9642
9696
  // src/shared/deep-merge.ts
@@ -9646,8 +9700,8 @@ function isPlainObject(value) {
9646
9700
 
9647
9701
  // src/core/apply-plan.ts
9648
9702
  function resolveWithinRoot(cwd, relativePath) {
9649
- const root = resolve6(cwd);
9650
- const absolutePath = resolve6(root, relativePath);
9703
+ const root = resolve7(cwd);
9704
+ const absolutePath = resolve7(root, relativePath);
9651
9705
  if (absolutePath !== root && !absolutePath.startsWith(root + sep)) {
9652
9706
  throw new Error(`Refusing to write outside the module root: "${relativePath}".`);
9653
9707
  }
@@ -9772,7 +9826,7 @@ function applyPlan(cwd, plan4) {
9772
9826
  }
9773
9827
 
9774
9828
  // src/core/config/preset-evidence.ts
9775
- import { existsSync as existsSync33, readdirSync as readdirSync8, readFileSync as readFileSync34 } from "fs";
9829
+ import { existsSync as existsSync33, readdirSync as readdirSync9, readFileSync as readFileSync34 } from "fs";
9776
9830
  import { join as join40 } from "path";
9777
9831
  var PATH_SIGNALS = [
9778
9832
  {
@@ -9801,7 +9855,7 @@ function sourceImports(cwd, pattern) {
9801
9855
  const dir = stack.pop();
9802
9856
  let entries;
9803
9857
  try {
9804
- entries = readdirSync8(dir, { withFileTypes: true });
9858
+ entries = readdirSync9(dir, { withFileTypes: true });
9805
9859
  } catch {
9806
9860
  continue;
9807
9861
  }
@@ -9839,7 +9893,7 @@ function dependencyNames(cwd) {
9839
9893
  function declaresJsx(cwd) {
9840
9894
  let entries;
9841
9895
  try {
9842
- entries = readdirSync8(cwd).filter(
9896
+ entries = readdirSync9(cwd).filter(
9843
9897
  (name) => name.startsWith("tsconfig") && name.endsWith(".json")
9844
9898
  );
9845
9899
  } catch {
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  registerAdapters,
8
8
  resolve,
9
9
  setDefaultRunner
10
- } from "./chunk-B73S4RZP.js";
10
+ } from "./chunk-QP37G2HO.js";
11
11
  import "./chunk-WLFE5RUU.js";
12
12
  export {
13
13
  BaseAdapter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.4.0-alpha.6",
3
+ "version": "1.4.0-alpha.8",
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",