@hublo/sentinel 1.7.0-alpha.3 → 1.7.0-alpha.30
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/README.md +3 -0
- package/dist/bin/sentinel.js +88 -81
- package/dist/{chunk-P6KTBQ2Q.js → chunk-2PRJJRJI.js} +24 -15
- package/dist/{chunk-THTXP2QU.js → chunk-APBEGLRI.js} +6 -6
- package/dist/chunk-APBEGLRI.js.map +1 -0
- package/dist/{chunk-F6ART7RH.js → chunk-HYXFUUF5.js} +14959 -6817
- package/dist/{chunk-4YQXLPJ5.js → chunk-LVY5NPOC.js} +2 -2
- package/dist/chunk-PXTU5MPW.js +9 -0
- package/dist/chunk-PXTU5MPW.js.map +1 -0
- package/dist/chunk-SHF46ALB.js +190 -0
- package/dist/chunk-SHF46ALB.js.map +1 -0
- package/dist/chunk-TMVKYXZ3.js +18 -0
- package/dist/chunk-TMVKYXZ3.js.map +1 -0
- package/dist/chunk-XYOIXC6A.js +126 -0
- package/dist/chunk-XYOIXC6A.js.map +1 -0
- package/dist/{chunk-ZNANJEMK.js → chunk-YUZB4LRJ.js} +35 -16
- package/dist/chunk-YUZB4LRJ.js.map +1 -0
- package/dist/chunk-ZZMYV576.js +297 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -5
- package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
- package/dist/roles/arch/config.d.ts +25 -0
- package/dist/roles/arch/config.js +8 -0
- package/dist/roles/arch/config.js.map +1 -0
- package/dist/roles/build/nest/toolchain.js +3 -3
- package/dist/roles/code-churn/config.d.ts +92 -0
- package/dist/roles/code-churn/config.js +10 -0
- package/dist/roles/code-churn/config.js.map +1 -0
- package/dist/roles/sql/config.d.ts +68 -0
- package/dist/roles/sql/config.js +8 -0
- package/dist/roles/sql/config.js.map +1 -0
- package/dist/roles/static-analysis/config.js +2 -1
- package/dist/roles/test/setup/file-boundary.js +3 -3
- package/dist/roles/test/setup/jest-parity.js +4 -4
- package/dist/roles/test/setup/workspace-entry.js +2 -2
- package/dist/{validate-4V3EGTXN.js → validate-4GMB32V7.js} +2 -2
- package/docs/arch-adoption.md +201 -0
- package/docs/code-churn-adoption.md +237 -0
- package/docs/sql-adoption.md +672 -0
- package/docs/static-analysis-adoption.md +1 -1
- package/docs/static-analysis-study.md +49 -10
- package/docs/typescript-adoption.md +47 -6
- package/docs/typescript-traces.md +546 -6
- package/docs/using-sentinel.md +4 -2
- package/package.json +17 -1
- package/dist/chunk-THTXP2QU.js.map +0 -1
- package/dist/chunk-ZNANJEMK.js.map +0 -1
- /package/dist/{chunk-4YQXLPJ5.js.map → chunk-LVY5NPOC.js.map} +0 -0
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LEGACY_ENTRY,
|
|
3
|
+
appliedOptions,
|
|
4
|
+
diffConfigs,
|
|
5
|
+
extendsList,
|
|
6
|
+
isBaseEntry,
|
|
7
|
+
isStackPresetEntry,
|
|
8
|
+
remainder
|
|
9
|
+
} from "./chunk-ZZMYV576.js";
|
|
1
10
|
import {
|
|
2
11
|
binFromOwnInstall,
|
|
3
12
|
resolveBin,
|
|
@@ -11,96 +20,11 @@ import {
|
|
|
11
20
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
12
21
|
import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
13
22
|
import { createRequire } from "node:module";
|
|
14
|
-
import { dirname as dirname2, join, relative as relative2, resolve as resolve2 } from "node:path";
|
|
23
|
+
import { dirname as dirname2, isAbsolute, join, relative as relative2, resolve as resolve2 } from "node:path";
|
|
15
24
|
import { stripComments } from "jsonc-parser";
|
|
16
25
|
|
|
17
|
-
// src/roles/typescript/migrate/compare.ts
|
|
18
|
-
var STRICT_FAMILY = [
|
|
19
|
-
"alwaysStrict",
|
|
20
|
-
"noImplicitAny",
|
|
21
|
-
"noImplicitThis",
|
|
22
|
-
"strictBindCallApply",
|
|
23
|
-
"strictBuiltinIteratorReturn",
|
|
24
|
-
"strictFunctionTypes",
|
|
25
|
-
"strictNullChecks",
|
|
26
|
-
"strictPropertyInitialization",
|
|
27
|
-
"useUnknownInCatchVariables"
|
|
28
|
-
];
|
|
29
|
-
var CASE_INSENSITIVE = /* @__PURE__ */ new Set([
|
|
30
|
-
"jsx",
|
|
31
|
-
"lib",
|
|
32
|
-
"module",
|
|
33
|
-
"moduleDetection",
|
|
34
|
-
"moduleResolution",
|
|
35
|
-
"target"
|
|
36
|
-
]);
|
|
37
|
-
function targetYear(target) {
|
|
38
|
-
const name = typeof target === "string" ? target.toLowerCase() : "es5";
|
|
39
|
-
if (name === "esnext") return Number.MAX_SAFE_INTEGER;
|
|
40
|
-
const year = Number(name.replace(/^es/, ""));
|
|
41
|
-
return Number.isFinite(year) ? year : 5;
|
|
42
|
-
}
|
|
43
|
-
function comparable(key, value) {
|
|
44
|
-
const json = JSON.stringify(value) ?? "undefined";
|
|
45
|
-
return CASE_INSENSITIVE.has(key) ? json.toLowerCase() : json;
|
|
46
|
-
}
|
|
47
|
-
function appliedOptions(config) {
|
|
48
|
-
const options = new Map(Object.entries(config.compilerOptions ?? {}));
|
|
49
|
-
options.delete("paths");
|
|
50
|
-
const derive = (key, value) => {
|
|
51
|
-
if (!options.has(key)) options.set(key, value);
|
|
52
|
-
};
|
|
53
|
-
if (options.get("strict") === true) for (const key of STRICT_FAMILY) derive(key, true);
|
|
54
|
-
derive("allowJs", false);
|
|
55
|
-
if (options.get("esModuleInterop") === true) derive("allowSyntheticDefaultImports", true);
|
|
56
|
-
if (options.get("verbatimModuleSyntax") === true) derive("isolatedModules", true);
|
|
57
|
-
if (options.get("isolatedModules") === true) derive("preserveConstEnums", true);
|
|
58
|
-
derive("useDefineForClassFields", targetYear(options.get("target")) >= 2022);
|
|
59
|
-
return new Map([...options].map(([key, value]) => [key, comparable(key, value)]));
|
|
60
|
-
}
|
|
61
|
-
function diffConfigs(before, after) {
|
|
62
|
-
const was = appliedOptions(before);
|
|
63
|
-
const now = appliedOptions(after);
|
|
64
|
-
const differences = [];
|
|
65
|
-
for (const key of /* @__PURE__ */ new Set([...was.keys(), ...now.keys()])) {
|
|
66
|
-
if (was.get(key) !== now.get(key)) {
|
|
67
|
-
differences.push({ key: `compilerOptions.${key}`, before: was.get(key), after: now.get(key) });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
71
|
-
if (key === "compilerOptions") continue;
|
|
72
|
-
const left = JSON.stringify(before[key]);
|
|
73
|
-
const right = JSON.stringify(after[key]);
|
|
74
|
-
if (left !== right) differences.push({ key, before: left, after: right });
|
|
75
|
-
}
|
|
76
|
-
return differences;
|
|
77
|
-
}
|
|
78
|
-
function remainder(effective, layers, ownKeys) {
|
|
79
|
-
const applied = appliedOptions(effective);
|
|
80
|
-
const given = appliedOptions(layers);
|
|
81
|
-
const written = [];
|
|
82
|
-
for (const [key, value] of applied) {
|
|
83
|
-
if (ownKeys.has(key) || given.get(key) === value) continue;
|
|
84
|
-
written.push({ key, value: effective.compilerOptions?.[key] ?? JSON.parse(value) });
|
|
85
|
-
}
|
|
86
|
-
return written;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
26
|
// src/roles/typescript/migrate/detach.ts
|
|
90
27
|
import { dirname, posix, relative, resolve, sep } from "node:path";
|
|
91
|
-
var BASE_FILE = "tsconfig.base.json";
|
|
92
|
-
var LEGACY_ENTRY = "@hublo/sentinel/typescript/legacy";
|
|
93
|
-
function isBaseEntry(entry) {
|
|
94
|
-
return entry === BASE_FILE || entry.endsWith(`/${BASE_FILE}`);
|
|
95
|
-
}
|
|
96
|
-
function isStackPresetEntry(entry) {
|
|
97
|
-
return /^@hublo\/sentinel\/(?:typescript|tsconfig)\/(?!legacy$)[a-z-]+$/.test(entry);
|
|
98
|
-
}
|
|
99
|
-
function extendsList(config) {
|
|
100
|
-
const value = config.extends;
|
|
101
|
-
if (typeof value === "string") return [value];
|
|
102
|
-
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
103
|
-
}
|
|
104
28
|
function rebaseTarget(target, pathsRoot, directory) {
|
|
105
29
|
const moved = relative(directory, resolve(pathsRoot, target)).split(sep).join(posix.sep);
|
|
106
30
|
const kept = target.endsWith("/") && !moved.endsWith("/") ? `${moved}/` : moved;
|
|
@@ -155,7 +79,7 @@ function parseTrace(text) {
|
|
|
155
79
|
const patterns = /* @__PURE__ */ new Set();
|
|
156
80
|
let open;
|
|
157
81
|
let afterPathsLine = false;
|
|
158
|
-
for (const line of text.split(
|
|
82
|
+
for (const line of text.split(/\r?\n/)) {
|
|
159
83
|
const isPathsMatch = afterPathsLine;
|
|
160
84
|
afterPathsLine = line.startsWith("'paths' option is specified");
|
|
161
85
|
const resolving = RESOLVING_MODULE.exec(line) ?? RESOLVING_TYPE.exec(line);
|
|
@@ -186,9 +110,10 @@ function diffResolutions(before, after) {
|
|
|
186
110
|
for (const key of /* @__PURE__ */ new Set([...before.keys(), ...after.keys()])) {
|
|
187
111
|
const was = before.get(key);
|
|
188
112
|
const now = after.get(key);
|
|
189
|
-
if (was === now) continue;
|
|
113
|
+
if (was === now && before.has(key) === after.has(key)) continue;
|
|
190
114
|
const [from, name] = key.split("\0");
|
|
191
|
-
|
|
115
|
+
const say = (side, value) => side.has(key) ? value ?? "unresolved" : "absent";
|
|
116
|
+
lines.push(`${from ?? ""}: '${name ?? ""}' ${say(before, was)} -> ${say(after, now)}`);
|
|
192
117
|
}
|
|
193
118
|
return lines;
|
|
194
119
|
}
|
|
@@ -204,25 +129,33 @@ function readTsconfig(file) {
|
|
|
204
129
|
function tscFor(directory) {
|
|
205
130
|
return resolveBin(directory, "tsc") ?? binFromOwnInstall("typescript", "tsc") ?? "tsc";
|
|
206
131
|
}
|
|
132
|
+
var TSC_OUTPUT_LIMIT = 512 * 1024 * 1024;
|
|
207
133
|
function tsc(directory, tsconfig, extra) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
134
|
+
const command = `tsc -p ${tsconfig} ${extra.join(" ")}`;
|
|
135
|
+
const run = spawnSync(tscFor(directory), ["-p", tsconfig, ...extra], {
|
|
136
|
+
cwd: directory,
|
|
137
|
+
encoding: "utf8",
|
|
138
|
+
maxBuffer: TSC_OUTPUT_LIMIT,
|
|
139
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
140
|
+
});
|
|
141
|
+
if (run.error !== void 0)
|
|
142
|
+
throw new Error(`${command}: ${run.error.message}`, { cause: run.error });
|
|
143
|
+
if (run.signal !== null) throw new Error(`${command}: killed by ${run.signal}`);
|
|
144
|
+
if (run.status === 0) return run.stdout;
|
|
145
|
+
const typeErrors = run.status === 1 || run.status === 2;
|
|
146
|
+
if (typeErrors && run.stdout.length > 0) return run.stdout;
|
|
147
|
+
const said = run.stderr.trim() || run.stdout.trim() || `exit ${String(run.status)}, no output`;
|
|
148
|
+
throw new Error(`${command}: ${said}`);
|
|
223
149
|
}
|
|
224
150
|
function showConfig(directory, tsconfig) {
|
|
225
|
-
|
|
151
|
+
const printed = tsc(directory, tsconfig, ["--showConfig"]);
|
|
152
|
+
try {
|
|
153
|
+
return JSON.parse(printed);
|
|
154
|
+
} catch {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`tsc --showConfig on ${join(directory, tsconfig)} did not print a config: ${printed.trim().slice(0, 300)}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
226
159
|
}
|
|
227
160
|
function withProbe(directory, config, use) {
|
|
228
161
|
writeFileSync(join(directory, PROBE), JSON.stringify(config));
|
|
@@ -233,7 +166,8 @@ function withProbe(directory, config, use) {
|
|
|
233
166
|
}
|
|
234
167
|
}
|
|
235
168
|
function compilesFiles(config) {
|
|
236
|
-
|
|
169
|
+
const empty = (list) => Array.isArray(list) && list.length === 0;
|
|
170
|
+
return !(empty(config.files) && (config.include === void 0 || empty(config.include)));
|
|
237
171
|
}
|
|
238
172
|
function inheritors(directory, names, target) {
|
|
239
173
|
const reaches = (name, seen) => {
|
|
@@ -254,20 +188,25 @@ function owner(file, directory) {
|
|
|
254
188
|
}
|
|
255
189
|
return directory;
|
|
256
190
|
}
|
|
257
|
-
function
|
|
191
|
+
function moduleFiles(directory) {
|
|
192
|
+
let listed;
|
|
258
193
|
try {
|
|
259
|
-
|
|
194
|
+
listed = execFileSync("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
|
|
195
|
+
cwd: directory,
|
|
196
|
+
encoding: "utf8"
|
|
197
|
+
});
|
|
260
198
|
} catch {
|
|
261
199
|
return void 0;
|
|
262
200
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const listed = new Set(
|
|
266
|
-
chained.flatMap(
|
|
267
|
-
(name) => tsc(directory, name, ["--listFilesOnly"]).split("\n").map((line) => line.trim()).filter(Boolean)
|
|
268
|
-
)
|
|
201
|
+
return [...new Set(listed.split("\0").filter(Boolean))].filter(
|
|
202
|
+
(name) => existsSync(join(directory, name))
|
|
269
203
|
);
|
|
270
|
-
|
|
204
|
+
}
|
|
205
|
+
function programFiles(directory, name) {
|
|
206
|
+
return tsc(directory, name, ["--listFilesOnly"]).split(/\r?\n/).map((line) => line.trim()).filter((line) => isAbsolute(line));
|
|
207
|
+
}
|
|
208
|
+
function outsidePrograms(directory, listed, files) {
|
|
209
|
+
return files.filter((name) => SOURCE.test(name) && !name.endsWith(".d.ts")).map((name) => join(directory, name)).filter((file) => existsSync(file) && !listed.has(file) && owner(file, directory) === directory);
|
|
271
210
|
}
|
|
272
211
|
function trace(directory, name) {
|
|
273
212
|
return parseTrace(tsc(directory, name, ["--noEmit", "--traceResolution"]));
|
|
@@ -302,29 +241,47 @@ function sentinelInstalls(directory, presets) {
|
|
|
302
241
|
if (legacy === void 0) return "no-legacy";
|
|
303
242
|
return presets.every((preset) => packageRoot(preset) === legacy) ? "one" : "several";
|
|
304
243
|
}
|
|
305
|
-
function
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
244
|
+
function refused(file, refusal, reason) {
|
|
245
|
+
return { file, kept: false, refusal, reason };
|
|
246
|
+
}
|
|
247
|
+
function refuseEarly(directory, shown, original, chain) {
|
|
309
248
|
if (stripComments(original) !== original) {
|
|
310
|
-
return
|
|
249
|
+
return refused(shown, "comments", "it has comments a rewrite would drop; left as is");
|
|
311
250
|
}
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
251
|
+
const installs = sentinelInstalls(directory, chain.filter(isStackPresetEntry));
|
|
252
|
+
if (installs === "no-legacy") {
|
|
253
|
+
return refused(
|
|
254
|
+
shown,
|
|
255
|
+
"no-legacy",
|
|
256
|
+
`${LEGACY_ENTRY} does not resolve from this module: bump its @hublo/sentinel to the version running this command, run \`pnpm install\`, and run it again`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (installs === "several") {
|
|
260
|
+
return refused(
|
|
261
|
+
shown,
|
|
262
|
+
"several-installs",
|
|
263
|
+
`${LEGACY_ENTRY} and the stack preset resolve from two different @hublo/sentinel installs here; give this module one sentinel version and run \`pnpm install\``
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return void 0;
|
|
267
|
+
}
|
|
268
|
+
function baseline(directory, target, names, files) {
|
|
320
269
|
const chained = inheritors(directory, names, target).filter(
|
|
321
270
|
(name) => compilesFiles(readTsconfig(join(directory, name)))
|
|
322
271
|
);
|
|
323
272
|
const before = new Map(names.map((name) => [name, showConfig(directory, name)]));
|
|
273
|
+
const listed = new Map(chained.map((name) => [name, programFiles(directory, name)]));
|
|
274
|
+
const empty = new Set(chained.filter((name) => listed.get(name)?.length === 0));
|
|
324
275
|
const traces = new Map(chained.map((name) => [name, trace(directory, name)]));
|
|
325
|
-
const
|
|
326
|
-
const outside =
|
|
276
|
+
const compiled = new Set([...listed.values()].flat());
|
|
277
|
+
const outside = files === void 0 ? [] : outsidePrograms(directory, compiled, files);
|
|
327
278
|
if (outside.length > 0) traces.set(OUTSIDE, traceOutside(directory, target, outside));
|
|
279
|
+
return { before, traces, outside, empty };
|
|
280
|
+
}
|
|
281
|
+
function planDetach(directory, config, chain, effective, traces) {
|
|
282
|
+
const baseFile = resolve2(directory, chain.find(isBaseEntry) ?? "");
|
|
283
|
+
const base = readTsconfig(baseFile);
|
|
284
|
+
const basePaths = base.compilerOptions?.paths ?? {};
|
|
328
285
|
const matched = new Set([...traces.values()].flatMap((one) => [...one.patterns]));
|
|
329
286
|
const paths = pickPaths(
|
|
330
287
|
basePaths,
|
|
@@ -332,21 +289,11 @@ function migrateTsconfig(directory, target, names, options) {
|
|
|
332
289
|
pathsRootOf(baseFile, base.compilerOptions?.baseUrl),
|
|
333
290
|
directory
|
|
334
291
|
);
|
|
335
|
-
const effective = before.get(target) ?? {};
|
|
336
|
-
const withoutBase = chain.filter((entry) => !isBaseEntry(entry));
|
|
337
292
|
const inputs = Object.fromEntries(
|
|
338
293
|
["files", "include", "references"].filter((key) => key in config).map((key) => [key, config[key]])
|
|
339
294
|
);
|
|
340
295
|
const layers = (entries) => withProbe(directory, { extends: entries, ...inputs }, (probe) => showConfig(directory, probe));
|
|
341
|
-
const
|
|
342
|
-
if (installs !== "one") {
|
|
343
|
-
return {
|
|
344
|
-
file: shown,
|
|
345
|
-
kept: false,
|
|
346
|
-
reason: installs === "no-legacy" ? `${LEGACY_ENTRY} does not resolve from this module: bump its @hublo/sentinel to the version running this command, run \`pnpm install\`, and run it again` : `${LEGACY_ENTRY} and the stack preset resolve from two different @hublo/sentinel installs here; give this module one sentinel version and run \`pnpm install\``
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
const stack = layers(withoutBase);
|
|
296
|
+
const stack = layers(chain.filter((entry) => !isBaseEntry(entry)));
|
|
350
297
|
const withLegacy = layers(chain.map((entry) => isBaseEntry(entry) ? LEGACY_ENTRY : entry));
|
|
351
298
|
const stackApplied = appliedOptions(stack);
|
|
352
299
|
const legacyKeys = new Set(
|
|
@@ -359,22 +306,14 @@ function migrateTsconfig(directory, target, names, options) {
|
|
|
359
306
|
({ key }) => key !== "paths"
|
|
360
307
|
);
|
|
361
308
|
const exclude = config.exclude === void 0 ? effective.exclude : void 0;
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
resolutions: [...traces.values()].reduce((sum, one) => sum + one.resolutions.size, 0),
|
|
368
|
-
outsidePrograms: outside.map((path) => relative2(directory, path))
|
|
369
|
-
};
|
|
370
|
-
let kept = false;
|
|
309
|
+
return { paths, legacy, copied, exclude, aliasesOfBase: Object.keys(basePaths).length };
|
|
310
|
+
}
|
|
311
|
+
function proveRewrite(directory, target, names, contents, { before, traces, outside }) {
|
|
312
|
+
const file = join(directory, target);
|
|
313
|
+
const original = readFileSync(file, "utf8");
|
|
371
314
|
writeFileSync(`${file}${ORIGINAL}`, original);
|
|
372
315
|
try {
|
|
373
|
-
writeFileSync(
|
|
374
|
-
file,
|
|
375
|
-
`${JSON.stringify(detachedConfig({ config, legacy, copied, paths, exclude }), null, 2)}
|
|
376
|
-
`
|
|
377
|
-
);
|
|
316
|
+
writeFileSync(file, contents);
|
|
378
317
|
const configDifferences = names.flatMap(
|
|
379
318
|
(name) => diffConfigs(before.get(name) ?? {}, showConfig(directory, name)).map((difference) => ({
|
|
380
319
|
...difference,
|
|
@@ -387,24 +326,65 @@ function migrateTsconfig(directory, target, names, options) {
|
|
|
387
326
|
(name === OUTSIDE ? traceOutside(directory, target, outside) : trace(directory, name)).resolutions
|
|
388
327
|
).map((line) => `${name}: ${line}`)
|
|
389
328
|
);
|
|
390
|
-
|
|
391
|
-
kept = proved && options.write;
|
|
392
|
-
return {
|
|
393
|
-
...report,
|
|
394
|
-
kept,
|
|
395
|
-
...proved ? {} : { reason: "tsc does not agree before and after; restored" },
|
|
396
|
-
configDifferences,
|
|
397
|
-
resolutionDifferences
|
|
398
|
-
};
|
|
329
|
+
return { configDifferences, resolutionDifferences };
|
|
399
330
|
} finally {
|
|
400
|
-
|
|
331
|
+
writeFileSync(file, original);
|
|
401
332
|
unlinkSync(`${file}${ORIGINAL}`);
|
|
402
333
|
}
|
|
403
334
|
}
|
|
404
|
-
function
|
|
335
|
+
function proveTsconfig(directory, target, names, files, workspaceRoot) {
|
|
336
|
+
const file = join(directory, target);
|
|
337
|
+
const shown = relative2(workspaceRoot, file);
|
|
338
|
+
const original = readFileSync(file, "utf8");
|
|
339
|
+
const config = readTsconfig(file);
|
|
340
|
+
const chain = extendsList(config);
|
|
341
|
+
const early = refuseEarly(directory, shown, original, chain);
|
|
342
|
+
if (early !== void 0) return { result: early };
|
|
343
|
+
const known = baseline(directory, target, names, files);
|
|
344
|
+
const unread = [...known.traces].filter(
|
|
345
|
+
([name, one]) => name !== OUTSIDE && !known.empty.has(name) && one.resolutions.size === 0
|
|
346
|
+
);
|
|
347
|
+
if (unread.length > 0) {
|
|
348
|
+
return {
|
|
349
|
+
result: refused(
|
|
350
|
+
shown,
|
|
351
|
+
"no-trace",
|
|
352
|
+
`tsc --traceResolution printed no resolution sentinel could read for ${unread.map(([name]) => name).join(", ")}; nothing can be proved`
|
|
353
|
+
)
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
const plan = planDetach(directory, config, chain, known.before.get(target) ?? {}, known.traces);
|
|
357
|
+
const contents = `${JSON.stringify(
|
|
358
|
+
detachedConfig({
|
|
359
|
+
config,
|
|
360
|
+
legacy: plan.legacy,
|
|
361
|
+
copied: plan.copied,
|
|
362
|
+
paths: plan.paths,
|
|
363
|
+
exclude: plan.exclude
|
|
364
|
+
}),
|
|
365
|
+
null,
|
|
366
|
+
2
|
|
367
|
+
)}
|
|
368
|
+
`;
|
|
369
|
+
const differences = proveRewrite(directory, target, names, contents, known);
|
|
370
|
+
const agrees = differences.configDifferences.length === 0 && differences.resolutionDifferences.length === 0;
|
|
371
|
+
const result = {
|
|
372
|
+
file: shown,
|
|
373
|
+
kept: false,
|
|
374
|
+
...agrees ? {} : { refusal: "disagrees", reason: "tsc does not agree before and after; restored" },
|
|
375
|
+
legacy: plan.legacy,
|
|
376
|
+
aliases: { kept: Object.keys(plan.paths).length, of: plan.aliasesOfBase },
|
|
377
|
+
written: plan.copied.map(({ key }) => key),
|
|
378
|
+
resolutions: [...known.traces.values()].reduce((sum, one) => sum + one.resolutions.size, 0),
|
|
379
|
+
outsidePrograms: known.outside.map((path) => relative2(directory, path)),
|
|
380
|
+
...differences
|
|
381
|
+
};
|
|
382
|
+
return agrees ? { result, contents } : { result };
|
|
383
|
+
}
|
|
384
|
+
function restoreInterrupted(moduleRoot, files, notes, workspaceRoot) {
|
|
405
385
|
const folders = /* @__PURE__ */ new Set([
|
|
406
386
|
moduleRoot,
|
|
407
|
-
...(
|
|
387
|
+
...(files ?? []).filter((name) => TSCONFIG_NAME.test(name.slice(name.lastIndexOf("/") + 1))).map((name) => join(moduleRoot, dirname2(name)))
|
|
408
388
|
]);
|
|
409
389
|
for (const folder of folders) {
|
|
410
390
|
for (const name of readdirSync(folder).filter((entry) => entry.endsWith(ORIGINAL))) {
|
|
@@ -417,9 +397,7 @@ function restoreInterrupted(moduleRoot, tracked, notes, workspaceRoot) {
|
|
|
417
397
|
}
|
|
418
398
|
}
|
|
419
399
|
function formatWritten(moduleRoot, files, notes, options) {
|
|
420
|
-
const proved = files.filter(
|
|
421
|
-
(one) => options.write ? one.kept : one.configDifferences?.length === 0 && one.resolutionDifferences?.length === 0
|
|
422
|
-
);
|
|
400
|
+
const proved = files.filter((one) => options.write ? one.kept : one.refusal === void 0);
|
|
423
401
|
if (proved.length === 0) return;
|
|
424
402
|
const formatter = writtenFileFormatter(moduleRoot);
|
|
425
403
|
if (formatter === void 0) {
|
|
@@ -444,10 +422,10 @@ function formatWritten(moduleRoot, files, notes, options) {
|
|
|
444
422
|
function isOwnModule(folder) {
|
|
445
423
|
return existsSync(join(folder, "package.json")) || existsSync(join(folder, "project.json"));
|
|
446
424
|
}
|
|
447
|
-
function foldersToMigrate(moduleRoot,
|
|
425
|
+
function foldersToMigrate(moduleRoot, files, notes) {
|
|
448
426
|
const nested = [
|
|
449
427
|
...new Set(
|
|
450
|
-
(
|
|
428
|
+
(files ?? []).filter(
|
|
451
429
|
(name) => TSCONFIG_NAME.test(name.slice(name.lastIndexOf("/") + 1)) && name.includes("/")
|
|
452
430
|
).map((name) => join(moduleRoot, dirname2(name)))
|
|
453
431
|
)
|
|
@@ -466,14 +444,83 @@ function foldersToMigrate(moduleRoot, tracked, notes) {
|
|
|
466
444
|
(folder) => readdirSync(folder).filter((name) => TSCONFIG_NAME.test(name) && name !== PROBE).some((name) => extendsList(readTsconfig(join(folder, name))).some(isBaseEntry))
|
|
467
445
|
);
|
|
468
446
|
}
|
|
447
|
+
function removeLeftProbe(folder, notes, workspaceRoot) {
|
|
448
|
+
if (!existsSync(join(folder, PROBE))) return;
|
|
449
|
+
unlinkSync(join(folder, PROBE));
|
|
450
|
+
notes.push(`removed ${relative2(workspaceRoot, join(folder, PROBE))}, left by an interrupted run`);
|
|
451
|
+
}
|
|
452
|
+
function proveFolder(folder, files, workspaceRoot) {
|
|
453
|
+
const names = readdirSync(folder).filter((name) => TSCONFIG_NAME.test(name) && name !== PROBE);
|
|
454
|
+
const targets = names.filter(
|
|
455
|
+
(name) => extendsList(readTsconfig(join(folder, name))).some(isBaseEntry)
|
|
456
|
+
);
|
|
457
|
+
return targets.map((target) => {
|
|
458
|
+
const shown = relative2(workspaceRoot, join(folder, target));
|
|
459
|
+
if (!extendsList(readTsconfig(join(folder, target))).some(isStackPresetEntry)) {
|
|
460
|
+
return {
|
|
461
|
+
result: refused(
|
|
462
|
+
shown,
|
|
463
|
+
"not-adopted",
|
|
464
|
+
"it extends the base but no sentinel preset: only an adopted module is detached. Run `sentinel --init --typescript` first"
|
|
465
|
+
)
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
try {
|
|
469
|
+
return proveTsconfig(folder, target, names, files, workspaceRoot);
|
|
470
|
+
} catch (error) {
|
|
471
|
+
return { result: refused(shown, "error", error.message) };
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
function markPartlyAdopted(proved) {
|
|
476
|
+
const adopted = proved.filter(({ result }) => result.refusal !== "not-adopted");
|
|
477
|
+
if (adopted.length === 0) return;
|
|
478
|
+
for (const one of proved) {
|
|
479
|
+
if (one.result.refusal !== "not-adopted") continue;
|
|
480
|
+
const name = one.result.file.slice(one.result.file.lastIndexOf("/") + 1);
|
|
481
|
+
one.result = {
|
|
482
|
+
...one.result,
|
|
483
|
+
refusal: "partly-adopted",
|
|
484
|
+
reason: `${name} extends the base without a sentinel preset, while this module's other tsconfigs are adopted: add the module's stack preset to its \`extends\` (or make it extend the adopted tsconfig), then run again`
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function summarize(results, write) {
|
|
489
|
+
const plural = (count) => `${count} tsconfig${count === 1 ? "" : "s"}`;
|
|
490
|
+
if (results.every((one) => one.refusal === "not-adopted")) {
|
|
491
|
+
return {
|
|
492
|
+
outcome: "blocked",
|
|
493
|
+
message: "this module is not adopted: run `sentinel --init --typescript` first. Nothing was written"
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
const refusals = results.filter((one) => one.refusal !== void 0);
|
|
497
|
+
if (refusals.length === 0) {
|
|
498
|
+
return write ? {
|
|
499
|
+
outcome: "migrated",
|
|
500
|
+
message: `detached ${plural(results.length)} from tsconfig.base.json`
|
|
501
|
+
} : {
|
|
502
|
+
outcome: "proved",
|
|
503
|
+
message: "dry run: tsc agrees before and after on every tsconfig; nothing was written"
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
const disagreeing = refusals.filter((one) => one.refusal === "disagrees").length;
|
|
507
|
+
const unproved = refusals.length - disagreeing;
|
|
508
|
+
const why = [
|
|
509
|
+
...disagreeing > 0 ? [`tsc does not agree on ${plural(disagreeing)}`] : [],
|
|
510
|
+
...unproved > 0 ? [`${plural(unproved)} could not be proved`] : []
|
|
511
|
+
].join(", ");
|
|
512
|
+
return { outcome: "failed", message: `${write ? "" : "dry run: "}${why}; nothing was written` };
|
|
513
|
+
}
|
|
469
514
|
function migrateModule(moduleRoot, options) {
|
|
470
515
|
const notes = [];
|
|
471
|
-
const
|
|
472
|
-
if (
|
|
473
|
-
notes.push(
|
|
516
|
+
const files = moduleFiles(moduleRoot);
|
|
517
|
+
if (files === void 0) {
|
|
518
|
+
notes.push(
|
|
519
|
+
"not a git checkout: the files outside every program were not traced, and only the module's own folder was checked for nested tsconfigs and for a run left interrupted"
|
|
520
|
+
);
|
|
474
521
|
}
|
|
475
|
-
restoreInterrupted(moduleRoot,
|
|
476
|
-
const folders = foldersToMigrate(moduleRoot,
|
|
522
|
+
restoreInterrupted(moduleRoot, files, notes, options.workspaceRoot);
|
|
523
|
+
const folders = foldersToMigrate(moduleRoot, files, notes);
|
|
477
524
|
if (folders.length === 0) {
|
|
478
525
|
return {
|
|
479
526
|
outcome: "skipped",
|
|
@@ -482,60 +529,22 @@ function migrateModule(moduleRoot, options) {
|
|
|
482
529
|
notes
|
|
483
530
|
};
|
|
484
531
|
}
|
|
485
|
-
const
|
|
532
|
+
const proved = [];
|
|
486
533
|
for (const folder of folders) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
notes.push(
|
|
490
|
-
`removed ${relative2(options.workspaceRoot, join(folder, PROBE))}, left by an interrupted run`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
const names = readdirSync(folder).filter((name) => TSCONFIG_NAME.test(name) && name !== PROBE);
|
|
494
|
-
const targets = names.filter(
|
|
495
|
-
(name) => extendsList(readTsconfig(join(folder, name))).some(isBaseEntry)
|
|
496
|
-
);
|
|
497
|
-
for (const target of targets) {
|
|
498
|
-
const chain = extendsList(readTsconfig(join(folder, target)));
|
|
499
|
-
if (!chain.some(isStackPresetEntry)) {
|
|
500
|
-
files.push({
|
|
501
|
-
file: relative2(options.workspaceRoot, join(folder, target)),
|
|
502
|
-
kept: false,
|
|
503
|
-
reason: "it extends the base but no sentinel preset: only an adopted module is detached. Run `sentinel --init --typescript` first"
|
|
504
|
-
});
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
files.push(migrateTsconfig(folder, target, names, options));
|
|
508
|
-
}
|
|
534
|
+
removeLeftProbe(folder, notes, options.workspaceRoot);
|
|
535
|
+
proved.push(...proveFolder(folder, files, options.workspaceRoot));
|
|
509
536
|
}
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
const
|
|
513
|
-
if (
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
files,
|
|
518
|
-
notes
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
const unproved = files.filter((one) => one.configDifferences === void 0);
|
|
522
|
-
if (!options.write) {
|
|
523
|
-
const proved = files.every(
|
|
524
|
-
(one) => one.configDifferences?.length === 0 && one.resolutionDifferences?.length === 0
|
|
525
|
-
);
|
|
526
|
-
return {
|
|
527
|
-
outcome: proved ? "proved" : "failed",
|
|
528
|
-
message: proved ? "dry run: tsc agrees before and after on every tsconfig; nothing was written" : unproved.length > 0 ? `dry run: ${unproved.length} tsconfig${unproved.length === 1 ? "" : "s"} could not be proved; nothing was written` : "dry run: tsc does not agree on every tsconfig; nothing was written",
|
|
529
|
-
files,
|
|
530
|
-
notes
|
|
531
|
-
};
|
|
537
|
+
markPartlyAdopted(proved);
|
|
538
|
+
const allHold = proved.every(({ result }) => result.refusal === void 0);
|
|
539
|
+
const write = options.write && allHold;
|
|
540
|
+
if (write) {
|
|
541
|
+
for (const { result, contents } of proved) {
|
|
542
|
+
writeFileSync(resolve2(options.workspaceRoot, result.file), contents ?? "");
|
|
543
|
+
}
|
|
532
544
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
files,
|
|
537
|
-
notes
|
|
538
|
-
};
|
|
545
|
+
const results = proved.map(({ result }) => ({ ...result, kept: write }));
|
|
546
|
+
formatWritten(moduleRoot, results, notes, options);
|
|
547
|
+
return { ...summarize(results, options.write), files: results, notes };
|
|
539
548
|
}
|
|
540
549
|
export {
|
|
541
550
|
ORIGINAL,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** A rule's level in one module: `off` skips it, which no rule set may say. */
|
|
2
|
+
type ModuleSeverity = 'error' | 'warn' | 'off';
|
|
3
|
+
/** What a module may move. */
|
|
4
|
+
interface ArchOverrides {
|
|
5
|
+
/** A level per rule, by the rule's name in the decision's rule set. */
|
|
6
|
+
severity?: Record<string, ModuleSeverity>;
|
|
7
|
+
}
|
|
8
|
+
/** What a module's config file passes. Everything is optional, including the file itself. */
|
|
9
|
+
interface ArchInput {
|
|
10
|
+
/** The module's own directory, normally `import.meta.dirname`. */
|
|
11
|
+
root?: string;
|
|
12
|
+
overrides?: ArchOverrides;
|
|
13
|
+
}
|
|
14
|
+
interface ResolvedArchConfig {
|
|
15
|
+
/** The module's directory, or null when its config file did not say. */
|
|
16
|
+
root: string | null;
|
|
17
|
+
/** The levels the module set, by rule. The others come from the map, then the rule set. */
|
|
18
|
+
severity: Record<string, ModuleSeverity>;
|
|
19
|
+
/** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */
|
|
20
|
+
moved: string[];
|
|
21
|
+
}
|
|
22
|
+
/** Resolve a module's declaration. */
|
|
23
|
+
declare function defineArch(input?: ArchInput): ResolvedArchConfig;
|
|
24
|
+
|
|
25
|
+
export { type ArchInput, type ArchOverrides, type ModuleSeverity, type ResolvedArchConfig, defineArch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
globToRegExp
|
|
3
|
-
} from "../../../chunk-O7REVMOC.js";
|
|
4
1
|
import {
|
|
5
2
|
decoratorMetadata,
|
|
6
3
|
tsconfigAliases
|
|
7
4
|
} from "../../../chunk-LNFGVGLE.js";
|
|
5
|
+
import {
|
|
6
|
+
globToRegExp
|
|
7
|
+
} from "../../../chunk-O7REVMOC.js";
|
|
8
8
|
import "../../../chunk-H4HAFJFZ.js";
|
|
9
9
|
import "../../../chunk-QXFCZON7.js";
|
|
10
10
|
|