@hublo/sentinel 1.7.0-alpha.5 → 1.7.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/sentinel.js
CHANGED
|
@@ -594,7 +594,7 @@ async function runMigrate(ctx) {
|
|
|
594
594
|
);
|
|
595
595
|
}
|
|
596
596
|
if (!ctx.targets.includes("typescript")) return 1;
|
|
597
|
-
const { migrateModule } = await import("../migrate-
|
|
597
|
+
const { migrateModule } = await import("../migrate-X7PB2X7R.js");
|
|
598
598
|
const migration = migrateModule(module.root, {
|
|
599
599
|
write: !ctx.dryRun,
|
|
600
600
|
workspaceRoot: findWorkspaceRoot(module.root) ?? module.root
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
21
21
|
import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
22
22
|
import { createRequire } from "node:module";
|
|
23
|
-
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";
|
|
24
24
|
import { stripComments } from "jsonc-parser";
|
|
25
25
|
|
|
26
26
|
// src/roles/typescript/migrate/detach.ts
|
|
@@ -141,8 +141,9 @@ function tsc(directory, tsconfig, extra) {
|
|
|
141
141
|
if (run.error !== void 0)
|
|
142
142
|
throw new Error(`${command}: ${run.error.message}`, { cause: run.error });
|
|
143
143
|
if (run.signal !== null) throw new Error(`${command}: killed by ${run.signal}`);
|
|
144
|
-
|
|
145
|
-
|
|
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;
|
|
146
147
|
const said = run.stderr.trim() || run.stdout.trim() || `exit ${String(run.status)}, no output`;
|
|
147
148
|
throw new Error(`${command}: ${said}`);
|
|
148
149
|
}
|
|
@@ -165,7 +166,8 @@ function withProbe(directory, config, use) {
|
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
function compilesFiles(config) {
|
|
168
|
-
|
|
169
|
+
const empty = (list) => Array.isArray(list) && list.length === 0;
|
|
170
|
+
return !(empty(config.files) && (config.include === void 0 || empty(config.include)));
|
|
169
171
|
}
|
|
170
172
|
function inheritors(directory, names, target) {
|
|
171
173
|
const reaches = (name, seen) => {
|
|
@@ -200,12 +202,10 @@ function moduleFiles(directory) {
|
|
|
200
202
|
(name) => existsSync(join(directory, name))
|
|
201
203
|
);
|
|
202
204
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
)
|
|
208
|
-
);
|
|
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
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);
|
|
210
210
|
}
|
|
211
211
|
function trace(directory, name) {
|
|
@@ -270,10 +270,13 @@ function baseline(directory, target, names, files) {
|
|
|
270
270
|
(name) => compilesFiles(readTsconfig(join(directory, name)))
|
|
271
271
|
);
|
|
272
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));
|
|
273
275
|
const traces = new Map(chained.map((name) => [name, trace(directory, name)]));
|
|
274
|
-
const
|
|
276
|
+
const compiled = new Set([...listed.values()].flat());
|
|
277
|
+
const outside = files === void 0 ? [] : outsidePrograms(directory, compiled, files);
|
|
275
278
|
if (outside.length > 0) traces.set(OUTSIDE, traceOutside(directory, target, outside));
|
|
276
|
-
return { before, traces, outside };
|
|
279
|
+
return { before, traces, outside, empty };
|
|
277
280
|
}
|
|
278
281
|
function planDetach(directory, config, chain, effective, traces) {
|
|
279
282
|
const baseFile = resolve2(directory, chain.find(isBaseEntry) ?? "");
|
|
@@ -338,15 +341,15 @@ function proveTsconfig(directory, target, names, files, workspaceRoot) {
|
|
|
338
341
|
const early = refuseEarly(directory, shown, original, chain);
|
|
339
342
|
if (early !== void 0) return { result: early };
|
|
340
343
|
const known = baseline(directory, target, names, files);
|
|
341
|
-
const
|
|
342
|
-
([name, one]) => name !== OUTSIDE && one.resolutions.size === 0
|
|
344
|
+
const unread = [...known.traces].filter(
|
|
345
|
+
([name, one]) => name !== OUTSIDE && !known.empty.has(name) && one.resolutions.size === 0
|
|
343
346
|
);
|
|
344
|
-
if (
|
|
347
|
+
if (unread.length > 0) {
|
|
345
348
|
return {
|
|
346
349
|
result: refused(
|
|
347
350
|
shown,
|
|
348
351
|
"no-trace",
|
|
349
|
-
`tsc --traceResolution printed no resolution sentinel could read for ${
|
|
352
|
+
`tsc --traceResolution printed no resolution sentinel could read for ${unread.map(([name]) => name).join(", ")}; nothing can be proved`
|
|
350
353
|
)
|
|
351
354
|
};
|
|
352
355
|
}
|
|
@@ -100,6 +100,10 @@ It refuses, and writes nothing, for:
|
|
|
100
100
|
- a tsconfig tsc cannot read (`error`, naming what tsc said), or a program that compiles files and
|
|
101
101
|
whose trace yields no resolution at all (`no-trace`): every program resolves at least its type
|
|
102
102
|
references, the smallest of the monorepo's 111 traces 447, so none means the trace was not read.
|
|
103
|
+
A solution file (`files: []`, `include` absent or `[]`) compiles nothing and is not traced: its
|
|
104
|
+
programs are, through the tsconfigs that extend it. A program tsc lists no file for (a spec
|
|
105
|
+
tsconfig in a library with no tests) is not a `no-trace` either: its trace must stay empty
|
|
106
|
+
after the rewrite.
|
|
103
107
|
|
|
104
108
|
A nested folder that is a module of its own is named and left to its own run. Each refusal carries a
|
|
105
109
|
`refusal` code in `--json` (`not-adopted`, `partly-adopted`, `comments`, `no-legacy`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hublo/sentinel",
|
|
3
|
-
"version": "1.7.0-alpha.
|
|
3
|
+
"version": "1.7.0-alpha.6",
|
|
4
4
|
"description": "One CLI that guards code health across Hublo repos: shared lint/typescript/build/test presets, static & dynamic analysis, and architecture checks.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|