@hublo/sentinel 1.2.0-alpha.36 → 1.2.0-alpha.38
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.
- package/dist/bin/sentinel.js +5 -2
- package/dist/chunk-NKFGYPIQ.js +13 -0
- package/dist/{chunk-U2KUKV4C.js → chunk-PBCVWRXM.js} +52 -11
- package/dist/index.js +1 -1
- package/dist/roles/test/setup/msw-server.d.ts +15 -0
- package/dist/roles/test/setup/msw-server.js +7 -0
- package/dist/roles/test/setup/nest.d.ts +2 -15
- package/dist/roles/test/setup/nest.js +5 -8
- package/package.json +7 -2
package/dist/bin/sentinel.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
WORKSPACE_ROOT_MARKER,
|
|
10
10
|
availableTargets,
|
|
11
11
|
buildConfigFile,
|
|
12
|
+
contradictingPreset,
|
|
12
13
|
declaredPresetFor,
|
|
13
14
|
describeFramework,
|
|
14
15
|
dispatch,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
registerAdapters,
|
|
23
24
|
resolve,
|
|
24
25
|
resolveBin
|
|
25
|
-
} from "../chunk-
|
|
26
|
+
} from "../chunk-PBCVWRXM.js";
|
|
26
27
|
|
|
27
28
|
// bin/sentinel.ts
|
|
28
29
|
import { program } from "commander";
|
|
@@ -238,7 +239,9 @@ async function analyse(params) {
|
|
|
238
239
|
}
|
|
239
240
|
for (const target of params.targets) {
|
|
240
241
|
let adapter;
|
|
241
|
-
const
|
|
242
|
+
const declared = declaredPresetFor(target, module.root);
|
|
243
|
+
const corrected = params.preset ?? declared ?? contradictingPreset(module.root, preset2)?.preset ?? preset2;
|
|
244
|
+
const resolutionPreset = corrected;
|
|
242
245
|
try {
|
|
243
246
|
adapter = resolve(target, resolutionPreset, params.runner);
|
|
244
247
|
} catch (error) {
|
|
@@ -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
|
|
@@ -5799,7 +5799,7 @@ function readTestAdoption(cwd) {
|
|
|
5799
5799
|
}
|
|
5800
5800
|
|
|
5801
5801
|
// src/roles/test/codemod/migrate-file.ts
|
|
5802
|
-
import { parseSync as
|
|
5802
|
+
import { parseSync as parseSync6 } from "oxc-parser";
|
|
5803
5803
|
|
|
5804
5804
|
// src/roles/test/codemod/scope.ts
|
|
5805
5805
|
function readIdentifiers(node) {
|
|
@@ -6224,6 +6224,38 @@ function applyNamedRules(source, program) {
|
|
|
6224
6224
|
return { source: applyEdits(source, edits), applied: [...applied].sort() };
|
|
6225
6225
|
}
|
|
6226
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
|
+
|
|
6227
6259
|
// src/roles/test/codemod/migrate-file.ts
|
|
6228
6260
|
function mockFactories(program) {
|
|
6229
6261
|
const factories = [];
|
|
@@ -6242,7 +6274,7 @@ function mockFactories(program) {
|
|
|
6242
6274
|
return factories;
|
|
6243
6275
|
}
|
|
6244
6276
|
function parse2(fileName, source) {
|
|
6245
|
-
const { program, errors } =
|
|
6277
|
+
const { program, errors } = parseSync6(fileName, source, { sourceType: "module" });
|
|
6246
6278
|
return errors.length > 0 ? void 0 : program;
|
|
6247
6279
|
}
|
|
6248
6280
|
function migrateTestFile(fileName, source) {
|
|
@@ -6253,7 +6285,8 @@ function migrateTestFile(fileName, source) {
|
|
|
6253
6285
|
hoisted: [],
|
|
6254
6286
|
unhandled: [],
|
|
6255
6287
|
refusals: [],
|
|
6256
|
-
rulesApplied: []
|
|
6288
|
+
rulesApplied: [],
|
|
6289
|
+
mswRepointed: false
|
|
6257
6290
|
};
|
|
6258
6291
|
const original = parse2(fileName, source);
|
|
6259
6292
|
if (original === void 0) return untouched;
|
|
@@ -6269,14 +6302,16 @@ function migrateTestFile(fileName, source) {
|
|
|
6269
6302
|
importedNames(program)
|
|
6270
6303
|
);
|
|
6271
6304
|
const withImport = injectTypeImport(fileName, hoist.source, renamed.typeImports);
|
|
6305
|
+
const repointed = repointMswServer(fileName, withImport);
|
|
6272
6306
|
return {
|
|
6273
|
-
source:
|
|
6274
|
-
changed:
|
|
6307
|
+
source: repointed.source,
|
|
6308
|
+
changed: repointed.source !== source,
|
|
6275
6309
|
renamed: renamed.rewritten,
|
|
6276
6310
|
hoisted: hoist.hoisted,
|
|
6277
6311
|
unhandled: renamed.unhandled,
|
|
6278
6312
|
refusals: hoist.refusals,
|
|
6279
|
-
rulesApplied: ruled.applied
|
|
6313
|
+
rulesApplied: ruled.applied,
|
|
6314
|
+
mswRepointed: repointed.repointed
|
|
6280
6315
|
};
|
|
6281
6316
|
}
|
|
6282
6317
|
|
|
@@ -7771,6 +7806,11 @@ function presetContradiction(declared, cwd) {
|
|
|
7771
7806
|
const evidence = signals.map((signal) => signal.evidence).join(", and ");
|
|
7772
7807
|
return `--preset ${declared} does not match this module: ${evidence}, which makes it "${first.preset}". Nothing was written. Re-run with --preset ${first.preset}, or adopt from the module you actually meant.`;
|
|
7773
7808
|
}
|
|
7809
|
+
function contradictingPreset(cwd, detected) {
|
|
7810
|
+
const [signal] = presetSignals(cwd);
|
|
7811
|
+
if (signal === void 0 || signal.preset === detected) return void 0;
|
|
7812
|
+
return { preset: signal.preset, evidence: signal.evidence };
|
|
7813
|
+
}
|
|
7774
7814
|
|
|
7775
7815
|
// src/core/dispatch.ts
|
|
7776
7816
|
function resolveFlavour(opts) {
|
|
@@ -7848,11 +7888,11 @@ async function dispatch(opts) {
|
|
|
7848
7888
|
}
|
|
7849
7889
|
let effective = preset;
|
|
7850
7890
|
if (opts.preset === void 0 && adapter.declaredPreset?.(opts.cwd) === void 0) {
|
|
7851
|
-
const
|
|
7852
|
-
if (
|
|
7853
|
-
effective =
|
|
7891
|
+
const contradiction = contradictingPreset(opts.cwd, preset);
|
|
7892
|
+
if (contradiction !== void 0) {
|
|
7893
|
+
effective = contradiction.preset;
|
|
7854
7894
|
process.stderr.write(
|
|
7855
|
-
` detected "${preset}" from dependencies, but ${
|
|
7895
|
+
` detected "${preset}" from dependencies, but ${contradiction.evidence}, so adopting as "${contradiction.preset}". Pass --preset to override.
|
|
7856
7896
|
`
|
|
7857
7897
|
);
|
|
7858
7898
|
}
|
|
@@ -7917,8 +7957,9 @@ export {
|
|
|
7917
7957
|
PRESET_NAMES,
|
|
7918
7958
|
palette,
|
|
7919
7959
|
registerAdapters,
|
|
7960
|
+
contradictingPreset,
|
|
7920
7961
|
describeFramework,
|
|
7921
7962
|
detectFramework,
|
|
7922
7963
|
dispatch
|
|
7923
7964
|
};
|
|
7924
|
-
//# sourceMappingURL=chunk-
|
|
7965
|
+
//# sourceMappingURL=chunk-PBCVWRXM.js.map
|
package/dist/index.js
CHANGED
|
@@ -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 };
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
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.
|
|
3
|
+
"version": "1.2.0-alpha.38",
|
|
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:.",
|