@hublo/sentinel 1.7.0-alpha.32 → 1.7.0-alpha.34
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 +2 -2
- package/dist/{chunk-SHF46ALB.js → chunk-53HYHJTD.js} +3 -2
- package/dist/chunk-53HYHJTD.js.map +1 -0
- package/dist/{chunk-UJ5VLEZF.js → chunk-Z2QRW7T4.js} +404 -127
- package/dist/index.js +2 -2
- package/dist/roles/sql/config.d.ts +10 -0
- package/dist/roles/sql/config.js +1 -1
- package/docs/sql-adoption.md +58 -19
- package/package.json +1 -1
- package/dist/chunk-SHF46ALB.js.map +0 -1
|
@@ -135,7 +135,7 @@ import {
|
|
|
135
135
|
defaults as defaults3,
|
|
136
136
|
defineSql,
|
|
137
137
|
squawkRules
|
|
138
|
-
} from "./chunk-
|
|
138
|
+
} from "./chunk-53HYHJTD.js";
|
|
139
139
|
import {
|
|
140
140
|
CODE_CHURN_CONFIG_FILE,
|
|
141
141
|
REPORT_DIR as REPORT_DIR2,
|
|
@@ -11233,8 +11233,8 @@ function registerLint() {
|
|
|
11233
11233
|
|
|
11234
11234
|
// src/roles/sql/adapters/squawk/squawk.adapter.ts
|
|
11235
11235
|
import { spawnSync as spawnSync13 } from "node:child_process";
|
|
11236
|
-
import { existsSync as existsSync29, readFileSync as
|
|
11237
|
-
import { join as
|
|
11236
|
+
import { existsSync as existsSync29, readFileSync as readFileSync25 } from "node:fs";
|
|
11237
|
+
import { join as join47 } from "node:path";
|
|
11238
11238
|
|
|
11239
11239
|
// src/roles/sql/configs/resolve.ts
|
|
11240
11240
|
import { existsSync as existsSync26 } from "node:fs";
|
|
@@ -12007,10 +12007,10 @@ function callShape(node, imports) {
|
|
|
12007
12007
|
const object = alias(target) === void 0 ? unwrap(target.object) : void 0;
|
|
12008
12008
|
if (name === "call") return { name: method, object, args: args.slice(1), callee: target };
|
|
12009
12009
|
const list = args[1] === void 0 ? void 0 : unwrap(args[1]);
|
|
12010
|
-
const
|
|
12010
|
+
const applied2 = list === void 0 ? [] : list.type === "ArrayExpression" ? list.elements.filter(
|
|
12011
12011
|
(item) => item !== null
|
|
12012
12012
|
) : [{ type: "SpreadElement", argument: list, start: list.start, end: list.end }];
|
|
12013
|
-
return { name: method, object, args:
|
|
12013
|
+
return { name: method, object, args: applied2, callee: target };
|
|
12014
12014
|
}
|
|
12015
12015
|
return { name, object: unwrap(callee.object), args, callee };
|
|
12016
12016
|
}
|
|
@@ -12227,11 +12227,11 @@ function exportedConst(file, name) {
|
|
|
12227
12227
|
return void 0;
|
|
12228
12228
|
}
|
|
12229
12229
|
function isPlaceholderList(call, context2) {
|
|
12230
|
-
const
|
|
12231
|
-
if (!MEMBER_TYPES.has(
|
|
12230
|
+
const join56 = unwrap(call.callee);
|
|
12231
|
+
if (!MEMBER_TYPES.has(join56.type) || join56.property.name !== "join") return false;
|
|
12232
12232
|
const separator = call.arguments[0];
|
|
12233
12233
|
if (separator !== void 0 && !isSafe(separator, context2)) return false;
|
|
12234
|
-
const map = unwrap(
|
|
12234
|
+
const map = unwrap(join56.object);
|
|
12235
12235
|
if (map.type !== "CallExpression") return false;
|
|
12236
12236
|
const mapCallee = unwrap(map.callee);
|
|
12237
12237
|
if (!MEMBER_TYPES.has(mapCallee.type) || mapCallee.property.name !== "map")
|
|
@@ -12450,7 +12450,11 @@ function readTemplate(template) {
|
|
|
12450
12450
|
if (parsed2.ok) {
|
|
12451
12451
|
return {
|
|
12452
12452
|
kind: "read",
|
|
12453
|
-
reading: readingOf(
|
|
12453
|
+
reading: readingOf(
|
|
12454
|
+
parsed2.statements,
|
|
12455
|
+
{ wrap, before, fill: fillName, values: template.values },
|
|
12456
|
+
text
|
|
12457
|
+
)
|
|
12454
12458
|
};
|
|
12455
12459
|
}
|
|
12456
12460
|
firstError ??= parsed2.message;
|
|
@@ -12458,7 +12462,12 @@ function readTemplate(template) {
|
|
|
12458
12462
|
}
|
|
12459
12463
|
return { kind: "unread", reason: `PostgreSQL's parser does not read it alone (${firstError})` };
|
|
12460
12464
|
}
|
|
12461
|
-
function readingOf(statements, {
|
|
12465
|
+
function readingOf(statements, {
|
|
12466
|
+
wrap,
|
|
12467
|
+
before,
|
|
12468
|
+
fill,
|
|
12469
|
+
values
|
|
12470
|
+
}, text) {
|
|
12462
12471
|
const wrapped = `${before}${text.sql}`;
|
|
12463
12472
|
const indexIn = (location) => indexOfByte(wrapped, location) - before.length;
|
|
12464
12473
|
return {
|
|
@@ -12469,20 +12478,69 @@ function readingOf(statements, { wrap, before, fill }, text) {
|
|
|
12469
12478
|
const index = indexIn(location);
|
|
12470
12479
|
return index >= 0 && index < text.sql.length;
|
|
12471
12480
|
},
|
|
12472
|
-
fileOffset: (location) => fileOffsetOf(text, indexIn(location))
|
|
12481
|
+
fileOffset: (location) => fileOffsetOf(text, indexIn(location)),
|
|
12482
|
+
valueStart: (n) => fill === "value" ? values[n - 1] : void 0
|
|
12473
12483
|
};
|
|
12474
12484
|
}
|
|
12475
12485
|
|
|
12486
|
+
// src/roles/sql/raw/template-rule.ts
|
|
12487
|
+
var NO_CONTEXT = { trigramIndexes: () => [], indexesFrom: [] };
|
|
12488
|
+
|
|
12489
|
+
// src/roles/sql/raw/value-starts.ts
|
|
12490
|
+
var MAX_DEPTH2 = 8;
|
|
12491
|
+
function valueStart(node, bindings, depth = 0) {
|
|
12492
|
+
if (depth > MAX_DEPTH2) return void 0;
|
|
12493
|
+
const current = unwrap(node);
|
|
12494
|
+
const deeper = (next) => valueStart(next, bindings, depth + 1);
|
|
12495
|
+
switch (current.type) {
|
|
12496
|
+
case "Literal":
|
|
12497
|
+
return typeof current.value === "string" ? current.value : void 0;
|
|
12498
|
+
case "TemplateLiteral":
|
|
12499
|
+
return templateStart(current, deeper);
|
|
12500
|
+
case "BinaryExpression":
|
|
12501
|
+
return current.operator === "+" ? sumStart(current, deeper) : void 0;
|
|
12502
|
+
case "Identifier":
|
|
12503
|
+
return nameStart(current.name, bindings, deeper);
|
|
12504
|
+
default:
|
|
12505
|
+
return void 0;
|
|
12506
|
+
}
|
|
12507
|
+
}
|
|
12508
|
+
function templateStart(node, deeper) {
|
|
12509
|
+
const [first] = node.quasis;
|
|
12510
|
+
const value = first?.value;
|
|
12511
|
+
const text = value?.cooked ?? value?.raw;
|
|
12512
|
+
if (text === void 0) return void 0;
|
|
12513
|
+
const [expression] = node.expressions;
|
|
12514
|
+
if (text !== "" || expression === void 0) return text;
|
|
12515
|
+
return deeper(expression);
|
|
12516
|
+
}
|
|
12517
|
+
function sumStart(node, deeper) {
|
|
12518
|
+
const left = deeper(node.left);
|
|
12519
|
+
if (left !== "") return left;
|
|
12520
|
+
return deeper(node.right);
|
|
12521
|
+
}
|
|
12522
|
+
function nameStart(name, bindings, deeper) {
|
|
12523
|
+
const found = bindings.get(name) ?? [];
|
|
12524
|
+
const [binding] = found;
|
|
12525
|
+
if (found.length !== 1 || binding?.kind !== "const") return void 0;
|
|
12526
|
+
return deeper(binding.init);
|
|
12527
|
+
}
|
|
12528
|
+
|
|
12476
12529
|
// src/roles/sql/raw/templates.ts
|
|
12477
12530
|
function sqlTemplatesOf(program, prisma, fileText) {
|
|
12478
12531
|
const templates = [];
|
|
12532
|
+
let bindings;
|
|
12479
12533
|
walk(program, (node) => {
|
|
12480
12534
|
if (node.type !== "TaggedTemplateExpression") return;
|
|
12481
12535
|
const tag = tagOf(node.tag, prisma);
|
|
12482
12536
|
if (tag === void 0) return;
|
|
12483
12537
|
const quasis = node.quasi.quasis;
|
|
12484
12538
|
const parts = quasis.map((element) => partOf(element, fileText));
|
|
12485
|
-
|
|
12539
|
+
bindings ??= bindingsOf(program);
|
|
12540
|
+
const known = bindings;
|
|
12541
|
+
const expressions = node.quasi.expressions;
|
|
12542
|
+
const values = expressions.map((expression) => valueStart(expression, known));
|
|
12543
|
+
templates.push({ tag, parts, values, start: node.start });
|
|
12486
12544
|
});
|
|
12487
12545
|
return templates;
|
|
12488
12546
|
}
|
|
@@ -12504,7 +12562,7 @@ function partOf(element, fileText) {
|
|
|
12504
12562
|
}
|
|
12505
12563
|
|
|
12506
12564
|
// src/roles/sql/raw/check-templates.ts
|
|
12507
|
-
async function checkSqlTemplates(cwd, files, readFile, rules) {
|
|
12565
|
+
async function checkSqlTemplates(cwd, files, readFile, rules, context2 = NO_CONTEXT) {
|
|
12508
12566
|
const run = { templates: 0, read: 0, unread: [], unparsed: [], findings: [] };
|
|
12509
12567
|
if (files.length === 0) return run;
|
|
12510
12568
|
const loaded2 = await parserLoaded();
|
|
@@ -12518,7 +12576,7 @@ async function checkSqlTemplates(cwd, files, readFile, rules) {
|
|
|
12518
12576
|
run.unparsed.push({ file, reason: "could not be read, so its SQL templates are not read" });
|
|
12519
12577
|
continue;
|
|
12520
12578
|
}
|
|
12521
|
-
checkFile({ file, text, rules }, run);
|
|
12579
|
+
checkFile({ file, text, rules, context: context2 }, run);
|
|
12522
12580
|
}
|
|
12523
12581
|
return run;
|
|
12524
12582
|
}
|
|
@@ -12577,7 +12635,7 @@ function checkTemplate(input, template, run) {
|
|
|
12577
12635
|
function checkRule(input, rule, reading, run) {
|
|
12578
12636
|
let hits;
|
|
12579
12637
|
try {
|
|
12580
|
-
hits = rule.check(reading);
|
|
12638
|
+
hits = rule.check(reading, input.context);
|
|
12581
12639
|
} catch {
|
|
12582
12640
|
return;
|
|
12583
12641
|
}
|
|
@@ -12655,6 +12713,62 @@ function firstLocation(node) {
|
|
|
12655
12713
|
function wholeStatement(reading) {
|
|
12656
12714
|
return reading.wrap === "statement" && reading.fill === "value";
|
|
12657
12715
|
}
|
|
12716
|
+
function expressionKey(node) {
|
|
12717
|
+
const column = bodyOf(node, "ColumnRef");
|
|
12718
|
+
if (column) {
|
|
12719
|
+
const name = columnNames(column).at(-1);
|
|
12720
|
+
return name === void 0 || name === "*" || name === "" ? void 0 : name;
|
|
12721
|
+
}
|
|
12722
|
+
const call = bodyOf(node, "FuncCall");
|
|
12723
|
+
if (call) return callKey(call);
|
|
12724
|
+
const cast = bodyOf(node, "TypeCast");
|
|
12725
|
+
if (cast) {
|
|
12726
|
+
const inner = expressionKey(cast.arg);
|
|
12727
|
+
const names = cast.typeName?.names ?? [];
|
|
12728
|
+
const type = bodyOf(names.at(-1), "String")?.sval;
|
|
12729
|
+
return inner === void 0 || typeof type !== "string" ? void 0 : `${inner}::${type}`;
|
|
12730
|
+
}
|
|
12731
|
+
const constant = bodyOf(node, "A_Const");
|
|
12732
|
+
if (constant) return constantKey(constant);
|
|
12733
|
+
const operation = bodyOf(node, "A_Expr");
|
|
12734
|
+
if (operation?.kind === "AEXPR_OP") {
|
|
12735
|
+
const operator = bodyOf(operation.name?.at(-1), "String")?.sval;
|
|
12736
|
+
const left = expressionKey(operation.lexpr);
|
|
12737
|
+
const right = expressionKey(operation.rexpr);
|
|
12738
|
+
if (typeof operator !== "string" || left === void 0 || right === void 0) return void 0;
|
|
12739
|
+
return `${left} ${operator} ${right}`;
|
|
12740
|
+
}
|
|
12741
|
+
return void 0;
|
|
12742
|
+
}
|
|
12743
|
+
function callKey(call) {
|
|
12744
|
+
const name = bodyOf(call.funcname?.at(-1), "String")?.sval;
|
|
12745
|
+
if (typeof name !== "string") return void 0;
|
|
12746
|
+
const args = (call.args ?? []).map(expressionKey);
|
|
12747
|
+
if (args.some((arg) => arg === void 0)) return void 0;
|
|
12748
|
+
return `${name}(${args.join(", ")})`;
|
|
12749
|
+
}
|
|
12750
|
+
function constantKey(constant) {
|
|
12751
|
+
if (constant.isnull === true) return "null";
|
|
12752
|
+
const text = bodyOf(constant, "sval")?.sval;
|
|
12753
|
+
if (typeof text === "string") return `'${text}'`;
|
|
12754
|
+
for (const [kind, zero] of [
|
|
12755
|
+
["ival", "0"],
|
|
12756
|
+
["fval", "0"],
|
|
12757
|
+
["boolval", "false"]
|
|
12758
|
+
]) {
|
|
12759
|
+
const body = bodyOf(constant, kind);
|
|
12760
|
+
if (body) return body[kind] === void 0 ? zero : String(body[kind]);
|
|
12761
|
+
}
|
|
12762
|
+
return void 0;
|
|
12763
|
+
}
|
|
12764
|
+
function qualifiersUnder(node) {
|
|
12765
|
+
const qualifiers = /* @__PURE__ */ new Set();
|
|
12766
|
+
for (const names of columnsUnder(node)) {
|
|
12767
|
+
const qualifier = names.at(-2);
|
|
12768
|
+
if (qualifier !== void 0) qualifiers.add(qualifier);
|
|
12769
|
+
}
|
|
12770
|
+
return qualifiers;
|
|
12771
|
+
}
|
|
12658
12772
|
|
|
12659
12773
|
// src/roles/sql/raw/rules/exists-union-correlated-outside.ts
|
|
12660
12774
|
var existsUnionCorrelatedOutside = {
|
|
@@ -12738,37 +12852,104 @@ function unlistedInsert(statement) {
|
|
|
12738
12852
|
|
|
12739
12853
|
// src/roles/sql/raw/rules/leading-wildcard-like.ts
|
|
12740
12854
|
var QUERIES = /* @__PURE__ */ new Set(["SelectStmt", "UpdateStmt", "DeleteStmt", "InsertStmt"]);
|
|
12855
|
+
var KEEPS_START = /* @__PURE__ */ new Set(["lower", "upper", "unaccent", "immutable_unaccent", "like_escape"]);
|
|
12741
12856
|
var leadingWildcardLike = {
|
|
12742
12857
|
name: LIKE_WILDCARD_RULE,
|
|
12743
|
-
help: "anchor the pattern at its start when the search allows it (`LIKE 'abc%'`); for a search inside the text, a trigram index (`pg_trgm`) is
|
|
12744
|
-
check: (reading) => {
|
|
12858
|
+
help: "anchor the pattern at its start when the search allows it (`LIKE 'abc%'`); for a search inside the text, a trigram index (`pg_trgm`) on this very expression; when that index is in another module's migrations, name their folder in `migrations.indexesFrom`",
|
|
12859
|
+
check: (reading, context2) => {
|
|
12745
12860
|
if (!statementKinds(reading.statements).every((kind) => QUERIES.has(kind))) return [];
|
|
12746
12861
|
return [...pgNodes(reading.statements)].flatMap((node) => {
|
|
12747
|
-
const like =
|
|
12748
|
-
return like
|
|
12862
|
+
const like = unservedLike(node, reading, context2);
|
|
12863
|
+
return like ? [hitOf(like, context2)] : [];
|
|
12749
12864
|
});
|
|
12750
12865
|
}
|
|
12751
12866
|
};
|
|
12752
|
-
function
|
|
12867
|
+
function unservedLike(node, reading, context2) {
|
|
12753
12868
|
const like = bodyOf(node, "A_Expr");
|
|
12754
12869
|
if (like?.kind !== "AEXPR_LIKE" && like?.kind !== "AEXPR_ILIKE") return void 0;
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
if (
|
|
12870
|
+
if (typeof like.location !== "number" || !reading.own(like.location)) return void 0;
|
|
12871
|
+
const pattern = patternStart(like.rexpr, reading);
|
|
12872
|
+
if (!pattern?.text.startsWith("%")) return void 0;
|
|
12873
|
+
const expression = expressionKey(like.lexpr);
|
|
12874
|
+
if (expression === void 0) return void 0;
|
|
12875
|
+
const table = tableOf(like.lexpr, reading);
|
|
12876
|
+
if (served(context2.trigramIndexes(), expression, table)) return void 0;
|
|
12758
12877
|
return {
|
|
12759
12878
|
location: like.location,
|
|
12879
|
+
operator: like.kind === "AEXPR_ILIKE" ? "ILIKE" : "LIKE",
|
|
12760
12880
|
pattern,
|
|
12761
|
-
|
|
12881
|
+
expression,
|
|
12882
|
+
table
|
|
12762
12883
|
};
|
|
12763
12884
|
}
|
|
12764
|
-
function
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12885
|
+
function patternStart(node, reading) {
|
|
12886
|
+
const text = bodyOf(bodyOf(node, "A_Const"), "sval")?.sval;
|
|
12887
|
+
if (typeof text === "string") return { text, shape: `'${text}'` };
|
|
12888
|
+
const parameter = bodyOf(node, "ParamRef")?.number;
|
|
12889
|
+
if (typeof parameter === "number") {
|
|
12890
|
+
const start = reading.valueStart(parameter);
|
|
12891
|
+
return start === void 0 ? void 0 : { text: start, shape: `$${parameter}`, bound: parameter };
|
|
12892
|
+
}
|
|
12893
|
+
const cast = bodyOf(node, "TypeCast");
|
|
12894
|
+
if (cast) return patternStart(cast.arg, reading);
|
|
12895
|
+
const joined2 = bodyOf(node, "A_Expr");
|
|
12896
|
+
if (joined2?.kind === "AEXPR_OP" && operatorOf(joined2) === "||") {
|
|
12897
|
+
return startOfSum(joined2.lexpr, joined2.rexpr, reading, (first2) => `${first2} || \u2026`);
|
|
12898
|
+
}
|
|
12899
|
+
const call = bodyOf(node, "FuncCall");
|
|
12900
|
+
const name = call ? functionName(call) : void 0;
|
|
12901
|
+
const [first, ...rest] = call?.args ?? [];
|
|
12902
|
+
if (name === "concat")
|
|
12903
|
+
return startOfSum(first, rest[0], reading, (inner) => `concat(${inner}, \u2026)`);
|
|
12904
|
+
if (name !== void 0 && KEEPS_START.has(name)) {
|
|
12905
|
+
const inner = patternStart(first, reading);
|
|
12906
|
+
return inner && { ...inner, shape: `${name}(${inner.shape}${rest.length > 0 ? ", \u2026" : ""})` };
|
|
12907
|
+
}
|
|
12908
|
+
return void 0;
|
|
12909
|
+
}
|
|
12910
|
+
function startOfSum(left, right, reading, shapeOf) {
|
|
12911
|
+
const first = patternStart(left, reading);
|
|
12912
|
+
if (first === void 0) return void 0;
|
|
12913
|
+
if (first.text !== "") return { ...first, shape: shapeOf(first.shape) };
|
|
12914
|
+
const next = right === void 0 ? void 0 : patternStart(right, reading);
|
|
12915
|
+
return next && { ...next, shape: shapeOf(first.shape) };
|
|
12916
|
+
}
|
|
12917
|
+
function operatorOf(operation) {
|
|
12918
|
+
const name = bodyOf(operation.name?.at(-1), "String")?.sval;
|
|
12919
|
+
return typeof name === "string" ? name : void 0;
|
|
12920
|
+
}
|
|
12921
|
+
function functionName(call) {
|
|
12922
|
+
const name = bodyOf(call.funcname?.at(-1), "String")?.sval;
|
|
12923
|
+
return typeof name === "string" ? name : void 0;
|
|
12924
|
+
}
|
|
12925
|
+
function tableOf(expression, reading) {
|
|
12926
|
+
const byName = /* @__PURE__ */ new Map();
|
|
12927
|
+
for (const node of pgNodes(reading.statements)) {
|
|
12928
|
+
const range = bodyOf(node, "RangeVar");
|
|
12929
|
+
if (!range || typeof range.relname !== "string") continue;
|
|
12930
|
+
if (typeof range.location !== "number" || !reading.own(range.location)) continue;
|
|
12931
|
+
const alias = range.alias?.aliasname;
|
|
12932
|
+
const name = typeof alias === "string" ? alias : range.relname;
|
|
12933
|
+
byName.set(name, /* @__PURE__ */ new Set([...byName.get(name) ?? [], range.relname]));
|
|
12934
|
+
}
|
|
12935
|
+
const qualifiers = [...qualifiersUnder(expression)];
|
|
12936
|
+
if (qualifiers.length > 1) return void 0;
|
|
12937
|
+
const tables = qualifiers.length === 1 ? [...byName.get(qualifiers[0] ?? "") ?? []] : [...new Set([...byName.values()].flatMap((names) => [...names]))];
|
|
12938
|
+
return tables.length === 1 ? tables[0] : void 0;
|
|
12939
|
+
}
|
|
12940
|
+
function served(indexes, expression, table) {
|
|
12941
|
+
return indexes.some(
|
|
12942
|
+
(index) => index.expression === expression && (table === void 0 || index.table === table)
|
|
12943
|
+
);
|
|
12944
|
+
}
|
|
12945
|
+
function hitOf(like, context2) {
|
|
12946
|
+
const { pattern, operator, expression, table } = like;
|
|
12947
|
+
const bound = pattern.bound === void 0 ? "" : ` (the TypeScript binds \`${pattern.text}\u2026\` to $${pattern.bound})`;
|
|
12948
|
+
const on = `\`${expression}\`${table === void 0 ? "" : ` of \`${table}\``}`;
|
|
12949
|
+
const read2 = context2.indexesFrom.length === 0 ? "the module's own" : `the module's and those of ${context2.indexesFrom.map((folder) => `\`${folder}\``).join(", ")}`;
|
|
12769
12950
|
return {
|
|
12770
|
-
location,
|
|
12771
|
-
message: `the pattern
|
|
12951
|
+
location: like.location,
|
|
12952
|
+
message: `the pattern ${pattern.shape} starts with a wildcard${bound}: no B-tree index can serve this ${operator}, and no trigram index on ${on} is in the migrations read (${read2}; an index created by hand in the database is not seen), so every row is read`
|
|
12772
12953
|
};
|
|
12773
12954
|
}
|
|
12774
12955
|
|
|
@@ -13464,7 +13645,7 @@ function renderMarkdown5(report) {
|
|
|
13464
13645
|
...templatesLine(report),
|
|
13465
13646
|
...fileBlocks(report),
|
|
13466
13647
|
"",
|
|
13467
|
-
`<sub
|
|
13648
|
+
`<sub>Every place, with the SQL behind it and sentinel's notes, is in the \`sql.html\` this run keeps. Measured by sentinel ${report.sentinel}.</sub>`,
|
|
13468
13649
|
""
|
|
13469
13650
|
].join("\n");
|
|
13470
13651
|
}
|
|
@@ -13479,8 +13660,8 @@ function headline3(report) {
|
|
|
13479
13660
|
}
|
|
13480
13661
|
const counts2 = (count, what, noun) => `**${count}** ${what} ${noun}${count === 1 ? "" : "s"}`;
|
|
13481
13662
|
const calls = [
|
|
13482
|
-
...report.rulesOff.includes(UNSAFE_RULE) ? [] : [counts2(report.unsafe.calls, "raw SQL", "call")],
|
|
13483
|
-
...report.rulesOff.includes(RAW_FRAGMENT_RULE) ? [] : [counts2(report.unsafe.rawCalls, "Prisma", "fragment")]
|
|
13663
|
+
...report.rulesOff.includes(UNSAFE_RULE) || report.unsafe.calls === 0 ? [] : [counts2(report.unsafe.calls, "raw SQL", "call")],
|
|
13664
|
+
...report.rulesOff.includes(RAW_FRAGMENT_RULE) || report.unsafe.rawCalls === 0 ? [] : [counts2(report.unsafe.rawCalls, "Prisma", "fragment")]
|
|
13484
13665
|
];
|
|
13485
13666
|
const items = [
|
|
13486
13667
|
...migrations > 0 ? [`**${migrations}** migration${migrations === 1 ? "" : "s"}`] : [],
|
|
@@ -13535,8 +13716,9 @@ function byFile2(findings) {
|
|
|
13535
13716
|
const errors = (list) => list.filter((finding3) => finding3.level === "error").length;
|
|
13536
13717
|
return [...groups].map(([file, list]) => [
|
|
13537
13718
|
file,
|
|
13719
|
+
// By line; on one line, a finding at `error` first, since it is what the module refuses.
|
|
13538
13720
|
[...list].sort(
|
|
13539
|
-
(a, b) => a.line - b.line || a.column - b.column || a.rule.localeCompare(b.rule)
|
|
13721
|
+
(a, b) => a.line - b.line || Number(b.level === "error") - Number(a.level === "error") || a.column - b.column || a.rule.localeCompare(b.rule)
|
|
13540
13722
|
)
|
|
13541
13723
|
]).sort(
|
|
13542
13724
|
([fileA, a], [fileB, b]) => errors(b) - errors(a) || b.length - a.length || fileA.localeCompare(fileB)
|
|
@@ -13567,9 +13749,6 @@ function endOf(text) {
|
|
|
13567
13749
|
function cell3(text) {
|
|
13568
13750
|
return text.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
|
|
13569
13751
|
}
|
|
13570
|
-
function levelsLine(report) {
|
|
13571
|
-
return errorFindings(report.findings).length === 0 ? "" : "A rule the module sets to `error` fails the module's `sql` run; every other finding is a warning. ";
|
|
13572
|
-
}
|
|
13573
13752
|
function offBlock(report) {
|
|
13574
13753
|
if (report.read.length === 0 && report.unsafe.files.length === 0 || report.rulesOff.length === 0)
|
|
13575
13754
|
return [];
|
|
@@ -13811,6 +13990,103 @@ function migrationsInNested(cwd, settings = defaults3, nested = adoptedInnerDirs
|
|
|
13811
13990
|
return out.sort((a, b) => a.dir.localeCompare(b.dir));
|
|
13812
13991
|
}
|
|
13813
13992
|
|
|
13993
|
+
// src/roles/sql/trigram-indexes.ts
|
|
13994
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync23 } from "node:fs";
|
|
13995
|
+
import { join as join44 } from "node:path";
|
|
13996
|
+
var TRIGRAM_CLASSES = /* @__PURE__ */ new Set(["gin_trgm_ops", "gist_trgm_ops"]);
|
|
13997
|
+
function trigramContext(cwd, own, indexesFrom) {
|
|
13998
|
+
let indexes;
|
|
13999
|
+
return {
|
|
14000
|
+
indexesFrom,
|
|
14001
|
+
trigramIndexes: () => {
|
|
14002
|
+
indexes ??= trigramIndexesOf([
|
|
14003
|
+
...own.flatMap((file) => readable(cwd, file)),
|
|
14004
|
+
...indexesFrom.flatMap(
|
|
14005
|
+
(folder) => migrationsIn(join44(cwd, folder)).flatMap(
|
|
14006
|
+
(name) => readable(cwd, `${folder}/${name}/migration.sql`)
|
|
14007
|
+
)
|
|
14008
|
+
)
|
|
14009
|
+
]);
|
|
14010
|
+
return indexes;
|
|
14011
|
+
}
|
|
14012
|
+
};
|
|
14013
|
+
}
|
|
14014
|
+
function migrationsIn(directory) {
|
|
14015
|
+
try {
|
|
14016
|
+
return readdirSync5(directory, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
14017
|
+
} catch {
|
|
14018
|
+
return [];
|
|
14019
|
+
}
|
|
14020
|
+
}
|
|
14021
|
+
function readable(cwd, file) {
|
|
14022
|
+
try {
|
|
14023
|
+
return [{ file, text: readFileSync23(join44(cwd, file), "utf8") }];
|
|
14024
|
+
} catch {
|
|
14025
|
+
return [];
|
|
14026
|
+
}
|
|
14027
|
+
}
|
|
14028
|
+
function trigramIndexesOf(migrations) {
|
|
14029
|
+
let indexes = [];
|
|
14030
|
+
for (const { file, text } of migrations) {
|
|
14031
|
+
const parsed2 = parseSql(text);
|
|
14032
|
+
if (!parsed2.ok) continue;
|
|
14033
|
+
for (const statement of parsed2.statements) indexes = applied(indexes, statement, file);
|
|
14034
|
+
}
|
|
14035
|
+
return indexes;
|
|
14036
|
+
}
|
|
14037
|
+
function applied(indexes, statement, file) {
|
|
14038
|
+
const created = bodyOf(statement, "IndexStmt");
|
|
14039
|
+
if (created) return [...indexes, ...indexesOf(created, file)];
|
|
14040
|
+
const dropped = bodyOf(statement, "DropStmt");
|
|
14041
|
+
if (dropped) return withoutDropped(indexes, dropped);
|
|
14042
|
+
const renamed3 = bodyOf(statement, "RenameStmt");
|
|
14043
|
+
if (renamed3) return withRenamed(indexes, renamed3);
|
|
14044
|
+
return indexes;
|
|
14045
|
+
}
|
|
14046
|
+
function indexesOf(index, file) {
|
|
14047
|
+
const table = index.relation?.relname;
|
|
14048
|
+
if (typeof table !== "string") return [];
|
|
14049
|
+
const name = typeof index.idxname === "string" ? index.idxname : void 0;
|
|
14050
|
+
return (index.indexParams ?? []).flatMap((param) => {
|
|
14051
|
+
const element = bodyOf(param, "IndexElem");
|
|
14052
|
+
if (!element || !isTrigram(element)) return [];
|
|
14053
|
+
const expression = typeof element.name === "string" ? element.name : expressionKey(element.expr);
|
|
14054
|
+
return expression === void 0 ? [] : [{ name, table, expression, file }];
|
|
14055
|
+
});
|
|
14056
|
+
}
|
|
14057
|
+
function isTrigram(element) {
|
|
14058
|
+
const classes = element.opclass ?? [];
|
|
14059
|
+
const name = bodyOf(classes.at(-1), "String")?.sval;
|
|
14060
|
+
return typeof name === "string" && TRIGRAM_CLASSES.has(name);
|
|
14061
|
+
}
|
|
14062
|
+
function withoutDropped(indexes, drop) {
|
|
14063
|
+
const names = (drop.objects ?? []).flatMap((object) => {
|
|
14064
|
+
const items = bodyOf(object, "List")?.items ?? [];
|
|
14065
|
+
const last = bodyOf(items.at(-1), "String")?.sval;
|
|
14066
|
+
return typeof last === "string" ? [last] : [];
|
|
14067
|
+
});
|
|
14068
|
+
if (drop.removeType === "OBJECT_INDEX")
|
|
14069
|
+
return indexes.filter((index) => !names.includes(index.name ?? ""));
|
|
14070
|
+
if (drop.removeType === "OBJECT_TABLE")
|
|
14071
|
+
return indexes.filter((index) => !names.includes(index.table));
|
|
14072
|
+
return indexes;
|
|
14073
|
+
}
|
|
14074
|
+
function withRenamed(indexes, rename) {
|
|
14075
|
+
const from = rename.relation?.relname;
|
|
14076
|
+
const to = rename.newname;
|
|
14077
|
+
if (typeof from !== "string" || typeof to !== "string") return indexes;
|
|
14078
|
+
if (rename.renameType === "OBJECT_INDEX")
|
|
14079
|
+
return indexes.map((index) => index.name === from ? { ...index, name: to } : index);
|
|
14080
|
+
if (rename.renameType === "OBJECT_TABLE")
|
|
14081
|
+
return indexes.map((index) => index.table === from ? { ...index, table: to } : index);
|
|
14082
|
+
if (rename.renameType === "OBJECT_COLUMN") {
|
|
14083
|
+
return indexes.map(
|
|
14084
|
+
(index) => index.table === from && index.expression === rename.subname ? { ...index, expression: to } : index
|
|
14085
|
+
);
|
|
14086
|
+
}
|
|
14087
|
+
return indexes;
|
|
14088
|
+
}
|
|
14089
|
+
|
|
13814
14090
|
// src/roles/sql/adapters/squawk/resolve-squawk.ts
|
|
13815
14091
|
function resolveSquawk(cwd) {
|
|
13816
14092
|
return resolveBin(cwd, "squawk") ?? binFromOwnInstall("squawk-cli", "squawk");
|
|
@@ -13821,9 +14097,9 @@ function squawkNotFound(cwd) {
|
|
|
13821
14097
|
|
|
13822
14098
|
// src/roles/sql/adapters/squawk/run-squawk.ts
|
|
13823
14099
|
import { spawnSync as spawnSync12 } from "node:child_process";
|
|
13824
|
-
import { mkdtempSync as mkdtempSync4, readFileSync as
|
|
14100
|
+
import { mkdtempSync as mkdtempSync4, readFileSync as readFileSync24, rmSync as rmSync6, writeFileSync as writeFileSync12 } from "node:fs";
|
|
13825
14101
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
13826
|
-
import { join as
|
|
14102
|
+
import { join as join46 } from "node:path";
|
|
13827
14103
|
|
|
13828
14104
|
// src/roles/sql/adapters/squawk/read-output.ts
|
|
13829
14105
|
function readSquawkOutput(stdout, stderr) {
|
|
@@ -13881,7 +14157,7 @@ function toFinding(entry) {
|
|
|
13881
14157
|
// src/roles/sql/adapters/squawk/squawk-config.ts
|
|
13882
14158
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync5, writeFileSync as writeFileSync11 } from "node:fs";
|
|
13883
14159
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
13884
|
-
import { join as
|
|
14160
|
+
import { join as join45 } from "node:path";
|
|
13885
14161
|
function squawkToml(settings) {
|
|
13886
14162
|
const squawks = (rule) => !NOT_SQUAWK_CONFIG.includes(rule);
|
|
13887
14163
|
const off = rulesOff(settings.rules ?? {}).filter(squawks);
|
|
@@ -13895,9 +14171,9 @@ function squawkToml(settings) {
|
|
|
13895
14171
|
].join("\n");
|
|
13896
14172
|
}
|
|
13897
14173
|
function withSquawkConfig(settings, use) {
|
|
13898
|
-
const dir = mkdtempSync3(
|
|
14174
|
+
const dir = mkdtempSync3(join45(tmpdir3(), "sentinel-squawk-"));
|
|
13899
14175
|
try {
|
|
13900
|
-
const configPath =
|
|
14176
|
+
const configPath = join45(dir, "squawk.toml");
|
|
13901
14177
|
writeFileSync11(configPath, squawkToml(settings));
|
|
13902
14178
|
return use(configPath);
|
|
13903
14179
|
} finally {
|
|
@@ -13945,14 +14221,14 @@ var BATCH_FILES = 200;
|
|
|
13945
14221
|
var BATCH_CHARACTERS = 2e4;
|
|
13946
14222
|
var OUTPUT_BUFFER = 64 * 1024 * 1024;
|
|
13947
14223
|
function runSquawk(invocation, files) {
|
|
13948
|
-
const { readable, unread } = openable(invocation.cwd, files);
|
|
13949
|
-
const statements = statementsOf(invocation,
|
|
14224
|
+
const { readable: readable2, unread } = openable(invocation.cwd, files);
|
|
14225
|
+
const statements = statementsOf(invocation, readable2);
|
|
13950
14226
|
const wrapped = (file) => (statements.get(file)?.count ?? 0) > 1;
|
|
13951
14227
|
const quietNesting = (file) => !invocation.reportNesting && statements.get(file)?.ownTransaction === "paired";
|
|
13952
14228
|
const findings = [];
|
|
13953
14229
|
for (const [list, inTransaction] of [
|
|
13954
|
-
[
|
|
13955
|
-
[
|
|
14230
|
+
[readable2.filter((file) => !wrapped(file)), false],
|
|
14231
|
+
[readable2.filter(wrapped), true]
|
|
13956
14232
|
]) {
|
|
13957
14233
|
for (const batch of batches(list)) {
|
|
13958
14234
|
const reading = runBatch(invocation, batch, inTransaction);
|
|
@@ -13964,18 +14240,18 @@ function runSquawk(invocation, files) {
|
|
|
13964
14240
|
);
|
|
13965
14241
|
}
|
|
13966
14242
|
}
|
|
13967
|
-
const quietTimeouts = quietTimeoutFiles(invocation,
|
|
14243
|
+
const quietTimeouts = quietTimeoutFiles(invocation, readable2, statements, wrapped);
|
|
13968
14244
|
const kept = findings.filter(
|
|
13969
14245
|
(finding3) => !(TIMEOUTS.has(finding3.rule) && quietTimeouts.has(finding3.file))
|
|
13970
14246
|
);
|
|
13971
|
-
const order = new Map(
|
|
14247
|
+
const order = new Map(readable2.map((file, index) => [file, index]));
|
|
13972
14248
|
kept.sort((a, b) => (order.get(a.file) ?? 0) - (order.get(b.file) ?? 0));
|
|
13973
14249
|
const statementCounts = new Map([...statements].map(([file, read2]) => [file, read2.count]));
|
|
13974
14250
|
return { ok: true, findings: kept, unread, statementCounts };
|
|
13975
14251
|
}
|
|
13976
|
-
function quietTimeoutFiles(invocation,
|
|
14252
|
+
function quietTimeoutFiles(invocation, readable2, statements, wrapped) {
|
|
13977
14253
|
const texts = /* @__PURE__ */ new Map();
|
|
13978
|
-
for (const file of
|
|
14254
|
+
for (const file of readable2) {
|
|
13979
14255
|
const read2 = statements.get(file);
|
|
13980
14256
|
if (read2 === void 0 || !wrapped(file)) continue;
|
|
13981
14257
|
const text = readText(invocation.cwd, file);
|
|
@@ -13987,9 +14263,9 @@ function quietTimeoutFiles(invocation, readable, statements, wrapped) {
|
|
|
13987
14263
|
return new Set([...texts.keys()].filter((file) => !onExisting.has(file)));
|
|
13988
14264
|
}
|
|
13989
14265
|
function indexesOnExistingTables(invocation, files) {
|
|
13990
|
-
const dir = mkdtempSync4(
|
|
14266
|
+
const dir = mkdtempSync4(join46(tmpdir4(), "sentinel-squawk-"));
|
|
13991
14267
|
try {
|
|
13992
|
-
const configPath =
|
|
14268
|
+
const configPath = join46(dir, "squawk.toml");
|
|
13993
14269
|
writeFileSync12(configPath, DEFAULT_SQUAWK_TOML);
|
|
13994
14270
|
const found = /* @__PURE__ */ new Set();
|
|
13995
14271
|
for (const batch of batches(files)) {
|
|
@@ -14005,7 +14281,7 @@ function indexesOnExistingTables(invocation, files) {
|
|
|
14005
14281
|
}
|
|
14006
14282
|
function readText(cwd, file) {
|
|
14007
14283
|
try {
|
|
14008
|
-
return
|
|
14284
|
+
return readFileSync24(join46(cwd, file), "utf8");
|
|
14009
14285
|
} catch {
|
|
14010
14286
|
return void 0;
|
|
14011
14287
|
}
|
|
@@ -14082,18 +14358,18 @@ function jsonObjects(text) {
|
|
|
14082
14358
|
return depth === 0 ? objects : void 0;
|
|
14083
14359
|
}
|
|
14084
14360
|
function openable(cwd, files) {
|
|
14085
|
-
const
|
|
14361
|
+
const readable2 = [];
|
|
14086
14362
|
const unread = [];
|
|
14087
14363
|
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
14088
14364
|
for (const file of files) {
|
|
14089
14365
|
try {
|
|
14090
|
-
utf8.decode(
|
|
14091
|
-
|
|
14366
|
+
utf8.decode(readFileSync24(join46(cwd, file)));
|
|
14367
|
+
readable2.push(file);
|
|
14092
14368
|
} catch (error) {
|
|
14093
14369
|
unread.push({ file, reason: unreadReason(error) });
|
|
14094
14370
|
}
|
|
14095
14371
|
}
|
|
14096
|
-
return { readable, unread };
|
|
14372
|
+
return { readable: readable2, unread };
|
|
14097
14373
|
}
|
|
14098
14374
|
function unreadReason(error) {
|
|
14099
14375
|
const code = error?.code;
|
|
@@ -14250,7 +14526,7 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
14250
14526
|
skipped: `no migration (${defaults3.migrations.include.join(", ")}) and no raw SQL call in this module: nothing for the ${TARGET3} role to read.`
|
|
14251
14527
|
};
|
|
14252
14528
|
}
|
|
14253
|
-
const hasConfig = existsSync29(
|
|
14529
|
+
const hasConfig = existsSync29(join47(context2.cwd, SQL_CONFIG_FILE));
|
|
14254
14530
|
const declared = moduleScripts(context2.cwd);
|
|
14255
14531
|
const missingScripts = Object.keys(scripts2()).filter((name) => !(name in declared));
|
|
14256
14532
|
return {
|
|
@@ -14361,7 +14637,8 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
14361
14637
|
ctx.cwd,
|
|
14362
14638
|
templateCode,
|
|
14363
14639
|
readAbsolute,
|
|
14364
|
-
templateRules(config.rules)
|
|
14640
|
+
templateRules(config.rules),
|
|
14641
|
+
trigramContext(ctx.cwd, reading.migrations, config.migrations.indexesFrom)
|
|
14365
14642
|
);
|
|
14366
14643
|
const findings = withNotes(
|
|
14367
14644
|
[
|
|
@@ -14394,7 +14671,7 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
14394
14671
|
if (mode.speaking) {
|
|
14395
14672
|
for (const line of describeRun(outcome, reading, config, selection.quietNote)) this.say(line);
|
|
14396
14673
|
for (const dir of reading.nested) {
|
|
14397
|
-
const count = migrationFiles(
|
|
14674
|
+
const count = migrationFiles(join47(ctx.cwd, dir), defaults3).length;
|
|
14398
14675
|
if (count > 0)
|
|
14399
14676
|
this.say(
|
|
14400
14677
|
`the ${count} migration(s) under ${dir} are reported by that project, which adopted the role itself.`
|
|
@@ -14472,7 +14749,7 @@ var SquawkAdapter = class extends BaseAdapter {
|
|
|
14472
14749
|
const expected = Object.keys(scripts2());
|
|
14473
14750
|
const missing = expected.filter((name) => !(name in declared));
|
|
14474
14751
|
const adopted = missing.length < expected.length;
|
|
14475
|
-
const hasConfig = existsSync29(
|
|
14752
|
+
const hasConfig = existsSync29(join47(ctx.cwd, SQL_CONFIG_FILE));
|
|
14476
14753
|
return {
|
|
14477
14754
|
adopted,
|
|
14478
14755
|
preset: adopted ? ctx.preset : null,
|
|
@@ -14674,14 +14951,14 @@ function reportOf(ctx, config, files, result) {
|
|
|
14674
14951
|
}
|
|
14675
14952
|
function readAbsolute(path2) {
|
|
14676
14953
|
try {
|
|
14677
|
-
return
|
|
14954
|
+
return readFileSync25(path2, "utf8");
|
|
14678
14955
|
} catch {
|
|
14679
14956
|
return void 0;
|
|
14680
14957
|
}
|
|
14681
14958
|
}
|
|
14682
14959
|
function readText2(cwd, file) {
|
|
14683
14960
|
try {
|
|
14684
|
-
return
|
|
14961
|
+
return readFileSync25(join47(cwd, file), "utf8");
|
|
14685
14962
|
} catch {
|
|
14686
14963
|
return void 0;
|
|
14687
14964
|
}
|
|
@@ -14726,8 +15003,8 @@ function registerSql() {
|
|
|
14726
15003
|
|
|
14727
15004
|
// src/roles/static-analysis/adapters/jscpd/jscpd.adapter.ts
|
|
14728
15005
|
import { spawnSync as spawnSync15 } from "node:child_process";
|
|
14729
|
-
import { existsSync as existsSync33, mkdirSync as mkdirSync7, readFileSync as
|
|
14730
|
-
import { join as
|
|
15006
|
+
import { existsSync as existsSync33, mkdirSync as mkdirSync7, readFileSync as readFileSync29, unlinkSync as unlinkSync4, writeFileSync as writeFileSync14 } from "node:fs";
|
|
15007
|
+
import { join as join52, relative as relative9, sep as sep6 } from "node:path";
|
|
14731
15008
|
import { globSync as globSync8 } from "tinyglobby";
|
|
14732
15009
|
|
|
14733
15010
|
// src/roles/static-analysis/bundle/budgets.ts
|
|
@@ -14756,21 +15033,21 @@ function bandFor(valueKb, referenceKb) {
|
|
|
14756
15033
|
}
|
|
14757
15034
|
|
|
14758
15035
|
// src/roles/static-analysis/bundle/scan.ts
|
|
14759
|
-
import { existsSync as existsSync31, readFileSync as
|
|
14760
|
-
import { basename as basename4, join as
|
|
15036
|
+
import { existsSync as existsSync31, readFileSync as readFileSync27 } from "node:fs";
|
|
15037
|
+
import { basename as basename4, join as join49 } from "node:path";
|
|
14761
15038
|
import { pathToFileURL as pathToFileURL6 } from "node:url";
|
|
14762
15039
|
import { gzipSync } from "node:zlib";
|
|
14763
15040
|
import { globSync as globSync6 } from "tinyglobby";
|
|
14764
15041
|
|
|
14765
15042
|
// src/roles/static-analysis/bundle/find-build.ts
|
|
14766
|
-
import { existsSync as existsSync30, readFileSync as
|
|
14767
|
-
import { join as
|
|
15043
|
+
import { existsSync as existsSync30, readFileSync as readFileSync26, statSync as statSync7 } from "node:fs";
|
|
15044
|
+
import { join as join48 } from "node:path";
|
|
14768
15045
|
import { globSync as globSync5 } from "tinyglobby";
|
|
14769
15046
|
var MANIFEST_GLOB = "server/_tanstack-start-manifest*.mjs";
|
|
14770
15047
|
function candidateDirs(cwd) {
|
|
14771
15048
|
const declared = readProjectPackageJson(cwd).nx?.targets?.build?.["outputs"];
|
|
14772
|
-
const fromDeclaration = Array.isArray(declared) ? declared.filter((token) => typeof token === "string").map((token) =>
|
|
14773
|
-
return [...fromDeclaration,
|
|
15049
|
+
const fromDeclaration = Array.isArray(declared) ? declared.filter((token) => typeof token === "string").map((token) => join48(cwd, token.replace(/^\{projectRoot\}\//, ""))) : [];
|
|
15050
|
+
return [...fromDeclaration, join48(cwd, ".output"), join48(cwd, "dist"), join48(cwd, "build")];
|
|
14774
15051
|
}
|
|
14775
15052
|
function findBuildOutput(cwd) {
|
|
14776
15053
|
const lookedIn = [];
|
|
@@ -14780,7 +15057,7 @@ function findBuildOutput(cwd) {
|
|
|
14780
15057
|
const found = globSync5(MANIFEST_GLOB, { cwd: dir, absolute: true, dot: false });
|
|
14781
15058
|
if (found.length === 0) continue;
|
|
14782
15059
|
const manifestPath = found[0];
|
|
14783
|
-
const publicDir =
|
|
15060
|
+
const publicDir = join48(dir, "public");
|
|
14784
15061
|
if (!existsSync30(publicDir)) continue;
|
|
14785
15062
|
return { manifestPath, publicDir, ...dateOf(dir, manifestPath) };
|
|
14786
15063
|
}
|
|
@@ -14803,10 +15080,10 @@ function findBuildOutput(cwd) {
|
|
|
14803
15080
|
};
|
|
14804
15081
|
}
|
|
14805
15082
|
function dateOf(dir, manifestPath) {
|
|
14806
|
-
const record =
|
|
15083
|
+
const record = join48(dir, "nitro.json");
|
|
14807
15084
|
if (existsSync30(record)) {
|
|
14808
15085
|
try {
|
|
14809
|
-
const parsed2 = JSON.parse(
|
|
15086
|
+
const parsed2 = JSON.parse(readFileSync26(record, "utf8"));
|
|
14810
15087
|
if (typeof parsed2.date === "string") {
|
|
14811
15088
|
const date = new Date(parsed2.date);
|
|
14812
15089
|
if (!Number.isNaN(date.getTime())) return { builtAt: date, builtAtFrom: "build record" };
|
|
@@ -14832,9 +15109,9 @@ function kindOf3(path2) {
|
|
|
14832
15109
|
return "other";
|
|
14833
15110
|
}
|
|
14834
15111
|
function resolveAnnounced(publicDir, announced) {
|
|
14835
|
-
const direct =
|
|
15112
|
+
const direct = join49(publicDir, announced);
|
|
14836
15113
|
if (existsSync31(direct)) return direct;
|
|
14837
|
-
const stripped =
|
|
15114
|
+
const stripped = join49(publicDir, announced.replace(/^\/[^/]+\//, "/"));
|
|
14838
15115
|
return existsSync31(stripped) ? stripped : void 0;
|
|
14839
15116
|
}
|
|
14840
15117
|
function emptyWeight() {
|
|
@@ -14871,7 +15148,7 @@ async function scanBundle(cwd) {
|
|
|
14871
15148
|
unresolved.push(announced);
|
|
14872
15149
|
measured.set(announced, void 0);
|
|
14873
15150
|
} else {
|
|
14874
|
-
const buffer =
|
|
15151
|
+
const buffer = readFileSync27(path2);
|
|
14875
15152
|
measured.set(announced, {
|
|
14876
15153
|
parsed: buffer.length,
|
|
14877
15154
|
transfer: gzipSync(buffer, { level: 9 }).length
|
|
@@ -14958,7 +15235,7 @@ function scanDynamicLayer(publicDir, references) {
|
|
|
14958
15235
|
})) {
|
|
14959
15236
|
const name = basename4(path2);
|
|
14960
15237
|
if (referenced.has(name)) continue;
|
|
14961
|
-
const buffer =
|
|
15238
|
+
const buffer = readFileSync27(path2);
|
|
14962
15239
|
const size = { parsed: buffer.length, transfer: gzipSync(buffer, { level: 9 }).length };
|
|
14963
15240
|
add(all2, size);
|
|
14964
15241
|
const group = groupOf(name);
|
|
@@ -15026,10 +15303,10 @@ function hasUnreadableCode(coverage) {
|
|
|
15026
15303
|
}
|
|
15027
15304
|
function coverageOf(cwd, config) {
|
|
15028
15305
|
const ignore = exclusions(config, "product");
|
|
15029
|
-
const
|
|
15306
|
+
const readable2 = extensionsOf(config.languages).map((extension) => extension.slice(1)).join(",");
|
|
15030
15307
|
const roots = measuredRoots(cwd);
|
|
15031
15308
|
const under2 = (extensions) => roots.map((root) => root === "." ? `**/*.{${extensions}}` : `${root}/**/*.{${extensions}}`);
|
|
15032
|
-
const read2 =
|
|
15309
|
+
const read2 = readable2 ? globSync7(under2(readable2), { cwd, ignore, dot: false }).length : 0;
|
|
15033
15310
|
const unreadable = UNREADABLE_EXTENSIONS.map((extension) => extension.slice(1)).join(",");
|
|
15034
15311
|
const found = globSync7(under2(unreadable), { cwd, ignore, dot: false });
|
|
15035
15312
|
const total = read2 + found.length;
|
|
@@ -15050,7 +15327,7 @@ function unreadableNote(coverage) {
|
|
|
15050
15327
|
import { spawnSync as spawnSync14 } from "node:child_process";
|
|
15051
15328
|
import { existsSync as existsSync32, mkdirSync as mkdirSync6, mkdtempSync as mkdtempSync5, rmSync as rmSync7, writeFileSync as writeFileSync13 } from "node:fs";
|
|
15052
15329
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
15053
|
-
import { join as
|
|
15330
|
+
import { join as join50 } from "node:path";
|
|
15054
15331
|
var ROOT_FILES = ["nx.json", "tsconfig.base.json"];
|
|
15055
15332
|
function git5(cwd, args) {
|
|
15056
15333
|
const run = spawnSync14("git", args, { cwd, encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
|
|
@@ -15076,9 +15353,9 @@ function checkoutModuleAt(workspaceRoot, modulePath, sha) {
|
|
|
15076
15353
|
if (!listed.ok) return { ok: false, reason: `git could not list the base: ${listed.said}` };
|
|
15077
15354
|
const present = new Set(listed.out.split("\n").filter((line) => line !== ""));
|
|
15078
15355
|
const existed = present.has(modulePath);
|
|
15079
|
-
const root = mkdtempSync5(
|
|
15356
|
+
const root = mkdtempSync5(join50(tmpdir5(), "sentinel-static-base-"));
|
|
15080
15357
|
const dispose = () => rmSync7(root, { recursive: true, force: true });
|
|
15081
|
-
const moduleDir =
|
|
15358
|
+
const moduleDir = join50(root, modulePath);
|
|
15082
15359
|
mkdirSync6(moduleDir, { recursive: true });
|
|
15083
15360
|
const paths2 = [
|
|
15084
15361
|
...ROOT_FILES.filter((file) => present.has(file)),
|
|
@@ -15105,7 +15382,7 @@ function checkoutModuleAt(workspaceRoot, modulePath, sha) {
|
|
|
15105
15382
|
};
|
|
15106
15383
|
}
|
|
15107
15384
|
}
|
|
15108
|
-
if (!existsSync32(
|
|
15385
|
+
if (!existsSync32(join50(root, "nx.json"))) writeFileSync13(join50(root, "nx.json"), "{}\n");
|
|
15109
15386
|
return { ok: true, moduleDir, existed, dispose };
|
|
15110
15387
|
}
|
|
15111
15388
|
|
|
@@ -15202,8 +15479,8 @@ function comparePlaces(branch, base, renames) {
|
|
|
15202
15479
|
}
|
|
15203
15480
|
|
|
15204
15481
|
// src/roles/static-analysis/excerpt.ts
|
|
15205
|
-
import { readFileSync as
|
|
15206
|
-
import { join as
|
|
15482
|
+
import { readFileSync as readFileSync28 } from "node:fs";
|
|
15483
|
+
import { join as join51 } from "node:path";
|
|
15207
15484
|
var WINDOW = { lines: 10, nesting: { before: 3, after: 6 } };
|
|
15208
15485
|
var NESTS_UPWARD = /* @__PURE__ */ new Set(["max-depth", "max-nested-callbacks"]);
|
|
15209
15486
|
var SHOWS_THE_HEAD = /* @__PURE__ */ new Set(["max-lines"]);
|
|
@@ -15212,7 +15489,7 @@ function linesOf(cache, cwd, relative10) {
|
|
|
15212
15489
|
if (cache.has(relative10)) return cache.get(relative10);
|
|
15213
15490
|
let lines;
|
|
15214
15491
|
try {
|
|
15215
|
-
lines =
|
|
15492
|
+
lines = readFileSync28(join51(cwd, relative10), "utf8").split("\n");
|
|
15216
15493
|
} catch {
|
|
15217
15494
|
lines = void 0;
|
|
15218
15495
|
}
|
|
@@ -15530,7 +15807,7 @@ var JscpdAdapter = class extends BaseAdapter {
|
|
|
15530
15807
|
operations: [
|
|
15531
15808
|
// `write` and not `merge-json`: this file is code, and the engine's in-place merge is for
|
|
15532
15809
|
// JSON. A re-init therefore RESTORES the stub, so an existing one is left alone below.
|
|
15533
|
-
...existsSync33(
|
|
15810
|
+
...existsSync33(join52(context2.cwd, STATIC_CONFIG_FILE)) ? [] : [{ kind: "write", path: STATIC_CONFIG_FILE, contents: configStub4() }],
|
|
15534
15811
|
manifestOperation(context2.cwd, scripts3()),
|
|
15535
15812
|
...nxTargetOperations({ cwd: context2.cwd, targets: targets3() })
|
|
15536
15813
|
// The report directory is ignored ONCE at the workspace root, by `--init`'s workspace prep,
|
|
@@ -15748,7 +16025,7 @@ var JscpdAdapter = class extends BaseAdapter {
|
|
|
15748
16025
|
const declared = moduleScripts(ctx.cwd);
|
|
15749
16026
|
const missing = Object.keys(scripts3()).filter((name) => !(name in declared));
|
|
15750
16027
|
const adopted = missing.length < Object.keys(scripts3()).length;
|
|
15751
|
-
const hasConfig = existsSync33(
|
|
16028
|
+
const hasConfig = existsSync33(join52(ctx.cwd, STATIC_CONFIG_FILE));
|
|
15752
16029
|
return {
|
|
15753
16030
|
adopted,
|
|
15754
16031
|
preset: adopted ? ctx.preset : null,
|
|
@@ -15840,7 +16117,7 @@ function runDeadCode(jscpd, config, paths2, cwd, extraEntries = []) {
|
|
|
15840
16117
|
try {
|
|
15841
16118
|
const ran = runTool(jscpd, args, cwd, "dead-code");
|
|
15842
16119
|
if (ran.kind !== "ran") return ran;
|
|
15843
|
-
const path2 =
|
|
16120
|
+
const path2 = join52(rawReportDir, RAW_REPORT["dead-code"]);
|
|
15844
16121
|
if (!existsSync33(path2)) {
|
|
15845
16122
|
process.stderr.write(
|
|
15846
16123
|
`sentinel static-analysis(jscpd): the dead-code pass wrote no ${RAW_REPORT["dead-code"]}
|
|
@@ -15848,7 +16125,7 @@ function runDeadCode(jscpd, config, paths2, cwd, extraEntries = []) {
|
|
|
15848
16125
|
);
|
|
15849
16126
|
return { kind: "failed", code: 1 };
|
|
15850
16127
|
}
|
|
15851
|
-
const parsed2 = safeParseDeadCode(
|
|
16128
|
+
const parsed2 = safeParseDeadCode(readFileSync29(path2, "utf8"));
|
|
15852
16129
|
const statistics = parsed2?.statistics;
|
|
15853
16130
|
if (!statistics) {
|
|
15854
16131
|
process.stderr.write(
|
|
@@ -15871,11 +16148,11 @@ function runDeadCode(jscpd, config, paths2, cwd, extraEntries = []) {
|
|
|
15871
16148
|
}
|
|
15872
16149
|
}
|
|
15873
16150
|
function moduleRelative(name, roots, cwd) {
|
|
15874
|
-
if (existsSync33(
|
|
16151
|
+
if (existsSync33(join52(cwd, name))) return name;
|
|
15875
16152
|
for (const root of roots) {
|
|
15876
16153
|
if (root === ".") continue;
|
|
15877
16154
|
const candidate = `${root}/${name}`;
|
|
15878
|
-
if (existsSync33(
|
|
16155
|
+
if (existsSync33(join52(cwd, candidate))) return candidate;
|
|
15879
16156
|
}
|
|
15880
16157
|
return name;
|
|
15881
16158
|
}
|
|
@@ -15884,8 +16161,8 @@ function runDuplication(jscpd, config, paths2, scope, cwd) {
|
|
|
15884
16161
|
try {
|
|
15885
16162
|
const ran = runTool(jscpd, args, cwd, scope);
|
|
15886
16163
|
if (ran.kind !== "ran") return ran;
|
|
15887
|
-
const path2 =
|
|
15888
|
-
const parsed2 = existsSync33(path2) ? safeParse(
|
|
16164
|
+
const path2 = join52(rawReportDir, RAW_REPORT.duplication);
|
|
16165
|
+
const parsed2 = existsSync33(path2) ? safeParse(readFileSync29(path2, "utf8")) : void 0;
|
|
15889
16166
|
const total = parsed2?.statistics?.total;
|
|
15890
16167
|
if (!total) {
|
|
15891
16168
|
process.stderr.write(
|
|
@@ -16173,7 +16450,7 @@ function moduleRenames(cwd, renames) {
|
|
|
16173
16450
|
function moduleRootsOf(workspaceRoot) {
|
|
16174
16451
|
const roots = [];
|
|
16175
16452
|
for (const area of ["apps", "libs"]) {
|
|
16176
|
-
const base =
|
|
16453
|
+
const base = join52(workspaceRoot, area);
|
|
16177
16454
|
if (!existsSync33(base)) continue;
|
|
16178
16455
|
for (const entry of globSync8([`${area}/**/package.json`, `${area}/**/project.json`], {
|
|
16179
16456
|
cwd: workspaceRoot,
|
|
@@ -16516,7 +16793,7 @@ var PICTURE_FILE = `${TARGET}-graph.svg`;
|
|
|
16516
16793
|
function clearStaleOutputs(cwd, keeping) {
|
|
16517
16794
|
for (const name of [...Object.values(SHAPE_FILE4), PICTURE_FILE]) {
|
|
16518
16795
|
if (keeping.has(name)) continue;
|
|
16519
|
-
const path2 =
|
|
16796
|
+
const path2 = join52(cwd, REPORT_DIR, name);
|
|
16520
16797
|
if (existsSync33(path2)) unlinkSync4(path2);
|
|
16521
16798
|
}
|
|
16522
16799
|
}
|
|
@@ -16535,11 +16812,11 @@ function drawsPicture(graph, coverage) {
|
|
|
16535
16812
|
async function emit(report, shape, cwd, graph, coverage) {
|
|
16536
16813
|
if (shape === "console") return [];
|
|
16537
16814
|
const detailed = shape === "markdown" ? report : withExcerpts(report, cwd);
|
|
16538
|
-
mkdirSync7(
|
|
16815
|
+
mkdirSync7(join52(cwd, REPORT_DIR), { recursive: true });
|
|
16539
16816
|
const written = [];
|
|
16540
16817
|
if (shape === "html" && drawsPicture(graph, coverage)) {
|
|
16541
16818
|
const drawn = layOut(graph.graph, graph.communityOf);
|
|
16542
|
-
const path2 =
|
|
16819
|
+
const path2 = join52(cwd, REPORT_DIR, PICTURE_FILE);
|
|
16543
16820
|
await writeGraphPicture(drawn, path2);
|
|
16544
16821
|
written.push(`${REPORT_DIR}/${PICTURE_FILE}`);
|
|
16545
16822
|
detailed.picture = buildExplorer(drawn, graph.communityOf).markup;
|
|
@@ -16547,7 +16824,7 @@ async function emit(report, shape, cwd, graph, coverage) {
|
|
|
16547
16824
|
const RENDER = { json: renderJson, html: renderHtml, markdown: renderMarkdown };
|
|
16548
16825
|
const name = SHAPE_FILE4[shape] ?? `${TARGET}.${shape}`;
|
|
16549
16826
|
const body = RENDER[shape](detailed);
|
|
16550
|
-
writeFileSync14(
|
|
16827
|
+
writeFileSync14(join52(cwd, REPORT_DIR, name), body, "utf8");
|
|
16551
16828
|
written.unshift(`${REPORT_DIR}/${name}`);
|
|
16552
16829
|
return written;
|
|
16553
16830
|
}
|
|
@@ -16581,9 +16858,9 @@ function registerTest() {
|
|
|
16581
16858
|
|
|
16582
16859
|
// src/roles/typescript/adapters/tsc/tsc.adapter.ts
|
|
16583
16860
|
import { spawnSync as spawnSync16 } from "node:child_process";
|
|
16584
|
-
import { existsSync as existsSync34, readdirSync as
|
|
16861
|
+
import { existsSync as existsSync34, readdirSync as readdirSync6, readFileSync as readFileSync31 } from "node:fs";
|
|
16585
16862
|
import { createRequire } from "node:module";
|
|
16586
|
-
import { join as
|
|
16863
|
+
import { join as join54 } from "node:path";
|
|
16587
16864
|
|
|
16588
16865
|
// src/roles/typescript/config-policy.ts
|
|
16589
16866
|
var PERMITTED_COMPILER_OPTIONS = [
|
|
@@ -16637,11 +16914,11 @@ function standardOverrides(compilerOptions, preset) {
|
|
|
16637
16914
|
}
|
|
16638
16915
|
function legacyCompromises(compilerOptions, preset) {
|
|
16639
16916
|
const stack = preset !== void 0 && hasShippedPreset(preset) ? tsPresetFor(preset).compilerOptions : {};
|
|
16640
|
-
const
|
|
16917
|
+
const applied2 = appliedOptions({ compilerOptions: stack });
|
|
16641
16918
|
return Object.entries(tsLegacyLayer().compilerOptions).filter(
|
|
16642
16919
|
([key]) => !(key in stack) && !(compilerOptions !== void 0 && key in compilerOptions)
|
|
16643
16920
|
).map(([key, value]) => {
|
|
16644
|
-
const standard =
|
|
16921
|
+
const standard = applied2.has(key) ? JSON.parse(applied2.get(key) ?? "null") : null;
|
|
16645
16922
|
return {
|
|
16646
16923
|
rule: key,
|
|
16647
16924
|
value,
|
|
@@ -16696,8 +16973,8 @@ function readTsconfigAdoption(cwd) {
|
|
|
16696
16973
|
}
|
|
16697
16974
|
|
|
16698
16975
|
// src/roles/typescript/adapters/tsc/plan.ts
|
|
16699
|
-
import { readFileSync as
|
|
16700
|
-
import { join as
|
|
16976
|
+
import { readFileSync as readFileSync30 } from "node:fs";
|
|
16977
|
+
import { join as join53 } from "node:path";
|
|
16701
16978
|
|
|
16702
16979
|
// src/roles/typescript/typecheck-script.ts
|
|
16703
16980
|
var SENTINEL_TYPECHECK_COMMAND = "sentinel --run --typescript";
|
|
@@ -16792,7 +17069,7 @@ function planAdoption(context2) {
|
|
|
16792
17069
|
};
|
|
16793
17070
|
}
|
|
16794
17071
|
const existing = parseJsonc(
|
|
16795
|
-
|
|
17072
|
+
readFileSync30(join53(context2.cwd, target.path), "utf8"),
|
|
16796
17073
|
target.path
|
|
16797
17074
|
);
|
|
16798
17075
|
const extendsChain = composeExtends(existing.extends, preset);
|
|
@@ -16852,10 +17129,10 @@ var PHASED_STRICTNESS_WARNING = `sentinel typescript: phase 1 (non-breaking) \u2
|
|
|
16852
17129
|
var TSCONFIG_FILE = /^tsconfig.*\.json$/;
|
|
16853
17130
|
function configStateOf(reason, moduleDir) {
|
|
16854
17131
|
if (reason !== "extends-base") return reason;
|
|
16855
|
-
const onBase =
|
|
17132
|
+
const onBase = readdirSync6(moduleDir).filter((name) => TSCONFIG_FILE.test(name)).some((name) => {
|
|
16856
17133
|
try {
|
|
16857
17134
|
const config = parseJsonc(
|
|
16858
|
-
|
|
17135
|
+
readFileSync31(join54(moduleDir, name), "utf8"),
|
|
16859
17136
|
name
|
|
16860
17137
|
);
|
|
16861
17138
|
return extendsList(config).some(isBaseEntry);
|
|
@@ -16946,7 +17223,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
16946
17223
|
let chain;
|
|
16947
17224
|
try {
|
|
16948
17225
|
const parsed2 = parseJsonc(
|
|
16949
|
-
|
|
17226
|
+
readFileSync31(join54(cwd, target.path), "utf8"),
|
|
16950
17227
|
target.path
|
|
16951
17228
|
);
|
|
16952
17229
|
chain = parsed2.extends;
|
|
@@ -16959,7 +17236,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
16959
17236
|
);
|
|
16960
17237
|
if (preset === void 0) return void 0;
|
|
16961
17238
|
try {
|
|
16962
|
-
createRequire(
|
|
17239
|
+
createRequire(join54(cwd, "noop.js")).resolve(preset);
|
|
16963
17240
|
return void 0;
|
|
16964
17241
|
} catch {
|
|
16965
17242
|
return preset;
|
|
@@ -17055,7 +17332,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
17055
17332
|
referencedProjects(cwd, config) {
|
|
17056
17333
|
try {
|
|
17057
17334
|
const parsed2 = parseJsonc(
|
|
17058
|
-
|
|
17335
|
+
readFileSync31(join54(cwd, config), "utf8"),
|
|
17059
17336
|
config
|
|
17060
17337
|
);
|
|
17061
17338
|
const referenced = (parsed2.references ?? []).map((reference) => reference.path).filter((path2) => typeof path2 === "string" && path2.length > 0);
|
|
@@ -17071,7 +17348,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
17071
17348
|
* check.
|
|
17072
17349
|
*/
|
|
17073
17350
|
typecheckTarget(cwd) {
|
|
17074
|
-
if (existsSync34(
|
|
17351
|
+
if (existsSync34(join54(cwd, "tsconfig.json"))) return "tsconfig.json";
|
|
17075
17352
|
const target = resolveTsconfigTarget(cwd);
|
|
17076
17353
|
return target.reason === "none" ? null : target.path;
|
|
17077
17354
|
}
|
|
@@ -17084,7 +17361,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
17084
17361
|
const target = resolveTsconfigTarget(ctx.cwd);
|
|
17085
17362
|
const { preset } = readTsconfigAdoption(ctx.cwd);
|
|
17086
17363
|
const stack = preset === null ? void 0 : preset.slice(preset.lastIndexOf("/") + 1);
|
|
17087
|
-
const config = this.readConfig(
|
|
17364
|
+
const config = this.readConfig(join54(ctx.cwd, target.path));
|
|
17088
17365
|
const options = config?.compilerOptions;
|
|
17089
17366
|
const overrides = standardOverrides(options, stack);
|
|
17090
17367
|
const legacy = config !== void 0 && extendsList(config).some(isLegacyEntry) ? legacyCompromises(options, stack) : [];
|
|
@@ -17102,7 +17379,7 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
17102
17379
|
readConfig(file) {
|
|
17103
17380
|
if (!existsSync34(file)) return void 0;
|
|
17104
17381
|
try {
|
|
17105
|
-
return parseJsonc(
|
|
17382
|
+
return parseJsonc(readFileSync31(file, "utf8"), file);
|
|
17106
17383
|
} catch {
|
|
17107
17384
|
return void 0;
|
|
17108
17385
|
}
|
|
@@ -17298,7 +17575,7 @@ function replaceLines(current, replacements) {
|
|
|
17298
17575
|
}
|
|
17299
17576
|
|
|
17300
17577
|
// src/core/apply-plan.ts
|
|
17301
|
-
import { existsSync as existsSync35, readFileSync as
|
|
17578
|
+
import { existsSync as existsSync35, readFileSync as readFileSync32, renameSync, rmSync as rmSync8, writeFileSync as writeFileSync15 } from "node:fs";
|
|
17302
17579
|
import { resolve as resolve5, sep as sep7 } from "node:path";
|
|
17303
17580
|
import { applyEdits, findNodeAtLocation, modify, parseTree } from "jsonc-parser";
|
|
17304
17581
|
function resolveWithinRoot(cwd, relativePath) {
|
|
@@ -17310,7 +17587,7 @@ function resolveWithinRoot(cwd, relativePath) {
|
|
|
17310
17587
|
return absolutePath;
|
|
17311
17588
|
}
|
|
17312
17589
|
function readIfExists(absolutePath) {
|
|
17313
|
-
return existsSync35(absolutePath) ?
|
|
17590
|
+
return existsSync35(absolutePath) ? readFileSync32(absolutePath, "utf8") : void 0;
|
|
17314
17591
|
}
|
|
17315
17592
|
function* leaves(value, prefix = []) {
|
|
17316
17593
|
for (const [key, keyValue] of Object.entries(value)) {
|
|
@@ -17428,8 +17705,8 @@ function applyPlan(cwd, plan3) {
|
|
|
17428
17705
|
}
|
|
17429
17706
|
|
|
17430
17707
|
// src/core/config/preset-evidence.ts
|
|
17431
|
-
import { existsSync as existsSync36, readdirSync as
|
|
17432
|
-
import { join as
|
|
17708
|
+
import { existsSync as existsSync36, readdirSync as readdirSync7, readFileSync as readFileSync33 } from "node:fs";
|
|
17709
|
+
import { join as join55 } from "node:path";
|
|
17433
17710
|
var PATH_SIGNALS = [
|
|
17434
17711
|
{
|
|
17435
17712
|
preset: "nest",
|
|
@@ -17457,18 +17734,18 @@ function sourceImports(cwd, pattern) {
|
|
|
17457
17734
|
const dir = stack.pop();
|
|
17458
17735
|
let entries;
|
|
17459
17736
|
try {
|
|
17460
|
-
entries =
|
|
17737
|
+
entries = readdirSync7(dir, { withFileTypes: true });
|
|
17461
17738
|
} catch {
|
|
17462
17739
|
continue;
|
|
17463
17740
|
}
|
|
17464
17741
|
for (const entry of entries) {
|
|
17465
17742
|
if (entry.isDirectory()) {
|
|
17466
|
-
if (!NOT_SCANNED.has(entry.name)) stack.push(
|
|
17743
|
+
if (!NOT_SCANNED.has(entry.name)) stack.push(join55(dir, entry.name));
|
|
17467
17744
|
continue;
|
|
17468
17745
|
}
|
|
17469
17746
|
if (!SOURCE_FILE.test(entry.name)) continue;
|
|
17470
17747
|
try {
|
|
17471
|
-
if (pattern.test(
|
|
17748
|
+
if (pattern.test(readFileSync33(join55(dir, entry.name), "utf8"))) return true;
|
|
17472
17749
|
} catch {
|
|
17473
17750
|
continue;
|
|
17474
17751
|
}
|
|
@@ -17477,11 +17754,11 @@ function sourceImports(cwd, pattern) {
|
|
|
17477
17754
|
return false;
|
|
17478
17755
|
}
|
|
17479
17756
|
function dependencyNames(cwd) {
|
|
17480
|
-
const path2 =
|
|
17757
|
+
const path2 = join55(cwd, "package.json");
|
|
17481
17758
|
if (!existsSync36(path2)) return [];
|
|
17482
17759
|
try {
|
|
17483
17760
|
const manifest = parseJsonc(
|
|
17484
|
-
|
|
17761
|
+
readFileSync33(path2, "utf8"),
|
|
17485
17762
|
path2
|
|
17486
17763
|
);
|
|
17487
17764
|
return [
|
|
@@ -17496,7 +17773,7 @@ var REACT_TYPESCRIPT_PRESET = "@hublo/sentinel/typescript/react";
|
|
|
17496
17773
|
function reactTsconfigEvidence(cwd) {
|
|
17497
17774
|
let entries;
|
|
17498
17775
|
try {
|
|
17499
|
-
entries =
|
|
17776
|
+
entries = readdirSync7(cwd).filter(
|
|
17500
17777
|
(name) => name.startsWith("tsconfig") && name.endsWith(".json")
|
|
17501
17778
|
);
|
|
17502
17779
|
} catch {
|
|
@@ -17504,7 +17781,7 @@ function reactTsconfigEvidence(cwd) {
|
|
|
17504
17781
|
}
|
|
17505
17782
|
for (const name of entries) {
|
|
17506
17783
|
try {
|
|
17507
|
-
const config = parseJsonc(
|
|
17784
|
+
const config = parseJsonc(readFileSync33(join55(cwd, name), "utf8"), name);
|
|
17508
17785
|
if (config.compilerOptions?.jsx !== void 0) return 'its tsconfig sets "jsx"';
|
|
17509
17786
|
const extended = Array.isArray(config.extends) ? config.extends : config.extends === void 0 ? [] : [config.extends];
|
|
17510
17787
|
if (extended.some((entry) => entry === REACT_TYPESCRIPT_PRESET)) {
|