@stateward/core 1.2.2 → 1.3.0

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.
Files changed (67) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/program-record.d.ts +7 -0
  4. package/dist/backend/typescript6.d.ts +33 -32
  5. package/dist/backend/typescript6.js +1438 -139
  6. package/dist/baseline.d.ts +1 -1
  7. package/dist/baseline.js +14 -10
  8. package/dist/cache.d.ts +74 -4
  9. package/dist/cache.js +211 -37
  10. package/dist/checker.d.ts +6 -1
  11. package/dist/checker.js +10 -0
  12. package/dist/class-id.d.ts +34 -0
  13. package/dist/class-id.js +93 -0
  14. package/dist/code-text.d.ts +8 -0
  15. package/dist/code-text.js +66 -0
  16. package/dist/config-file.js +7 -5
  17. package/dist/config.d.ts +10 -2
  18. package/dist/config.js +490 -48
  19. package/dist/define.d.ts +8 -2
  20. package/dist/disk-cache.d.ts +2 -0
  21. package/dist/disk-cache.js +77 -11
  22. package/dist/engine.d.ts +33 -1
  23. package/dist/engine.js +344 -24
  24. package/dist/fact-lines.d.ts +31 -0
  25. package/dist/fact-lines.js +197 -0
  26. package/dist/facts-versions.d.ts +27 -0
  27. package/dist/facts-versions.js +99 -0
  28. package/dist/fixes.js +4 -1
  29. package/dist/ignores.d.ts +11 -0
  30. package/dist/ignores.js +74 -27
  31. package/dist/implementation.d.ts +0 -6
  32. package/dist/implementation.js +0 -17
  33. package/dist/index.d.ts +8 -9
  34. package/dist/index.js +10 -7
  35. package/dist/internal.d.ts +7 -4
  36. package/dist/internal.js +5 -3
  37. package/dist/lazy.d.ts +8 -1
  38. package/dist/lazy.js +27 -2
  39. package/dist/ledger.d.ts +2 -2
  40. package/dist/ledger.js +2 -2
  41. package/dist/off-by-default.d.ts +13 -0
  42. package/dist/off-by-default.js +15 -0
  43. package/dist/options.d.ts +21 -5
  44. package/dist/options.js +22 -7
  45. package/dist/package-facts.d.ts +211 -17
  46. package/dist/package-facts.js +520 -38
  47. package/dist/plan.d.ts +1 -1
  48. package/dist/plan.js +7 -2
  49. package/dist/release.d.ts +12 -21
  50. package/dist/release.js +26 -38
  51. package/dist/renamed.d.ts +22 -3
  52. package/dist/renamed.js +50 -16
  53. package/dist/rollout.js +7 -4
  54. package/dist/severity.d.ts +1 -1
  55. package/dist/severity.js +17 -3
  56. package/dist/test-runner.d.ts +18 -0
  57. package/dist/test-runner.js +483 -0
  58. package/dist/testing.d.ts +3 -3
  59. package/dist/testing.js +5 -5
  60. package/dist/timing.d.ts +8 -0
  61. package/dist/timing.js +35 -1
  62. package/dist/types.d.ts +692 -19
  63. package/dist/unread.d.ts +90 -0
  64. package/dist/unread.js +405 -0
  65. package/dist/vocabulary.d.ts +1 -1
  66. package/dist/vocabulary.js +1 -1
  67. package/package.json +4 -2
