@hublo/sentinel 1.2.0-alpha.35 → 1.2.0-alpha.37

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.
@@ -22,7 +22,7 @@ import {
22
22
  registerAdapters,
23
23
  resolve,
24
24
  resolveBin
25
- } from "../chunk-GQID2U34.js";
25
+ } from "../chunk-MQR7FYM5.js";
26
26
 
27
27
  // bin/sentinel.ts
28
28
  import { program } from "commander";
@@ -5618,7 +5618,15 @@ var toolchain_default2 = {
5618
5618
  var OWNED_TEST_PACKAGES = toolchain_default2.owned;
5619
5619
 
5620
5620
  // src/roles/test/config-policy.ts
5621
- var TEST_PRESET_SPECIFIER = "@hublo/sentinel/test/react";
5621
+ var TEST_PRESET_SPECIFIERS = {
5622
+ react: "@hublo/sentinel/test/react",
5623
+ nest: "@hublo/sentinel/test/nest"
5624
+ };
5625
+ function testPresetSpecifier(preset) {
5626
+ return TEST_PRESET_SPECIFIERS[preset] ?? TEST_PRESET_SPECIFIERS.react;
5627
+ }
5628
+ var ALL_TEST_PRESET_SPECIFIERS = Object.values(TEST_PRESET_SPECIFIERS);
5629
+ var TEST_PRESET_SPECIFIER = TEST_PRESET_SPECIFIERS.react;
5622
5630
  var TEST_CONFIG_FILES = [
5623
5631
  "vitest.config.ts",
5624
5632
  "vitest.config.mts",
@@ -5629,10 +5637,9 @@ var TEST_OWNED_PACKAGES = OWNED_TEST_PACKAGES;
5629
5637
  var SENTINEL_OWNED_TEST_PACKAGES = TEST_OWNED_PACKAGES.filter(
5630
5638
  (entry) => entry.package !== "vite"
5631
5639
  ).map((entry) => entry.package);
5632
- var TEST_TOOLCHAIN = {
5633
- presetSpecifier: TEST_PRESET_SPECIFIER,
5634
- owned: TEST_OWNED_PACKAGES
5635
- };
5640
+ function testToolchain(preset) {
5641
+ return { presetSpecifier: testPresetSpecifier(preset), owned: TEST_OWNED_PACKAGES };
5642
+ }
5636
5643
  var TEST_SCRIPT_NAME = "test";
5637
5644
  var SENTINEL_TEST_COMMAND = "sentinel --run --test --";
5638
5645
  var VITEST_INVOCATION = /(^|&&\s*|\|\|\s*|;\s*)(?:npx\s+|pnpm\s+(?:exec\s+|dlx\s+)?)?vitest\b([^&|;]*)/g;
@@ -5728,8 +5735,10 @@ function readTestConfigSource(cwd, fileName) {
5728
5735
  }
5729
5736
  }
5730
5737
  function importsPreset2(source) {
5731
- const escaped = TEST_PRESET_SPECIFIER.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5732
- return new RegExp(String.raw`(?:from|import)\s*\(?\s*['"]${escaped}['"]`).test(source);
5738
+ return ALL_TEST_PRESET_SPECIFIERS.some((specifier) => {
5739
+ const escaped = specifier.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5740
+ return new RegExp(String.raw`(?:from|import)\s*\(?\s*['"]${escaped}['"]`).test(source);
5741
+ });
5733
5742
  }
5734
5743
  function readTestAdoption(cwd) {
5735
5744
  const manifest = readProjectPackageJson(cwd);
@@ -5790,7 +5799,7 @@ function readTestAdoption(cwd) {
5790
5799
  }
5791
5800
 
5792
5801
  // src/roles/test/codemod/migrate-file.ts
5793
- import { parseSync as parseSync5 } from "oxc-parser";
5802
+ import { parseSync as parseSync6 } from "oxc-parser";
5794
5803
 
5795
5804
  // src/roles/test/codemod/scope.ts
5796
5805
  function readIdentifiers(node) {
@@ -6215,6 +6224,38 @@ function applyNamedRules(source, program) {
6215
6224
  return { source: applyEdits(source, edits), applied: [...applied].sort() };
6216
6225
  }
6217
6226
 
6227
+ // src/roles/test/codemod/repoint-msw.ts
6228
+ import { parseSync as parseSync5 } from "oxc-parser";
6229
+ var SENTINEL_MSW_SERVER = "@hublo/sentinel/test/msw";
6230
+ var MSW_SERVER_MODULE = /(^|\/)msw\/server$/;
6231
+ function importsServer(declaration) {
6232
+ return (declaration.specifiers ?? []).some((specifier) => {
6233
+ const imported = specifier.imported;
6234
+ const local = specifier.local;
6235
+ return imported?.name === "server" || imported === void 0 && local?.name === "server";
6236
+ });
6237
+ }
6238
+ function repointMswServer(fileName, source) {
6239
+ const { program, errors } = parseSync5(fileName, source, { sourceType: "module" });
6240
+ if (errors.length > 0) return { source, repointed: false };
6241
+ const edits = [];
6242
+ walk(program, (node) => {
6243
+ if (node.type !== "ImportDeclaration") return;
6244
+ const specifier = node.source;
6245
+ if (specifier?.value === void 0) return;
6246
+ if (!MSW_SERVER_MODULE.test(specifier.value)) return;
6247
+ if (!importsServer(node)) return;
6248
+ edits.push({ start: specifier.start, end: specifier.end });
6249
+ });
6250
+ if (edits.length === 0) return { source, repointed: false };
6251
+ let rewritten = source;
6252
+ for (const edit of edits.sort((left, right) => right.start - left.start)) {
6253
+ const quote = source[edit.start] === '"' ? '"' : "'";
6254
+ rewritten = rewritten.slice(0, edit.start) + `${quote}${SENTINEL_MSW_SERVER}${quote}` + rewritten.slice(edit.end);
6255
+ }
6256
+ return { source: rewritten, repointed: true };
6257
+ }
6258
+
6218
6259
  // src/roles/test/codemod/migrate-file.ts
6219
6260
  function mockFactories(program) {
6220
6261
  const factories = [];
@@ -6233,7 +6274,7 @@ function mockFactories(program) {
6233
6274
  return factories;
6234
6275
  }
6235
6276
  function parse2(fileName, source) {
6236
- const { program, errors } = parseSync5(fileName, source, { sourceType: "module" });
6277
+ const { program, errors } = parseSync6(fileName, source, { sourceType: "module" });
6237
6278
  return errors.length > 0 ? void 0 : program;
6238
6279
  }
6239
6280
  function migrateTestFile(fileName, source) {
@@ -6244,7 +6285,8 @@ function migrateTestFile(fileName, source) {
6244
6285
  hoisted: [],
6245
6286
  unhandled: [],
6246
6287
  refusals: [],
6247
- rulesApplied: []
6288
+ rulesApplied: [],
6289
+ mswRepointed: false
6248
6290
  };
6249
6291
  const original = parse2(fileName, source);
6250
6292
  if (original === void 0) return untouched;
@@ -6260,14 +6302,16 @@ function migrateTestFile(fileName, source) {
6260
6302
  importedNames(program)
6261
6303
  );
6262
6304
  const withImport = injectTypeImport(fileName, hoist.source, renamed.typeImports);
6305
+ const repointed = repointMswServer(fileName, withImport);
6263
6306
  return {
6264
- source: withImport,
6265
- changed: withImport !== source,
6307
+ source: repointed.source,
6308
+ changed: repointed.source !== source,
6266
6309
  renamed: renamed.rewritten,
6267
6310
  hoisted: hoist.hoisted,
6268
6311
  unhandled: renamed.unhandled,
6269
6312
  refusals: hoist.refusals,
6270
- rulesApplied: ruled.applied
6313
+ rulesApplied: ruled.applied,
6314
+ mswRepointed: repointed.repointed
6271
6315
  };
6272
6316
  }
6273
6317
 
@@ -6615,7 +6659,7 @@ function plan3(context) {
6615
6659
  const operations = [];
6616
6660
  const notes = [];
6617
6661
  const rewrite = rewriteToolchainImports(
6618
- TEST_TOOLCHAIN,
6662
+ testToolchain(context.preset),
6619
6663
  readTestConfigSource(context.cwd, configFile),
6620
6664
  configFile
6621
6665
  );
@@ -7912,4 +7956,4 @@ export {
7912
7956
  detectFramework,
7913
7957
  dispatch
7914
7958
  };
7915
- //# sourceMappingURL=chunk-GQID2U34.js.map
7959
+ //# sourceMappingURL=chunk-MQR7FYM5.js.map
@@ -0,0 +1,13 @@
1
+ // src/roles/test/setup/msw.ts
2
+ import { setupServer } from "msw/node";
3
+ var server = setupServer();
4
+ function installMswLifecycle(hooks) {
5
+ hooks.beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
6
+ hooks.afterAll(() => server.close());
7
+ }
8
+
9
+ export {
10
+ server,
11
+ installMswLifecycle
12
+ };
13
+ //# sourceMappingURL=chunk-NKFGYPIQ.js.map
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  registerAdapters,
8
8
  resolve,
9
9
  setDefaultRunner
10
- } from "./chunk-GQID2U34.js";
10
+ } from "./chunk-MQR7FYM5.js";
11
11
  export {
12
12
  BaseAdapter,
13
13
  all,
@@ -0,0 +1,15 @@
1
+ import * as msw_node from 'msw/node';
2
+
3
+ /**
4
+ * No default handlers, deliberately.
5
+ *
6
+ * The repo's own server had `defaultHandlers = []` too, so nothing is lost. A handler here would
7
+ * be a Hublo endpoint inside a package meant to be usable by anyone, which is the line between
8
+ * what sentinel owns (the config) and what an app owns (what it mocks).
9
+ *
10
+ * A suite adds its own with `server.use(...)`, which is how all 600 files that touch this already
11
+ * work.
12
+ */
13
+ declare const server: msw_node.SetupServer;
14
+
15
+ export { server };
@@ -0,0 +1,7 @@
1
+ import {
2
+ server
3
+ } from "../../../chunk-NKFGYPIQ.js";
4
+ export {
5
+ server
6
+ };
7
+ //# sourceMappingURL=msw-server.js.map
@@ -1,15 +1,2 @@
1
- import * as msw_node from 'msw/node';
2
-
3
- /**
4
- * No default handlers, deliberately.
5
- *
6
- * The repo's own server had `defaultHandlers = []` too, so nothing is lost. A handler here would
7
- * be a Hublo endpoint inside a package meant to be usable by anyone, which is the line between
8
- * what sentinel owns (the config) and what an app owns (what it mocks).
9
- *
10
- * A suite adds its own with `server.use(...)`, which is how all 600 files that touch this already
11
- * work.
12
- */
13
- declare const server: msw_node.SetupServer;
14
-
15
- export { server };
1
+ export { server } from './msw-server.js';
2
+ import 'msw/node';
@@ -1,14 +1,11 @@
1
+ import {
2
+ installMswLifecycle,
3
+ server
4
+ } from "../../../chunk-NKFGYPIQ.js";
5
+
1
6
  // src/roles/test/setup/nest.ts
2
7
  import { afterAll, afterEach, beforeAll } from "vitest";
3
8
 
4
- // src/roles/test/setup/msw.ts
5
- import { setupServer } from "msw/node";
6
- var server = setupServer();
7
- function installMswLifecycle(hooks) {
8
- hooks.beforeAll(() => server.listen({ onUnhandledRequest: "error" }));
9
- hooks.afterAll(() => server.close());
10
- }
11
-
12
9
  // src/roles/test/setup/workspace.ts
13
10
  function isMissingModule(error) {
14
11
  return error?.code === "ERR_MODULE_NOT_FOUND";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hublo/sentinel",
3
- "version": "1.2.0-alpha.35",
3
+ "version": "1.2.0-alpha.37",
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",
@@ -57,6 +57,10 @@
57
57
  "./test/setup/nest": {
58
58
  "types": "./dist/roles/test/setup/nest.d.ts",
59
59
  "import": "./dist/roles/test/setup/nest.js"
60
+ },
61
+ "./test/msw": {
62
+ "types": "./dist/roles/test/setup/msw-server.d.ts",
63
+ "import": "./dist/roles/test/setup/msw-server.js"
60
64
  }
61
65
  },
62
66
  "files": [
@@ -87,7 +91,8 @@
87
91
  "typescript": "5.9.3",
88
92
  "vite": "8.2.2",
89
93
  "vite-plugin-svgr": "5.2.0",
90
- "vitest": "4.1.4"
94
+ "vitest": "4.1.4",
95
+ "vitest-mock-extended": "5.1.1"
91
96
  },
92
97
  "devDependencies": {
93
98
  "@hublo/sentinel": "link:.",