@hublo/sentinel 1.4.0-alpha.15 → 1.4.0-alpha.16
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
CHANGED
|
@@ -6990,6 +6990,78 @@ function rewriteMockFactoryDefault(source, program, defaultImported) {
|
|
|
6990
6990
|
};
|
|
6991
6991
|
}
|
|
6992
6992
|
|
|
6993
|
+
// src/roles/test/codemod/mock-promise-resolve.ts
|
|
6994
|
+
var MOCK_FACTORY = /* @__PURE__ */ new Set(["fn", "spyOn"]);
|
|
6995
|
+
function isMockFactory(source, node) {
|
|
6996
|
+
if (node.type !== "CallExpression") return false;
|
|
6997
|
+
const callee = node.callee;
|
|
6998
|
+
if (callee?.type !== "MemberExpression") return false;
|
|
6999
|
+
const object = callee.object;
|
|
7000
|
+
const property = callee.property;
|
|
7001
|
+
if (object?.type !== "Identifier" || property?.type !== "Identifier") return false;
|
|
7002
|
+
const runner = source.slice(object.start, object.end);
|
|
7003
|
+
const method = source.slice(property.start, property.end);
|
|
7004
|
+
return (runner === "jest" || runner === "vi") && MOCK_FACTORY.has(method);
|
|
7005
|
+
}
|
|
7006
|
+
function resolvedValue(source, executor) {
|
|
7007
|
+
if (executor.type !== "ArrowFunctionExpression" && executor.type !== "FunctionExpression") {
|
|
7008
|
+
return void 0;
|
|
7009
|
+
}
|
|
7010
|
+
const params = executor.params;
|
|
7011
|
+
if (params?.length !== 1) return void 0;
|
|
7012
|
+
const parameter = params[0];
|
|
7013
|
+
if (parameter.type !== "Identifier") return void 0;
|
|
7014
|
+
const resolveName = source.slice(parameter.start, parameter.end);
|
|
7015
|
+
const body = executor.body;
|
|
7016
|
+
if (body === void 0) return void 0;
|
|
7017
|
+
let call;
|
|
7018
|
+
if (body.type === "BlockStatement") {
|
|
7019
|
+
const statements = body.body;
|
|
7020
|
+
if (statements?.length !== 1) return void 0;
|
|
7021
|
+
const only = statements[0];
|
|
7022
|
+
if (only.type !== "ExpressionStatement") return void 0;
|
|
7023
|
+
call = only.expression;
|
|
7024
|
+
} else {
|
|
7025
|
+
call = body;
|
|
7026
|
+
}
|
|
7027
|
+
if (call?.type !== "CallExpression") return void 0;
|
|
7028
|
+
const callee = call.callee;
|
|
7029
|
+
if (callee?.type !== "Identifier") return void 0;
|
|
7030
|
+
if (source.slice(callee.start, callee.end) !== resolveName) return void 0;
|
|
7031
|
+
const args = call.arguments;
|
|
7032
|
+
if (args?.length !== 1) return void 0;
|
|
7033
|
+
return args[0];
|
|
7034
|
+
}
|
|
7035
|
+
function rewriteMockPromiseResolve(source, program) {
|
|
7036
|
+
const edits = [];
|
|
7037
|
+
walk(program, (node) => {
|
|
7038
|
+
if (!isMockFactory(source, node)) return;
|
|
7039
|
+
for (const argument of node.arguments ?? []) {
|
|
7040
|
+
walk(argument, (inner) => {
|
|
7041
|
+
if (inner.type !== "NewExpression") return;
|
|
7042
|
+
const callee = inner.callee;
|
|
7043
|
+
if (callee?.type !== "Identifier") return;
|
|
7044
|
+
if (source.slice(callee.start, callee.end) !== "Promise") return;
|
|
7045
|
+
if ((inner.typeArguments ?? inner.typeParameters) !== void 0) return;
|
|
7046
|
+
const executors = inner.arguments ?? [];
|
|
7047
|
+
if (executors.length !== 1) return;
|
|
7048
|
+
const value = resolvedValue(source, executors[0]);
|
|
7049
|
+
if (value === void 0) return;
|
|
7050
|
+
edits.push({
|
|
7051
|
+
start: inner.start,
|
|
7052
|
+
end: inner.end,
|
|
7053
|
+
text: `Promise.resolve(${source.slice(value.start, value.end)})`
|
|
7054
|
+
});
|
|
7055
|
+
});
|
|
7056
|
+
}
|
|
7057
|
+
});
|
|
7058
|
+
let result = source;
|
|
7059
|
+
for (const edit of [...edits].sort((left, right) => right.start - left.start)) {
|
|
7060
|
+
result = `${result.slice(0, edit.start)}${edit.text}${result.slice(edit.end)}`;
|
|
7061
|
+
}
|
|
7062
|
+
return { source: result, rewritten: edits.length };
|
|
7063
|
+
}
|
|
7064
|
+
|
|
6993
7065
|
// src/roles/test/codemod/propagate-await.ts
|
|
6994
7066
|
import { parseSync as parseSync5 } from "oxc-parser";
|
|
6995
7067
|
var FUNCTIONS3 = /* @__PURE__ */ new Set(["ArrowFunctionExpression", "FunctionExpression", "FunctionDeclaration"]);
|
|
@@ -7381,7 +7453,10 @@ function migrateTestFile(fileName, source, defaultImported = /* @__PURE__ */ new
|
|
|
7381
7453
|
const afterEmpty = parse2(fileName, emptyImplementations.source);
|
|
7382
7454
|
if (afterEmpty === void 0) return unparsable("empty mock implementation");
|
|
7383
7455
|
const hooks = rewriteHookReturnValue(emptyImplementations.source, afterEmpty);
|
|
7384
|
-
const
|
|
7456
|
+
const afterHooks = parse2(fileName, hooks.source);
|
|
7457
|
+
if (afterHooks === void 0) return unparsable("hook return value");
|
|
7458
|
+
const promises = rewriteMockPromiseResolve(hooks.source, afterHooks);
|
|
7459
|
+
const awaited = propagateAwait(fileName, promises.source, original, asyncHelpers);
|
|
7385
7460
|
const program = parse2(fileName, awaited.source);
|
|
7386
7461
|
if (program === void 0) return unparsable("hook body");
|
|
7387
7462
|
const hoist = hoistCapturedBindings(
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hublo/sentinel",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.16",
|
|
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",
|