@hublo/sentinel 1.7.0-alpha.3 → 1.7.0-alpha.5
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 +40 -34
- package/dist/{chunk-F6ART7RH.js → chunk-YRBFCQQI.js} +96 -177
- package/dist/chunk-ZZMYV576.js +297 -0
- package/dist/index.js +2 -1
- package/dist/{migrate-NWQ3LYER.js → migrate-5N7IPVF5.js} +227 -221
- package/docs/typescript-adoption.md +43 -6
- package/package.json +1 -1
package/dist/bin/sentinel.js
CHANGED
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
presetNotInstalledYet,
|
|
13
13
|
registerAdapters,
|
|
14
14
|
resolve
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-YRBFCQQI.js";
|
|
16
|
+
import "../chunk-ZZMYV576.js";
|
|
16
17
|
import {
|
|
17
18
|
resolveContext,
|
|
18
19
|
separateToolArgs
|
|
@@ -593,45 +594,42 @@ async function runMigrate(ctx) {
|
|
|
593
594
|
);
|
|
594
595
|
}
|
|
595
596
|
if (!ctx.targets.includes("typescript")) return 1;
|
|
596
|
-
const { migrateModule } = await import("../migrate-
|
|
597
|
+
const { migrateModule } = await import("../migrate-5N7IPVF5.js");
|
|
597
598
|
const migration = migrateModule(module.root, {
|
|
598
599
|
write: !ctx.dryRun,
|
|
599
600
|
workspaceRoot: findWorkspaceRoot(module.root) ?? module.root
|
|
600
601
|
});
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
602
|
+
process.stdout.write(
|
|
603
|
+
ctx.json ? `${JSON.stringify({ module: module.name, target: "typescript", ...migration }, null, 2)}
|
|
604
|
+
` : renderMigration(module.name, migration)
|
|
605
|
+
);
|
|
606
|
+
return migration.outcome === "migrated" || migration.outcome === "proved" || migration.outcome === "skipped" ? 0 : 1;
|
|
607
|
+
}
|
|
608
|
+
var SHOWN_DIFFERENCES = 20;
|
|
609
|
+
function renderMigration(name, migration) {
|
|
610
|
+
const mark = migration.outcome === "migrated" || migration.outcome === "proved" ? "\u2713" : migration.outcome === "skipped" ? "\xB7" : "\u2717";
|
|
611
|
+
const lines = [` ${mark} ${name} \u2014 ${migration.message}`];
|
|
612
|
+
for (const file of migration.files) {
|
|
613
|
+
lines.push(` ${file.kept ? "\u2713" : "\xB7"} ${file.file}${file.reason ? `: ${file.reason}` : ""}`);
|
|
614
|
+
if (file.aliases !== void 0) {
|
|
615
|
+
lines.push(
|
|
616
|
+
` ${file.legacy ? "extends legacy, " : ""}${file.aliases.kept} of ${file.aliases.of} aliases, ${file.resolutions ?? 0} resolutions compared${file.written && file.written.length > 0 ? `, wrote ${file.written.join(", ")}` : ""}`
|
|
614
617
|
);
|
|
615
|
-
if (file.aliases !== void 0) {
|
|
616
|
-
process.stdout.write(
|
|
617
|
-
` ${file.legacy ? "extends legacy, " : ""}${file.aliases.kept} of ${file.aliases.of} aliases, ${file.resolutions ?? 0} resolutions compared${file.written && file.written.length > 0 ? `, wrote ${file.written.join(", ")}` : ""}
|
|
618
|
-
`
|
|
619
|
-
);
|
|
620
|
-
}
|
|
621
|
-
for (const line of [
|
|
622
|
-
...(file.configDifferences ?? []).map(
|
|
623
|
-
(d) => `${d.key}: ${d.before ?? "unset"} -> ${d.after ?? "unset"}`
|
|
624
|
-
),
|
|
625
|
-
...file.resolutionDifferences ?? []
|
|
626
|
-
].slice(0, 20)) {
|
|
627
|
-
process.stdout.write(` ${line}
|
|
628
|
-
`);
|
|
629
|
-
}
|
|
630
618
|
}
|
|
631
|
-
|
|
632
|
-
|
|
619
|
+
const differences = [
|
|
620
|
+
...(file.configDifferences ?? []).map(
|
|
621
|
+
(difference) => `${difference.key}: ${difference.before ?? "unset"} -> ${difference.after ?? "unset"}`
|
|
622
|
+
),
|
|
623
|
+
...file.resolutionDifferences ?? []
|
|
624
|
+
];
|
|
625
|
+
for (const line of differences.slice(0, SHOWN_DIFFERENCES)) lines.push(` ${line}`);
|
|
626
|
+
if (differences.length > SHOWN_DIFFERENCES) {
|
|
627
|
+
lines.push(` \u2026 ${differences.length - SHOWN_DIFFERENCES} more, all of them under --json`);
|
|
628
|
+
}
|
|
633
629
|
}
|
|
634
|
-
|
|
630
|
+
for (const note of migration.notes) lines.push(` note: ${note}`);
|
|
631
|
+
return `${lines.join("\n")}
|
|
632
|
+
`;
|
|
635
633
|
}
|
|
636
634
|
|
|
637
635
|
// src/cli/run-validate.ts
|
|
@@ -698,7 +696,15 @@ var RULE_BLOCKS = [
|
|
|
698
696
|
// The other direction, and listed for the same reason: a rule a module adds to its lint
|
|
699
697
|
// preset is not drift, so nothing else on the row would ever show it was there.
|
|
700
698
|
{ key: "added", label: "added by the module (kept by --init, not drift):" },
|
|
701
|
-
{ key: "addedConfig", label: "config added by the module (kept by --init, not drift):" }
|
|
699
|
+
{ key: "addedConfig", label: "config added by the module (kept by --init, not drift):" },
|
|
700
|
+
// TypeScript's two: an option the preset took over from the base, set to another value by the
|
|
701
|
+
// module (kept, so `conformant` cannot show it), and the debt a migrated module takes from
|
|
702
|
+
// `legacy`. Both are this module departing from the standard, named.
|
|
703
|
+
{
|
|
704
|
+
key: "standardOverrides",
|
|
705
|
+
label: "differs from the repo standard (kept by --init, not drift):"
|
|
706
|
+
},
|
|
707
|
+
{ key: "legacyCompromises", label: "inherited compromises (debt to remove):" }
|
|
702
708
|
];
|
|
703
709
|
var MAX_INLINE_WIDTH = 60;
|
|
704
710
|
function renderValue(key, value, p) {
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFERRED_RULES,
|
|
3
|
+
LEGACY_ENTRY,
|
|
4
|
+
SHIPPED_PRESETS,
|
|
5
|
+
STACK_PRESET_PATTERN,
|
|
6
|
+
appliedOptions,
|
|
7
|
+
comparable,
|
|
8
|
+
extendsList,
|
|
9
|
+
hasShippedPreset,
|
|
10
|
+
isLegacyEntry,
|
|
11
|
+
raisedFromBase,
|
|
12
|
+
tsLegacyLayer,
|
|
13
|
+
tsPresetFor
|
|
14
|
+
} from "./chunk-ZZMYV576.js";
|
|
1
15
|
import {
|
|
2
16
|
BaseAdapter,
|
|
3
17
|
ESLINT_CONFIG_FILES,
|
|
@@ -3122,7 +3136,7 @@ var OxfmtAdapter = class extends BaseAdapter {
|
|
|
3122
3136
|
const adoption = readFormatAdoption(ctx.cwd);
|
|
3123
3137
|
const preset = formatPresetFor(adoption.preset ?? DEFAULT_PRESET);
|
|
3124
3138
|
const options = { ...preset, ...adoption.local };
|
|
3125
|
-
const
|
|
3139
|
+
const describe3 = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
3126
3140
|
return {
|
|
3127
3141
|
runner: "oxfmt",
|
|
3128
3142
|
configFile: adoption.configFile,
|
|
@@ -3131,7 +3145,7 @@ var OxfmtAdapter = class extends BaseAdapter {
|
|
|
3131
3145
|
options,
|
|
3132
3146
|
overrides: Object.entries(adoption.local).filter(([key]) => !ALWAYS_LOCAL_KEYS.includes(key)).map(([key, value]) => ({
|
|
3133
3147
|
rule: key,
|
|
3134
|
-
reason: key in preset ? `${
|
|
3148
|
+
reason: key in preset ? `${describe3(value)}, where the ${adoption.preset ?? DEFAULT_PRESET} preset says ${describe3(preset[key])}` : `${describe3(value)}, which the preset does not set`
|
|
3135
3149
|
})),
|
|
3136
3150
|
// Which files this module does not format at all. A long list here is worth a look:
|
|
3137
3151
|
// it is the quiet way a module stops being covered.
|
|
@@ -3377,8 +3391,8 @@ function ruleCount(cwd, specifier) {
|
|
|
3377
3391
|
return void 0;
|
|
3378
3392
|
}
|
|
3379
3393
|
}
|
|
3380
|
-
function extraLayers(cwd,
|
|
3381
|
-
return
|
|
3394
|
+
function extraLayers(cwd, extendsList2) {
|
|
3395
|
+
return extendsList2.filter((entry) => !isSentinelPreset(entry) && entry !== LINT_BASELINE_SPECIFIER).map((entry) => {
|
|
3382
3396
|
const count = ruleCount(cwd, entry);
|
|
3383
3397
|
return {
|
|
3384
3398
|
rule: entry,
|
|
@@ -7025,7 +7039,8 @@ function workspaceRootFrom(cwd) {
|
|
|
7025
7039
|
var IMPORTER_TSCONFIGS = ["tsconfig.app.json", "tsconfig.lib.json", "tsconfig.json"];
|
|
7026
7040
|
function toTable(workspaceRoot, found) {
|
|
7027
7041
|
const table = /* @__PURE__ */ new Map();
|
|
7028
|
-
|
|
7042
|
+
if (found === void 0) return table;
|
|
7043
|
+
for (const [alias, targets2] of Object.entries(found.paths)) {
|
|
7029
7044
|
if (alias === "apps/*" || alias === "libs/*") continue;
|
|
7030
7045
|
table.set(
|
|
7031
7046
|
alias,
|
|
@@ -7129,13 +7144,17 @@ function moduleOf(path2, roots) {
|
|
|
7129
7144
|
}
|
|
7130
7145
|
return best;
|
|
7131
7146
|
}
|
|
7132
|
-
function
|
|
7133
|
-
|
|
7134
|
-
|
|
7147
|
+
function chainKey(found) {
|
|
7148
|
+
return `${found.declaredIn}\0${found.baseDirectory}\0${JSON.stringify(found.paths)}`;
|
|
7149
|
+
}
|
|
7150
|
+
function importerTables(workspaceRoot, moduleRoots) {
|
|
7135
7151
|
const baseTable = aliasTable(workspaceRoot);
|
|
7136
|
-
const tableByChain = /* @__PURE__ */ new Map(
|
|
7137
|
-
|
|
7138
|
-
|
|
7152
|
+
const tableByChain = /* @__PURE__ */ new Map();
|
|
7153
|
+
try {
|
|
7154
|
+
const base = chainPaths(join30(workspaceRoot, WORKSPACE_TSCONFIG));
|
|
7155
|
+
if (base !== void 0) tableByChain.set(chainKey(base), baseTable);
|
|
7156
|
+
} catch {
|
|
7157
|
+
}
|
|
7139
7158
|
const tableByModule = /* @__PURE__ */ new Map();
|
|
7140
7159
|
const readCache = /* @__PURE__ */ new Map();
|
|
7141
7160
|
const unreadable = [];
|
|
@@ -7152,13 +7171,19 @@ function buildConsumerIndex(workspaceRoot, moduleRoots) {
|
|
|
7152
7171
|
const found = importerPaths(workspaceRoot, module, readCache, unreadable);
|
|
7153
7172
|
let table = baseTable;
|
|
7154
7173
|
if (found !== void 0) {
|
|
7155
|
-
const
|
|
7156
|
-
table = tableByChain.get(
|
|
7157
|
-
tableByChain.set(
|
|
7174
|
+
const key = chainKey(found);
|
|
7175
|
+
table = tableByChain.get(key) ?? toTable(workspaceRoot, found);
|
|
7176
|
+
tableByChain.set(key, table);
|
|
7158
7177
|
}
|
|
7159
7178
|
tableByModule.set(module, table);
|
|
7160
7179
|
return table;
|
|
7161
7180
|
};
|
|
7181
|
+
return { baseTable, tableFor, unreadable };
|
|
7182
|
+
}
|
|
7183
|
+
function buildConsumerIndex(workspaceRoot, moduleRoots) {
|
|
7184
|
+
const imported = /* @__PURE__ */ new Set();
|
|
7185
|
+
const testOnly = /* @__PURE__ */ new Set();
|
|
7186
|
+
const { baseTable, tableFor, unreadable } = importerTables(workspaceRoot, moduleRoots);
|
|
7162
7187
|
const hasAnyTable = baseTable.size > 0 || moduleRoots.some((module) => tableFor(`${module}/probe.ts`).size > 0);
|
|
7163
7188
|
if (!hasAnyTable) return { imported, testOnly, builtFrom: "no alias table" };
|
|
7164
7189
|
const result = spawnSync5(
|
|
@@ -7217,7 +7242,7 @@ function buildConsumerIndex(workspaceRoot, moduleRoots) {
|
|
|
7217
7242
|
imported,
|
|
7218
7243
|
testOnly,
|
|
7219
7244
|
builtFrom: `git grep over ${distinctSpecifiers} distinct specifiers, ${seenByTable.size} alias table(s)`,
|
|
7220
|
-
warnings: unreadable
|
|
7245
|
+
warnings: [...unreadable]
|
|
7221
7246
|
};
|
|
7222
7247
|
}
|
|
7223
7248
|
function cacheKey(workspaceRoot) {
|
|
@@ -8332,161 +8357,6 @@ import { existsSync as existsSync21, readFileSync as readFileSync23 } from "node
|
|
|
8332
8357
|
import { createRequire } from "node:module";
|
|
8333
8358
|
import { join as join33 } from "node:path";
|
|
8334
8359
|
|
|
8335
|
-
// src/roles/typescript/presets/nest.json
|
|
8336
|
-
var nest_default = {
|
|
8337
|
-
compilerOptions: {
|
|
8338
|
-
module: "esnext",
|
|
8339
|
-
moduleResolution: "bundler",
|
|
8340
|
-
types: ["node"],
|
|
8341
|
-
experimentalDecorators: true,
|
|
8342
|
-
emitDecoratorMetadata: true,
|
|
8343
|
-
declaration: true,
|
|
8344
|
-
sourceMap: true,
|
|
8345
|
-
importHelpers: true,
|
|
8346
|
-
target: "es2021",
|
|
8347
|
-
lib: ["es2023", "dom"]
|
|
8348
|
-
},
|
|
8349
|
-
notes: {
|
|
8350
|
-
module: "the backends are webpack-bundled and tsc only typechecks, so the module format is the bundler's concern; `bundler` resolution is what the repo already uses, and the only Node-friendly option TS7 still accepts since it removed classic `node`",
|
|
8351
|
-
target: "raised from tsconfig.base.json (sentinel#147) with the value every nest module already applied: `es2021`. Same value, so `useDefineForClassFields` does not flip (TS2612), which is why it was left to the base before. Moving it to a newer target is its own change, measured on its own",
|
|
8352
|
-
lib: "raised from tsconfig.base.json (sentinel#147) as the base had it, DOM included: narrowing `lib` drops DOM types some modules use (GLfloat), so that is its own change",
|
|
8353
|
-
importHelpers: "raised from tsconfig.base.json (sentinel#147): `true` in every module of this stack, through the base"
|
|
8354
|
-
},
|
|
8355
|
-
fromBase: ["importHelpers", "target", "lib"]
|
|
8356
|
-
};
|
|
8357
|
-
|
|
8358
|
-
// src/roles/typescript/presets/node.json
|
|
8359
|
-
var node_default = {
|
|
8360
|
-
compilerOptions: {
|
|
8361
|
-
module: "esnext",
|
|
8362
|
-
moduleResolution: "bundler",
|
|
8363
|
-
types: ["node"],
|
|
8364
|
-
declaration: true,
|
|
8365
|
-
importHelpers: true,
|
|
8366
|
-
target: "es2021",
|
|
8367
|
-
lib: ["es2023", "dom"],
|
|
8368
|
-
sourceMap: true
|
|
8369
|
-
},
|
|
8370
|
-
notes: {
|
|
8371
|
-
module: "esnext/bundler like the react and nest presets, matching a monorepo whose libs are bundler-resolved in practice. NOT NodeNext: that would force its stricter ESM rules onto libs the repo resolves through a bundler",
|
|
8372
|
-
target: "raised from tsconfig.base.json (sentinel#147) with the value every node module already applied: `es2021`. Same value, so `useDefineForClassFields` does not flip (TS2612), which is why it was left to the base before. Moving it to a newer target is its own change, measured on its own",
|
|
8373
|
-
lib: "raised from tsconfig.base.json (sentinel#147) as the base had it, DOM included: narrowing `lib` drops DOM types some modules use (GLfloat), so that is its own change",
|
|
8374
|
-
importHelpers: "raised from tsconfig.base.json (sentinel#147): `true` in every module of this stack, through the base",
|
|
8375
|
-
sourceMap: "raised from tsconfig.base.json (sentinel#147): `true` in every node module, through the base; nest already set it"
|
|
8376
|
-
},
|
|
8377
|
-
fromBase: ["importHelpers", "target", "lib", "sourceMap"]
|
|
8378
|
-
};
|
|
8379
|
-
|
|
8380
|
-
// src/roles/typescript/presets/react.json
|
|
8381
|
-
var react_default = {
|
|
8382
|
-
compilerOptions: {
|
|
8383
|
-
target: "ES2023",
|
|
8384
|
-
lib: ["ES2023", "DOM", "DOM.Iterable"],
|
|
8385
|
-
module: "ESNext",
|
|
8386
|
-
moduleResolution: "bundler",
|
|
8387
|
-
jsx: "react-jsx",
|
|
8388
|
-
useDefineForClassFields: true,
|
|
8389
|
-
isolatedModules: true,
|
|
8390
|
-
moduleDetection: "force",
|
|
8391
|
-
noEmit: true,
|
|
8392
|
-
noUncheckedSideEffectImports: true
|
|
8393
|
-
},
|
|
8394
|
-
notes: {
|
|
8395
|
-
noEmit: "vite owns the build; tsc only typechecks here"
|
|
8396
|
-
}
|
|
8397
|
-
};
|
|
8398
|
-
|
|
8399
|
-
// src/roles/typescript/presets/shared.json
|
|
8400
|
-
var shared_default2 = {
|
|
8401
|
-
$schema: "https://json.schemastore.org/tsconfig",
|
|
8402
|
-
compilerOptions: {
|
|
8403
|
-
strict: true,
|
|
8404
|
-
noFallthroughCasesInSwitch: true,
|
|
8405
|
-
forceConsistentCasingInFileNames: true,
|
|
8406
|
-
esModuleInterop: true,
|
|
8407
|
-
skipLibCheck: true,
|
|
8408
|
-
verbatimModuleSyntax: true,
|
|
8409
|
-
resolveJsonModule: true,
|
|
8410
|
-
skipDefaultLibCheck: true
|
|
8411
|
-
},
|
|
8412
|
-
deferred: {
|
|
8413
|
-
noImplicitAny: {
|
|
8414
|
-
phase: 2,
|
|
8415
|
-
reason: "the implicit-any migration (TS70xx)"
|
|
8416
|
-
},
|
|
8417
|
-
noUnusedLocals: {
|
|
8418
|
-
phase: 2,
|
|
8419
|
-
reason: "unused-local cleanup (TS6133)"
|
|
8420
|
-
},
|
|
8421
|
-
noUnusedParameters: {
|
|
8422
|
-
phase: 2,
|
|
8423
|
-
reason: "unused-parameter cleanup (TS6133)"
|
|
8424
|
-
}
|
|
8425
|
-
},
|
|
8426
|
-
notes: {
|
|
8427
|
-
verbatimModuleSyntax: "raised from tsconfig.base.json (HUB-43866, sentinel#147): every sentinel module applied `true` through the base, so a module that stops extending it keeps it. A module that sets `false` itself keeps its own value, and `--init` does not strip it (see fromBase)",
|
|
8428
|
-
resolveJsonModule: "raised from tsconfig.base.json (sentinel#147): `true` in all 113 sentinel modules, through the base",
|
|
8429
|
-
skipDefaultLibCheck: "raised from tsconfig.base.json (sentinel#147): `true` in all 113 sentinel modules, through the base"
|
|
8430
|
-
},
|
|
8431
|
-
fromBase: ["verbatimModuleSyntax", "resolveJsonModule", "skipDefaultLibCheck"]
|
|
8432
|
-
};
|
|
8433
|
-
|
|
8434
|
-
// src/roles/typescript/preset-data.ts
|
|
8435
|
-
var SHARED = shared_default2;
|
|
8436
|
-
var LAYERS = {
|
|
8437
|
-
nest: nest_default,
|
|
8438
|
-
node: node_default,
|
|
8439
|
-
react: react_default
|
|
8440
|
-
};
|
|
8441
|
-
var SHIPPED_PRESETS = Object.keys(LAYERS).sort();
|
|
8442
|
-
var DEFERRED_RULES = Object.entries(SHARED.deferred ?? {}).map(([rule, entry]) => ({ rule, phase: entry.phase, reason: entry.reason })).sort((left, right) => left.rule.localeCompare(right.rule));
|
|
8443
|
-
function validate() {
|
|
8444
|
-
for (const { rule, phase, reason } of DEFERRED_RULES) {
|
|
8445
|
-
if (!Number.isInteger(phase) || phase < 2) {
|
|
8446
|
-
throw new Error(
|
|
8447
|
-
`deferred rule "${rule}" has phase ${phase}; a deferred rule is scheduled for phase 2 or later`
|
|
8448
|
-
);
|
|
8449
|
-
}
|
|
8450
|
-
if (reason.trim() === "") {
|
|
8451
|
-
throw new Error(
|
|
8452
|
-
`deferred rule "${rule}" has no reason; --inspect reports it and would say nothing`
|
|
8453
|
-
);
|
|
8454
|
-
}
|
|
8455
|
-
if (rule in SHARED.compilerOptions) {
|
|
8456
|
-
throw new Error(
|
|
8457
|
-
`"${rule}" is deferred and also set by the shared layer; it would be announced as not enforced while being enforced`
|
|
8458
|
-
);
|
|
8459
|
-
}
|
|
8460
|
-
for (const [preset, layer] of Object.entries(LAYERS)) {
|
|
8461
|
-
if (layer && rule in layer.compilerOptions) {
|
|
8462
|
-
throw new Error(
|
|
8463
|
-
`"${rule}" is deferred and also set by the ${preset} preset; it would be announced as not enforced while being enforced`
|
|
8464
|
-
);
|
|
8465
|
-
}
|
|
8466
|
-
}
|
|
8467
|
-
}
|
|
8468
|
-
}
|
|
8469
|
-
validate();
|
|
8470
|
-
function raisedFromBase(preset) {
|
|
8471
|
-
return [...SHARED.fromBase ?? [], ...LAYERS[preset]?.fromBase ?? []];
|
|
8472
|
-
}
|
|
8473
|
-
function hasShippedPreset(preset) {
|
|
8474
|
-
return preset in LAYERS;
|
|
8475
|
-
}
|
|
8476
|
-
function tsPresetFor(preset) {
|
|
8477
|
-
const layer = LAYERS[preset];
|
|
8478
|
-
if (!layer) throw new Error(`no TypeScript preset ships for preset "${preset}"`);
|
|
8479
|
-
return {
|
|
8480
|
-
...SHARED.$schema === void 0 ? {} : { $schema: SHARED.$schema },
|
|
8481
|
-
compilerOptions: { ...SHARED.compilerOptions, ...layer.compilerOptions }
|
|
8482
|
-
};
|
|
8483
|
-
}
|
|
8484
|
-
|
|
8485
|
-
// src/roles/typescript/phased-rules.ts
|
|
8486
|
-
function deferredRuleNames2() {
|
|
8487
|
-
return deferredRuleNames(DEFERRED_RULES);
|
|
8488
|
-
}
|
|
8489
|
-
|
|
8490
8360
|
// src/roles/typescript/config-policy.ts
|
|
8491
8361
|
var PERMITTED_COMPILER_OPTIONS = [
|
|
8492
8362
|
"paths",
|
|
@@ -8509,11 +8379,11 @@ function presetOwnedKeys2(compilerOptions, preset) {
|
|
|
8509
8379
|
const raised = raisedFromBase(preset);
|
|
8510
8380
|
const presetOptions = tsPresetFor(preset).compilerOptions;
|
|
8511
8381
|
return owned.filter(
|
|
8512
|
-
(key) => !raised.includes(key) || sameOptionValue(compilerOptions?.[key], presetOptions[key])
|
|
8382
|
+
(key) => !raised.includes(key) || sameOptionValue(key, compilerOptions?.[key], presetOptions[key])
|
|
8513
8383
|
);
|
|
8514
8384
|
}
|
|
8515
|
-
function sameOptionValue(left, right) {
|
|
8516
|
-
return
|
|
8385
|
+
function sameOptionValue(key, left, right) {
|
|
8386
|
+
return comparable(key, left) === comparable(key, right);
|
|
8517
8387
|
}
|
|
8518
8388
|
function localOnlyCompilerOptions(compilerOptions, preset) {
|
|
8519
8389
|
const sets = presetCompilerOptionKeys(preset);
|
|
@@ -8524,6 +8394,39 @@ function localOnlyCompilerOptions(compilerOptions, preset) {
|
|
|
8524
8394
|
);
|
|
8525
8395
|
return [...localOnlyKeys(compilerOptions, PERMITTED_COMPILER_OPTIONS, sets), ...keptOverrides];
|
|
8526
8396
|
}
|
|
8397
|
+
var describe2 = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
8398
|
+
function standardOverrides(compilerOptions, preset) {
|
|
8399
|
+
if (preset === void 0 || !hasShippedPreset(preset)) return [];
|
|
8400
|
+
const presetOptions = tsPresetFor(preset).compilerOptions;
|
|
8401
|
+
return raisedFromBase(preset).filter(
|
|
8402
|
+
(key) => compilerOptions !== void 0 && key in compilerOptions && !sameOptionValue(key, compilerOptions[key], presetOptions[key])
|
|
8403
|
+
).map((key) => ({
|
|
8404
|
+
rule: key,
|
|
8405
|
+
value: compilerOptions?.[key],
|
|
8406
|
+
standard: presetOptions[key],
|
|
8407
|
+
reason: `${describe2(compilerOptions?.[key])}, where the ${preset} preset says ${describe2(presetOptions[key])}`
|
|
8408
|
+
}));
|
|
8409
|
+
}
|
|
8410
|
+
function legacyCompromises(compilerOptions, preset) {
|
|
8411
|
+
const stack = preset !== void 0 && hasShippedPreset(preset) ? tsPresetFor(preset).compilerOptions : {};
|
|
8412
|
+
const applied = appliedOptions({ compilerOptions: stack });
|
|
8413
|
+
return Object.entries(tsLegacyLayer().compilerOptions).filter(
|
|
8414
|
+
([key]) => !(key in stack) && !(compilerOptions !== void 0 && key in compilerOptions)
|
|
8415
|
+
).map(([key, value]) => {
|
|
8416
|
+
const standard = applied.has(key) ? JSON.parse(applied.get(key) ?? "null") : null;
|
|
8417
|
+
return {
|
|
8418
|
+
rule: key,
|
|
8419
|
+
value,
|
|
8420
|
+
standard,
|
|
8421
|
+
reason: `${describe2(value)}, ${standard === null ? "which the standard leaves to tsc" : `where the standard says ${describe2(standard)}`}, inherited from ${LEGACY_ENTRY}`
|
|
8422
|
+
};
|
|
8423
|
+
});
|
|
8424
|
+
}
|
|
8425
|
+
|
|
8426
|
+
// src/roles/typescript/phased-rules.ts
|
|
8427
|
+
function deferredRuleNames2() {
|
|
8428
|
+
return deferredRuleNames(DEFERRED_RULES);
|
|
8429
|
+
}
|
|
8527
8430
|
|
|
8528
8431
|
// src/roles/typescript/resolve-tsconfig-target.ts
|
|
8529
8432
|
var TSCONFIG_CANDIDATES = ["tsconfig.app.json", "tsconfig.json"];
|
|
@@ -8542,7 +8445,7 @@ function resolveTsconfigTarget(moduleDir) {
|
|
|
8542
8445
|
}
|
|
8543
8446
|
|
|
8544
8447
|
// src/roles/typescript/read-adoption.ts
|
|
8545
|
-
var SENTINEL_PRESET =
|
|
8448
|
+
var SENTINEL_PRESET = STACK_PRESET_PATTERN;
|
|
8546
8449
|
function readTsconfigAdoption(cwd) {
|
|
8547
8450
|
return readAdoption(cwd, {
|
|
8548
8451
|
candidates: TSCONFIG_CANDIDATES,
|
|
@@ -8601,11 +8504,10 @@ function typecheckScripts(cwd) {
|
|
|
8601
8504
|
};
|
|
8602
8505
|
}
|
|
8603
8506
|
var SENTINEL_TS_PRESET = /@hublo\/sentinel\/(?:typescript|tsconfig)\//;
|
|
8604
|
-
var SENTINEL_LEGACY = /@hublo\/sentinel\/(?:typescript|tsconfig)\/legacy$/;
|
|
8605
8507
|
function composeExtends(current, preset) {
|
|
8606
8508
|
const chain = typeof current === "string" ? [current] : Array.isArray(current) ? current.filter((entry) => typeof entry === "string") : [];
|
|
8607
8509
|
const withoutOwn = chain.filter(
|
|
8608
|
-
(entry) => entry !== preset && (!SENTINEL_TS_PRESET.test(entry) ||
|
|
8510
|
+
(entry) => entry !== preset && (!SENTINEL_TS_PRESET.test(entry) || isLegacyEntry(entry))
|
|
8609
8511
|
);
|
|
8610
8512
|
return [...withoutOwn, preset];
|
|
8611
8513
|
}
|
|
@@ -8936,14 +8838,31 @@ var TscAdapter = class _TscAdapter extends BaseAdapter {
|
|
|
8936
8838
|
*/
|
|
8937
8839
|
async inspect(ctx) {
|
|
8938
8840
|
const target = resolveTsconfigTarget(ctx.cwd);
|
|
8841
|
+
const { preset } = readTsconfigAdoption(ctx.cwd);
|
|
8842
|
+
const stack = preset === null ? void 0 : preset.slice(preset.lastIndexOf("/") + 1);
|
|
8843
|
+
const config = this.readConfig(join33(ctx.cwd, target.path));
|
|
8844
|
+
const options = config?.compilerOptions;
|
|
8845
|
+
const overrides = standardOverrides(options, stack);
|
|
8846
|
+
const legacy = config !== void 0 && extendsList(config).some(isLegacyEntry) ? legacyCompromises(options, stack) : [];
|
|
8939
8847
|
return {
|
|
8940
8848
|
runner: "tsc",
|
|
8941
8849
|
configFile: target.path,
|
|
8942
8850
|
configState: target.reason,
|
|
8943
8851
|
phase: 1,
|
|
8944
|
-
deferred: DEFERRED_RULES
|
|
8852
|
+
deferred: DEFERRED_RULES,
|
|
8853
|
+
...overrides.length > 0 ? { standardOverrides: overrides } : {},
|
|
8854
|
+
...legacy.length > 0 ? { legacyCompromises: legacy } : {}
|
|
8945
8855
|
};
|
|
8946
8856
|
}
|
|
8857
|
+
/** A tsconfig as written, or undefined when it is missing or not readable as JSONC. */
|
|
8858
|
+
readConfig(file) {
|
|
8859
|
+
if (!existsSync21(file)) return void 0;
|
|
8860
|
+
try {
|
|
8861
|
+
return parseJsonc(readFileSync23(file, "utf8"), file);
|
|
8862
|
+
} catch {
|
|
8863
|
+
return void 0;
|
|
8864
|
+
}
|
|
8865
|
+
}
|
|
8947
8866
|
/**
|
|
8948
8867
|
* Adoption + conformity from the committed tsconfig, for `--status`. No tsc run and
|
|
8949
8868
|
* no preset guessing: reads the actual `extends` chain, so a workspace-wide scan is
|