@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.
@@ -0,0 +1,297 @@
1
+ // src/roles/typescript/compare.ts
2
+ var STRICT_FAMILY = [
3
+ "alwaysStrict",
4
+ "noImplicitAny",
5
+ "noImplicitThis",
6
+ "strictBindCallApply",
7
+ "strictBuiltinIteratorReturn",
8
+ "strictFunctionTypes",
9
+ "strictNullChecks",
10
+ "strictPropertyInitialization",
11
+ "useUnknownInCatchVariables"
12
+ ];
13
+ var CASE_INSENSITIVE = /* @__PURE__ */ new Set([
14
+ "jsx",
15
+ "lib",
16
+ "module",
17
+ "moduleDetection",
18
+ "moduleResolution",
19
+ "target"
20
+ ]);
21
+ function targetYear(target) {
22
+ const name = typeof target === "string" ? target.toLowerCase() : "es5";
23
+ if (name === "esnext") return Number.MAX_SAFE_INTEGER;
24
+ const year = Number(name.replace(/^es/, ""));
25
+ return Number.isFinite(year) ? year : 5;
26
+ }
27
+ function comparable(key, value) {
28
+ const json = JSON.stringify(value) ?? "undefined";
29
+ return CASE_INSENSITIVE.has(key) ? json.toLowerCase() : json;
30
+ }
31
+ function appliedOptions(config) {
32
+ const options = new Map(Object.entries(config.compilerOptions ?? {}));
33
+ options.delete("paths");
34
+ const derive = (key, value) => {
35
+ if (!options.has(key)) options.set(key, value);
36
+ };
37
+ if (options.get("strict") === true) for (const key of STRICT_FAMILY) derive(key, true);
38
+ derive("allowJs", false);
39
+ if (options.get("esModuleInterop") === true) derive("allowSyntheticDefaultImports", true);
40
+ if (options.get("verbatimModuleSyntax") === true) derive("isolatedModules", true);
41
+ if (options.get("isolatedModules") === true) derive("preserveConstEnums", true);
42
+ derive("useDefineForClassFields", targetYear(options.get("target")) >= 2022);
43
+ return new Map([...options].map(([key, value]) => [key, comparable(key, value)]));
44
+ }
45
+ function diffConfigs(before, after) {
46
+ const was = appliedOptions(before);
47
+ const now = appliedOptions(after);
48
+ const differences = [];
49
+ for (const key of /* @__PURE__ */ new Set([...was.keys(), ...now.keys()])) {
50
+ if (was.get(key) !== now.get(key)) {
51
+ differences.push({ key: `compilerOptions.${key}`, before: was.get(key), after: now.get(key) });
52
+ }
53
+ }
54
+ for (const key of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(after)])) {
55
+ if (key === "compilerOptions") continue;
56
+ const left = JSON.stringify(before[key]);
57
+ const right = JSON.stringify(after[key]);
58
+ if (left !== right) differences.push({ key, before: left, after: right });
59
+ }
60
+ return differences;
61
+ }
62
+ function remainder(effective, layers, ownKeys) {
63
+ const applied = appliedOptions(effective);
64
+ const given = appliedOptions(layers);
65
+ const written = [];
66
+ for (const [key, value] of applied) {
67
+ if (ownKeys.has(key) || given.get(key) === value) continue;
68
+ written.push({ key, value: effective.compilerOptions?.[key] ?? JSON.parse(value) });
69
+ }
70
+ return written;
71
+ }
72
+
73
+ // src/roles/typescript/presets/legacy.json
74
+ var legacy_default = {
75
+ $schema: "https://json.schemastore.org/tsconfig",
76
+ compilerOptions: {
77
+ noImplicitAny: false,
78
+ noImplicitThis: false,
79
+ strictBindCallApply: false,
80
+ strictFunctionTypes: false,
81
+ strictPropertyInitialization: false,
82
+ useUnknownInCatchVariables: false,
83
+ ignoreDeprecations: "6.0",
84
+ experimentalDecorators: true,
85
+ emitDecoratorMetadata: true,
86
+ declaration: false,
87
+ types: ["vite/client", "@types/segment-analytics"],
88
+ importHelpers: true,
89
+ sourceMap: true
90
+ },
91
+ notes: {
92
+ purpose: "the compromises tsconfig.base.json applied to every module, kept in one place so a module that stops extending the base loses nothing (sentinel#147). Placed LEFT of the stack preset, where the base was, so the stack preset keeps winning wherever both set an option",
93
+ who: "added only by `--migrate --typescript`, never by `--init`: a new module is born with the full strict set, and a module that has paid this debt removes one `extends` line",
94
+ strict: "the six opt-outs below turn off parts of `strict`, which the shared layer sets; the base had them for every module",
95
+ ignoreDeprecations: "temporary by nature: it silences the TypeScript 6 deprecations the base still relies on",
96
+ react: "`declaration`, `types`, the decorator flags, `importHelpers` and `sourceMap` are what the base gave react modules that the react preset does not set. `types` moves whole: an array is replaced, never merged, so splitting it between two presets would lose an entry",
97
+ types: "`vite/client` and `@types/segment-analytics` are the base's, kept as they were: on react they apply, on nest and node the stack preset's `types: [node]` wins, exactly as it did over the base. Not a choice for a backend, a copy of the debt, to clean up with it"
98
+ }
99
+ };
100
+
101
+ // src/roles/typescript/presets/nest.json
102
+ var nest_default = {
103
+ compilerOptions: {
104
+ module: "esnext",
105
+ moduleResolution: "bundler",
106
+ types: ["node"],
107
+ experimentalDecorators: true,
108
+ emitDecoratorMetadata: true,
109
+ declaration: true,
110
+ sourceMap: true,
111
+ importHelpers: true,
112
+ target: "es2021",
113
+ lib: ["es2023", "dom"]
114
+ },
115
+ notes: {
116
+ 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`",
117
+ 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",
118
+ 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",
119
+ importHelpers: "raised from tsconfig.base.json (sentinel#147): `true` in every module of this stack, through the base"
120
+ },
121
+ fromBase: ["importHelpers", "target", "lib"]
122
+ };
123
+
124
+ // src/roles/typescript/presets/node.json
125
+ var node_default = {
126
+ compilerOptions: {
127
+ module: "esnext",
128
+ moduleResolution: "bundler",
129
+ types: ["node"],
130
+ declaration: true,
131
+ importHelpers: true,
132
+ target: "es2021",
133
+ lib: ["es2023", "dom"],
134
+ sourceMap: true
135
+ },
136
+ notes: {
137
+ 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",
138
+ 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",
139
+ 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",
140
+ importHelpers: "raised from tsconfig.base.json (sentinel#147): `true` in every module of this stack, through the base",
141
+ sourceMap: "raised from tsconfig.base.json (sentinel#147): `true` in every node module, through the base; nest already set it"
142
+ },
143
+ fromBase: ["importHelpers", "target", "lib", "sourceMap"]
144
+ };
145
+
146
+ // src/roles/typescript/presets/react.json
147
+ var react_default = {
148
+ compilerOptions: {
149
+ target: "ES2023",
150
+ lib: ["ES2023", "DOM", "DOM.Iterable"],
151
+ module: "ESNext",
152
+ moduleResolution: "bundler",
153
+ jsx: "react-jsx",
154
+ useDefineForClassFields: true,
155
+ isolatedModules: true,
156
+ moduleDetection: "force",
157
+ noEmit: true,
158
+ noUncheckedSideEffectImports: true
159
+ },
160
+ notes: {
161
+ noEmit: "vite owns the build; tsc only typechecks here"
162
+ }
163
+ };
164
+
165
+ // src/roles/typescript/presets/shared.json
166
+ var shared_default = {
167
+ $schema: "https://json.schemastore.org/tsconfig",
168
+ compilerOptions: {
169
+ strict: true,
170
+ noFallthroughCasesInSwitch: true,
171
+ forceConsistentCasingInFileNames: true,
172
+ esModuleInterop: true,
173
+ skipLibCheck: true,
174
+ verbatimModuleSyntax: true,
175
+ resolveJsonModule: true,
176
+ skipDefaultLibCheck: true
177
+ },
178
+ deferred: {
179
+ noImplicitAny: {
180
+ phase: 2,
181
+ reason: "the implicit-any migration (TS70xx)"
182
+ },
183
+ noUnusedLocals: {
184
+ phase: 2,
185
+ reason: "unused-local cleanup (TS6133)"
186
+ },
187
+ noUnusedParameters: {
188
+ phase: 2,
189
+ reason: "unused-parameter cleanup (TS6133)"
190
+ }
191
+ },
192
+ notes: {
193
+ 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)",
194
+ resolveJsonModule: "raised from tsconfig.base.json (sentinel#147): `true` in all 113 sentinel modules, through the base",
195
+ skipDefaultLibCheck: "raised from tsconfig.base.json (sentinel#147): `true` in all 113 sentinel modules, through the base"
196
+ },
197
+ fromBase: ["verbatimModuleSyntax", "resolveJsonModule", "skipDefaultLibCheck"]
198
+ };
199
+
200
+ // src/roles/typescript/preset-data.ts
201
+ var SHARED = shared_default;
202
+ var LAYERS = {
203
+ nest: nest_default,
204
+ node: node_default,
205
+ react: react_default
206
+ };
207
+ var LEGACY = legacy_default;
208
+ var LEGACY_LAYER = "legacy";
209
+ var SHIPPED_PRESETS = Object.keys(LAYERS).sort();
210
+ 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));
211
+ function validate() {
212
+ for (const { rule, phase, reason } of DEFERRED_RULES) {
213
+ if (!Number.isInteger(phase) || phase < 2) {
214
+ throw new Error(
215
+ `deferred rule "${rule}" has phase ${phase}; a deferred rule is scheduled for phase 2 or later`
216
+ );
217
+ }
218
+ if (reason.trim() === "") {
219
+ throw new Error(
220
+ `deferred rule "${rule}" has no reason; --inspect reports it and would say nothing`
221
+ );
222
+ }
223
+ if (rule in SHARED.compilerOptions) {
224
+ throw new Error(
225
+ `"${rule}" is deferred and also set by the shared layer; it would be announced as not enforced while being enforced`
226
+ );
227
+ }
228
+ for (const [preset, layer] of Object.entries(LAYERS)) {
229
+ if (layer && rule in layer.compilerOptions) {
230
+ throw new Error(
231
+ `"${rule}" is deferred and also set by the ${preset} preset; it would be announced as not enforced while being enforced`
232
+ );
233
+ }
234
+ }
235
+ }
236
+ }
237
+ validate();
238
+ function tsLegacyLayer() {
239
+ return {
240
+ ...LEGACY.$schema === void 0 ? {} : { $schema: LEGACY.$schema },
241
+ compilerOptions: { ...LEGACY.compilerOptions }
242
+ };
243
+ }
244
+ function raisedFromBase(preset) {
245
+ return [...SHARED.fromBase ?? [], ...LAYERS[preset]?.fromBase ?? []];
246
+ }
247
+ function hasShippedPreset(preset) {
248
+ return preset in LAYERS;
249
+ }
250
+ function tsPresetFor(preset) {
251
+ const layer = LAYERS[preset];
252
+ if (!layer) throw new Error(`no TypeScript preset ships for preset "${preset}"`);
253
+ return {
254
+ ...SHARED.$schema === void 0 ? {} : { $schema: SHARED.$schema },
255
+ compilerOptions: { ...SHARED.compilerOptions, ...layer.compilerOptions }
256
+ };
257
+ }
258
+
259
+ // src/roles/typescript/legacy.ts
260
+ var BASE_FILE = "tsconfig.base.json";
261
+ var LEGACY_ENTRY = `@hublo/sentinel/typescript/${LEGACY_LAYER}`;
262
+ function isLegacyEntry(entry) {
263
+ return entry === LEGACY_ENTRY;
264
+ }
265
+ var STACK_PRESET_PATTERN = new RegExp(
266
+ `^@hublo\\/sentinel\\/(?:typescript|tsconfig)\\/(?!${LEGACY_LAYER}$)[a-z-]+$`
267
+ );
268
+ function isBaseEntry(entry) {
269
+ return entry === BASE_FILE || entry.endsWith(`/${BASE_FILE}`);
270
+ }
271
+ function isStackPresetEntry(entry) {
272
+ return STACK_PRESET_PATTERN.test(entry);
273
+ }
274
+ function extendsList(config) {
275
+ const value = config.extends;
276
+ if (typeof value === "string") return [value];
277
+ return Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
278
+ }
279
+
280
+ export {
281
+ comparable,
282
+ appliedOptions,
283
+ diffConfigs,
284
+ remainder,
285
+ SHIPPED_PRESETS,
286
+ DEFERRED_RULES,
287
+ tsLegacyLayer,
288
+ raisedFromBase,
289
+ hasShippedPreset,
290
+ tsPresetFor,
291
+ LEGACY_ENTRY,
292
+ isLegacyEntry,
293
+ STACK_PRESET_PATTERN,
294
+ isBaseEntry,
295
+ isStackPresetEntry,
296
+ extendsList
297
+ };
package/dist/index.js CHANGED
@@ -6,7 +6,8 @@ import {
6
6
  registerAdapters,
7
7
  resolve,
8
8
  setDefaultRunner
9
- } from "./chunk-F6ART7RH.js";
9
+ } from "./chunk-YRBFCQQI.js";
10
+ import "./chunk-ZZMYV576.js";
10
11
  import {
11
12
  BaseAdapter
12
13
  } from "./chunk-P6KTBQ2Q.js";