@@ -0,0 +1,90 @@
1
+ import type { Location } from "./types.js";
2
+ /**
3
+ * Something a rule could not read: why, after "not checked: … : " (`the typeorm version is not
4
+ * known`), and optionally what would let it be read and the place where reading stopped.
5
+ */
6
+ export type Unread = {
7
+ readonly kind: "unread";
8
+ readonly reason: string;
9
+ /** What would let it be read: the hint of the "not checked" finding. */
10
+ readonly hint?: string;
11
+ /** Where reading stopped, when that is not where the finding is reported. */
12
+ readonly location?: Location;
13
+ };
14
+ /** An `Unread` with its reason, and a hint and place when given. */
15
+ export declare function unread(reason: string, more?: {
16
+ readonly hint?: string;
17
+ readonly location?: Location;
18
+ }): Unread;
19
+ /**
20
+ * The standard "not checked" finding of an `Unread`: `not checked: <what>: <reason>`, with the
21
+ * `Unread`'s own hint when it has one, else `hint`. Give it to `FileContext.unknown` with the node,
22
+ * or to `ProjectContext.unknown` with the location.
23
+ */
24
+ export declare function unreadFinding(found: Unread, input: {
25
+ readonly what: string;
26
+ readonly hint: string;
27
+ }): {
28
+ readonly message: string;
29
+ readonly hint: string;
30
+ };
31
+ /** One step of `followBounded`: the answer, the next thing to follow, or what stopped it. */
32
+ export type FollowStep<T, R> = {
33
+ readonly kind: "done";
34
+ readonly value: R;
35
+ } | {
36
+ readonly kind: "next";
37
+ readonly next: T;
38
+ } | Unread;
39
+ /** What `followBounded` ends with: the answer, or why there is none. */
40
+ export type Followed<R> = {
41
+ readonly kind: "done";
42
+ readonly value: R;
43
+ } | Unread;
44
+ /**
45
+ * Follows `step` from `start` (a call to its callee, a class to its base) up to `limit` steps. A
46
+ * follow that runs out of depth is `Unread` ("stateward follows calls up to N levels"), and one
47
+ * that comes back to a place it already followed is `Unread` too: neither is a pass or a guess.
48
+ * `key` says when two places are the same one (by default, the same value); `noun` names what is
49
+ * followed in the reason ("calls", "base classes"); `location` is where the follow started.
50
+ */
51
+ export declare function followBounded<T, R>(start: T, step: (at: T, depth: number) => FollowStep<T, R>, options: {
52
+ readonly limit: number;
53
+ readonly noun?: string;
54
+ readonly location?: Location;
55
+ readonly key?: (at: T) => unknown;
56
+ }): Followed<R>;
57
+ /**
58
+ * What stateward knows of the version of a package a file's project runs: the exact version (from
59
+ * the installed copy or the lockfile, either allowed by the declared range), the range
60
+ * package.json declares when nothing more says, or why it is not known. Ask it a question with
61
+ * `versionSatisfies`; it never stands for a guessed version.
62
+ */
63
+ export type PackageVersionRead = {
64
+ readonly kind: "exact";
65
+ readonly name: string;
66
+ /** The version, as semver writes it: `0.3.20`, `0.3.0-beta.2`. */
67
+ readonly version: string;
68
+ readonly from: "installed" | "lockfile";
69
+ } | {
70
+ readonly kind: "range";
71
+ readonly name: string;
72
+ /** The range package.json declares: `^0.3.0`, `>=0.2 <0.4` (after `workspace:` or an alias). */
73
+ readonly range: string;
74
+ } | Unread;
75
+ /**
76
+ * Whether the version a read gives satisfies `query` (`"<0.3.0"`, `">=2.0.6"`), by semver's rules.
77
+ * For a range it answers only when every version the range allows agrees (`^0.2.0` is `<0.3.0`;
78
+ * `^0.3.0` is not `>=0.3.27` for all its versions, so it is `Unread`). An `Unread` read is
79
+ * passed on.
80
+ */
81
+ export declare function versionSatisfies(read: PackageVersionRead, query: string): boolean | Unread;
82
+ /**
83
+ * The major version a read gives: the exact version's, or the one major every version of the
84
+ * range has (`^10.4.22` is 10). `Unread` when the range spans majors (`>=9`).
85
+ */
86
+ export declare function versionMajor(read: PackageVersionRead): number | Unread;
87
+ export declare function packageVersionOf(ctx: {
88
+ readonly file: string;
89
+ }, name: string): PackageVersionRead;
90
+ //# sourceMappingURL=unread.d.ts.map
package/dist/unread.js ADDED
@@ -0,0 +1,405 @@
1
+ /**
2
+ * What a rule could not read, as a typed result: an unknown version, a
3
+ * follow that runs out of depth, a name that does not resolve. An `Unread` becomes a "not checked"
4
+ * finding with its reason (`unreadFinding`), never a pass and never a default guess.
5
+ */
6
+ import { existsSync, readFileSync, statSync } from "node:fs";
7
+ import path from "node:path";
8
+ import semver from "semver";
9
+ /** An `Unread` with its reason, and a hint and place when given. */
10
+ export function unread(reason, more = {}) {
11
+ return {
12
+ kind: "unread",
13
+ reason,
14
+ ...(more.hint === undefined ? {} : { hint: more.hint }),
15
+ ...(more.location === undefined ? {} : { location: more.location }),
16
+ };
17
+ }
18
+ /**
19
+ * The standard "not checked" finding of an `Unread`: `not checked: <what>: <reason>`, with the
20
+ * `Unread`'s own hint when it has one, else `hint`. Give it to `FileContext.unknown` with the node,
21
+ * or to `ProjectContext.unknown` with the location.
22
+ */
23
+ export function unreadFinding(found, input) {
24
+ return { message: `not checked: ${input.what}: ${found.reason}`, hint: found.hint ?? input.hint };
25
+ }
26
+ /**
27
+ * Follows `step` from `start` (a call to its callee, a class to its base) up to `limit` steps. A
28
+ * follow that runs out of depth is `Unread` ("stateward follows calls up to N levels"), and one
29
+ * that comes back to a place it already followed is `Unread` too: neither is a pass or a guess.
30
+ * `key` says when two places are the same one (by default, the same value); `noun` names what is
31
+ * followed in the reason ("calls", "base classes"); `location` is where the follow started.
32
+ */
33
+ export function followBounded(start, step, options) {
34
+ const noun = options.noun ?? "calls";
35
+ const keyOf = options.key ?? ((at) => at);
36
+ const place = options.location === undefined ? {} : { location: options.location };
37
+ const seen = new Set([keyOf(start)]);
38
+ let at = start;
39
+ for (let depth = 0; depth < options.limit; depth++) {
40
+ const next = step(at, depth);
41
+ if (next.kind !== "next")
42
+ return next;
43
+ const key = keyOf(next.next);
44
+ if (seen.has(key))
45
+ return unread(`the ${noun} lead back to a place already followed`, place);
46
+ seen.add(key);
47
+ at = next.next;
48
+ }
49
+ const levels = options.limit === 1 ? "1 level" : `${String(options.limit)} levels`;
50
+ return unread(`stateward follows ${noun} up to ${levels}`, {
51
+ hint: "state the type or the value nearer to where it is used",
52
+ ...place,
53
+ });
54
+ }
55
+ /** The full version at the start of a text: `10.3.1` of `10.3.1(rxjs@7.8.1)` (pnpm), `0.3.20_pg@8`. */
56
+ function versionIn(text) {
57
+ // An alias's entry names its package first (`@acme/fork@0.3.21`); a version starts with a digit.
58
+ const bare = text.trim().replace(/^(?!v?\d).*?.@(?=v?\d)/, "");
59
+ const found = /^v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/.exec(bare)?.[1];
60
+ return found === undefined ? undefined : (semver.valid(found) ?? undefined);
61
+ }
62
+ /**
63
+ * The range a package.json entry declares, one semver reads, also after `workspace:` or as an
64
+ * `npm:<name>@<range>` alias. Undefined for a tag, a URL, a path, `catalog:` or a bare
65
+ * `workspace:^`: what such an entry allows is not read.
66
+ */
67
+ function rangeIn(text) {
68
+ let given = text.trim();
69
+ if (given.startsWith("workspace:"))
70
+ given = given.slice("workspace:".length);
71
+ else if (given.startsWith("npm:")) {
72
+ const at = given.lastIndexOf("@");
73
+ if (at <= "npm:".length)
74
+ return undefined;
75
+ given = given.slice(at + 1);
76
+ }
77
+ if (given === "^" || given === "~")
78
+ return undefined;
79
+ return semver.validRange(given) === null ? undefined : given;
80
+ }
81
+ /**
82
+ * Whether the version a read gives satisfies `query` (`"<0.3.0"`, `">=2.0.6"`), by semver's rules.
83
+ * For a range it answers only when every version the range allows agrees (`^0.2.0` is `<0.3.0`;
84
+ * `^0.3.0` is not `>=0.3.27` for all its versions, so it is `Unread`). An `Unread` read is
85
+ * passed on.
86
+ */
87
+ export function versionSatisfies(read, query) {
88
+ if (read.kind === "unread")
89
+ return read;
90
+ if (read.kind === "exact")
91
+ return semver.satisfies(read.version, query);
92
+ if (semver.subset(read.range, query))
93
+ return true;
94
+ if (!semver.intersects(read.range, query))
95
+ return false;
96
+ return unread(`package.json allows \`${read.name}@${read.range}\`, which spans \`${query}\``, {
97
+ hint: `install \`${read.name}\`, so the version it runs is known`,
98
+ });
99
+ }
100
+ /**
101
+ * The major version a read gives: the exact version's, or the one major every version of the
102
+ * range has (`^10.4.22` is 10). `Unread` when the range spans majors (`>=9`).
103
+ */
104
+ export function versionMajor(read) {
105
+ if (read.kind === "unread")
106
+ return read;
107
+ if (read.kind === "exact")
108
+ return semver.major(read.version);
109
+ const lowest = semver.minVersion(read.range);
110
+ if (lowest !== null && semver.subset(read.range, `${String(lowest.major)}.x`)) {
111
+ return lowest.major;
112
+ }
113
+ return unread(`package.json allows \`${read.name}@${read.range}\`, which spans majors`, {
114
+ hint: `install \`${read.name}\`, so the version it runs is known`,
115
+ });
116
+ }
117
+ function readText(file) {
118
+ try {
119
+ return readFileSync(file, "utf8");
120
+ }
121
+ catch {
122
+ // A file that cannot be read gives no version; the next place is tried.
123
+ return undefined;
124
+ }
125
+ }
126
+ function parseJson(text) {
127
+ if (text === undefined)
128
+ return undefined;
129
+ try {
130
+ const parsed = JSON.parse(text);
131
+ return parsed;
132
+ }
133
+ catch {
134
+ // As above: a broken file gives no version.
135
+ return undefined;
136
+ }
137
+ }
138
+ function field(value, key) {
139
+ return typeof value === "object" && value !== null && key in value
140
+ ? Reflect.get(value, key)
141
+ : undefined;
142
+ }
143
+ function stringField(value, key) {
144
+ const found = field(value, key);
145
+ return typeof found === "string" ? found : undefined;
146
+ }
147
+ function declaredRange(manifest, name) {
148
+ for (const group of ["dependencies", "devDependencies", "peerDependencies"]) {
149
+ const range = stringField(field(manifest, group), name);
150
+ if (range !== undefined)
151
+ return range;
152
+ }
153
+ return undefined;
154
+ }
155
+ /** Each lockfile, by path: a lockfile is large, so it is read and parsed once per stamp. */
156
+ const lockfiles = new Map();
157
+ function lockfileAt(file) {
158
+ let stamp;
159
+ try {
160
+ const stats = statSync(file);
161
+ stamp = `${String(stats.size)}:${String(stats.mtimeMs)}`;
162
+ }
163
+ catch {
164
+ return undefined;
165
+ }
166
+ const known = lockfiles.get(file);
167
+ if (known?.stamp === stamp)
168
+ return known;
169
+ const made = {
170
+ stamp,
171
+ text: readText(file),
172
+ json: undefined,
173
+ parsed: false,
174
+ answers: new Map(),
175
+ };
176
+ lockfiles.set(file, made);
177
+ return made;
178
+ }
179
+ /** `package-lock.json` (npm 7 and later, then npm 6): the version installed for `project`. */
180
+ function npmLocked(json, project, name) {
181
+ const packages = field(json, "packages");
182
+ const nested = project === ""
183
+ ? undefined
184
+ : stringField(field(packages, `${project}/node_modules/${name}`), "version");
185
+ if (nested !== undefined)
186
+ return { version: nested, own: true };
187
+ const hoisted = stringField(field(packages, `node_modules/${name}`), "version") ??
188
+ stringField(field(field(json, "dependencies"), name), "version");
189
+ return hoisted === undefined ? undefined : { version: hoisted, own: project === "" };
190
+ }
191
+ /** A YAML key as pnpm writes it, quoted or not. */
192
+ function yamlKey(line) {
193
+ const key = line.trim().replace(/:\s*.*$/, "");
194
+ return key.replace(/^['"]|['"]$/g, "");
195
+ }
196
+ /**
197
+ * `pnpm-lock.yaml`: the version `importers.<project>` resolves `name` to (pnpm 6 and later), or
198
+ * the top-level `dependencies` (a single-project lockfile of pnpm 5).
199
+ */
200
+ function pnpmLocked(text, project, name) {
201
+ const importers = /^importers:/m.test(text);
202
+ const importer = project === "" ? "." : project;
203
+ // Where the dependency groups sit: under the project's importer, or at the top (pnpm 5).
204
+ const base = importers ? 4 : 0;
205
+ let section = "";
206
+ let inProject = !importers;
207
+ let inGroup = false;
208
+ let inEntry = false;
209
+ for (const line of text.split(/\r?\n/)) {
210
+ const trimmed = line.trim();
211
+ if (trimmed === "" || trimmed.startsWith("#"))
212
+ continue;
213
+ const indent = line.length - line.trimStart().length;
214
+ if (indent === 0)
215
+ section = yamlKey(line);
216
+ if (importers && (section !== "importers" || indent === 0)) {
217
+ inProject = false;
218
+ continue;
219
+ }
220
+ if (importers && indent === 2) {
221
+ inProject = yamlKey(line) === importer;
222
+ continue;
223
+ }
224
+ if (!inProject)
225
+ continue;
226
+ if (indent === base) {
227
+ inGroup = /^(dev|optional)?[dD]ependencies:/.test(trimmed);
228
+ inEntry = false;
229
+ continue;
230
+ }
231
+ if (!inGroup)
232
+ continue;
233
+ if (indent === base + 2) {
234
+ inEntry = yamlKey(line) === name;
235
+ const inline = /:\s*['"]?(\d[^'"\s(]*)/.exec(trimmed);
236
+ if (inEntry && inline?.[1] !== undefined)
237
+ return { version: inline[1], own: true };
238
+ continue;
239
+ }
240
+ if (inEntry && indent === base + 4 && trimmed.startsWith("version:")) {
241
+ const version = trimmed
242
+ .slice("version:".length)
243
+ .trim()
244
+ .replace(/^['"]|['"]$/g, "");
245
+ return { version, own: true };
246
+ }
247
+ }
248
+ return undefined;
249
+ }
250
+ /** `yarn.lock` (classic and berry): the version of the entry of the declared range. */
251
+ function yarnLocked(text, name, range) {
252
+ const found = new Set();
253
+ let matches = false;
254
+ for (const line of text.split(/\r?\n/)) {
255
+ if (line.length > 0 && !line.startsWith(" ") && !line.startsWith("#")) {
256
+ const keys = line
257
+ .replace(/:\s*$/, "")
258
+ .split(",")
259
+ .map((key) => key.trim().replace(/^"|"$/g, ""));
260
+ matches = keys.some((key) => {
261
+ // `typeorm@^0.3.0`, `typeorm@npm:^0.3.0` (berry), `typeorm@npm:@acme/fork@^0.3.0` (alias).
262
+ const at = key.indexOf("@", 1);
263
+ if (at <= 0 || key.slice(0, at) !== name)
264
+ return false;
265
+ const given = key.slice(at + 1);
266
+ // Berry writes a `patch:` entry with its locator after `::`.
267
+ return given === range || given === `npm:${range}` || given.startsWith(`${range}::`);
268
+ });
269
+ continue;
270
+ }
271
+ const version = /^\s+version:?\s+"?([^"\s]+)"?/.exec(line)?.[1];
272
+ if (matches && version !== undefined) {
273
+ found.add(version);
274
+ matches = false;
275
+ }
276
+ }
277
+ const [only] = found;
278
+ return found.size === 1 && only !== undefined ? { version: only, own: true } : undefined;
279
+ }
280
+ /** The version a lockfile in `dir` gives `name` for the project in `projectDir`, if one does. */
281
+ function lockedIn(dir, projectDir, name, range) {
282
+ const project = path.relative(dir, projectDir).replaceAll("\\", "/");
283
+ const readers = [
284
+ [
285
+ "package-lock.json",
286
+ (lock) => {
287
+ if (!lock.parsed) {
288
+ lock.json = parseJson(lock.text);
289
+ lock.parsed = true;
290
+ }
291
+ return npmLocked(lock.json, project, name);
292
+ },
293
+ ],
294
+ [
295
+ "pnpm-lock.yaml",
296
+ (lock) => (lock.text === undefined ? undefined : pnpmLocked(lock.text, project, name)),
297
+ ],
298
+ [
299
+ "yarn.lock",
300
+ (lock) => (lock.text === undefined ? undefined : yarnLocked(lock.text, name, range)),
301
+ ],
302
+ ];
303
+ for (const [base, read] of readers) {
304
+ const file = path.join(dir, base);
305
+ if (!existsSync(file))
306
+ continue;
307
+ const lock = lockfileAt(file);
308
+ if (lock === undefined)
309
+ continue;
310
+ const key = `${project}\u0000${name}\u0000${range}`;
311
+ if (!lock.answers.has(key))
312
+ lock.answers.set(key, read(lock));
313
+ const found = lock.answers.get(key);
314
+ if (found !== undefined)
315
+ return found;
316
+ }
317
+ return undefined;
318
+ }
319
+ /** Whether `dir` is `parent` or inside it. */
320
+ function isWithin(dir, parent) {
321
+ const relative = path.relative(parent, dir);
322
+ return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
323
+ }
324
+ /**
325
+ * The version of package `name` that a file's project runs. The project is the nearest folder
326
+ * whose package.json declares `name`; its range is read as semver reads it (also after
327
+ * `workspace:` and as an `npm:` alias).
328
+ *
329
+ * In order: a copy installed in the project's own folders (the version Node loads); a copy
330
+ * installed above it (a workspace's hoisted copy) that the range allows; a lockfile entry
331
+ * (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock`, at the project or above) that is the
332
+ * project's own or that the range allows. Each gives the exact version. Else the declared range
333
+ * itself. A copy or entry the range does not allow, with nothing that it allows, is `Unread`:
334
+ * which version runs is not known. So is a project that declares nothing readable.
335
+ */
336
+ /**
337
+ * What package.json declares, as the reason names it: `the version package.json asks for (1.0.219)`
338
+ * for one exact version, `a version package.json allows (^0.3.17)` for a range.
339
+ */
340
+ function askedFor(declared) {
341
+ return semver.valid(declared.trim()) === null
342
+ ? `a version package.json allows (${declared})`
343
+ : `the version package.json asks for (${declared.trim()})`;
344
+ }
345
+ export function packageVersionOf(ctx, name) {
346
+ const notKnown = unread(`the ${name} version is not known`, {
347
+ hint: `install \`${name}\`, or declare its version in package.json`,
348
+ });
349
+ // The project: the nearest package.json that declares the package.
350
+ let projectDir;
351
+ let rangeText;
352
+ for (let dir = path.dirname(ctx.file);; dir = path.dirname(dir)) {
353
+ const manifest = path.join(dir, "package.json");
354
+ if (existsSync(manifest)) {
355
+ rangeText = declaredRange(parseJson(readText(manifest)), name);
356
+ if (rangeText !== undefined) {
357
+ projectDir = dir;
358
+ break;
359
+ }
360
+ }
361
+ if (path.dirname(dir) === dir)
362
+ break;
363
+ }
364
+ const range = rangeText === undefined ? undefined : rangeIn(rangeText);
365
+ let rejected;
366
+ for (let dir = path.dirname(ctx.file);; dir = path.dirname(dir)) {
367
+ const installedFile = path.join(dir, "node_modules", ...name.split("/"), "package.json");
368
+ if (existsSync(installedFile)) {
369
+ const text = stringField(parseJson(readText(installedFile)), "version");
370
+ const installed = text === undefined ? undefined : versionIn(text);
371
+ // Not declared: the copy Node finds is the one that runs.
372
+ const own = projectDir === undefined || isWithin(dir, projectDir);
373
+ if (installed !== undefined &&
374
+ (range === undefined ? own : semver.satisfies(installed, range))) {
375
+ return { kind: "exact", name, version: installed, from: "installed" };
376
+ }
377
+ if (installed !== undefined && own) {
378
+ // The project's own copy is what Node loads, and the declared range does not allow it.
379
+ return unread(`the installed copy of ${name} (${installed}) is not ${askedFor(rangeText ?? "")}, so the project's version is not known`, { hint: `install \`${name}\` again, so the installed copy matches package.json` });
380
+ }
381
+ rejected ??= installed;
382
+ }
383
+ if (path.dirname(dir) === dir)
384
+ break;
385
+ }
386
+ if (projectDir === undefined || rangeText === undefined)
387
+ return notKnown;
388
+ for (let dir = projectDir;; dir = path.dirname(dir)) {
389
+ const entry = lockedIn(dir, projectDir, name, rangeText);
390
+ const locked = entry === undefined ? undefined : versionIn(entry.version);
391
+ if (entry !== undefined && locked !== undefined) {
392
+ if (range === undefined ? entry.own : semver.satisfies(locked, range)) {
393
+ return { kind: "exact", name, version: locked, from: "lockfile" };
394
+ }
395
+ rejected ??= locked;
396
+ }
397
+ if (path.dirname(dir) === dir)
398
+ break;
399
+ }
400
+ if (rejected !== undefined) {
401
+ return unread(`the copy of ${name} installed or locked for the project (${rejected}) is not ${askedFor(rangeText)}, so the project's version is not known`, { hint: `install \`${name}\` for this project, so its copy matches package.json` });
402
+ }
403
+ return range === undefined ? notKnown : { kind: "range", name, range };
404
+ }
405
+ //# sourceMappingURL=unread.js.map
@@ -1,5 +1,5 @@
1
1
  /** In the order the docs list them. */
2
- export declare const RULE_TIERS: readonly ["core", "coverage", "addon"];
2
+ export declare const RULE_TIERS: readonly ["core", "coverage", "convention", "addon"];
3
3
  /** `recommended` first: it is the default. */
4
4
  export declare const PRESETS: readonly ["recommended", "strict"];
5
5
  /** What `init` offers first. A config without `preset` gets none: no rule is on until it says so. */
@@ -3,7 +3,7 @@
3
3
  * questions and the generated docs all read these; none of them spells the words again.
4
4
  */
5
5
  /** In the order the docs list them. */
6
- export const RULE_TIERS = ["core", "coverage", "addon"];
6
+ export const RULE_TIERS = ["core", "coverage", "convention", "addon"];
7
7
  /** `recommended` first: it is the default. */
8
8
  export const PRESETS = ["recommended", "strict"];
9
9
  /** What `init` offers first. A config without `preset` gets none: no rule is on until it says so. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stateward/core",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "The engine of stateward (exclusive states and predictable code paths for TypeScript) and the API for writing your own rules and packs.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -49,9 +49,11 @@
49
49
  "dependencies": {
50
50
  "jiti": "^2.7.0",
51
51
  "picomatch": "^4.0.7",
52
+ "semver": "^7.8.5",
52
53
  "typescript": "~6.0.3"
53
54
  },
54
55
  "devDependencies": {
55
- "@types/picomatch": "^4.0.3"
56
+ "@types/picomatch": "^4.0.3",
57
+ "@types/semver": "^7.7.1"
56
58
  }
57
59
  }