@hublo/sentinel 1.7.0-alpha.0 → 1.7.0-alpha.2
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 +77 -17
- package/dist/chunk-4UUL4SEW.js +50 -0
- package/dist/{chunk-VVEKPCRY.js → chunk-DLGBRLUU.js} +9 -6
- package/dist/chunk-DLGBRLUU.js.map +1 -0
- package/dist/{chunk-WMBXYYLD.js → chunk-EETHWJBF.js} +78 -21
- package/dist/{chunk-ZVHUG6CA.js → chunk-H4HAFJFZ.js} +4 -13
- package/dist/chunk-H4HAFJFZ.js.map +1 -0
- package/dist/{chunk-POZDYETY.js → chunk-LNFGVGLE.js} +5 -3
- package/dist/{chunk-POZDYETY.js.map → chunk-LNFGVGLE.js.map} +1 -1
- package/dist/chunk-QXFCZON7.js +16 -0
- package/dist/chunk-QXFCZON7.js.map +1 -0
- package/dist/{chunk-7E6YTTAK.js → chunk-THTXP2QU.js} +1 -1
- package/dist/chunk-THTXP2QU.js.map +1 -0
- package/dist/{chunk-EVGG55ZO.js → chunk-Z3JI7ZWX.js} +192 -223
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -4
- package/dist/migrate-NI33SXZD.js +517 -0
- package/dist/roles/build/nest/toolchain.js +3 -2
- package/dist/roles/build/nest/toolchain.js.map +1 -1
- package/dist/roles/static-analysis/config.js +1 -1
- package/dist/roles/test/nest/toolchain.js +4 -3
- package/dist/roles/test/nest/toolchain.js.map +1 -1
- package/dist/roles/test/react/toolchain.js +4 -3
- package/dist/roles/test/react/toolchain.js.map +1 -1
- package/dist/roles/test/shared-test-config.js +4 -3
- package/dist/tsconfig/legacy.json +21 -0
- package/dist/tsconfig/nest.json +10 -1
- package/dist/tsconfig/node.json +11 -1
- package/dist/tsconfig/react.json +3 -0
- package/dist/{validate-VWP6YZP5.js → validate-LRHF63AW.js} +4 -2
- package/docs/typescript-adoption.md +52 -13
- package/docs/typescript-traces.md +1 -1
- package/package.json +4 -1
- package/dist/chunk-7E6YTTAK.js.map +0 -1
- package/dist/chunk-VVEKPCRY.js.map +0 -1
- package/dist/chunk-ZVHUG6CA.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare function registerAdapters(): void;
|
|
|
19
19
|
* | verb | writes | what remains |
|
|
20
20
|
* | --- | --- | --- |
|
|
21
21
|
* | `init` | a module's config + the workspace prep it needs | the module's new state, that IS the deliverable |
|
|
22
|
-
* | `migrate` | changes an already-initialized setup | same;
|
|
22
|
+
* | `migrate` | changes an already-initialized setup | same; `--typescript` detaches the module from `tsconfig.base.json` (sentinel#147) |
|
|
23
23
|
* | `validate` | instrumentation, if it needs any | **nothing**, the project returns to what it was |
|
|
24
24
|
* | `run` / `inspect` / `report` / `status` | nothing | they execute or introspect |
|
|
25
25
|
*
|
package/dist/index.js
CHANGED
|
@@ -6,15 +6,17 @@ import {
|
|
|
6
6
|
registerAdapters,
|
|
7
7
|
resolve,
|
|
8
8
|
setDefaultRunner
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EETHWJBF.js";
|
|
10
10
|
import {
|
|
11
11
|
BaseAdapter
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-Z3JI7ZWX.js";
|
|
13
|
+
import "./chunk-4UUL4SEW.js";
|
|
13
14
|
import "./chunk-ZNANJEMK.js";
|
|
14
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-THTXP2QU.js";
|
|
15
16
|
import "./chunk-4EIY7TTR.js";
|
|
16
17
|
import "./chunk-O7REVMOC.js";
|
|
17
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-H4HAFJFZ.js";
|
|
19
|
+
import "./chunk-QXFCZON7.js";
|
|
18
20
|
export {
|
|
19
21
|
BaseAdapter,
|
|
20
22
|
all,
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import {
|
|
2
|
+
binFromOwnInstall,
|
|
3
|
+
resolveBin
|
|
4
|
+
} from "./chunk-4UUL4SEW.js";
|
|
5
|
+
import {
|
|
6
|
+
parseJsonc
|
|
7
|
+
} from "./chunk-QXFCZON7.js";
|
|
8
|
+
|
|
9
|
+
// src/roles/typescript/migrate/migrate.ts
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { createRequire } from "node:module";
|
|
13
|
+
import { dirname as dirname2, join, relative as relative2, resolve as resolve2 } from "node:path";
|
|
14
|
+
import { stripComments } from "jsonc-parser";
|
|
15
|
+
|
|
16
|
+
// src/roles/typescript/migrate/compare.ts
|
|
17
|
+
var STRICT_FAMILY = [
|
|
18
|
+
"alwaysStrict",
|
|
19
|
+
"noImplicitAny",
|
|
20
|
+
"noImplicitThis",
|
|
21
|
+
"strictBindCallApply",
|
|
22
|
+
"strictBuiltinIteratorReturn",
|
|
23
|
+
"strictFunctionTypes",
|
|
24
|
+
"strictNullChecks",
|
|
25
|
+
"strictPropertyInitialization",
|
|
26
|
+
"useUnknownInCatchVariables"
|
|
27
|
+
];
|
|
28
|
+
var CASE_INSENSITIVE = /* @__PURE__ */ new Set([
|
|
29
|
+
"jsx",
|
|
30
|
+
"lib",
|
|
31
|
+
"module",
|
|
32
|
+
"moduleDetection",
|
|
33
|
+
"moduleResolution",
|
|
34
|
+
"target"
|
|
35
|
+
]);
|
|
36
|
+
function targetYear(target) {
|
|
37
|
+
const name = typeof target === "string" ? target.toLowerCase() : "es5";
|
|
38
|
+
if (name === "esnext") return Number.MAX_SAFE_INTEGER;
|
|
39
|
+
const year = Number(name.replace(/^es/, ""));
|
|
40
|
+
return Number.isFinite(year) ? year : 5;
|
|
41
|
+
}
|
|
42
|
+
function comparable(key, value) {
|
|
43
|
+
const json = JSON.stringify(value) ?? "undefined";
|
|
44
|
+
return CASE_INSENSITIVE.has(key) ? json.toLowerCase() : json;
|
|
45
|
+
}
|
|
46
|
+
function appliedOptions(config) {
|
|
47
|
+
const options = new Map(Object.entries(config.compilerOptions ?? {}));
|
|
48
|
+
options.delete("paths");
|
|
49
|
+
const derive = (key, value) => {
|
|
50
|
+
if (!options.has(key)) options.set(key, value);
|
|
51
|
+
};
|
|
52
|
+
if (options.get("strict") === true) for (const key of STRICT_FAMILY) derive(key, true);
|
|
53
|
+
derive("allowJs", false);
|
|
54
|
+
if (options.get("esModuleInterop") === true) derive("allowSyntheticDefaultImports", true);
|
|
55
|
+
if (options.get("verbatimModuleSyntax") === true) derive("isolatedModules", true);
|
|
56
|
+
if (options.get("isolatedModules") === true) derive("preserveConstEnums", true);
|
|
57
|
+
derive("useDefineForClassFields", targetYear(options.get("target")) >= 2022);
|
|
58
|
+
return new Map([...options].map(([key, value]) => [key, comparable(key, value)]));
|
|
59
|
+
}
|
|
60
|
+
function diffConfigs(before, after) {
|
|
61
|
+
const was = appliedOptions(before);
|
|
62
|
+
const now = appliedOptions(after);
|
|
63
|
+
const differences = [];
|
|
64
|
+
for (const key of /* @__PURE__ */ new Set([...was.keys(), ...now.keys()])) {
|
|
65
|
+
if (was.get(key) !== now.get(key)) {
|
|
66
|
+
differences.push({ key: `compilerOptions.${key}`, before: was.get(key), after: now.get(key) });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
70
|
+
if (key === "compilerOptions") continue;
|
|
71
|
+
const left = JSON.stringify(before[key]);
|
|
72
|
+
const right = JSON.stringify(after[key]);
|
|
73
|
+
if (left !== right) differences.push({ key, before: left, after: right });
|
|
74
|
+
}
|
|
75
|
+
return differences;
|
|
76
|
+
}
|
|
77
|
+
function remainder(effective, layers, ownKeys) {
|
|
78
|
+
const applied = appliedOptions(effective);
|
|
79
|
+
const given = appliedOptions(layers);
|
|
80
|
+
const written = [];
|
|
81
|
+
for (const [key, value] of applied) {
|
|
82
|
+
if (ownKeys.has(key) || given.get(key) === value) continue;
|
|
83
|
+
written.push({ key, value: effective.compilerOptions?.[key] ?? JSON.parse(value) });
|
|
84
|
+
}
|
|
85
|
+
return written;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// src/roles/typescript/migrate/detach.ts
|
|
89
|
+
import { dirname, posix, relative, resolve, sep } from "node:path";
|
|
90
|
+
var BASE_FILE = "tsconfig.base.json";
|
|
91
|
+
var LEGACY_ENTRY = "@hublo/sentinel/typescript/legacy";
|
|
92
|
+
function isBaseEntry(entry) {
|
|
93
|
+
return entry === BASE_FILE || entry.endsWith(`/${BASE_FILE}`);
|
|
94
|
+
}
|
|
95
|
+
function isStackPresetEntry(entry) {
|
|
96
|
+
return /^@hublo\/sentinel\/(?:typescript|tsconfig)\/(?!legacy$)[a-z-]+$/.test(entry);
|
|
97
|
+
}
|
|
98
|
+
function extendsList(config) {
|
|
99
|
+
const value = config.extends;
|
|
100
|
+
if (typeof value === "string") return [value];
|
|
101
|
+
return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
|
|
102
|
+
}
|
|
103
|
+
function rebaseTarget(target, pathsRoot, directory) {
|
|
104
|
+
const moved = relative(directory, resolve(pathsRoot, target)).split(sep).join(posix.sep);
|
|
105
|
+
const kept = target.endsWith("/") && !moved.endsWith("/") ? `${moved}/` : moved;
|
|
106
|
+
if (kept === "") return ".";
|
|
107
|
+
return kept.startsWith(".") ? kept : `./${kept}`;
|
|
108
|
+
}
|
|
109
|
+
function pickPaths(basePaths, matched, pathsRoot, directory) {
|
|
110
|
+
const picked = {};
|
|
111
|
+
for (const [pattern, targets] of Object.entries(basePaths)) {
|
|
112
|
+
if (!matched.has(pattern)) continue;
|
|
113
|
+
picked[pattern] = targets.map((target) => rebaseTarget(target, pathsRoot, directory));
|
|
114
|
+
}
|
|
115
|
+
return picked;
|
|
116
|
+
}
|
|
117
|
+
function pathsRootOf(baseFile, baseUrl) {
|
|
118
|
+
return typeof baseUrl === "string" ? resolve(dirname(baseFile), baseUrl) : dirname(baseFile);
|
|
119
|
+
}
|
|
120
|
+
function detachedConfig(input) {
|
|
121
|
+
const chain = extendsList(input.config).flatMap(
|
|
122
|
+
(entry) => isBaseEntry(entry) ? input.legacy ? [LEGACY_ENTRY] : [] : [entry]
|
|
123
|
+
);
|
|
124
|
+
const own = { ...input.config.compilerOptions };
|
|
125
|
+
const ownPaths = own.paths;
|
|
126
|
+
delete own.paths;
|
|
127
|
+
const options = { ...own };
|
|
128
|
+
for (const { key, value } of input.copied) options[key] = value;
|
|
129
|
+
const paths = ownPaths ?? (Object.keys(input.paths).length > 0 ? input.paths : void 0);
|
|
130
|
+
if (paths !== void 0) options.paths = paths;
|
|
131
|
+
const ordered = {};
|
|
132
|
+
if (chain.length > 0) ordered.extends = chain.length === 1 ? chain[0] : chain;
|
|
133
|
+
for (const [key, value] of Object.entries(input.config)) {
|
|
134
|
+
if (key === "extends") continue;
|
|
135
|
+
ordered[key] = key === "compilerOptions" ? options : value;
|
|
136
|
+
}
|
|
137
|
+
if (!("compilerOptions" in ordered) && Object.keys(options).length > 0) {
|
|
138
|
+
ordered.compilerOptions = options;
|
|
139
|
+
}
|
|
140
|
+
if (input.exclude !== void 0 && !("exclude" in ordered)) ordered.exclude = input.exclude;
|
|
141
|
+
return ordered;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/roles/typescript/migrate/trace.ts
|
|
145
|
+
var RESOLVING_MODULE = /^======== Resolving module '(.+?)' from '(.+?)'\. ========$/;
|
|
146
|
+
var RESOLVING_TYPE = /^======== Resolving type reference directive '(.+?)', containing file '(.+?)'(?:, root directory '.*')?\. ========$/;
|
|
147
|
+
var MATCHED_PATTERN = /^Module name '(.+?)', matched pattern '(.+?)'\.$/;
|
|
148
|
+
var RESOLVED = /^======== (?:Module name|Type reference directive) '(.+?)' was (successfully resolved to '(.+?)'|not resolved)/;
|
|
149
|
+
function resolutionKey(from, name) {
|
|
150
|
+
return `${from}\0${name}`;
|
|
151
|
+
}
|
|
152
|
+
function parseTrace(text) {
|
|
153
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
154
|
+
const patterns = /* @__PURE__ */ new Set();
|
|
155
|
+
let open;
|
|
156
|
+
let afterPathsLine = false;
|
|
157
|
+
for (const line of text.split("\n")) {
|
|
158
|
+
const isPathsMatch = afterPathsLine;
|
|
159
|
+
afterPathsLine = line.startsWith("'paths' option is specified");
|
|
160
|
+
const resolving = RESOLVING_MODULE.exec(line) ?? RESOLVING_TYPE.exec(line);
|
|
161
|
+
if (resolving !== null) {
|
|
162
|
+
if (open !== void 0) throw new Error(`trace: unclosed resolution of '${open.name}'`);
|
|
163
|
+
open = { name: resolving[1] ?? "", from: resolving[2] ?? "" };
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const matched = MATCHED_PATTERN.exec(line);
|
|
167
|
+
if (matched !== null) {
|
|
168
|
+
if (isPathsMatch && matched[2] !== void 0) patterns.add(matched[2]);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const resolved = RESOLVED.exec(line);
|
|
172
|
+
if (resolved !== null) {
|
|
173
|
+
if (open === void 0 || open.name !== resolved[1]) {
|
|
174
|
+
throw new Error(`trace: result of '${resolved[1] ?? ""}' out of order`);
|
|
175
|
+
}
|
|
176
|
+
resolutions.set(resolutionKey(open.from, open.name), resolved[3] ?? null);
|
|
177
|
+
open = void 0;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (open !== void 0) throw new Error(`trace: unclosed resolution of '${open.name}'`);
|
|
181
|
+
return { resolutions, patterns };
|
|
182
|
+
}
|
|
183
|
+
function diffResolutions(before, after) {
|
|
184
|
+
const lines = [];
|
|
185
|
+
for (const key of /* @__PURE__ */ new Set([...before.keys(), ...after.keys()])) {
|
|
186
|
+
const was = before.get(key);
|
|
187
|
+
const now = after.get(key);
|
|
188
|
+
if (was === now) continue;
|
|
189
|
+
const [from, name] = key.split("\0");
|
|
190
|
+
lines.push(`${from ?? ""}: '${name ?? ""}' ${was ?? "unresolved"} -> ${now ?? "unresolved"}`);
|
|
191
|
+
}
|
|
192
|
+
return lines;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/roles/typescript/migrate/migrate.ts
|
|
196
|
+
var PROBE = "tsconfig.sentinel-migrate-probe.json";
|
|
197
|
+
var ORIGINAL = ".sentinel-migrate-original";
|
|
198
|
+
var TSCONFIG_NAME = /^tsconfig.*\.json$/;
|
|
199
|
+
var SOURCE = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
200
|
+
function readTsconfig(file) {
|
|
201
|
+
return parseJsonc(readFileSync(file, "utf8"), file);
|
|
202
|
+
}
|
|
203
|
+
function tscFor(directory) {
|
|
204
|
+
return resolveBin(directory, "tsc") ?? binFromOwnInstall("typescript", "tsc") ?? "tsc";
|
|
205
|
+
}
|
|
206
|
+
function tsc(directory, tsconfig, extra) {
|
|
207
|
+
try {
|
|
208
|
+
return execFileSync(tscFor(directory), ["-p", tsconfig, ...extra], {
|
|
209
|
+
cwd: directory,
|
|
210
|
+
encoding: "utf8",
|
|
211
|
+
maxBuffer: 2 ** 31 - 1,
|
|
212
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
const failure = error;
|
|
216
|
+
if (typeof failure.stdout === "string" && failure.stdout.length > 0) return failure.stdout;
|
|
217
|
+
const said = typeof failure.stderr === "string" && failure.stderr !== "" ? failure.stderr : failure.message;
|
|
218
|
+
throw new Error(`tsc -p ${tsconfig} ${extra.join(" ")}: ${String(said).trim()}`, {
|
|
219
|
+
cause: error
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function showConfig(directory, tsconfig) {
|
|
224
|
+
return JSON.parse(tsc(directory, tsconfig, ["--showConfig"]));
|
|
225
|
+
}
|
|
226
|
+
function withProbe(directory, config, use) {
|
|
227
|
+
writeFileSync(join(directory, PROBE), JSON.stringify(config));
|
|
228
|
+
try {
|
|
229
|
+
return use(PROBE);
|
|
230
|
+
} finally {
|
|
231
|
+
unlinkSync(join(directory, PROBE));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function compilesFiles(config) {
|
|
235
|
+
return !(Array.isArray(config.files) && config.files.length === 0 && config.include === void 0);
|
|
236
|
+
}
|
|
237
|
+
function inheritors(directory, names, target) {
|
|
238
|
+
const reaches = (name, seen) => {
|
|
239
|
+
if (name === target) return true;
|
|
240
|
+
if (seen.has(name)) return false;
|
|
241
|
+
seen.add(name);
|
|
242
|
+
return extendsList(readTsconfig(join(directory, name))).some((entry) => {
|
|
243
|
+
const file = resolve2(directory, entry.endsWith(".json") ? entry : `${entry}.json`);
|
|
244
|
+
return dirname2(file) === directory && reaches(relative2(directory, file), seen);
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
return names.filter((name) => reaches(name, /* @__PURE__ */ new Set()));
|
|
248
|
+
}
|
|
249
|
+
function owner(file, directory) {
|
|
250
|
+
for (let folder = dirname2(file); folder.startsWith(directory); folder = dirname2(folder)) {
|
|
251
|
+
if (readdirSync(folder).some((name) => TSCONFIG_NAME.test(name))) return folder;
|
|
252
|
+
if (folder === directory) break;
|
|
253
|
+
}
|
|
254
|
+
return directory;
|
|
255
|
+
}
|
|
256
|
+
function trackedFiles(directory) {
|
|
257
|
+
try {
|
|
258
|
+
return execFileSync("git", ["ls-files", "--cached"], { cwd: directory, encoding: "utf8" }).split("\n").filter(Boolean);
|
|
259
|
+
} catch {
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function outsidePrograms(directory, chained, tracked) {
|
|
264
|
+
const listed = new Set(
|
|
265
|
+
chained.flatMap(
|
|
266
|
+
(name) => tsc(directory, name, ["--listFilesOnly"]).split("\n").map((line) => line.trim()).filter(Boolean)
|
|
267
|
+
)
|
|
268
|
+
);
|
|
269
|
+
return tracked.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);
|
|
270
|
+
}
|
|
271
|
+
function trace(directory, name) {
|
|
272
|
+
return parseTrace(tsc(directory, name, ["--noEmit", "--traceResolution"]));
|
|
273
|
+
}
|
|
274
|
+
function traceOutside(directory, target, files) {
|
|
275
|
+
return withProbe(
|
|
276
|
+
directory,
|
|
277
|
+
{
|
|
278
|
+
extends: `./${target}`,
|
|
279
|
+
compilerOptions: { allowJs: true, checkJs: false, noEmit: true },
|
|
280
|
+
files: files.map((file) => `./${relative2(directory, file)}`),
|
|
281
|
+
include: []
|
|
282
|
+
},
|
|
283
|
+
(probe) => trace(directory, probe)
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
var OUTSIDE = "(outside the programs)";
|
|
287
|
+
function sentinelInstalls(directory, presets) {
|
|
288
|
+
const require2 = createRequire(join(directory, "package.json"));
|
|
289
|
+
const packageRoot = (specifier) => {
|
|
290
|
+
let folder;
|
|
291
|
+
try {
|
|
292
|
+
folder = dirname2(require2.resolve(specifier));
|
|
293
|
+
} catch {
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
296
|
+
while (!existsSync(join(folder, "package.json")) && dirname2(folder) !== folder)
|
|
297
|
+
folder = dirname2(folder);
|
|
298
|
+
return folder;
|
|
299
|
+
};
|
|
300
|
+
const legacy = packageRoot(LEGACY_ENTRY);
|
|
301
|
+
if (legacy === void 0) return "no-legacy";
|
|
302
|
+
return presets.every((preset) => packageRoot(preset) === legacy) ? "one" : "several";
|
|
303
|
+
}
|
|
304
|
+
function migrateTsconfig(directory, target, names, options) {
|
|
305
|
+
const file = join(directory, target);
|
|
306
|
+
const shown = relative2(options.workspaceRoot, file);
|
|
307
|
+
const original = readFileSync(file, "utf8");
|
|
308
|
+
if (stripComments(original) !== original) {
|
|
309
|
+
return { file: shown, kept: false, reason: "it has comments a rewrite would drop; left as is" };
|
|
310
|
+
}
|
|
311
|
+
const config = readTsconfig(file);
|
|
312
|
+
const chain = extendsList(config);
|
|
313
|
+
const baseEntry = chain.find(isBaseEntry);
|
|
314
|
+
if (baseEntry === void 0)
|
|
315
|
+
return { file: shown, kept: false, reason: "it does not extend the base" };
|
|
316
|
+
const baseFile = resolve2(directory, baseEntry);
|
|
317
|
+
const base = readTsconfig(baseFile);
|
|
318
|
+
const basePaths = base.compilerOptions?.paths ?? {};
|
|
319
|
+
const chained = inheritors(directory, names, target).filter(
|
|
320
|
+
(name) => compilesFiles(readTsconfig(join(directory, name)))
|
|
321
|
+
);
|
|
322
|
+
const before = new Map(names.map((name) => [name, showConfig(directory, name)]));
|
|
323
|
+
const traces = new Map(chained.map((name) => [name, trace(directory, name)]));
|
|
324
|
+
const tracked = trackedFiles(directory);
|
|
325
|
+
const outside = tracked === void 0 ? [] : outsidePrograms(directory, chained, tracked);
|
|
326
|
+
if (outside.length > 0) traces.set(OUTSIDE, traceOutside(directory, target, outside));
|
|
327
|
+
const matched = new Set([...traces.values()].flatMap((one) => [...one.patterns]));
|
|
328
|
+
const paths = pickPaths(
|
|
329
|
+
basePaths,
|
|
330
|
+
matched,
|
|
331
|
+
pathsRootOf(baseFile, base.compilerOptions?.baseUrl),
|
|
332
|
+
directory
|
|
333
|
+
);
|
|
334
|
+
const effective = before.get(target) ?? {};
|
|
335
|
+
const withoutBase = chain.filter((entry) => !isBaseEntry(entry));
|
|
336
|
+
const inputs = Object.fromEntries(
|
|
337
|
+
["files", "include", "references"].filter((key) => key in config).map((key) => [key, config[key]])
|
|
338
|
+
);
|
|
339
|
+
const layers = (entries) => withProbe(directory, { extends: entries, ...inputs }, (probe) => showConfig(directory, probe));
|
|
340
|
+
const installs = sentinelInstalls(directory, chain.filter(isStackPresetEntry));
|
|
341
|
+
if (installs !== "one") {
|
|
342
|
+
return {
|
|
343
|
+
file: shown,
|
|
344
|
+
kept: false,
|
|
345
|
+
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\``
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
const stack = layers(withoutBase);
|
|
349
|
+
const withLegacy = layers(chain.map((entry) => isBaseEntry(entry) ? LEGACY_ENTRY : entry));
|
|
350
|
+
const stackApplied = appliedOptions(stack);
|
|
351
|
+
const legacyKeys = new Set(
|
|
352
|
+
[...appliedOptions(withLegacy)].filter(([key, value]) => stackApplied.get(key) !== value).map(([key]) => key)
|
|
353
|
+
);
|
|
354
|
+
const ownKeys = new Set(Object.keys(config.compilerOptions ?? {}));
|
|
355
|
+
const withoutLegacy = remainder(effective, stack, ownKeys);
|
|
356
|
+
const legacy = withoutLegacy.some(({ key }) => legacyKeys.has(key));
|
|
357
|
+
const copied = (legacy ? remainder(effective, withLegacy, ownKeys) : withoutLegacy).filter(
|
|
358
|
+
({ key }) => key !== "paths"
|
|
359
|
+
);
|
|
360
|
+
const exclude = config.exclude === void 0 ? effective.exclude : void 0;
|
|
361
|
+
const report = {
|
|
362
|
+
file: shown,
|
|
363
|
+
legacy,
|
|
364
|
+
aliases: { kept: Object.keys(paths).length, of: Object.keys(basePaths).length },
|
|
365
|
+
written: copied.map(({ key }) => key),
|
|
366
|
+
resolutions: [...traces.values()].reduce((sum, one) => sum + one.resolutions.size, 0),
|
|
367
|
+
outsidePrograms: outside.map((path) => relative2(directory, path))
|
|
368
|
+
};
|
|
369
|
+
let kept = false;
|
|
370
|
+
writeFileSync(`${file}${ORIGINAL}`, original);
|
|
371
|
+
try {
|
|
372
|
+
writeFileSync(
|
|
373
|
+
file,
|
|
374
|
+
`${JSON.stringify(detachedConfig({ config, legacy, copied, paths, exclude }), null, 2)}
|
|
375
|
+
`
|
|
376
|
+
);
|
|
377
|
+
const configDifferences = names.flatMap(
|
|
378
|
+
(name) => diffConfigs(before.get(name) ?? {}, showConfig(directory, name)).map((difference) => ({
|
|
379
|
+
...difference,
|
|
380
|
+
key: `${name}: ${difference.key}`
|
|
381
|
+
}))
|
|
382
|
+
);
|
|
383
|
+
const resolutionDifferences = [...traces].flatMap(
|
|
384
|
+
([name, was]) => diffResolutions(
|
|
385
|
+
was.resolutions,
|
|
386
|
+
(name === OUTSIDE ? traceOutside(directory, target, outside) : trace(directory, name)).resolutions
|
|
387
|
+
).map((line) => `${name}: ${line}`)
|
|
388
|
+
);
|
|
389
|
+
const proved = configDifferences.length === 0 && resolutionDifferences.length === 0;
|
|
390
|
+
kept = proved && options.write;
|
|
391
|
+
return {
|
|
392
|
+
...report,
|
|
393
|
+
kept,
|
|
394
|
+
...proved ? {} : { reason: "tsc does not agree before and after; restored" },
|
|
395
|
+
configDifferences,
|
|
396
|
+
resolutionDifferences
|
|
397
|
+
};
|
|
398
|
+
} finally {
|
|
399
|
+
if (!kept) writeFileSync(file, original);
|
|
400
|
+
unlinkSync(`${file}${ORIGINAL}`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function restoreInterrupted(moduleRoot, tracked, notes, workspaceRoot) {
|
|
404
|
+
const folders = /* @__PURE__ */ new Set([
|
|
405
|
+
moduleRoot,
|
|
406
|
+
...(tracked ?? []).filter((name) => TSCONFIG_NAME.test(name.slice(name.lastIndexOf("/") + 1))).map((name) => join(moduleRoot, dirname2(name)))
|
|
407
|
+
]);
|
|
408
|
+
for (const folder of folders) {
|
|
409
|
+
for (const name of readdirSync(folder).filter((entry) => entry.endsWith(ORIGINAL))) {
|
|
410
|
+
const saved = join(folder, name);
|
|
411
|
+
const file = saved.slice(0, -ORIGINAL.length);
|
|
412
|
+
writeFileSync(file, readFileSync(saved, "utf8"));
|
|
413
|
+
unlinkSync(saved);
|
|
414
|
+
notes.push(`restored ${relative2(workspaceRoot, file)}, left rewritten by an interrupted run`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function isOwnModule(folder) {
|
|
419
|
+
return existsSync(join(folder, "package.json")) || existsSync(join(folder, "project.json"));
|
|
420
|
+
}
|
|
421
|
+
function foldersToMigrate(moduleRoot, tracked, notes) {
|
|
422
|
+
const nested = [
|
|
423
|
+
...new Set(
|
|
424
|
+
(tracked ?? []).filter(
|
|
425
|
+
(name) => TSCONFIG_NAME.test(name.slice(name.lastIndexOf("/") + 1)) && name.includes("/")
|
|
426
|
+
).map((name) => join(moduleRoot, dirname2(name)))
|
|
427
|
+
)
|
|
428
|
+
].filter((folder) => {
|
|
429
|
+
if (!isOwnModule(folder)) return true;
|
|
430
|
+
if (readdirSync(folder).some(
|
|
431
|
+
(name) => TSCONFIG_NAME.test(name) && extendsList(readTsconfig(join(folder, name))).some(isBaseEntry)
|
|
432
|
+
)) {
|
|
433
|
+
notes.push(
|
|
434
|
+
`${relative2(moduleRoot, folder)} is a module of its own: run \`sentinel --migrate --typescript\` there`
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
return false;
|
|
438
|
+
});
|
|
439
|
+
return [moduleRoot, ...nested].filter(
|
|
440
|
+
(folder) => readdirSync(folder).filter((name) => TSCONFIG_NAME.test(name) && name !== PROBE).some((name) => extendsList(readTsconfig(join(folder, name))).some(isBaseEntry))
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function migrateModule(moduleRoot, options) {
|
|
444
|
+
const notes = [];
|
|
445
|
+
const tracked = trackedFiles(moduleRoot);
|
|
446
|
+
if (tracked === void 0) {
|
|
447
|
+
notes.push("not a git checkout: the files outside every program were not traced");
|
|
448
|
+
}
|
|
449
|
+
restoreInterrupted(moduleRoot, tracked, notes, options.workspaceRoot);
|
|
450
|
+
const folders = foldersToMigrate(moduleRoot, tracked, notes);
|
|
451
|
+
if (folders.length === 0) {
|
|
452
|
+
return {
|
|
453
|
+
outcome: "skipped",
|
|
454
|
+
message: "no tsconfig of this module extends tsconfig.base.json: nothing to detach",
|
|
455
|
+
files: [],
|
|
456
|
+
notes
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const files = [];
|
|
460
|
+
for (const folder of folders) {
|
|
461
|
+
if (existsSync(join(folder, PROBE))) {
|
|
462
|
+
unlinkSync(join(folder, PROBE));
|
|
463
|
+
notes.push(
|
|
464
|
+
`removed ${relative2(options.workspaceRoot, join(folder, PROBE))}, left by an interrupted run`
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const names = readdirSync(folder).filter((name) => TSCONFIG_NAME.test(name) && name !== PROBE);
|
|
468
|
+
const targets = names.filter(
|
|
469
|
+
(name) => extendsList(readTsconfig(join(folder, name))).some(isBaseEntry)
|
|
470
|
+
);
|
|
471
|
+
for (const target of targets) {
|
|
472
|
+
const chain = extendsList(readTsconfig(join(folder, target)));
|
|
473
|
+
if (!chain.some(isStackPresetEntry)) {
|
|
474
|
+
files.push({
|
|
475
|
+
file: relative2(options.workspaceRoot, join(folder, target)),
|
|
476
|
+
kept: false,
|
|
477
|
+
reason: "it extends the base but no sentinel preset: only an adopted module is detached. Run `sentinel --init --typescript` first"
|
|
478
|
+
});
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
files.push(migrateTsconfig(folder, target, names, options));
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const refused = files.filter((one) => !one.kept);
|
|
485
|
+
const notAdopted = files.every((one) => one.reason?.includes("no sentinel preset") === true);
|
|
486
|
+
if (notAdopted) {
|
|
487
|
+
return {
|
|
488
|
+
outcome: "blocked",
|
|
489
|
+
message: "this module is not adopted: run `sentinel --init --typescript` first. Nothing was written",
|
|
490
|
+
files,
|
|
491
|
+
notes
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
const unproved = files.filter((one) => one.configDifferences === void 0);
|
|
495
|
+
if (!options.write) {
|
|
496
|
+
const proved = files.every(
|
|
497
|
+
(one) => one.configDifferences?.length === 0 && one.resolutionDifferences?.length === 0
|
|
498
|
+
);
|
|
499
|
+
return {
|
|
500
|
+
outcome: proved ? "proved" : "failed",
|
|
501
|
+
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",
|
|
502
|
+
files,
|
|
503
|
+
notes
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
outcome: refused.length === 0 ? "migrated" : "failed",
|
|
508
|
+
message: refused.length === 0 ? `detached ${files.length} tsconfig${files.length === 1 ? "" : "s"} from tsconfig.base.json` : `${refused.length} of ${files.length} tsconfig${files.length === 1 ? "" : "s"} kept as they were`,
|
|
509
|
+
files,
|
|
510
|
+
notes
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
export {
|
|
514
|
+
ORIGINAL,
|
|
515
|
+
PROBE,
|
|
516
|
+
migrateModule
|
|
517
|
+
};
|
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
decoratorMetadata,
|
|
6
6
|
tsconfigAliases
|
|
7
|
-
} from "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
7
|
+
} from "../../../chunk-LNFGVGLE.js";
|
|
8
|
+
import "../../../chunk-H4HAFJFZ.js";
|
|
9
|
+
import "../../../chunk-QXFCZON7.js";
|
|
9
10
|
|
|
10
11
|
// src/roles/build/nest/nest-service.ts
|
|
11
12
|
import { join as join4 } from "node:path";
|