@hublo/sentinel 1.7.0-alpha.27 → 1.7.0-alpha.29
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 +1 -1
- package/dist/{chunk-B23ACOC4.js → chunk-ZZP4DWQK.js} +440 -255
- package/dist/index.js +1 -1
- package/dist/roles/runtime-analysis/gateway.js +8 -1
- package/dist/roles/runtime-analysis/gateway.js.map +1 -1
- package/docs/runtime-analysis-adoption.md +35 -0
- package/package.json +1 -1
|
@@ -623,10 +623,10 @@ function nxTargetCommand(cwd, target) {
|
|
|
623
623
|
}
|
|
624
624
|
const entry = project.targets?.[target];
|
|
625
625
|
if (!entry || entry.executor !== "nx:run-commands") return void 0;
|
|
626
|
-
const { command, commands, cwd: targetCwd } = entry.options ?? {};
|
|
626
|
+
const { command: command2, commands, cwd: targetCwd } = entry.options ?? {};
|
|
627
627
|
const ranInModule = typeof targetCwd === "string" && targetCwd.trim() !== "";
|
|
628
|
-
if (typeof
|
|
629
|
-
return { command:
|
|
628
|
+
if (typeof command2 === "string" && command2.trim() !== "") {
|
|
629
|
+
return { command: command2.trim(), ranInModule };
|
|
630
630
|
}
|
|
631
631
|
if (Array.isArray(commands)) {
|
|
632
632
|
const parts = commands.filter((c) => typeof c === "string" && c.trim() !== "");
|
|
@@ -634,8 +634,8 @@ function nxTargetCommand(cwd, target) {
|
|
|
634
634
|
}
|
|
635
635
|
return void 0;
|
|
636
636
|
}
|
|
637
|
-
function rootedForScript(
|
|
638
|
-
return
|
|
637
|
+
function rootedForScript(command2) {
|
|
638
|
+
return command2.replace(/(^|&&\s*)pnpm exec /g, "$1pnpm --workspace-root exec ");
|
|
639
639
|
}
|
|
640
640
|
function existingCommand(cwd, target) {
|
|
641
641
|
const script = moduleScripts(cwd)[target];
|
|
@@ -658,8 +658,8 @@ function isSentinelSegment(segment, roleFlag) {
|
|
|
658
658
|
return runsSentinel && new RegExp(String.raw`(^|\s)${roleFlag}(\s|$)`).test(segment);
|
|
659
659
|
}
|
|
660
660
|
function composeToolScript(existing, options) {
|
|
661
|
-
const { command } = options;
|
|
662
|
-
if (!existing || existing.trim() === "") return
|
|
661
|
+
const { command: command2 } = options;
|
|
662
|
+
if (!existing || existing.trim() === "") return command2;
|
|
663
663
|
const { roleFlag } = options;
|
|
664
664
|
const isReplaceable = (segment) => options.replaces(segment) || roleFlag !== void 0 && isSentinelSegment(segment, roleFlag);
|
|
665
665
|
const parts = existing.split(SEGMENT_SEPARATOR);
|
|
@@ -670,7 +670,7 @@ function composeToolScript(existing, options) {
|
|
|
670
670
|
if (isSeparatorAt(index) || !isReplaceable(part)) return part;
|
|
671
671
|
if (replacedOnce) return null;
|
|
672
672
|
replacedOnce = true;
|
|
673
|
-
return options.keepFix && /(^|\s)--fix(\s|$)/.test(part) ? `${
|
|
673
|
+
return options.keepFix && /(^|\s)--fix(\s|$)/.test(part) ? `${command2} --fix` : command2;
|
|
674
674
|
});
|
|
675
675
|
const kept = [];
|
|
676
676
|
for (let index = 0; index < rebuilt.length; index += 1) {
|
|
@@ -709,14 +709,14 @@ function appOptions(rest) {
|
|
|
709
709
|
const kept = tokens.filter((token, at) => !(at === 0 && DEV_SUBCOMMANDS.has(token)));
|
|
710
710
|
return kept.join(" ");
|
|
711
711
|
}
|
|
712
|
-
function composeDevScript(existing,
|
|
713
|
-
if (existing === void 0 || existing.trim() === "") return
|
|
712
|
+
function composeDevScript(existing, command2) {
|
|
713
|
+
if (existing === void 0 || existing.trim() === "") return command2;
|
|
714
714
|
const chunks = existing.trim().split(CHAIN);
|
|
715
715
|
const at = chunks.map((chunk) => VITE_TOKEN.test(chunk)).lastIndexOf(true);
|
|
716
716
|
if (at === -1) return existing;
|
|
717
717
|
const rest = (chunks[at] ?? "").replace(/^.*?(^|\s|\/)vite(\s|$)/, "");
|
|
718
718
|
const options = appOptions(rest);
|
|
719
|
-
chunks[at] = options === "" ? `${
|
|
719
|
+
chunks[at] = options === "" ? `${command2} --` : `${command2} -- ${options}`;
|
|
720
720
|
return chunks.join(CHAIN);
|
|
721
721
|
}
|
|
722
722
|
|
|
@@ -732,9 +732,9 @@ function delegatesToScript(target, scriptName) {
|
|
|
732
732
|
if (typeof options !== "object" || options === null || Array.isArray(options)) return false;
|
|
733
733
|
const declared = options;
|
|
734
734
|
if (!Object.keys(declared).every((key) => DELEGATION_OPTION_KEYS.has(key))) return false;
|
|
735
|
-
const
|
|
736
|
-
if (typeof
|
|
737
|
-
return new RegExp(String.raw`(^|\s)run\s+${scriptName}$`).test(
|
|
735
|
+
const command2 = declared["command"];
|
|
736
|
+
if (typeof command2 !== "string") return false;
|
|
737
|
+
return new RegExp(String.raw`(^|\s)run\s+${scriptName}$`).test(command2.trim());
|
|
738
738
|
}
|
|
739
739
|
function devScriptIsAdopted(devScript) {
|
|
740
740
|
return devScript !== void 0 && devScript.includes(SENTINEL_DEV_COMMAND);
|
|
@@ -2310,26 +2310,26 @@ function escapeProperty(text) {
|
|
|
2310
2310
|
return escapeData(text).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
2311
2311
|
}
|
|
2312
2312
|
var GITHUB_ANNOTATION_CAP = 10;
|
|
2313
|
-
function summaryAnnotation(
|
|
2314
|
-
const what =
|
|
2315
|
-
const message = `${count} ${what} (GitHub shows at most ${GITHUB_ANNOTATION_CAP} ${
|
|
2316
|
-
return `::${
|
|
2313
|
+
function summaryAnnotation(command2, count, level) {
|
|
2314
|
+
const what = command2 === "error" ? "blocking findings" : level === "error" ? "advisory findings" : "findings";
|
|
2315
|
+
const message = `${count} ${what} (GitHub shows at most ${GITHUB_ANNOTATION_CAP} ${command2} annotations per step): the full list is in the env report, in this step's log, and in env-report/env.md with --output markdown`;
|
|
2316
|
+
return `::${command2} title=${escapeProperty(`env: ${count} ${what}`)}::${escapeData(message)}`;
|
|
2317
2317
|
}
|
|
2318
2318
|
function renderAnnotations(report) {
|
|
2319
2319
|
if (report.level === "info") return [];
|
|
2320
2320
|
const annotations = report.findings.filter((entry) => entry.severity !== "info").map((entry) => {
|
|
2321
|
-
const
|
|
2321
|
+
const command2 = report.level === "error" && entry.severity === "blocking" ? "error" : "warning";
|
|
2322
2322
|
const properties = [
|
|
2323
2323
|
entry.file === void 0 ? void 0 : `file=${escapeProperty(entry.file)}`,
|
|
2324
2324
|
entry.line === void 0 ? void 0 : `line=${entry.line}`,
|
|
2325
2325
|
`title=${escapeProperty(`env rule ${entry.number}: ${entry.rule}`)}`
|
|
2326
2326
|
].filter(Boolean);
|
|
2327
2327
|
const message = `${entry.name}${entry.detail ? ` (${entry.detail})` : ""}: ${RULES[entry.rule].help}`;
|
|
2328
|
-
return { command, line: `::${
|
|
2328
|
+
return { command: command2, line: `::${command2} ${properties.join(",")}::${escapeData(message)}` };
|
|
2329
2329
|
});
|
|
2330
|
-
const summaries = ["error", "warning"].flatMap((
|
|
2331
|
-
const count = annotations.filter((entry) => entry.command ===
|
|
2332
|
-
return count > GITHUB_ANNOTATION_CAP ? [summaryAnnotation(
|
|
2330
|
+
const summaries = ["error", "warning"].flatMap((command2) => {
|
|
2331
|
+
const count = annotations.filter((entry) => entry.command === command2).length;
|
|
2332
|
+
return count > GITHUB_ANNOTATION_CAP ? [summaryAnnotation(command2, count, report.level)] : [];
|
|
2333
2333
|
});
|
|
2334
2334
|
return [...summaries, ...annotations.map((entry) => entry.line)];
|
|
2335
2335
|
}
|
|
@@ -2698,10 +2698,10 @@ function isPrettierSegment(segment) {
|
|
|
2698
2698
|
return invokes(segment, "prettier");
|
|
2699
2699
|
}
|
|
2700
2700
|
function composeFormatScript(existing, options = {}) {
|
|
2701
|
-
const
|
|
2701
|
+
const command2 = options.command ?? SENTINEL_FORMAT_COMMAND;
|
|
2702
2702
|
const rewritten = composeToolScript(existing, {
|
|
2703
2703
|
replaces: isPrettierSegment,
|
|
2704
|
-
command: options.keepFix === true ? `${
|
|
2704
|
+
command: options.keepFix === true ? `${command2} --fix` : command2,
|
|
2705
2705
|
roleFlag: options.command === void 0 ? void 0 : "--format"
|
|
2706
2706
|
});
|
|
2707
2707
|
return rewritten;
|
|
@@ -2709,13 +2709,13 @@ function composeFormatScript(existing, options = {}) {
|
|
|
2709
2709
|
function invokesFormat(script) {
|
|
2710
2710
|
return /--format\b/.test(script) || isPrettierSegment(script);
|
|
2711
2711
|
}
|
|
2712
|
-
function keepsOtherCommands2(script,
|
|
2713
|
-
return keepsOtherCommands(script,
|
|
2712
|
+
function keepsOtherCommands2(script, command2) {
|
|
2713
|
+
return keepsOtherCommands(script, command2 ?? SENTINEL_FORMAT_COMMAND);
|
|
2714
2714
|
}
|
|
2715
|
-
function writesWhenRewritten(name,
|
|
2715
|
+
function writesWhenRewritten(name, command2) {
|
|
2716
2716
|
if (/[:-](fix|write)$/.test(name)) return true;
|
|
2717
2717
|
if (CHECK_SCRIPT_NAMES.has(name) || /[:-]check$/.test(name)) return false;
|
|
2718
|
-
return /--write\b/.test(
|
|
2718
|
+
return /--write\b/.test(command2);
|
|
2719
2719
|
}
|
|
2720
2720
|
var CHECK_SCRIPT_NAMES = /* @__PURE__ */ new Set(["lint", "format", "check", "test", "typecheck", "verify"]);
|
|
2721
2721
|
|
|
@@ -3242,14 +3242,14 @@ var OxfmtAdapter = class extends BaseAdapter {
|
|
|
3242
3242
|
[FORMAT_SCRIPT_NAME]: compose(existingCommand(cwd, FORMAT_SCRIPT_NAME), false),
|
|
3243
3243
|
[`${FORMAT_SCRIPT_NAME}:fix`]: compose(scripts2[`${FORMAT_SCRIPT_NAME}:fix`], true)
|
|
3244
3244
|
};
|
|
3245
|
-
for (const [name,
|
|
3245
|
+
for (const [name, command2] of Object.entries(scripts2)) {
|
|
3246
3246
|
if (name in rewritten) continue;
|
|
3247
|
-
const needsRewrite = /\bprettier\b/.test(
|
|
3247
|
+
const needsRewrite = /\bprettier\b/.test(command2) || // ...and, for a self-adopting package, a script already running sentinel FOR FORMAT.
|
|
3248
3248
|
// The `--format` check is load-bearing: without it this matched the module's `lint`
|
|
3249
3249
|
// script too and rewrote it into a second format run.
|
|
3250
|
-
ownCommand !== void 0 && /\bsentinel\b/.test(
|
|
3250
|
+
ownCommand !== void 0 && /\bsentinel\b/.test(command2) && /--format\b/.test(command2);
|
|
3251
3251
|
if (!needsRewrite) continue;
|
|
3252
|
-
rewritten[name] = compose(
|
|
3252
|
+
rewritten[name] = compose(command2, writesWhenRewritten(name, command2));
|
|
3253
3253
|
}
|
|
3254
3254
|
return this.joinFormatIntoLint(scripts2, rewritten, ownCommand);
|
|
3255
3255
|
}
|
|
@@ -3274,7 +3274,7 @@ var OxfmtAdapter = class extends BaseAdapter {
|
|
|
3274
3274
|
* The dedicated `format` / `format:fix` scripts stay, for running the formatter alone.
|
|
3275
3275
|
*/
|
|
3276
3276
|
joinFormatIntoLint(original, rewritten, selfCommand2) {
|
|
3277
|
-
const
|
|
3277
|
+
const command2 = selfCommand2 ?? SENTINEL_FORMAT_COMMAND;
|
|
3278
3278
|
for (const [name, keepFix] of [
|
|
3279
3279
|
["lint", false],
|
|
3280
3280
|
["lint:fix", true]
|
|
@@ -3282,7 +3282,7 @@ var OxfmtAdapter = class extends BaseAdapter {
|
|
|
3282
3282
|
const script = rewritten[name] ?? original[name];
|
|
3283
3283
|
if (!script || script.trim() === "") continue;
|
|
3284
3284
|
if (invokesFormat(script)) continue;
|
|
3285
|
-
rewritten[name] = `${script} && ${keepFix ? `${
|
|
3285
|
+
rewritten[name] = `${script} && ${keepFix ? `${command2} --fix` : command2}`;
|
|
3286
3286
|
}
|
|
3287
3287
|
return rewritten;
|
|
3288
3288
|
}
|
|
@@ -3862,14 +3862,14 @@ function lintScripts(cwd) {
|
|
|
3862
3862
|
})
|
|
3863
3863
|
};
|
|
3864
3864
|
const ownCommand = selfCommand(cwd, "--run --lint");
|
|
3865
|
-
for (const [name,
|
|
3865
|
+
for (const [name, command2] of Object.entries(scripts2)) {
|
|
3866
3866
|
if (name === LINT_SCRIPT_NAME) continue;
|
|
3867
|
-
const needsRewrite = /\beslint\b/.test(
|
|
3867
|
+
const needsRewrite = /\beslint\b/.test(command2) || // ...and, for a self-adopting package, a script already running sentinel FOR LINT.
|
|
3868
3868
|
// The `--lint` check is load-bearing: without it this matched the module's `format`
|
|
3869
3869
|
// script too and rewrote it into a second lint run.
|
|
3870
|
-
ownCommand !== void 0 && /\bsentinel\b/.test(
|
|
3870
|
+
ownCommand !== void 0 && /\bsentinel\b/.test(command2) && /--lint\b/.test(command2);
|
|
3871
3871
|
if (!needsRewrite) continue;
|
|
3872
|
-
rewritten[name] = composeLintScript(
|
|
3872
|
+
rewritten[name] = composeLintScript(command2, { keepFix: true, command: ownCommand });
|
|
3873
3873
|
}
|
|
3874
3874
|
return rewritten;
|
|
3875
3875
|
}
|
|
@@ -4463,14 +4463,14 @@ function registerLint() {
|
|
|
4463
4463
|
import { spawnSync as spawnSync7 } from "node:child_process";
|
|
4464
4464
|
import {
|
|
4465
4465
|
cpSync as cpSync2,
|
|
4466
|
-
existsSync as
|
|
4466
|
+
existsSync as existsSync25,
|
|
4467
4467
|
mkdirSync as mkdirSync7,
|
|
4468
4468
|
readdirSync as readdirSync8,
|
|
4469
|
-
readFileSync as
|
|
4469
|
+
readFileSync as readFileSync26,
|
|
4470
4470
|
rmSync as rmSync4,
|
|
4471
4471
|
writeFileSync as writeFileSync8
|
|
4472
4472
|
} from "node:fs";
|
|
4473
|
-
import { join as
|
|
4473
|
+
import { join as join34, relative as relative6, resolve as resolve7, sep as sep2 } from "node:path";
|
|
4474
4474
|
|
|
4475
4475
|
// src/roles/static-analysis/workspace/consumers.ts
|
|
4476
4476
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
@@ -4697,8 +4697,8 @@ function outsideView(index, workspaceRoot, moduleRoot) {
|
|
|
4697
4697
|
}
|
|
4698
4698
|
|
|
4699
4699
|
// src/roles/runtime-analysis/config/checks.ts
|
|
4700
|
-
import { existsSync as
|
|
4701
|
-
import { join as
|
|
4700
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18 } from "node:fs";
|
|
4701
|
+
import { join as join25 } from "node:path";
|
|
4702
4702
|
|
|
4703
4703
|
// src/roles/runtime-analysis/config/framework.ts
|
|
4704
4704
|
import { existsSync as existsSync16, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -4713,9 +4713,69 @@ function framework(dir) {
|
|
|
4713
4713
|
return "unknown";
|
|
4714
4714
|
}
|
|
4715
4715
|
|
|
4716
|
+
// src/roles/runtime-analysis/config/server-side.ts
|
|
4717
|
+
import { existsSync as existsSync17, readFileSync as readFileSync17 } from "node:fs";
|
|
4718
|
+
import { join as join24 } from "node:path";
|
|
4719
|
+
var SERVER_ENV_FILE = join24("runtime-analysis", "server.env");
|
|
4720
|
+
var SESSION_FILE = join24("runtime-analysis", "session.json");
|
|
4721
|
+
function parseEnvFile2(text, file = SERVER_ENV_FILE) {
|
|
4722
|
+
const env = {};
|
|
4723
|
+
for (const [at, raw] of text.split("\n").entries()) {
|
|
4724
|
+
const line = raw.trim();
|
|
4725
|
+
if (line === "" || line.startsWith("#")) continue;
|
|
4726
|
+
const equals = line.indexOf("=");
|
|
4727
|
+
if (equals <= 0) throw new Error(`${file}:${at + 1}: expected KEY=VALUE, found "${line}"`);
|
|
4728
|
+
const key = line.slice(0, equals).trim();
|
|
4729
|
+
const value = line.slice(equals + 1).trim();
|
|
4730
|
+
env[key] = /^(["']).*\1$/.test(value) ? value.slice(1, -1) : value;
|
|
4731
|
+
}
|
|
4732
|
+
return env;
|
|
4733
|
+
}
|
|
4734
|
+
function readServerEnv(moduleDir) {
|
|
4735
|
+
const path2 = join24(moduleDir, SERVER_ENV_FILE);
|
|
4736
|
+
return existsSync17(path2) ? parseEnvFile2(readFileSync17(path2, "utf8")) : {};
|
|
4737
|
+
}
|
|
4738
|
+
function serverEnvFor(env, at) {
|
|
4739
|
+
const host = new URL(at).host;
|
|
4740
|
+
return Object.fromEntries(
|
|
4741
|
+
Object.entries(env).map(([key, value]) => [
|
|
4742
|
+
key,
|
|
4743
|
+
value.replaceAll("{origin}", at).replaceAll("{host}", host)
|
|
4744
|
+
])
|
|
4745
|
+
);
|
|
4746
|
+
}
|
|
4747
|
+
var isText = (value) => typeof value === "string" && value !== "";
|
|
4748
|
+
function readSession(moduleDir) {
|
|
4749
|
+
const path2 = join24(moduleDir, SESSION_FILE);
|
|
4750
|
+
if (!existsSync17(path2)) return void 0;
|
|
4751
|
+
let parsed;
|
|
4752
|
+
try {
|
|
4753
|
+
parsed = JSON.parse(readFileSync17(path2, "utf8"));
|
|
4754
|
+
} catch (error) {
|
|
4755
|
+
throw new Error(`${SESSION_FILE}: ${error instanceof Error ? error.message : String(error)}`, {
|
|
4756
|
+
cause: error
|
|
4757
|
+
});
|
|
4758
|
+
}
|
|
4759
|
+
const session = parsed;
|
|
4760
|
+
const cookies = session?.cookies;
|
|
4761
|
+
if (!Array.isArray(cookies) || cookies.length === 0)
|
|
4762
|
+
throw new Error(`${SESSION_FILE}: "cookies" must list the cookies the browser sends back`);
|
|
4763
|
+
for (const cookie of cookies)
|
|
4764
|
+
if (!isText(cookie?.name) || !isText(cookie?.value))
|
|
4765
|
+
throw new Error(`${SESSION_FILE}: every cookie needs a "name" and a "value"`);
|
|
4766
|
+
const store = session?.store;
|
|
4767
|
+
if (store !== void 0) {
|
|
4768
|
+
if (!isText(store.url) || !store.url.startsWith("redis://"))
|
|
4769
|
+
throw new Error(`${SESSION_FILE}: "store.url" must be a redis://host:port URL`);
|
|
4770
|
+
if (!Array.isArray(store.entries) || store.entries.some((entry) => !isText(entry?.key)))
|
|
4771
|
+
throw new Error(`${SESSION_FILE}: "store.entries" must list { "key", "value" } pairs`);
|
|
4772
|
+
}
|
|
4773
|
+
return { cookies, ...store === void 0 ? {} : { store } };
|
|
4774
|
+
}
|
|
4775
|
+
|
|
4716
4776
|
// src/roles/runtime-analysis/config/checks.ts
|
|
4717
4777
|
var isPath = (value) => typeof value === "string" && value.startsWith("/");
|
|
4718
|
-
var
|
|
4778
|
+
var isText2 = (value) => typeof value === "string" && value.trim() !== "";
|
|
4719
4779
|
var isList = (value) => Array.isArray(value) && value.length > 0;
|
|
4720
4780
|
var under = (path2, prefix) => path2 === prefix || path2.startsWith(`${prefix}/`);
|
|
4721
4781
|
var isEnv = (env) => env !== null && typeof env === "object" && !Array.isArray(env) && Object.values(env).every((value) => typeof value === "string");
|
|
@@ -4747,23 +4807,39 @@ function checkGateway(front, { byBase, byPrefixes, report }) {
|
|
|
4747
4807
|
else if (byBase && isPath(front.basePath) && under(front.ready, front.basePath))
|
|
4748
4808
|
report("ready", `\`${front.ready}\` is under \`basePath\`: it goes to the app, not the mocks`);
|
|
4749
4809
|
}
|
|
4750
|
-
function checkBuild(front, { report }) {
|
|
4751
|
-
if (!
|
|
4752
|
-
if (!
|
|
4753
|
-
|
|
4810
|
+
function checkBuild(front, { moduleDir, report }) {
|
|
4811
|
+
if (!isText2(front.build?.output)) report("build.output", "missing");
|
|
4812
|
+
if (!isText2(front.build?.server)) report("build.server", "missing");
|
|
4813
|
+
let serverEnv = {};
|
|
4814
|
+
try {
|
|
4815
|
+
serverEnv = readServerEnv(moduleDir);
|
|
4816
|
+
} catch (error) {
|
|
4817
|
+
report(SERVER_ENV_FILE, error instanceof Error ? error.message : String(error));
|
|
4818
|
+
}
|
|
4819
|
+
const hasServerEnv = Object.keys(serverEnv).length > 0;
|
|
4820
|
+
if (!isEnv(front.build?.env) || !Object.keys(front.build.env).length && !hasServerEnv)
|
|
4754
4821
|
report("build.env", "the build variables, an object of strings");
|
|
4755
|
-
else if (!Object.values(front.build.env).
|
|
4822
|
+
else if (![...Object.values(front.build.env), ...Object.values(serverEnv)].some(
|
|
4823
|
+
(value) => value.includes("{origin}")
|
|
4824
|
+
))
|
|
4756
4825
|
report(
|
|
4757
4826
|
"build.env",
|
|
4758
|
-
|
|
4827
|
+
`no variable holds \`{origin}\`, here or in ${SERVER_ENV_FILE}: the app would call a real API, not the mocks`
|
|
4759
4828
|
);
|
|
4760
4829
|
}
|
|
4830
|
+
function checkSession(_front, { moduleDir, report }) {
|
|
4831
|
+
try {
|
|
4832
|
+
readSession(moduleDir);
|
|
4833
|
+
} catch (error) {
|
|
4834
|
+
report(SESSION_FILE, error instanceof Error ? error.message : String(error));
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
4761
4837
|
function checkApi(front, { moduleDir, byPrefixes, report }) {
|
|
4762
4838
|
if (!isList(front.api))
|
|
4763
4839
|
return report("api", "the answers of the calls the screens make, a non-empty list");
|
|
4764
4840
|
const goesToApp = (path2) => byPrefixes ? !front.mockPrefixes?.some((prefix) => under(path2, prefix)) : isPath(front.basePath) && under(path2, front.basePath);
|
|
4765
4841
|
for (const [index, entry] of front.api.entries()) {
|
|
4766
|
-
const field = `api[${index}]${
|
|
4842
|
+
const field = `api[${index}]${isText2(entry?.path) ? ` (${entry.path})` : ""}`;
|
|
4767
4843
|
if (entry?.method !== void 0 && !METHODS.includes(entry.method))
|
|
4768
4844
|
report(field, `\`method\`: one of ${METHODS.join(", ")}`);
|
|
4769
4845
|
if (!isPath(entry?.path)) report(field, "`path`: a path starting with `/`");
|
|
@@ -4771,12 +4847,12 @@ function checkApi(front, { moduleDir, byPrefixes, report }) {
|
|
|
4771
4847
|
report(field, "`path` goes to the app, not the mocks: it never answers");
|
|
4772
4848
|
if (entry?.status !== void 0 && !isStatus(entry.status))
|
|
4773
4849
|
report(field, "`status`: an HTTP status (200 when left out)");
|
|
4774
|
-
if (!
|
|
4775
|
-
else if (!
|
|
4850
|
+
if (!isText2(entry?.file)) report(field, "`file` missing");
|
|
4851
|
+
else if (!existsSync18(join25(moduleDir, entry.file)))
|
|
4776
4852
|
report(field, `\`file\`: no ${entry.file} in the module`);
|
|
4777
4853
|
else
|
|
4778
4854
|
try {
|
|
4779
|
-
expand(JSON.parse(
|
|
4855
|
+
expand(JSON.parse(readFileSync18(join25(moduleDir, entry.file), "utf8")));
|
|
4780
4856
|
} catch (failure) {
|
|
4781
4857
|
report(field, `\`file\` ${entry.file}: ${failure.message}`);
|
|
4782
4858
|
}
|
|
@@ -4789,40 +4865,40 @@ function checkApi(front, { moduleDir, byPrefixes, report }) {
|
|
|
4789
4865
|
}
|
|
4790
4866
|
function checkRouter(front, { inModule, report }) {
|
|
4791
4867
|
const { tsconfig, shell, routes } = front.router ?? {};
|
|
4792
|
-
if (!
|
|
4793
|
-
else if (!
|
|
4868
|
+
if (!isText2(tsconfig)) report("router.tsconfig", "missing");
|
|
4869
|
+
else if (!existsSync18(inModule(tsconfig)))
|
|
4794
4870
|
report("router.tsconfig", `no ${tsconfig} in the module`);
|
|
4795
4871
|
if (!isList(shell))
|
|
4796
4872
|
report("router.shell", "the app shell files every screen loads, a non-empty list");
|
|
4797
4873
|
else
|
|
4798
4874
|
for (const file of shell)
|
|
4799
|
-
if (!
|
|
4800
|
-
if (!
|
|
4801
|
-
else if (!
|
|
4875
|
+
if (!existsSync18(inModule(file))) report("router.shell", `no ${file} in the module`);
|
|
4876
|
+
if (!isText2(routes)) report("router.routes", "missing");
|
|
4877
|
+
else if (!existsSync18(inModule(join25(routes, "__root.tsx"))))
|
|
4802
4878
|
report("router.routes", `no __root.tsx in ${routes}: not TanStack Router file routes`);
|
|
4803
4879
|
}
|
|
4804
4880
|
function isAction(action) {
|
|
4805
4881
|
if (!action || typeof action !== "object" || Object.keys(action).length !== 1) return false;
|
|
4806
4882
|
const [[name, arg]] = Object.entries(action);
|
|
4807
|
-
if (name === "click" || name === "clickText") return
|
|
4883
|
+
if (name === "click" || name === "clickText") return isText2(arg);
|
|
4808
4884
|
const typed = arg;
|
|
4809
|
-
return name === "type" &&
|
|
4885
|
+
return name === "type" && isText2(typed?.selector) && typeof typed?.text === "string";
|
|
4810
4886
|
}
|
|
4811
|
-
var isRows = (rows) =>
|
|
4887
|
+
var isRows = (rows) => isText2(rows?.selector) && (Number.isInteger(rows?.count) || Number.isInteger(rows?.min));
|
|
4812
4888
|
function checkScreens(front, { inModule, report }) {
|
|
4813
4889
|
if (!isList(front.screens)) return report("screens", "at least one screen");
|
|
4814
4890
|
const routes = front.router?.routes;
|
|
4815
4891
|
const seen = /* @__PURE__ */ new Set();
|
|
4816
4892
|
for (const [index, screen] of front.screens.entries()) {
|
|
4817
|
-
const field = `screens[${index}]${
|
|
4818
|
-
if (!
|
|
4893
|
+
const field = `screens[${index}]${isText2(screen?.id) ? ` (${screen.id})` : ""}`;
|
|
4894
|
+
if (!isText2(screen?.id)) report(field, "`id` missing");
|
|
4819
4895
|
else if (seen.has(screen.id)) report(field, `\`id\` \`${screen.id}\` is used twice`);
|
|
4820
4896
|
else seen.add(screen.id);
|
|
4821
|
-
if (!
|
|
4822
|
-
else if (
|
|
4897
|
+
if (!isText2(screen?.route)) report(field, "`route` missing");
|
|
4898
|
+
else if (isText2(routes) && !existsSync18(inModule(join25(routes, screen.route))))
|
|
4823
4899
|
report(field, `\`route\`: no ${screen.route} in ${routes}`);
|
|
4824
4900
|
if (!isPath(screen?.path)) report(field, "`path`: a path starting with `/`");
|
|
4825
|
-
if (!isList(screen?.expectText) || !screen.expectText.every(
|
|
4901
|
+
if (!isList(screen?.expectText) || !screen.expectText.every(isText2))
|
|
4826
4902
|
report(field, "`expectText`: a non-empty list of texts the screen shows once opened");
|
|
4827
4903
|
if (!isAction(screen?.interact))
|
|
4828
4904
|
report(
|
|
@@ -4839,20 +4915,20 @@ function validateRuntimeConfig(front, moduleDir) {
|
|
|
4839
4915
|
moduleDir,
|
|
4840
4916
|
byBase: front.basePath !== void 0,
|
|
4841
4917
|
byPrefixes: front.mockPrefixes !== void 0,
|
|
4842
|
-
inModule: (path2) =>
|
|
4918
|
+
inModule: (path2) => join25(moduleDir, path2),
|
|
4843
4919
|
report: (field, message) => errors.push({ field, message })
|
|
4844
4920
|
};
|
|
4845
4921
|
checkIdentity(front, context2);
|
|
4846
4922
|
if (errors.length) return errors;
|
|
4847
|
-
for (const check of [checkGateway, checkBuild, checkApi, checkRouter, checkScreens])
|
|
4923
|
+
for (const check of [checkGateway, checkBuild, checkSession, checkApi, checkRouter, checkScreens])
|
|
4848
4924
|
check(front, context2);
|
|
4849
4925
|
return errors;
|
|
4850
4926
|
}
|
|
4851
4927
|
|
|
4852
4928
|
// src/roles/runtime-analysis/detect/affected.ts
|
|
4853
4929
|
import { spawnSync as spawnSync6 } from "node:child_process";
|
|
4854
|
-
import { existsSync as
|
|
4855
|
-
import { dirname as dirname3, join as
|
|
4930
|
+
import { existsSync as existsSync19, readFileSync as readFileSync19 } from "node:fs";
|
|
4931
|
+
import { dirname as dirname3, join as join26, posix, relative as relative5, resolve as resolve4 } from "node:path";
|
|
4856
4932
|
import ts from "typescript";
|
|
4857
4933
|
var WORKSPACE_INPUTS = /* @__PURE__ */ new Set([
|
|
4858
4934
|
"package.json",
|
|
@@ -4866,14 +4942,14 @@ var WORKSPACE_INPUTS = /* @__PURE__ */ new Set([
|
|
|
4866
4942
|
var NOT_BUILT = /^(\.oxlintrc\.json|\.oxfmtrc\.json|oxlint\/|catalog-info\.yaml|Dockerfile|helm_values\/|nginx\/|README\.md|vitest\.config\.ts|\.gitignore|\.env(\.test)?\.example|scripts\/)/;
|
|
4867
4943
|
var NAMESPACE_LITERAL = /['"`](\w+\.[\w.]+?)['"`:]/g;
|
|
4868
4944
|
function routeChain(routes, route) {
|
|
4869
|
-
const chain = [
|
|
4945
|
+
const chain = [join26(routes, "__root.tsx")];
|
|
4870
4946
|
const segments = dirname3(route).split("/");
|
|
4871
4947
|
for (let depth = 1; depth <= segments.length; depth++) {
|
|
4872
|
-
const dir =
|
|
4873
|
-
for (const layout of [
|
|
4874
|
-
if (
|
|
4948
|
+
const dir = join26(routes, ...segments.slice(0, depth));
|
|
4949
|
+
for (const layout of [join26(dir, "route.tsx"), `${dir}.tsx`])
|
|
4950
|
+
if (existsSync19(layout)) chain.push(layout);
|
|
4875
4951
|
}
|
|
4876
|
-
return [...chain,
|
|
4952
|
+
return [...chain, join26(routes, route)];
|
|
4877
4953
|
}
|
|
4878
4954
|
function shown(workspaceRoot, sha, file) {
|
|
4879
4955
|
const run = spawnSync6("git", ["show", `${sha}:${file}`], {
|
|
@@ -4889,7 +4965,7 @@ function affectedScreens(input) {
|
|
|
4889
4965
|
const namespaceOf = (file) => translations !== void 0 && file.startsWith(translations) ? file.slice(translations.length).match(/^[a-z]+\/(\w+\.[\w.]+)\.json$/)?.[1] ?? null : null;
|
|
4890
4966
|
const readByEveryScreen = (file) => WORKSPACE_INPUTS.has(file) || file.startsWith(`${modulePath}/`) && !file.startsWith(`${modulePath}/src/`) && !NOT_BUILT.test(file.slice(modulePath.length + 1)) || translations !== void 0 && file.startsWith(translations) && !namespaceOf(file);
|
|
4891
4967
|
const parsed = ts.getParsedCommandLineOfConfigFile(
|
|
4892
|
-
|
|
4968
|
+
join26(root, modulePath, config.router.tsconfig),
|
|
4893
4969
|
{},
|
|
4894
4970
|
{
|
|
4895
4971
|
...ts.sys,
|
|
@@ -4914,7 +4990,7 @@ function affectedScreens(input) {
|
|
|
4914
4990
|
const erased = (file) => {
|
|
4915
4991
|
if (!base || !/\.[cm]?tsx?$/.test(file)) return false;
|
|
4916
4992
|
const before = shown(root, base, file);
|
|
4917
|
-
const after = head ? shown(root, head, file) :
|
|
4993
|
+
const after = head ? shown(root, head, file) : existsSync19(join26(root, file)) ? readFileSync19(join26(root, file), "utf8") : null;
|
|
4918
4994
|
return before !== null && after !== null && emitted(file, before) === emitted(file, after);
|
|
4919
4995
|
};
|
|
4920
4996
|
const changed = input.changed.filter((file) => !erased(file));
|
|
@@ -4923,13 +4999,13 @@ function affectedScreens(input) {
|
|
|
4923
4999
|
const namespaces = /* @__PURE__ */ new Set();
|
|
4924
5000
|
const stack = [...entries];
|
|
4925
5001
|
for (const entry of entries)
|
|
4926
|
-
if (!
|
|
5002
|
+
if (!existsSync19(entry)) throw new Error(`no such entry: ${relative5(root, entry)}`);
|
|
4927
5003
|
while (stack.length) {
|
|
4928
5004
|
const file = stack.pop();
|
|
4929
5005
|
if (seen.has(file)) continue;
|
|
4930
5006
|
seen.add(file);
|
|
4931
5007
|
if (!/\.[cm]?[jt]sx?$/.test(file)) continue;
|
|
4932
|
-
let text =
|
|
5008
|
+
let text = readFileSync19(file, "utf8");
|
|
4933
5009
|
for (const [, name] of text.matchAll(NAMESPACE_LITERAL)) namespaces.add(name);
|
|
4934
5010
|
if (/\.[cm]?tsx?$/.test(file) && !file.endsWith(".d.ts"))
|
|
4935
5011
|
text = ts.transpileModule(text, { fileName: file, compilerOptions: transpile }).outputText;
|
|
@@ -4937,14 +5013,14 @@ function affectedScreens(input) {
|
|
|
4937
5013
|
if (fileName.endsWith("routeTree.gen")) continue;
|
|
4938
5014
|
const resolved = ts.resolveModuleName(fileName, file, options, host).resolvedModule;
|
|
4939
5015
|
const target = resolved?.resolvedFileName ?? (fileName.startsWith(".") ? resolve4(dirname3(file), fileName.replace(/\?.*$/, "")) : null);
|
|
4940
|
-
if (target &&
|
|
5016
|
+
if (target && existsSync19(target) && !target.includes("/node_modules/")) stack.push(target);
|
|
4941
5017
|
}
|
|
4942
5018
|
}
|
|
4943
5019
|
return { files: new Set([...seen].map((file) => relative5(root, file))), namespaces };
|
|
4944
5020
|
};
|
|
4945
5021
|
const reaches = (loaded, file) => loaded.files.has(file) || loaded.namespaces.has(namespaceOf(file));
|
|
4946
|
-
const shell = closure(config.router.shell.map((file) =>
|
|
4947
|
-
const routes =
|
|
5022
|
+
const shell = closure(config.router.shell.map((file) => join26(root, modulePath, file)));
|
|
5023
|
+
const routes = join26(root, modulePath, config.router.routes);
|
|
4948
5024
|
const everyScreen = changed.find((file) => readByEveryScreen(file) || reaches(shell, file));
|
|
4949
5025
|
return config.screens.map((screen) => {
|
|
4950
5026
|
if (everyScreen) return { id: screen.id, measured: true, because: everyScreen };
|
|
@@ -5040,7 +5116,7 @@ function detectionMarkdown({
|
|
|
5040
5116
|
}
|
|
5041
5117
|
|
|
5042
5118
|
// src/roles/runtime-analysis/measure/browser.ts
|
|
5043
|
-
import { existsSync as
|
|
5119
|
+
import { existsSync as existsSync20 } from "node:fs";
|
|
5044
5120
|
var BLOCK_THIRD_PARTIES = "--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1";
|
|
5045
5121
|
var DEBUGGING_PORT = 9333;
|
|
5046
5122
|
function findChrome() {
|
|
@@ -5048,7 +5124,7 @@ function findChrome() {
|
|
|
5048
5124
|
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
5049
5125
|
"/usr/bin/google-chrome",
|
|
5050
5126
|
"/usr/bin/google-chrome-stable"
|
|
5051
|
-
].find((candidate) =>
|
|
5127
|
+
].find((candidate) => existsSync20(candidate));
|
|
5052
5128
|
}
|
|
5053
5129
|
async function openBrowser({ chromium, puppeteer }, chromePath, locale) {
|
|
5054
5130
|
const launched = await chromium.launch({
|
|
@@ -5086,33 +5162,33 @@ async function openBrowser({ chromium, puppeteer }, chromePath, locale) {
|
|
|
5086
5162
|
// src/roles/runtime-analysis/measure/measure.ts
|
|
5087
5163
|
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync7 } from "node:fs";
|
|
5088
5164
|
import { freemem, loadavg, totalmem } from "node:os";
|
|
5089
|
-
import { join as
|
|
5165
|
+
import { join as join30, resolve as resolve5 } from "node:path";
|
|
5090
5166
|
|
|
5091
5167
|
// src/roles/runtime-analysis/measure/deps.ts
|
|
5092
5168
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
5093
5169
|
import { createHash } from "node:crypto";
|
|
5094
5170
|
import {
|
|
5095
5171
|
cpSync,
|
|
5096
|
-
existsSync as
|
|
5172
|
+
existsSync as existsSync22,
|
|
5097
5173
|
mkdirSync as mkdirSync3,
|
|
5098
5174
|
readdirSync as readdirSync4,
|
|
5099
|
-
readFileSync as
|
|
5175
|
+
readFileSync as readFileSync21,
|
|
5100
5176
|
renameSync,
|
|
5101
5177
|
rmSync as rmSync3
|
|
5102
5178
|
} from "node:fs";
|
|
5103
5179
|
import { homedir } from "node:os";
|
|
5104
|
-
import { join as
|
|
5180
|
+
import { join as join28 } from "node:path";
|
|
5105
5181
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
5106
5182
|
|
|
5107
5183
|
// src/roles/runtime-analysis/package-root.ts
|
|
5108
|
-
import { existsSync as
|
|
5109
|
-
import { dirname as dirname4, join as
|
|
5184
|
+
import { existsSync as existsSync21, readFileSync as readFileSync20 } from "node:fs";
|
|
5185
|
+
import { dirname as dirname4, join as join27 } from "node:path";
|
|
5110
5186
|
import { fileURLToPath } from "node:url";
|
|
5111
5187
|
function packageRoot() {
|
|
5112
5188
|
let dir = dirname4(fileURLToPath(import.meta.url));
|
|
5113
5189
|
for (; ; ) {
|
|
5114
|
-
const manifest =
|
|
5115
|
-
if (
|
|
5190
|
+
const manifest = join27(dir, "package.json");
|
|
5191
|
+
if (existsSync21(manifest) && JSON.parse(readFileSync20(manifest, "utf8")).name === "@hublo/sentinel")
|
|
5116
5192
|
return dir;
|
|
5117
5193
|
const parent = dirname4(dir);
|
|
5118
5194
|
if (parent === dir) throw new Error("cannot find @hublo/sentinel's own folder");
|
|
@@ -5123,32 +5199,32 @@ function packageRoot() {
|
|
|
5123
5199
|
// src/roles/runtime-analysis/measure/deps.ts
|
|
5124
5200
|
var SHIPPED = ["package.json", "package-lock.json", "load.mjs"];
|
|
5125
5201
|
function shippedDeps() {
|
|
5126
|
-
return
|
|
5202
|
+
return join28(packageRoot(), "runtime-analysis-deps");
|
|
5127
5203
|
}
|
|
5128
5204
|
function depsDir(shipped = shippedDeps()) {
|
|
5129
|
-
const lock =
|
|
5205
|
+
const lock = readFileSync21(join28(shipped, "package-lock.json"));
|
|
5130
5206
|
const key = createHash("sha256").update(lock).digest("hex").slice(0, 12);
|
|
5131
|
-
const cache = process.env.SENTINEL_CACHE_DIR ||
|
|
5132
|
-
return
|
|
5207
|
+
const cache = process.env.SENTINEL_CACHE_DIR || join28(homedir(), ".cache", "sentinel");
|
|
5208
|
+
return join28(cache, "runtime-analysis", key);
|
|
5133
5209
|
}
|
|
5134
5210
|
function installBrowserDeps(say, shipped = shippedDeps()) {
|
|
5135
5211
|
const dir = depsDir(shipped);
|
|
5136
|
-
if (
|
|
5212
|
+
if (existsSync22(dir)) return dir;
|
|
5137
5213
|
const partial = `${dir}.partial-${process.pid}`;
|
|
5138
5214
|
rmSync3(partial, { recursive: true, force: true });
|
|
5139
5215
|
mkdirSync3(partial, { recursive: true });
|
|
5140
|
-
for (const file of SHIPPED) cpSync(
|
|
5216
|
+
for (const file of SHIPPED) cpSync(join28(shipped, file), join28(partial, file));
|
|
5141
5217
|
say(`installing the measure's browser packages once, into ${dir}`);
|
|
5142
5218
|
try {
|
|
5143
5219
|
const args = ["ci", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund"];
|
|
5144
|
-
execFileSync2("npm", [...args, `--logs-dir=${
|
|
5220
|
+
execFileSync2("npm", [...args, `--logs-dir=${join28(partial, ".npm-logs")}`], {
|
|
5145
5221
|
cwd: partial,
|
|
5146
5222
|
stdio: ["ignore", "ignore", "pipe"],
|
|
5147
5223
|
encoding: "utf8"
|
|
5148
5224
|
});
|
|
5149
5225
|
} catch (error) {
|
|
5150
5226
|
const stderr = String(error.stderr ?? error.message);
|
|
5151
|
-
const cause = npmCause(stderr,
|
|
5227
|
+
const cause = npmCause(stderr, join28(partial, ".npm-logs"));
|
|
5152
5228
|
rmSync3(partial, { recursive: true, force: true });
|
|
5153
5229
|
throw new Error(
|
|
5154
5230
|
`could not install the measure's browser packages (lighthouse, puppeteer-core, playwright-core) into ${dir}: ${cause}. They come from the npm registry once per sentinel version; in CI, cache the folder named by SENTINEL_CACHE_DIR.`,
|
|
@@ -5159,24 +5235,24 @@ function installBrowserDeps(say, shipped = shippedDeps()) {
|
|
|
5159
5235
|
renameSync(partial, dir);
|
|
5160
5236
|
} catch (error) {
|
|
5161
5237
|
rmSync3(partial, { recursive: true, force: true });
|
|
5162
|
-
if (!
|
|
5238
|
+
if (!existsSync22(dir)) throw error;
|
|
5163
5239
|
}
|
|
5164
5240
|
return dir;
|
|
5165
5241
|
}
|
|
5166
5242
|
function npmCause(stderr, logsDir) {
|
|
5167
|
-
const logged =
|
|
5243
|
+
const logged = existsSync22(logsDir) ? readdirSync4(logsDir).map((file) => readFileSync21(join28(logsDir, file), "utf8")).join("\n") : "";
|
|
5168
5244
|
const unreachable = logged.match(/http fetch \S+ (\S+) attempt \d+ failed with (\w+)/);
|
|
5169
5245
|
if (unreachable) return `${unreachable[2]} on ${unreachable[1]}`;
|
|
5170
5246
|
return stderr.trim().split("\n").slice(0, 3).join(" ");
|
|
5171
5247
|
}
|
|
5172
5248
|
async function loadBrowserDeps(say) {
|
|
5173
5249
|
const dir = installBrowserDeps(say);
|
|
5174
|
-
return await import(pathToFileURL2(
|
|
5250
|
+
return await import(pathToFileURL2(join28(dir, "load.mjs")).href);
|
|
5175
5251
|
}
|
|
5176
5252
|
|
|
5177
5253
|
// src/roles/runtime-analysis/measure/flow.ts
|
|
5178
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
5179
|
-
import { join as
|
|
5254
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync22, writeFileSync as writeFileSync6 } from "node:fs";
|
|
5255
|
+
import { join as join29 } from "node:path";
|
|
5180
5256
|
|
|
5181
5257
|
// src/roles/runtime-analysis/measure/actions.ts
|
|
5182
5258
|
async function click(page, selector) {
|
|
@@ -5404,8 +5480,19 @@ var METRICS = [
|
|
|
5404
5480
|
"secondLcp",
|
|
5405
5481
|
"secondCls"
|
|
5406
5482
|
];
|
|
5483
|
+
function sessionCookies(cookies, origin2) {
|
|
5484
|
+
const { hostname } = new URL(origin2);
|
|
5485
|
+
return cookies.map(({ name, value }) => ({
|
|
5486
|
+
name,
|
|
5487
|
+
value,
|
|
5488
|
+
domain: hostname,
|
|
5489
|
+
path: "/",
|
|
5490
|
+
httpOnly: true,
|
|
5491
|
+
...name.startsWith("__Secure-") || name.startsWith("__Host-") ? { secure: true } : {}
|
|
5492
|
+
}));
|
|
5493
|
+
}
|
|
5407
5494
|
function readLog(path2, fromMs, toMs) {
|
|
5408
|
-
return
|
|
5495
|
+
return readFileSync22(path2, "utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line)).filter((entry) => {
|
|
5409
5496
|
const at = Date.parse(entry.at);
|
|
5410
5497
|
return at >= fromMs && at <= toMs;
|
|
5411
5498
|
});
|
|
@@ -5421,11 +5508,11 @@ var pickSettings = (lhr) => ({
|
|
|
5421
5508
|
});
|
|
5422
5509
|
function saveLighthouseImages(navigation, dir, name) {
|
|
5423
5510
|
const final = navigation.audits["final-screenshot"]?.details?.data;
|
|
5424
|
-
if (final) saveImage(
|
|
5511
|
+
if (final) saveImage(join29(dir, `${name}-lighthouse-final.jpg`), final);
|
|
5425
5512
|
const frames = navigation.audits["screenshot-thumbnails"]?.details?.items ?? [];
|
|
5426
5513
|
for (const [index, frame] of frames.entries())
|
|
5427
5514
|
saveImage(
|
|
5428
|
-
|
|
5515
|
+
join29(dir, "filmstrip", `${name}-${String(index).padStart(2, "0")}-${frame.timing}ms.jpg`),
|
|
5429
5516
|
frame.data
|
|
5430
5517
|
);
|
|
5431
5518
|
}
|
|
@@ -5446,11 +5533,25 @@ function saveRequests(path2, requests) {
|
|
|
5446
5533
|
);
|
|
5447
5534
|
}
|
|
5448
5535
|
async function runFlow(input) {
|
|
5449
|
-
const {
|
|
5536
|
+
const {
|
|
5537
|
+
browser,
|
|
5538
|
+
startFlow,
|
|
5539
|
+
config,
|
|
5540
|
+
out,
|
|
5541
|
+
front,
|
|
5542
|
+
ready,
|
|
5543
|
+
screen,
|
|
5544
|
+
variant,
|
|
5545
|
+
origin: origin2,
|
|
5546
|
+
logPath,
|
|
5547
|
+
round: round2,
|
|
5548
|
+
cookies
|
|
5549
|
+
} = input;
|
|
5450
5550
|
const name = `${variant}-r${round2}`;
|
|
5451
|
-
const dir =
|
|
5452
|
-
mkdirSync4(
|
|
5551
|
+
const dir = join29(out, "screens", front, screen.id);
|
|
5552
|
+
mkdirSync4(join29(dir, "filmstrip"), { recursive: true });
|
|
5453
5553
|
const context2 = await browser.createBrowserContext();
|
|
5554
|
+
if (cookies.length > 0) await context2.setCookie(...sessionCookies(cookies, origin2));
|
|
5454
5555
|
const page = await context2.newPage();
|
|
5455
5556
|
const pageEvents = [];
|
|
5456
5557
|
page.on("error", (error) => pageEvents.push(`crashed: ${error.message}`));
|
|
@@ -5466,7 +5567,7 @@ async function runFlow(input) {
|
|
|
5466
5567
|
await flow.navigate(`${origin2}${screen.path}`, { name: `${screen.id} navigation` });
|
|
5467
5568
|
const navigatedAt = Date.now();
|
|
5468
5569
|
await proveScreen(page, screen, origin2, proofs);
|
|
5469
|
-
await page.screenshot({ path:
|
|
5570
|
+
await page.screenshot({ path: join29(dir, `${name}-navigation.png`) });
|
|
5470
5571
|
await flow.startTimespan({ name: `${screen.id} interaction` });
|
|
5471
5572
|
await interact(page, screen.interact).then(
|
|
5472
5573
|
() => proofs.pass("interaction", "done"),
|
|
@@ -5474,14 +5575,14 @@ async function runFlow(input) {
|
|
|
5474
5575
|
);
|
|
5475
5576
|
await page.waitForNetworkIdle({ idleTime: 500, timeout: 1e4 }).catch(() => void 0);
|
|
5476
5577
|
await flow.endTimespan();
|
|
5477
|
-
await page.screenshot({ path:
|
|
5578
|
+
await page.screenshot({ path: join29(dir, `${name}-interaction.png`) });
|
|
5478
5579
|
const second = await page.evaluate(
|
|
5479
5580
|
() => window.__second
|
|
5480
5581
|
);
|
|
5481
5582
|
const endedAt = Date.now();
|
|
5482
5583
|
const result = await flow.createFlowResult();
|
|
5483
5584
|
const [navigation, interaction] = result.steps.map((step) => step.lhr);
|
|
5484
|
-
writeFileSync6(
|
|
5585
|
+
writeFileSync6(join29(dir, `${name}.html`), await flow.generateReport());
|
|
5485
5586
|
saveLighthouseImages(navigation, dir, name);
|
|
5486
5587
|
const lcpElement = proveLcpElement(navigation, proofs);
|
|
5487
5588
|
const requests = readLog(logPath, startedAt, endedAt);
|
|
@@ -5490,10 +5591,10 @@ async function runFlow(input) {
|
|
|
5490
5591
|
proveSecondReading(second, observed, proofs);
|
|
5491
5592
|
if (har)
|
|
5492
5593
|
writeFileSync6(
|
|
5493
|
-
|
|
5594
|
+
join29(out, "har", `${variant}-${front}-${screen.id}.har`),
|
|
5494
5595
|
JSON.stringify(har(), null, 1)
|
|
5495
5596
|
);
|
|
5496
|
-
saveRequests(
|
|
5597
|
+
saveRequests(join29(out, "requests", `${front}-${screen.id}-${name}.json`), requests);
|
|
5497
5598
|
if (pageEvents.length) proofs.fail("page", pageEvents.join(", "));
|
|
5498
5599
|
await context2.close();
|
|
5499
5600
|
const audit = (lhr, id) => lhr.audits[id]?.numericValue;
|
|
@@ -5567,7 +5668,7 @@ async function measure(options) {
|
|
|
5567
5668
|
...screen,
|
|
5568
5669
|
key: `${options.front}/${screen.id}`
|
|
5569
5670
|
}));
|
|
5570
|
-
for (const sub of ["screens", "har", "requests"]) mkdirSync5(
|
|
5671
|
+
for (const sub of ["screens", "har", "requests"]) mkdirSync5(join30(out, sub), { recursive: true });
|
|
5571
5672
|
const { browser, version, close } = await openBrowser(deps, options.chromePath, options.locale);
|
|
5572
5673
|
const startedAt = Date.now();
|
|
5573
5674
|
const lateRejections = [];
|
|
@@ -5591,7 +5692,8 @@ async function measure(options) {
|
|
|
5591
5692
|
variant,
|
|
5592
5693
|
origin: side.origin,
|
|
5593
5694
|
logPath: resolve5(side.log),
|
|
5594
|
-
round: round2
|
|
5695
|
+
round: round2,
|
|
5696
|
+
cookies: options.cookies ?? []
|
|
5595
5697
|
};
|
|
5596
5698
|
const before = machineLoad();
|
|
5597
5699
|
const result = await runFlow(flow).catch((error) => crashedFlow(flow, error));
|
|
@@ -5626,7 +5728,7 @@ async function measure(options) {
|
|
|
5626
5728
|
`${result.ok ? "ok " : "FAIL"} ${screen.key} ${variant[0]} r${round2}: LCP ${Math.round(lcp ?? Number.NaN)} ms, CLS ${cls?.toFixed(4)}, INP ${inp ?? "-"} ms, ${result.seconds.flow}s, load ${before.load.toFixed(1)}, free ${before.freeMemoryMb} MB${result.ok ? "" : ` ${failedChecks(result)}`}`
|
|
5627
5729
|
);
|
|
5628
5730
|
}
|
|
5629
|
-
const save = (file, value, indent = 1) => writeFileSync7(
|
|
5731
|
+
const save = (file, value, indent = 1) => writeFileSync7(join30(out, file), JSON.stringify(value, null, indent));
|
|
5630
5732
|
save("runs.json", results);
|
|
5631
5733
|
save("warmup.json", warmups);
|
|
5632
5734
|
save(
|
|
@@ -5728,8 +5830,53 @@ function parsePhase(toolArgs = []) {
|
|
|
5728
5830
|
|
|
5729
5831
|
// src/roles/runtime-analysis/serve/serve.ts
|
|
5730
5832
|
import { spawn } from "node:child_process";
|
|
5731
|
-
import { mkdirSync as mkdirSync6, openSync, readdirSync as readdirSync5, readFileSync as
|
|
5732
|
-
import { join as
|
|
5833
|
+
import { mkdirSync as mkdirSync6, openSync, readdirSync as readdirSync5, readFileSync as readFileSync23 } from "node:fs";
|
|
5834
|
+
import { join as join31, resolve as resolve6 } from "node:path";
|
|
5835
|
+
|
|
5836
|
+
// src/roles/runtime-analysis/serve/session-store.ts
|
|
5837
|
+
import { createConnection } from "node:net";
|
|
5838
|
+
function command(...parts) {
|
|
5839
|
+
return `*${parts.length}\r
|
|
5840
|
+
${parts.map((part) => `$${Buffer.byteLength(part)}\r
|
|
5841
|
+
${part}\r
|
|
5842
|
+
`).join("")}`;
|
|
5843
|
+
}
|
|
5844
|
+
async function seedStore(store, timeoutMs = 5e3) {
|
|
5845
|
+
const url = new URL(store.url);
|
|
5846
|
+
const host = url.hostname || "127.0.0.1";
|
|
5847
|
+
const port = Number(url.port || 6379);
|
|
5848
|
+
const commands = store.entries.map(
|
|
5849
|
+
({ key, value }) => command("SET", key, typeof value === "string" ? value : JSON.stringify(value))
|
|
5850
|
+
);
|
|
5851
|
+
if (commands.length === 0) return;
|
|
5852
|
+
await new Promise((done, fail) => {
|
|
5853
|
+
const socket = createConnection({ host, port });
|
|
5854
|
+
let replies = "";
|
|
5855
|
+
const failWith = (reason) => {
|
|
5856
|
+
socket.destroy();
|
|
5857
|
+
fail(
|
|
5858
|
+
new Error(
|
|
5859
|
+
`could not write the session to ${store.url}: ${reason}. Start the store the front's server reads (in the monorepo, \`pnpm redis:start\`), then run again.`
|
|
5860
|
+
)
|
|
5861
|
+
);
|
|
5862
|
+
};
|
|
5863
|
+
socket.setTimeout(timeoutMs, () => failWith(`no answer in ${timeoutMs} ms`));
|
|
5864
|
+
socket.on("error", (error) => failWith(error.message));
|
|
5865
|
+
socket.on("connect", () => socket.write(commands.join("")));
|
|
5866
|
+
socket.on("data", (chunk) => {
|
|
5867
|
+
replies += chunk.toString("utf8");
|
|
5868
|
+
const lines = replies.split("\r\n").filter(Boolean);
|
|
5869
|
+
const refused = lines.find((line) => line.startsWith("-"));
|
|
5870
|
+
if (refused) return failWith(refused.slice(1));
|
|
5871
|
+
if (lines.length >= commands.length) {
|
|
5872
|
+
socket.end();
|
|
5873
|
+
done();
|
|
5874
|
+
}
|
|
5875
|
+
});
|
|
5876
|
+
});
|
|
5877
|
+
}
|
|
5878
|
+
|
|
5879
|
+
// src/roles/runtime-analysis/serve/serve.ts
|
|
5733
5880
|
var DEFAULT_PORTS = {
|
|
5734
5881
|
mock: 4199,
|
|
5735
5882
|
base: { port: 4101, appPort: 4111 },
|
|
@@ -5745,7 +5892,7 @@ function buildEnv(config, at) {
|
|
|
5745
5892
|
);
|
|
5746
5893
|
}
|
|
5747
5894
|
function shippedScript(name) {
|
|
5748
|
-
return
|
|
5895
|
+
return join31(packageRoot(), "dist", "roles", "runtime-analysis", `${name}.js`);
|
|
5749
5896
|
}
|
|
5750
5897
|
async function waitFor(url) {
|
|
5751
5898
|
for (let attempt = 0; attempt < 120; attempt++) {
|
|
@@ -5758,11 +5905,19 @@ async function waitFor(url) {
|
|
|
5758
5905
|
throw new Error(`${url} never answered`);
|
|
5759
5906
|
}
|
|
5760
5907
|
async function serve(options) {
|
|
5761
|
-
const {
|
|
5908
|
+
const {
|
|
5909
|
+
config,
|
|
5910
|
+
moduleDir,
|
|
5911
|
+
builds,
|
|
5912
|
+
logs,
|
|
5913
|
+
detached = false,
|
|
5914
|
+
ports = DEFAULT_PORTS,
|
|
5915
|
+
stopGraceMs = 5e3
|
|
5916
|
+
} = options;
|
|
5762
5917
|
mkdirSync6(logs, { recursive: true });
|
|
5763
5918
|
const children = [];
|
|
5764
5919
|
const start = (name, args, cwd = process.cwd(), env = {}) => {
|
|
5765
|
-
const log = openSync(
|
|
5920
|
+
const log = openSync(join31(logs, `${name}.log`), "w");
|
|
5766
5921
|
const child = spawn("node", args, {
|
|
5767
5922
|
cwd,
|
|
5768
5923
|
env: { ...process.env, ...env },
|
|
@@ -5770,8 +5925,11 @@ async function serve(options) {
|
|
|
5770
5925
|
detached
|
|
5771
5926
|
});
|
|
5772
5927
|
if (detached) child.unref();
|
|
5773
|
-
children.push(child);
|
|
5928
|
+
children.push({ name, child });
|
|
5774
5929
|
};
|
|
5930
|
+
const session = readSession(moduleDir);
|
|
5931
|
+
if (session?.store !== void 0) await seedStore(session.store);
|
|
5932
|
+
const serverEnv = readServerEnv(moduleDir);
|
|
5775
5933
|
start("mock-api", [
|
|
5776
5934
|
shippedScript("mock-api"),
|
|
5777
5935
|
"--module",
|
|
@@ -5782,6 +5940,8 @@ async function serve(options) {
|
|
|
5782
5940
|
for (const [side, dir] of Object.entries(builds)) {
|
|
5783
5941
|
const { port, appPort } = ports[side];
|
|
5784
5942
|
start(`app-${side}`, [config.build.server], resolve6(dir), {
|
|
5943
|
+
...serverEnvFor(serverEnv, origin(side, ports)),
|
|
5944
|
+
// Last, so a `server.env` cannot move the server off the port its gateway forwards to.
|
|
5785
5945
|
HOST: "127.0.0.1",
|
|
5786
5946
|
PORT: String(appPort)
|
|
5787
5947
|
});
|
|
@@ -5796,11 +5956,19 @@ async function serve(options) {
|
|
|
5796
5956
|
"--mock-port",
|
|
5797
5957
|
String(ports.mock),
|
|
5798
5958
|
"--log",
|
|
5799
|
-
|
|
5959
|
+
join31(logs, `requests-${side}.jsonl`)
|
|
5800
5960
|
]);
|
|
5801
5961
|
}
|
|
5802
5962
|
const stop = () => {
|
|
5803
|
-
for (const child of children) child.kill();
|
|
5963
|
+
for (const { child } of children) child.kill();
|
|
5964
|
+
setTimeout(() => {
|
|
5965
|
+
for (const { name, child } of children) {
|
|
5966
|
+
if (child.exitCode !== null || child.signalCode !== null) continue;
|
|
5967
|
+
process.stderr.write(`${name} did not stop on SIGTERM in ${stopGraceMs} ms: killed
|
|
5968
|
+
`);
|
|
5969
|
+
child.kill("SIGKILL");
|
|
5970
|
+
}
|
|
5971
|
+
}, stopGraceMs).unref();
|
|
5804
5972
|
};
|
|
5805
5973
|
try {
|
|
5806
5974
|
for (const side of Object.keys(builds)) {
|
|
@@ -5811,7 +5979,7 @@ async function serve(options) {
|
|
|
5811
5979
|
stop();
|
|
5812
5980
|
for (const file of readdirSync5(logs).filter((name) => name.endsWith(".log")))
|
|
5813
5981
|
process.stderr.write(`--- ${file}
|
|
5814
|
-
${
|
|
5982
|
+
${readFileSync23(join31(logs, file), "utf8")}
|
|
5815
5983
|
`);
|
|
5816
5984
|
throw error;
|
|
5817
5985
|
}
|
|
@@ -5943,15 +6111,15 @@ function verdictMarkdown(verdict, source, throttling) {
|
|
|
5943
6111
|
}
|
|
5944
6112
|
|
|
5945
6113
|
// src/roles/runtime-analysis/verdict/report.ts
|
|
5946
|
-
import { existsSync as
|
|
5947
|
-
import { join as
|
|
6114
|
+
import { existsSync as existsSync23, readdirSync as readdirSync6, readFileSync as readFileSync24 } from "node:fs";
|
|
6115
|
+
import { join as join32 } from "node:path";
|
|
5948
6116
|
var MARKER = "<!-- sentinel-runtime-analysis -->";
|
|
5949
6117
|
var TITLE = "Frontend Core Web Vitals";
|
|
5950
6118
|
var minutes = (seconds) => `${Math.floor(seconds / 60)}m${String(Math.round(seconds % 60)).padStart(2, "0")}s`;
|
|
5951
6119
|
function readNumber(dir, file) {
|
|
5952
6120
|
if (dir === void 0) return null;
|
|
5953
|
-
const path2 =
|
|
5954
|
-
return
|
|
6121
|
+
const path2 = join32(dir, file);
|
|
6122
|
+
return existsSync23(path2) ? Number(readFileSync24(path2, "utf8")) : null;
|
|
5955
6123
|
}
|
|
5956
6124
|
var folded = (summary2, lines) => lines.length ? [`<details><summary>${summary2}</summary>`, "", ...lines, "", "</details>", ""] : [];
|
|
5957
6125
|
function headline2(input) {
|
|
@@ -6011,10 +6179,10 @@ function proofTable(runs) {
|
|
|
6011
6179
|
return lines;
|
|
6012
6180
|
}
|
|
6013
6181
|
function evidenceOf(evidence) {
|
|
6014
|
-
const dirs =
|
|
6182
|
+
const dirs = existsSync23(evidence) ? readdirSync6(evidence).map((dir) => join32(evidence, dir)) : [];
|
|
6015
6183
|
const settingsOf = (dir) => {
|
|
6016
|
-
const file =
|
|
6017
|
-
const text =
|
|
6184
|
+
const file = join32(dir, "settings.json");
|
|
6185
|
+
const text = existsSync23(file) ? readFileSync24(file, "utf8") : "";
|
|
6018
6186
|
return text ? JSON.parse(text) : null;
|
|
6019
6187
|
};
|
|
6020
6188
|
const builtFronts = [
|
|
@@ -6023,7 +6191,7 @@ function evidenceOf(evidence) {
|
|
|
6023
6191
|
)
|
|
6024
6192
|
];
|
|
6025
6193
|
const buildEvidence = (front) => dirs.find(
|
|
6026
|
-
(dir) => settingsOf(dir)?.front === front &&
|
|
6194
|
+
(dir) => settingsOf(dir)?.front === front && existsSync23(join32(dir, "build-base-seconds"))
|
|
6027
6195
|
);
|
|
6028
6196
|
return { dirs, settingsOf, builtFronts, buildEvidence };
|
|
6029
6197
|
}
|
|
@@ -6208,13 +6376,13 @@ function noticeMarkdown(input) {
|
|
|
6208
6376
|
}
|
|
6209
6377
|
|
|
6210
6378
|
// src/roles/runtime-analysis/verdict/runs.ts
|
|
6211
|
-
import { existsSync as
|
|
6212
|
-
import { join as
|
|
6213
|
-
var read = (file) => JSON.parse(
|
|
6379
|
+
import { existsSync as existsSync24, readdirSync as readdirSync7, readFileSync as readFileSync25, statSync as statSync6 } from "node:fs";
|
|
6380
|
+
import { join as join33 } from "node:path";
|
|
6381
|
+
var read = (file) => JSON.parse(readFileSync25(file, "utf8"));
|
|
6214
6382
|
function readRuns(path2) {
|
|
6215
|
-
if (!
|
|
6383
|
+
if (!existsSync24(path2)) return [];
|
|
6216
6384
|
if (!statSync6(path2).isDirectory()) return read(path2);
|
|
6217
|
-
return readdirSync7(path2).map((dir) =>
|
|
6385
|
+
return readdirSync7(path2).map((dir) => join33(path2, dir, "runs.json")).filter((file) => existsSync24(file)).flatMap(read);
|
|
6218
6386
|
}
|
|
6219
6387
|
|
|
6220
6388
|
// src/roles/runtime-analysis/adapters/lighthouse/runtime-analysis.adapter.ts
|
|
@@ -6258,7 +6426,7 @@ var RuntimeAnalysisAdapter = class extends BaseAdapter {
|
|
|
6258
6426
|
const kind = framework(context2.cwd);
|
|
6259
6427
|
if (kind !== "React")
|
|
6260
6428
|
return { operations: [], skipped: `${kind} is out of scope: React frontends only.` };
|
|
6261
|
-
const hasConfig =
|
|
6429
|
+
const hasConfig = existsSync25(join34(context2.cwd, RUNTIME_CONFIG_FILE));
|
|
6262
6430
|
return {
|
|
6263
6431
|
operations: [
|
|
6264
6432
|
// A re-init never rewrites a front's config: its screens and mocks are its own.
|
|
@@ -6301,7 +6469,7 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6301
6469
|
const parsed = parsePhase(ctx.toolArgs);
|
|
6302
6470
|
if (parsed.phase === "invalid") return this.fail(parsed.reason);
|
|
6303
6471
|
if (parsed.phase === "detect") return this.detect(ctx, parsed.values);
|
|
6304
|
-
if (!
|
|
6472
|
+
if (!existsSync25(join34(ctx.cwd, RUNTIME_CONFIG_FILE))) {
|
|
6305
6473
|
this.say(`not adopted here; \`sentinel --init --runtime-analysis\` sets it up.`);
|
|
6306
6474
|
return { ok: true, code: 0, metrics: { adopted: false } };
|
|
6307
6475
|
}
|
|
@@ -6362,9 +6530,9 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6362
6530
|
front.invalid = true;
|
|
6363
6531
|
detection.invalid = { name: ctx.module, errors: checked.problems };
|
|
6364
6532
|
}
|
|
6365
|
-
const out =
|
|
6533
|
+
const out = join34(ctx.cwd, REPORT_DIR3);
|
|
6366
6534
|
mkdirSync7(out, { recursive: true });
|
|
6367
|
-
writeFileSync8(
|
|
6535
|
+
writeFileSync8(join34(out, "detect.json"), `${JSON.stringify(detection, null, 1)}
|
|
6368
6536
|
`);
|
|
6369
6537
|
const measured = detection.screens.filter((screen) => screen.measured).map((screen) => screen.id);
|
|
6370
6538
|
process.stdout.write(`screens=${measured.join(",")}
|
|
@@ -6379,8 +6547,10 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6379
6547
|
const unknown = wanted.filter((id) => !config.screens.some((screen) => screen.id === id));
|
|
6380
6548
|
if (unknown.length)
|
|
6381
6549
|
return this.fail(`no screen ${unknown.join(", ")} in ${RUNTIME_CONFIG_FILE}`);
|
|
6382
|
-
const out = resolve7(ctx.cwd, String(values.out ??
|
|
6383
|
-
const logs =
|
|
6550
|
+
const out = resolve7(ctx.cwd, String(values.out ?? join34(REPORT_DIR3, "evidence")));
|
|
6551
|
+
const logs = join34(out, "logs");
|
|
6552
|
+
const session = this.session(ctx.cwd);
|
|
6553
|
+
if (typeof session === "string") return this.fail(session);
|
|
6384
6554
|
const served = await serve({
|
|
6385
6555
|
config,
|
|
6386
6556
|
moduleDir: ctx.cwd,
|
|
@@ -6397,21 +6567,33 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6397
6567
|
ready: config.ready,
|
|
6398
6568
|
screens: config.screens.filter((screen) => wanted.includes(screen.id)),
|
|
6399
6569
|
locale: config.locale ?? DEFAULT_LOCALE,
|
|
6400
|
-
base: { origin: origin("base"), log:
|
|
6401
|
-
head: { origin: origin("head"), log:
|
|
6570
|
+
base: { origin: origin("base"), log: join34(logs, "requests-base.jsonl") },
|
|
6571
|
+
head: { origin: origin("head"), log: join34(logs, "requests-head.jsonl") },
|
|
6402
6572
|
runs: Number(values.runs),
|
|
6403
6573
|
out,
|
|
6404
|
-
throttling: values.throttling
|
|
6574
|
+
throttling: values.throttling,
|
|
6575
|
+
cookies: session?.cookies
|
|
6405
6576
|
});
|
|
6406
6577
|
return { ok: result.ok, code: result.ok ? 0 : 1, metrics: { flows: result.runs.length } };
|
|
6407
6578
|
} finally {
|
|
6408
6579
|
served.stop();
|
|
6409
6580
|
}
|
|
6410
6581
|
}
|
|
6582
|
+
/**
|
|
6583
|
+
* The front's `runtime-analysis/session.json`, read before anything is built or served: a file
|
|
6584
|
+
* that is wrong is the reason the run stops, said in its own words (a string), not a crash later.
|
|
6585
|
+
*/
|
|
6586
|
+
session(cwd) {
|
|
6587
|
+
try {
|
|
6588
|
+
return readSession(cwd);
|
|
6589
|
+
} catch (error) {
|
|
6590
|
+
return error instanceof Error ? error.message : String(error);
|
|
6591
|
+
}
|
|
6592
|
+
}
|
|
6411
6593
|
/** Judge every measure job's evidence and write the comment, the verdict and the budget. */
|
|
6412
6594
|
async verdict(ctx, values) {
|
|
6413
6595
|
const detections = values.detect === void 0 ? [] : readDetections(resolve7(ctx.cwd, String(values.detect)));
|
|
6414
|
-
const readJson = (file) => typeof file === "string" &&
|
|
6596
|
+
const readJson = (file) => typeof file === "string" && existsSync25(resolve7(ctx.cwd, file)) ? JSON.parse(readFileSync26(resolve7(ctx.cwd, file), "utf8")) : void 0;
|
|
6415
6597
|
const detect = detectionMarkdown({
|
|
6416
6598
|
fronts: detections.map((detection) => detection.front),
|
|
6417
6599
|
screensOf: Object.fromEntries(
|
|
@@ -6434,7 +6616,7 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6434
6616
|
invalid: detections.some((detection) => detection.invalid),
|
|
6435
6617
|
...runUrl === void 0 ? {} : { runUrl }
|
|
6436
6618
|
});
|
|
6437
|
-
writeFileSync8(
|
|
6619
|
+
writeFileSync8(join34(out, "runtime-analysis.md"), `${pending}
|
|
6438
6620
|
`);
|
|
6439
6621
|
return { ok: true, code: 0, metrics: { pending: true } };
|
|
6440
6622
|
}
|
|
@@ -6471,15 +6653,15 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6471
6653
|
} : {}
|
|
6472
6654
|
};
|
|
6473
6655
|
const comment = reportMarkdown(input);
|
|
6474
|
-
writeFileSync8(
|
|
6656
|
+
writeFileSync8(join34(out, "runtime-analysis.md"), `${comment}
|
|
6475
6657
|
`);
|
|
6476
6658
|
const full = reportMarkdown(input, Number.POSITIVE_INFINITY);
|
|
6477
|
-
if (full !== comment) writeFileSync8(
|
|
6659
|
+
if (full !== comment) writeFileSync8(join34(out, FULL_REPORT), `${full}
|
|
6478
6660
|
`);
|
|
6479
6661
|
const state = typeof values.state === "string" ? values.state : "open";
|
|
6480
6662
|
if (verdict.failed && state !== "open")
|
|
6481
6663
|
writeFileSync8(
|
|
6482
|
-
|
|
6664
|
+
join34(out, "notice.md"),
|
|
6483
6665
|
`${noticeMarkdown({
|
|
6484
6666
|
rows: verdict.rows,
|
|
6485
6667
|
state,
|
|
@@ -6489,8 +6671,8 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6489
6671
|
})}
|
|
6490
6672
|
`
|
|
6491
6673
|
);
|
|
6492
|
-
writeFileSync8(
|
|
6493
|
-
writeFileSync8(
|
|
6674
|
+
writeFileSync8(join34(out, "verdict.json"), JSON.stringify(verdict, null, 2));
|
|
6675
|
+
writeFileSync8(join34(out, "budget.md"), `${budget}
|
|
6494
6676
|
`);
|
|
6495
6677
|
process.stdout.write(`${budget}
|
|
6496
6678
|
`);
|
|
@@ -6507,8 +6689,10 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6507
6689
|
async local(ctx, config, runs, throttling) {
|
|
6508
6690
|
const chromePath = findChrome();
|
|
6509
6691
|
if (!chromePath) return this.fail("no Google Chrome found: set CHROME_PATH");
|
|
6510
|
-
const
|
|
6511
|
-
|
|
6692
|
+
const session = this.session(ctx.cwd);
|
|
6693
|
+
if (typeof session === "string") return this.fail(session);
|
|
6694
|
+
const out = join34(ctx.cwd, REPORT_DIR3);
|
|
6695
|
+
const build = join34(out, "build");
|
|
6512
6696
|
this.say(
|
|
6513
6697
|
`building ${ctx.module} with its runtime-analysis variables (placeholders, no secret)...`
|
|
6514
6698
|
);
|
|
@@ -6519,10 +6703,10 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6519
6703
|
});
|
|
6520
6704
|
if (built.status !== 0) return this.fail(`the build failed (exit ${built.status})`);
|
|
6521
6705
|
rmSync4(out, { recursive: true, force: true });
|
|
6522
|
-
cpSync2(
|
|
6523
|
-
const evidence =
|
|
6524
|
-
const logs =
|
|
6525
|
-
const log =
|
|
6706
|
+
cpSync2(join34(ctx.cwd, config.build.output), build, { recursive: true });
|
|
6707
|
+
const evidence = join34(out, "evidence", ctx.module);
|
|
6708
|
+
const logs = join34(evidence, "logs");
|
|
6709
|
+
const log = join34(logs, "requests-base.jsonl");
|
|
6526
6710
|
const served = await serve({ config, moduleDir: ctx.cwd, builds: { base: build }, logs });
|
|
6527
6711
|
try {
|
|
6528
6712
|
await measure({
|
|
@@ -6535,12 +6719,13 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6535
6719
|
head: { origin: origin("base"), log },
|
|
6536
6720
|
runs: Number(runs),
|
|
6537
6721
|
out: evidence,
|
|
6538
|
-
throttling
|
|
6722
|
+
throttling,
|
|
6723
|
+
cookies: session?.cookies
|
|
6539
6724
|
});
|
|
6540
6725
|
} finally {
|
|
6541
6726
|
served.stop();
|
|
6542
6727
|
}
|
|
6543
|
-
return this.verdict(ctx, { evidence:
|
|
6728
|
+
return this.verdict(ctx, { evidence: join34(out, "evidence"), throttling, out });
|
|
6544
6729
|
}
|
|
6545
6730
|
/**
|
|
6546
6731
|
* `--report`: what a machine reads about this front, WITHOUT measuring. A measure builds, serves
|
|
@@ -6548,7 +6733,7 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6548
6733
|
* whether the front is adopted, and whether its config can be measured.
|
|
6549
6734
|
*/
|
|
6550
6735
|
async report(ctx) {
|
|
6551
|
-
if (!
|
|
6736
|
+
if (!existsSync25(join34(ctx.cwd, RUNTIME_CONFIG_FILE)))
|
|
6552
6737
|
return { ok: true, code: 0, metrics: { adopted: false } };
|
|
6553
6738
|
const checked = await this.configOf(ctx.cwd);
|
|
6554
6739
|
return "config" in checked ? {
|
|
@@ -6565,29 +6750,29 @@ ${problems.map(({ field, message }) => ` - ${field}: ${message}`).join("\n")}`,
|
|
|
6565
6750
|
screens: checked.config.screens.map((screen) => screen.id)
|
|
6566
6751
|
} : {
|
|
6567
6752
|
runner: this.runner,
|
|
6568
|
-
configFile:
|
|
6753
|
+
configFile: existsSync25(join34(ctx.cwd, RUNTIME_CONFIG_FILE)) ? RUNTIME_CONFIG_FILE : null,
|
|
6569
6754
|
unreadable: checked.reason
|
|
6570
6755
|
};
|
|
6571
6756
|
}
|
|
6572
6757
|
/** Adopted is "the front has its config", read from disk: a workspace sweep executes nothing. */
|
|
6573
6758
|
async status(ctx) {
|
|
6574
|
-
const adopted =
|
|
6759
|
+
const adopted = existsSync25(join34(ctx.cwd, RUNTIME_CONFIG_FILE));
|
|
6575
6760
|
return { adopted, preset: adopted ? ctx.preset : null, conformant: adopted, drift: [] };
|
|
6576
6761
|
}
|
|
6577
6762
|
};
|
|
6578
6763
|
function readAffected(file) {
|
|
6579
|
-
if (file === void 0 || !
|
|
6580
|
-
const text =
|
|
6764
|
+
if (file === void 0 || !existsSync25(file)) return [];
|
|
6765
|
+
const text = readFileSync26(file, "utf8").trim();
|
|
6581
6766
|
if (text.startsWith("[")) return JSON.parse(text);
|
|
6582
6767
|
return text.split(/\s+/).filter(Boolean);
|
|
6583
6768
|
}
|
|
6584
6769
|
function readDetections(dir) {
|
|
6585
|
-
if (!
|
|
6770
|
+
if (!existsSync25(dir)) return [];
|
|
6586
6771
|
const files = [
|
|
6587
|
-
|
|
6588
|
-
...readdirSync8(dir).map((entry) =>
|
|
6772
|
+
join34(dir, "detect.json"),
|
|
6773
|
+
...readdirSync8(dir).map((entry) => join34(dir, entry, "detect.json"))
|
|
6589
6774
|
];
|
|
6590
|
-
return files.filter((file) =>
|
|
6775
|
+
return files.filter((file) => existsSync25(file)).map((file) => JSON.parse(readFileSync26(file, "utf8")));
|
|
6591
6776
|
}
|
|
6592
6777
|
|
|
6593
6778
|
// src/roles/runtime-analysis/register.ts
|
|
@@ -6598,8 +6783,8 @@ function registerRuntimeAnalysis() {
|
|
|
6598
6783
|
|
|
6599
6784
|
// src/roles/static-analysis/adapters/jscpd/jscpd.adapter.ts
|
|
6600
6785
|
import { spawnSync as spawnSync8 } from "node:child_process";
|
|
6601
|
-
import { existsSync as
|
|
6602
|
-
import { join as
|
|
6786
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync8, readFileSync as readFileSync31, unlinkSync as unlinkSync2, writeFileSync as writeFileSync11 } from "node:fs";
|
|
6787
|
+
import { join as join43 } from "node:path";
|
|
6603
6788
|
import { globSync as globSync5 } from "tinyglobby";
|
|
6604
6789
|
|
|
6605
6790
|
// src/roles/static-analysis/bundle/budgets.ts
|
|
@@ -6628,32 +6813,32 @@ function bandFor(valueKb, referenceKb) {
|
|
|
6628
6813
|
}
|
|
6629
6814
|
|
|
6630
6815
|
// src/roles/static-analysis/bundle/scan.ts
|
|
6631
|
-
import { existsSync as
|
|
6632
|
-
import { basename, join as
|
|
6816
|
+
import { existsSync as existsSync27, readFileSync as readFileSync28 } from "node:fs";
|
|
6817
|
+
import { basename, join as join36 } from "node:path";
|
|
6633
6818
|
import { pathToFileURL as pathToFileURL3 } from "node:url";
|
|
6634
6819
|
import { gzipSync } from "node:zlib";
|
|
6635
6820
|
import { globSync as globSync2 } from "tinyglobby";
|
|
6636
6821
|
|
|
6637
6822
|
// src/roles/static-analysis/bundle/find-build.ts
|
|
6638
|
-
import { existsSync as
|
|
6639
|
-
import { join as
|
|
6823
|
+
import { existsSync as existsSync26, readFileSync as readFileSync27, statSync as statSync7 } from "node:fs";
|
|
6824
|
+
import { join as join35 } from "node:path";
|
|
6640
6825
|
import { globSync } from "tinyglobby";
|
|
6641
6826
|
var MANIFEST_GLOB = "server/_tanstack-start-manifest*.mjs";
|
|
6642
6827
|
function candidateDirs(cwd) {
|
|
6643
6828
|
const declared = readProjectPackageJson(cwd).nx?.targets?.build?.["outputs"];
|
|
6644
|
-
const fromDeclaration = Array.isArray(declared) ? declared.filter((token) => typeof token === "string").map((token) =>
|
|
6645
|
-
return [...fromDeclaration,
|
|
6829
|
+
const fromDeclaration = Array.isArray(declared) ? declared.filter((token) => typeof token === "string").map((token) => join35(cwd, token.replace(/^\{projectRoot\}\//, ""))) : [];
|
|
6830
|
+
return [...fromDeclaration, join35(cwd, ".output"), join35(cwd, "dist"), join35(cwd, "build")];
|
|
6646
6831
|
}
|
|
6647
6832
|
function findBuildOutput(cwd) {
|
|
6648
6833
|
const lookedIn = [];
|
|
6649
6834
|
for (const dir of candidateDirs(cwd)) {
|
|
6650
6835
|
lookedIn.push(dir);
|
|
6651
|
-
if (!
|
|
6836
|
+
if (!existsSync26(dir)) continue;
|
|
6652
6837
|
const found = globSync(MANIFEST_GLOB, { cwd: dir, absolute: true, dot: false });
|
|
6653
6838
|
if (found.length === 0) continue;
|
|
6654
6839
|
const manifestPath = found[0];
|
|
6655
|
-
const publicDir =
|
|
6656
|
-
if (!
|
|
6840
|
+
const publicDir = join35(dir, "public");
|
|
6841
|
+
if (!existsSync26(publicDir)) continue;
|
|
6657
6842
|
return { manifestPath, publicDir, ...dateOf(dir, manifestPath) };
|
|
6658
6843
|
}
|
|
6659
6844
|
const pkg = readProjectPackageJson(cwd);
|
|
@@ -6675,10 +6860,10 @@ function findBuildOutput(cwd) {
|
|
|
6675
6860
|
};
|
|
6676
6861
|
}
|
|
6677
6862
|
function dateOf(dir, manifestPath) {
|
|
6678
|
-
const record =
|
|
6679
|
-
if (
|
|
6863
|
+
const record = join35(dir, "nitro.json");
|
|
6864
|
+
if (existsSync26(record)) {
|
|
6680
6865
|
try {
|
|
6681
|
-
const parsed = JSON.parse(
|
|
6866
|
+
const parsed = JSON.parse(readFileSync27(record, "utf8"));
|
|
6682
6867
|
if (typeof parsed.date === "string") {
|
|
6683
6868
|
const date = new Date(parsed.date);
|
|
6684
6869
|
if (!Number.isNaN(date.getTime())) return { builtAt: date, builtAtFrom: "build record" };
|
|
@@ -6704,10 +6889,10 @@ function kindOf(path2) {
|
|
|
6704
6889
|
return "other";
|
|
6705
6890
|
}
|
|
6706
6891
|
function resolveAnnounced(publicDir, announced) {
|
|
6707
|
-
const direct =
|
|
6708
|
-
if (
|
|
6709
|
-
const stripped =
|
|
6710
|
-
return
|
|
6892
|
+
const direct = join36(publicDir, announced);
|
|
6893
|
+
if (existsSync27(direct)) return direct;
|
|
6894
|
+
const stripped = join36(publicDir, announced.replace(/^\/[^/]+\//, "/"));
|
|
6895
|
+
return existsSync27(stripped) ? stripped : void 0;
|
|
6711
6896
|
}
|
|
6712
6897
|
function emptyWeight() {
|
|
6713
6898
|
return { transfer: 0, parsed: 0, files: 0 };
|
|
@@ -6743,7 +6928,7 @@ async function scanBundle(cwd) {
|
|
|
6743
6928
|
unresolved.push(announced);
|
|
6744
6929
|
measured.set(announced, void 0);
|
|
6745
6930
|
} else {
|
|
6746
|
-
const buffer =
|
|
6931
|
+
const buffer = readFileSync28(path2);
|
|
6747
6932
|
measured.set(announced, {
|
|
6748
6933
|
parsed: buffer.length,
|
|
6749
6934
|
transfer: gzipSync(buffer, { level: 9 }).length
|
|
@@ -6830,7 +7015,7 @@ function scanDynamicLayer(publicDir, references) {
|
|
|
6830
7015
|
})) {
|
|
6831
7016
|
const name = basename(path2);
|
|
6832
7017
|
if (referenced.has(name)) continue;
|
|
6833
|
-
const buffer =
|
|
7018
|
+
const buffer = readFileSync28(path2);
|
|
6834
7019
|
const size = { parsed: buffer.length, transfer: gzipSync(buffer, { level: 9 }).length };
|
|
6835
7020
|
add(all2, size);
|
|
6836
7021
|
const group = groupOf(name);
|
|
@@ -6858,24 +7043,24 @@ function scanDynamicLayer(publicDir, references) {
|
|
|
6858
7043
|
}
|
|
6859
7044
|
|
|
6860
7045
|
// src/roles/static-analysis/sources.ts
|
|
6861
|
-
import { readFileSync as
|
|
6862
|
-
import { join as
|
|
7046
|
+
import { readFileSync as readFileSync29 } from "node:fs";
|
|
7047
|
+
import { join as join39 } from "node:path";
|
|
6863
7048
|
import { parseSync as parseSync3 } from "oxc-parser";
|
|
6864
7049
|
import { globSync as globSync3 } from "tinyglobby";
|
|
6865
7050
|
|
|
6866
7051
|
// src/roles/static-analysis/adapters/jscpd/tool-config.ts
|
|
6867
|
-
import { existsSync as
|
|
7052
|
+
import { existsSync as existsSync29, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync9 } from "node:fs";
|
|
6868
7053
|
import { tmpdir } from "node:os";
|
|
6869
|
-
import { join as
|
|
7054
|
+
import { join as join38 } from "node:path";
|
|
6870
7055
|
|
|
6871
7056
|
// src/roles/static-analysis/configs/resolve.ts
|
|
6872
|
-
import { existsSync as
|
|
6873
|
-
import { join as
|
|
7057
|
+
import { existsSync as existsSync28 } from "node:fs";
|
|
7058
|
+
import { join as join37 } from "node:path";
|
|
6874
7059
|
import { pathToFileURL as pathToFileURL4 } from "node:url";
|
|
6875
7060
|
var STATIC_CONFIG_FILE = "static-analysis.config.mjs";
|
|
6876
7061
|
async function loadStaticConfig(cwd) {
|
|
6877
|
-
const path2 =
|
|
6878
|
-
if (!
|
|
7062
|
+
const path2 = join37(cwd, STATIC_CONFIG_FILE);
|
|
7063
|
+
if (!existsSync28(path2)) {
|
|
6879
7064
|
return { config: defineStaticAnalysis(), from: null, unreadable: null };
|
|
6880
7065
|
}
|
|
6881
7066
|
try {
|
|
@@ -6921,7 +7106,7 @@ function exclusions(config, scope = "tests") {
|
|
|
6921
7106
|
return [.../* @__PURE__ */ new Set([...config.ignore, ...OWN_ARTEFACTS, ...tests])];
|
|
6922
7107
|
}
|
|
6923
7108
|
function measuredRoots(cwd) {
|
|
6924
|
-
return
|
|
7109
|
+
return existsSync29(join38(cwd, "src")) ? ["src"] : ["."];
|
|
6925
7110
|
}
|
|
6926
7111
|
function fileSettings(config, scope, extraEntries = []) {
|
|
6927
7112
|
return {
|
|
@@ -6951,8 +7136,8 @@ function fileSettings(config, scope, extraEntries = []) {
|
|
|
6951
7136
|
};
|
|
6952
7137
|
}
|
|
6953
7138
|
function duplicationRun(config, paths, scope) {
|
|
6954
|
-
const dir = mkdtempSync(
|
|
6955
|
-
const configPath =
|
|
7139
|
+
const dir = mkdtempSync(join38(tmpdir(), "sentinel-static-"));
|
|
7140
|
+
const configPath = join38(dir, "jscpd.json");
|
|
6956
7141
|
writeFileSync9(configPath, `${JSON.stringify(fileSettings(config, scope), null, 2)}
|
|
6957
7142
|
`, "utf8");
|
|
6958
7143
|
const args = [
|
|
@@ -6978,8 +7163,8 @@ function duplicationRun(config, paths, scope) {
|
|
|
6978
7163
|
return { args, rawReportDir: dir, dispose: () => rmSync5(dir, { force: true, recursive: true }) };
|
|
6979
7164
|
}
|
|
6980
7165
|
function deadCodeRun(config, paths, extraEntries = []) {
|
|
6981
|
-
const dir = mkdtempSync(
|
|
6982
|
-
const configPath =
|
|
7166
|
+
const dir = mkdtempSync(join38(tmpdir(), "sentinel-static-"));
|
|
7167
|
+
const configPath = join38(dir, "jscpd.json");
|
|
6983
7168
|
writeFileSync9(
|
|
6984
7169
|
configPath,
|
|
6985
7170
|
`${JSON.stringify(fileSettings(config, "dead-code", extraEntries), null, 2)}
|
|
@@ -7031,7 +7216,7 @@ function readParsed(cwd, files, passes) {
|
|
|
7031
7216
|
function parsedSource(cwd, path2) {
|
|
7032
7217
|
let text;
|
|
7033
7218
|
try {
|
|
7034
|
-
text =
|
|
7219
|
+
text = readFileSync29(join39(cwd, path2), "utf8");
|
|
7035
7220
|
} catch {
|
|
7036
7221
|
return void 0;
|
|
7037
7222
|
}
|
|
@@ -7218,13 +7403,13 @@ function unreadableNote(coverage) {
|
|
|
7218
7403
|
}
|
|
7219
7404
|
|
|
7220
7405
|
// src/roles/static-analysis/excerpt.ts
|
|
7221
|
-
import { readFileSync as
|
|
7222
|
-
import { join as
|
|
7406
|
+
import { readFileSync as readFileSync30 } from "node:fs";
|
|
7407
|
+
import { join as join41 } from "node:path";
|
|
7223
7408
|
|
|
7224
7409
|
// src/roles/static-analysis/maintainability/size-rules.ts
|
|
7225
7410
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync10 } from "node:fs";
|
|
7226
7411
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
7227
|
-
import { join as
|
|
7412
|
+
import { join as join40 } from "node:path";
|
|
7228
7413
|
var GAUGE_THRESHOLDS = {
|
|
7229
7414
|
// McCabe 1976 says 10, our p90 says 11. The only indicator where two independent candidates agree
|
|
7230
7415
|
// within one unit, and 94.8% of our functions already sit in the 1-10 band SEI calls low risk.
|
|
@@ -7253,7 +7438,7 @@ var GAUGE_THRESHOLDS = {
|
|
|
7253
7438
|
"cognitive-complexity": 7
|
|
7254
7439
|
};
|
|
7255
7440
|
var COGNITIVE = "cognitive-complexity";
|
|
7256
|
-
var cognitivePlugin = () =>
|
|
7441
|
+
var cognitivePlugin = () => join40(ownPackageDir(), "plugins", "sonar-cognitive.js");
|
|
7257
7442
|
var CATEGORIES = [
|
|
7258
7443
|
"correctness",
|
|
7259
7444
|
"suspicious",
|
|
@@ -7285,8 +7470,8 @@ function sizeRulesConfig() {
|
|
|
7285
7470
|
};
|
|
7286
7471
|
}
|
|
7287
7472
|
function sizeRulesRun(paths, ignore) {
|
|
7288
|
-
const dir = mkdtempSync2(
|
|
7289
|
-
const configPath =
|
|
7473
|
+
const dir = mkdtempSync2(join40(tmpdir2(), "sentinel-size-"));
|
|
7474
|
+
const configPath = join40(dir, "oxlintrc.json");
|
|
7290
7475
|
writeFileSync10(configPath, `${JSON.stringify(sizeRulesConfig(), null, 2)}
|
|
7291
7476
|
`, "utf8");
|
|
7292
7477
|
return {
|
|
@@ -8744,7 +8929,7 @@ function linesOf(cache, cwd, relative7) {
|
|
|
8744
8929
|
if (cache.has(relative7)) return cache.get(relative7);
|
|
8745
8930
|
let lines;
|
|
8746
8931
|
try {
|
|
8747
|
-
lines =
|
|
8932
|
+
lines = readFileSync30(join41(cwd, relative7), "utf8").split("\n");
|
|
8748
8933
|
} catch {
|
|
8749
8934
|
lines = void 0;
|
|
8750
8935
|
}
|
|
@@ -8976,7 +9161,7 @@ var SCRIPT2 = `(function(){
|
|
|
8976
9161
|
})();`;
|
|
8977
9162
|
|
|
8978
9163
|
// src/roles/static-analysis/graph/imports.ts
|
|
8979
|
-
import { dirname as dirname5, join as
|
|
9164
|
+
import { dirname as dirname5, join as join42 } from "node:path";
|
|
8980
9165
|
var TS_BEHIND_JS = {
|
|
8981
9166
|
".js": [".ts", ".tsx"],
|
|
8982
9167
|
".mjs": [".mts"],
|
|
@@ -9029,7 +9214,7 @@ function specifiersOf(program) {
|
|
|
9029
9214
|
}
|
|
9030
9215
|
function resolveSpecifier2(from, specifier, known) {
|
|
9031
9216
|
if (!specifier.startsWith(".")) return void 0;
|
|
9032
|
-
const base =
|
|
9217
|
+
const base = join42(dirname5(from), specifier);
|
|
9033
9218
|
if (known.has(base)) return base;
|
|
9034
9219
|
for (const extension of RESOLVABLE_EXTENSIONS) {
|
|
9035
9220
|
if (known.has(base + extension)) return base + extension;
|
|
@@ -9040,7 +9225,7 @@ function resolveSpecifier2(from, specifier, known) {
|
|
|
9040
9225
|
if (known.has(swapped)) return swapped;
|
|
9041
9226
|
}
|
|
9042
9227
|
for (const extension of RESOLVABLE_EXTENSIONS) {
|
|
9043
|
-
const index =
|
|
9228
|
+
const index = join42(base, `index${extension}`);
|
|
9044
9229
|
if (known.has(index)) return index;
|
|
9045
9230
|
}
|
|
9046
9231
|
return void 0;
|
|
@@ -9226,7 +9411,7 @@ var JscpdAdapter = class extends BaseAdapter {
|
|
|
9226
9411
|
operations: [
|
|
9227
9412
|
// `write` and not `merge-json`: this file is code, and the engine's in-place merge is for
|
|
9228
9413
|
// JSON. A re-init therefore RESTORES the stub, so an existing one is left alone below.
|
|
9229
|
-
...
|
|
9414
|
+
...existsSync30(join43(context2.cwd, STATIC_CONFIG_FILE)) ? [] : [{ kind: "write", path: STATIC_CONFIG_FILE, contents: configStub2() }],
|
|
9230
9415
|
manifestOperation(context2.cwd, scripts()),
|
|
9231
9416
|
...nxTargetOperations({ cwd: context2.cwd, targets: targets() })
|
|
9232
9417
|
// The report directory is ignored ONCE at the workspace root, by `--init`'s workspace prep,
|
|
@@ -9476,7 +9661,7 @@ var JscpdAdapter = class extends BaseAdapter {
|
|
|
9476
9661
|
const declared = moduleScripts(ctx.cwd);
|
|
9477
9662
|
const missing = Object.keys(scripts()).filter((name) => !(name in declared));
|
|
9478
9663
|
const adopted = missing.length < Object.keys(scripts()).length;
|
|
9479
|
-
const hasConfig =
|
|
9664
|
+
const hasConfig = existsSync30(join43(ctx.cwd, STATIC_CONFIG_FILE));
|
|
9480
9665
|
return {
|
|
9481
9666
|
adopted,
|
|
9482
9667
|
preset: adopted ? ctx.preset : null,
|
|
@@ -9568,15 +9753,15 @@ function runDeadCode(jscpd, config, paths, cwd, extraEntries = []) {
|
|
|
9568
9753
|
try {
|
|
9569
9754
|
const ran = runTool(jscpd, args, cwd, "dead-code");
|
|
9570
9755
|
if (ran.kind !== "ran") return ran;
|
|
9571
|
-
const path2 =
|
|
9572
|
-
if (!
|
|
9756
|
+
const path2 = join43(rawReportDir, RAW_REPORT["dead-code"]);
|
|
9757
|
+
if (!existsSync30(path2)) {
|
|
9573
9758
|
process.stderr.write(
|
|
9574
9759
|
`sentinel static-analysis(jscpd): the dead-code pass wrote no ${RAW_REPORT["dead-code"]}
|
|
9575
9760
|
`
|
|
9576
9761
|
);
|
|
9577
9762
|
return { kind: "failed", code: 1 };
|
|
9578
9763
|
}
|
|
9579
|
-
const parsed = safeParseDeadCode(
|
|
9764
|
+
const parsed = safeParseDeadCode(readFileSync31(path2, "utf8"));
|
|
9580
9765
|
const statistics = parsed?.statistics;
|
|
9581
9766
|
if (!statistics) {
|
|
9582
9767
|
process.stderr.write(
|
|
@@ -9599,11 +9784,11 @@ function runDeadCode(jscpd, config, paths, cwd, extraEntries = []) {
|
|
|
9599
9784
|
}
|
|
9600
9785
|
}
|
|
9601
9786
|
function moduleRelative(name, roots, cwd) {
|
|
9602
|
-
if (
|
|
9787
|
+
if (existsSync30(join43(cwd, name))) return name;
|
|
9603
9788
|
for (const root of roots) {
|
|
9604
9789
|
if (root === ".") continue;
|
|
9605
9790
|
const candidate = `${root}/${name}`;
|
|
9606
|
-
if (
|
|
9791
|
+
if (existsSync30(join43(cwd, candidate))) return candidate;
|
|
9607
9792
|
}
|
|
9608
9793
|
return name;
|
|
9609
9794
|
}
|
|
@@ -9612,8 +9797,8 @@ function runDuplication(jscpd, config, paths, scope, cwd) {
|
|
|
9612
9797
|
try {
|
|
9613
9798
|
const ran = runTool(jscpd, args, cwd, scope);
|
|
9614
9799
|
if (ran.kind !== "ran") return ran;
|
|
9615
|
-
const path2 =
|
|
9616
|
-
const parsed =
|
|
9800
|
+
const path2 = join43(rawReportDir, RAW_REPORT.duplication);
|
|
9801
|
+
const parsed = existsSync30(path2) ? safeParse(readFileSync31(path2, "utf8")) : void 0;
|
|
9617
9802
|
const total = parsed?.statistics?.total;
|
|
9618
9803
|
if (!total) {
|
|
9619
9804
|
process.stderr.write(
|
|
@@ -9782,8 +9967,8 @@ function outsideOf(cwd) {
|
|
|
9782
9967
|
function moduleRootsOf(workspaceRoot) {
|
|
9783
9968
|
const roots = [];
|
|
9784
9969
|
for (const area of ["apps", "libs"]) {
|
|
9785
|
-
const base =
|
|
9786
|
-
if (!
|
|
9970
|
+
const base = join43(workspaceRoot, area);
|
|
9971
|
+
if (!existsSync30(base)) continue;
|
|
9787
9972
|
for (const entry of globSync5([`${area}/**/package.json`, `${area}/**/project.json`], {
|
|
9788
9973
|
cwd: workspaceRoot,
|
|
9789
9974
|
ignore: ["**/node_modules/**"],
|
|
@@ -10125,8 +10310,8 @@ var PICTURE_FILE = `${TARGET}-graph.svg`;
|
|
|
10125
10310
|
function clearStaleOutputs(cwd, keeping) {
|
|
10126
10311
|
for (const name of [...Object.values(SHAPE_FILE2), PICTURE_FILE]) {
|
|
10127
10312
|
if (keeping.has(name)) continue;
|
|
10128
|
-
const path2 =
|
|
10129
|
-
if (
|
|
10313
|
+
const path2 = join43(cwd, REPORT_DIR, name);
|
|
10314
|
+
if (existsSync30(path2)) unlinkSync2(path2);
|
|
10130
10315
|
}
|
|
10131
10316
|
}
|
|
10132
10317
|
function outputsOf(shapes, graph, coverage) {
|
|
@@ -10144,11 +10329,11 @@ function drawsPicture(graph, coverage) {
|
|
|
10144
10329
|
async function emit(report, shape, cwd, graph, coverage) {
|
|
10145
10330
|
if (shape === "console") return [];
|
|
10146
10331
|
const detailed = shape === "markdown" ? report : withExcerpts(report, cwd);
|
|
10147
|
-
mkdirSync8(
|
|
10332
|
+
mkdirSync8(join43(cwd, REPORT_DIR), { recursive: true });
|
|
10148
10333
|
const written = [];
|
|
10149
10334
|
if (shape === "html" && drawsPicture(graph, coverage)) {
|
|
10150
10335
|
const drawn = layOut(graph.graph, graph.communityOf);
|
|
10151
|
-
const path2 =
|
|
10336
|
+
const path2 = join43(cwd, REPORT_DIR, PICTURE_FILE);
|
|
10152
10337
|
await writeGraphPicture(drawn, path2);
|
|
10153
10338
|
written.push(`${REPORT_DIR}/${PICTURE_FILE}`);
|
|
10154
10339
|
detailed.picture = buildExplorer(drawn, graph.communityOf).markup;
|
|
@@ -10156,7 +10341,7 @@ async function emit(report, shape, cwd, graph, coverage) {
|
|
|
10156
10341
|
const RENDER = { json: renderJson2, html: renderHtml, markdown: renderMarkdown2 };
|
|
10157
10342
|
const name = SHAPE_FILE2[shape] ?? `${TARGET}.${shape}`;
|
|
10158
10343
|
const body = RENDER[shape](detailed);
|
|
10159
|
-
writeFileSync11(
|
|
10344
|
+
writeFileSync11(join43(cwd, REPORT_DIR, name), body, "utf8");
|
|
10160
10345
|
written.unshift(`${REPORT_DIR}/${name}`);
|
|
10161
10346
|
return written;
|
|
10162
10347
|
}
|
|
@@ -10190,9 +10375,9 @@ function registerTest() {
|
|
|
10190
10375
|
|
|
10191
10376
|
// src/roles/typescript/adapters/tsc/tsc.adapter.ts
|
|
10192
10377
|
import { spawnSync as spawnSync9 } from "node:child_process";
|
|
10193
|
-
import { existsSync as
|
|
10378
|
+
import { existsSync as existsSync31, readFileSync as readFileSync33 } from "node:fs";
|
|
10194
10379
|
import { createRequire } from "node:module";
|
|
10195
|
-
import { join as
|
|
10380
|
+
import { join as join45 } from "node:path";
|
|
10196
10381
|
|
|
10197
10382
|
// src/roles/typescript/presets/nest.json
|
|
10198
10383
|
var nest_default = {
|
|
@@ -10377,8 +10562,8 @@ function readTsconfigAdoption(cwd) {
|
|
|
10377
10562
|
}
|
|
10378
10563
|
|
|
10379
10564
|
// src/roles/typescript/adapters/tsc/plan.ts
|
|
10380
|
-
import { readFileSync as
|
|
10381
|
-
import { join as
|
|
10565
|
+
import { readFileSync as readFileSync32 } from "node:fs";
|
|
10566
|
+
import { join as join44 } from "node:path";
|
|
10382
10567
|
|
|
10383
10568
|
// src/roles/typescript/typecheck-script.ts
|
|
10384
10569
|
var SENTINEL_TYPECHECK_COMMAND = "sentinel --run --typescript";
|
|
@@ -10471,7 +10656,7 @@ function planAdoption(context2) {
|
|
|
10471
10656
|
};
|
|
10472
10657
|
}
|
|
10473
10658
|
const existing = parseJsonc(
|
|
10474
|
-
|
|
10659
|
+
readFileSync32(join44(context2.cwd, target.path), "utf8"),
|
|
10475
10660
|
target.path
|
|
10476
10661
|
);
|
|
10477
10662
|
const extendsChain = composeExtends(existing.extends, preset);
|
|
@@ -10609,7 +10794,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
10609
10794
|
let chain;
|
|
10610
10795
|
try {
|
|
10611
10796
|
const parsed = parseJsonc(
|
|
10612
|
-
|
|
10797
|
+
readFileSync33(join45(cwd, target.path), "utf8"),
|
|
10613
10798
|
target.path
|
|
10614
10799
|
);
|
|
10615
10800
|
chain = parsed.extends;
|
|
@@ -10622,7 +10807,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
10622
10807
|
);
|
|
10623
10808
|
if (preset === void 0) return void 0;
|
|
10624
10809
|
try {
|
|
10625
|
-
createRequire(
|
|
10810
|
+
createRequire(join45(cwd, "noop.js")).resolve(preset);
|
|
10626
10811
|
return void 0;
|
|
10627
10812
|
} catch {
|
|
10628
10813
|
return preset;
|
|
@@ -10718,7 +10903,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
10718
10903
|
referencedProjects(cwd, config) {
|
|
10719
10904
|
try {
|
|
10720
10905
|
const parsed = parseJsonc(
|
|
10721
|
-
|
|
10906
|
+
readFileSync33(join45(cwd, config), "utf8"),
|
|
10722
10907
|
config
|
|
10723
10908
|
);
|
|
10724
10909
|
const referenced = (parsed.references ?? []).map((reference) => reference.path).filter((path2) => typeof path2 === "string" && path2.length > 0);
|
|
@@ -10734,7 +10919,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
10734
10919
|
* check.
|
|
10735
10920
|
*/
|
|
10736
10921
|
typecheckTarget(cwd) {
|
|
10737
|
-
if (
|
|
10922
|
+
if (existsSync31(join45(cwd, "tsconfig.json"))) return "tsconfig.json";
|
|
10738
10923
|
const target = resolveTsconfigTarget(cwd);
|
|
10739
10924
|
return target.reason === "none" ? null : target.path;
|
|
10740
10925
|
}
|
|
@@ -10942,7 +11127,7 @@ function replaceLines(current, replacements) {
|
|
|
10942
11127
|
}
|
|
10943
11128
|
|
|
10944
11129
|
// src/core/apply-plan.ts
|
|
10945
|
-
import { existsSync as
|
|
11130
|
+
import { existsSync as existsSync32, readFileSync as readFileSync34, renameSync as renameSync2, rmSync as rmSync7, writeFileSync as writeFileSync12 } from "node:fs";
|
|
10946
11131
|
import { resolve as resolve8, sep as sep3 } from "node:path";
|
|
10947
11132
|
import { applyEdits, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
|
|
10948
11133
|
function resolveWithinRoot(cwd, relativePath) {
|
|
@@ -10954,7 +11139,7 @@ function resolveWithinRoot(cwd, relativePath) {
|
|
|
10954
11139
|
return absolutePath;
|
|
10955
11140
|
}
|
|
10956
11141
|
function readIfExists(absolutePath) {
|
|
10957
|
-
return
|
|
11142
|
+
return existsSync32(absolutePath) ? readFileSync34(absolutePath, "utf8") : void 0;
|
|
10958
11143
|
}
|
|
10959
11144
|
function* leaves(value, prefix = []) {
|
|
10960
11145
|
for (const [key, keyValue] of Object.entries(value)) {
|
|
@@ -11072,8 +11257,8 @@ function applyPlan(cwd, plan3) {
|
|
|
11072
11257
|
}
|
|
11073
11258
|
|
|
11074
11259
|
// src/core/config/preset-evidence.ts
|
|
11075
|
-
import { existsSync as
|
|
11076
|
-
import { join as
|
|
11260
|
+
import { existsSync as existsSync33, readdirSync as readdirSync9, readFileSync as readFileSync35 } from "node:fs";
|
|
11261
|
+
import { join as join46 } from "node:path";
|
|
11077
11262
|
var PATH_SIGNALS = [
|
|
11078
11263
|
{
|
|
11079
11264
|
preset: "nest",
|
|
@@ -11107,12 +11292,12 @@ function sourceImports(cwd, pattern) {
|
|
|
11107
11292
|
}
|
|
11108
11293
|
for (const entry of entries) {
|
|
11109
11294
|
if (entry.isDirectory()) {
|
|
11110
|
-
if (!NOT_SCANNED.has(entry.name)) stack.push(
|
|
11295
|
+
if (!NOT_SCANNED.has(entry.name)) stack.push(join46(dir, entry.name));
|
|
11111
11296
|
continue;
|
|
11112
11297
|
}
|
|
11113
11298
|
if (!SOURCE_FILE.test(entry.name)) continue;
|
|
11114
11299
|
try {
|
|
11115
|
-
if (pattern.test(
|
|
11300
|
+
if (pattern.test(readFileSync35(join46(dir, entry.name), "utf8"))) return true;
|
|
11116
11301
|
} catch {
|
|
11117
11302
|
continue;
|
|
11118
11303
|
}
|
|
@@ -11121,11 +11306,11 @@ function sourceImports(cwd, pattern) {
|
|
|
11121
11306
|
return false;
|
|
11122
11307
|
}
|
|
11123
11308
|
function dependencyNames(cwd) {
|
|
11124
|
-
const path2 =
|
|
11125
|
-
if (!
|
|
11309
|
+
const path2 = join46(cwd, "package.json");
|
|
11310
|
+
if (!existsSync33(path2)) return [];
|
|
11126
11311
|
try {
|
|
11127
11312
|
const manifest = parseJsonc(
|
|
11128
|
-
|
|
11313
|
+
readFileSync35(path2, "utf8"),
|
|
11129
11314
|
path2
|
|
11130
11315
|
);
|
|
11131
11316
|
return [
|
|
@@ -11148,7 +11333,7 @@ function reactTsconfigEvidence(cwd) {
|
|
|
11148
11333
|
}
|
|
11149
11334
|
for (const name of entries) {
|
|
11150
11335
|
try {
|
|
11151
|
-
const config = parseJsonc(
|
|
11336
|
+
const config = parseJsonc(readFileSync35(join46(cwd, name), "utf8"), name);
|
|
11152
11337
|
if (config.compilerOptions?.jsx !== void 0) return 'its tsconfig sets "jsx"';
|
|
11153
11338
|
const extended = Array.isArray(config.extends) ? config.extends : config.extends === void 0 ? [] : [config.extends];
|
|
11154
11339
|
if (extended.some((entry) => entry === REACT_TYPESCRIPT_PRESET)) {
|