@hublo/sentinel 1.4.0-alpha.50 → 1.4.0-alpha.51

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.
@@ -15,10 +15,10 @@ import {
15
15
  palette,
16
16
  registerAdapters,
17
17
  resolve
18
- } from "../chunk-GBEE3R3A.js";
18
+ } from "../chunk-YDO3N3LT.js";
19
19
  import {
20
20
  resolveContext
21
- } from "../chunk-3BV4JNDB.js";
21
+ } from "../chunk-MPVS4ZHK.js";
22
22
  import "../chunk-O7REVMOC.js";
23
23
  import "../chunk-QXFCZON7.js";
24
24
  import {
@@ -145,7 +145,7 @@ async function runValidate(ctx) {
145
145
  );
146
146
  }
147
147
  if (!ctx.targets.includes("test")) return 1;
148
- const { validateModuleTests } = await import("../validate-UWQGFY2L.js");
148
+ const { validateModuleTests } = await import("../validate-NCOSA4CW.js");
149
149
  const outcomes = modules.flatMap(
150
150
  (module) => validateModuleTests(module.name, module.root)
151
151
  );
@@ -2591,7 +2591,7 @@ function applyNamedRules(source, program, fileName = "") {
2591
2591
  edits.push({
2592
2592
  start: node.start,
2593
2593
  end: node.end,
2594
- text: castIfTestOnly(literal, `vi.mocked(${namespaces.bindingFor(literal)})`)
2594
+ text: castIfTestOnly(literal, namespaces.bindingFor(literal))
2595
2595
  });
2596
2596
  applied.add("require of a specifier this file mocks");
2597
2597
  return;
@@ -3021,6 +3021,21 @@ function awaitedImport(source, node) {
3021
3021
  if (specifier?.type !== "Literal") return void 0;
3022
3022
  return source.slice(specifier.start, specifier.end).slice(1, -1);
3023
3023
  }
3024
+ function namespaceImports(source, program) {
3025
+ const names = /* @__PURE__ */ new Map();
3026
+ for (const statement2 of program.body ?? []) {
3027
+ if (statement2.type !== "ImportDeclaration") continue;
3028
+ const from = statement2.source;
3029
+ if (from?.type !== "Literal") continue;
3030
+ const specifier = source.slice(from.start, from.end).slice(1, -1);
3031
+ for (const clause of statement2.specifiers ?? []) {
3032
+ if (clause.type !== "ImportNamespaceSpecifier") continue;
3033
+ const local = clause.local;
3034
+ if (local?.type === "Identifier") names.set(local.name, specifier);
3035
+ }
3036
+ }
3037
+ return names;
3038
+ }
3024
3039
  function annotateMockedBindings(source, program) {
3025
3040
  const mocked = /* @__PURE__ */ new Set();
3026
3041
  walk(program, (node) => {
@@ -3028,6 +3043,7 @@ function annotateMockedBindings(source, program) {
3028
3043
  if (specifier !== void 0) mocked.add(specifier);
3029
3044
  });
3030
3045
  if (mocked.size === 0) return { source, rewritten: 0, typeImports: [] };
3046
+ const namespaces = namespaceImports(source, program);
3031
3047
  const edits = [];
3032
3048
  for (const statement2 of program.body ?? []) {
3033
3049
  if (statement2.type !== "VariableDeclaration") continue;
@@ -3037,7 +3053,7 @@ function annotateMockedBindings(source, program) {
3037
3053
  if (only === void 0) continue;
3038
3054
  if (only.id?.type !== "Identifier") continue;
3039
3055
  const init = only.init;
3040
- const specifier = awaitedImport(source, init);
3056
+ const specifier = awaitedImport(source, init) ?? (init?.type === "Identifier" ? namespaces.get(init.name) : void 0);
3041
3057
  if (specifier === void 0 || !mocked.has(specifier)) continue;
3042
3058
  const start = init?.start;
3043
3059
  const end = init?.end;
@@ -3047,7 +3063,8 @@ function annotateMockedBindings(source, program) {
3047
3063
  edits.push({
3048
3064
  start,
3049
3065
  end,
3050
- text: `(${expression}) as unknown as Record<string, Mock>`
3066
+ // Parentheses only where the expression needs them: `await import(S)` does, a name does not.
3067
+ text: init?.type === "Identifier" ? `${expression} as unknown as Record<string, Mock>` : `(${expression}) as unknown as Record<string, Mock>`
3051
3068
  });
3052
3069
  }
3053
3070
  if (edits.length === 0) return { source, rewritten: 0, typeImports: [] };
@@ -3675,7 +3692,7 @@ function lineOf2(source, offset) {
3675
3692
  }
3676
3693
  return line;
3677
3694
  }
3678
- function namespaceImports(program) {
3695
+ function namespaceImports2(program) {
3679
3696
  const found = /* @__PURE__ */ new Map();
3680
3697
  for (const statement2 of program.body ?? []) {
3681
3698
  if (statement2.type !== "ImportDeclaration") continue;
@@ -3865,7 +3882,7 @@ function remainingUses(program, binding, spent) {
3865
3882
  function rewriteInternalCallSpies(fileName, source, program) {
3866
3883
  const unchanged = { source, rewritten: [], refusals: [] };
3867
3884
  if (!source.includes("spyOn")) return unchanged;
3868
- const namespaces = namespaceImports(program);
3885
+ const namespaces = namespaceImports2(program);
3869
3886
  if (namespaces.size === 0) return unchanged;
3870
3887
  const bindings = declarators(program);
3871
3888
  const mocked = existingMocks(program);
@@ -53,7 +53,7 @@ import {
53
53
  selfCommand,
54
54
  splitToolArgs,
55
55
  walk
56
- } from "./chunk-3BV4JNDB.js";
56
+ } from "./chunk-MPVS4ZHK.js";
57
57
  import {
58
58
  parseJsonc
59
59
  } from "./chunk-QXFCZON7.js";
package/dist/index.js CHANGED
@@ -6,10 +6,10 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-GBEE3R3A.js";
9
+ } from "./chunk-YDO3N3LT.js";
10
10
  import {
11
11
  BaseAdapter
12
- } from "./chunk-3BV4JNDB.js";
12
+ } from "./chunk-MPVS4ZHK.js";
13
13
  import "./chunk-O7REVMOC.js";
14
14
  import "./chunk-QXFCZON7.js";
15
15
  import "./chunk-KMKQDGI6.js";
@@ -7,7 +7,7 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-3BV4JNDB.js";
10
+ } from "./chunk-MPVS4ZHK.js";
11
11
  import "./chunk-O7REVMOC.js";
12
12
  import "./chunk-QXFCZON7.js";
13
13
  import "./chunk-KMKQDGI6.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.4.0-alpha.50",
3
+ "version": "1.4.0-alpha.51",
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",