@stateward/core 1.2.2 → 1.3.1
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/analyses.d.ts +37 -0
- package/dist/analyses.js +57 -0
- package/dist/backend/fingerprints.d.ts +3 -1
- package/dist/backend/fingerprints.js +198 -9
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/program-size.d.ts +32 -0
- package/dist/backend/program-size.js +166 -0
- package/dist/backend/typescript6.d.ts +62 -32
- package/dist/backend/typescript6.js +1615 -164
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +92 -4
- package/dist/cache.js +257 -68
- package/dist/checker.d.ts +28 -3
- package/dist/checker.js +42 -8
- package/dist/class-id.d.ts +34 -0
- package/dist/class-id.js +93 -0
- package/dist/code-text.d.ts +8 -0
- package/dist/code-text.js +66 -0
- package/dist/config-file.js +7 -5
- package/dist/config.d.ts +10 -2
- package/dist/config.js +490 -48
- package/dist/define.d.ts +8 -2
- package/dist/disk-cache.d.ts +34 -2
- package/dist/disk-cache.js +82 -15
- package/dist/engine.d.ts +64 -3
- package/dist/engine.js +474 -59
- package/dist/fact-lines.d.ts +31 -0
- package/dist/fact-lines.js +197 -0
- package/dist/facts-versions.d.ts +27 -0
- package/dist/facts-versions.js +99 -0
- package/dist/fixes.js +4 -1
- package/dist/ignores.d.ts +11 -0
- package/dist/ignores.js +74 -27
- package/dist/implementation.d.ts +0 -6
- package/dist/implementation.js +0 -17
- package/dist/index.d.ts +9 -9
- package/dist/index.js +12 -7
- package/dist/internal.d.ts +13 -6
- package/dist/internal.js +7 -3
- package/dist/journal.d.ts +40 -0
- package/dist/journal.js +197 -0
- package/dist/lazy.d.ts +8 -1
- package/dist/lazy.js +27 -2
- package/dist/ledger.d.ts +2 -2
- package/dist/ledger.js +2 -2
- package/dist/memory-plan.d.ts +121 -0
- package/dist/memory-plan.js +174 -0
- package/dist/off-by-default.d.ts +13 -0
- package/dist/off-by-default.js +15 -0
- package/dist/options.d.ts +21 -5
- package/dist/options.js +22 -7
- package/dist/package-facts.d.ts +211 -17
- package/dist/package-facts.js +520 -38
- package/dist/plan.d.ts +1 -1
- package/dist/plan.js +7 -2
- package/dist/release.d.ts +12 -21
- package/dist/release.js +26 -38
- package/dist/renamed.d.ts +22 -3
- package/dist/renamed.js +50 -16
- package/dist/rollout.js +7 -4
- package/dist/severity.d.ts +1 -1
- package/dist/severity.js +17 -3
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +483 -0
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +5 -5
- package/dist/timing.d.ts +17 -7
- package/dist/timing.js +60 -38
- package/dist/types.d.ts +704 -20
- package/dist/unread.d.ts +90 -0
- package/dist/unread.js +405 -0
- package/dist/vocabulary.d.ts +1 -1
- package/dist/vocabulary.js +1 -1
- package/package.json +4 -2
package/dist/internal.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from "./index.js";
|
|
2
2
|
export { isMaxMemory, isPreset, MIN_MAX_MEMORY } from "./config.js";
|
|
3
|
+
export { FACT_CHOICES, applyConfigEdit, factChoiceTitle, factLineEdit, factLineFixes, factValueText, } from "./fact-lines.js";
|
|
4
|
+
export type { ConfigEdit, FactChoice, FactLineFix } from "./fact-lines.js";
|
|
5
|
+
export { PLACEHOLDER_CLASS } from "./package-facts.js";
|
|
3
6
|
export { CONFIG_FILE_NAMES, CONFIG_FILE_PATTERN, DEFAULT_CONFIG_FILE, DEFAULT_PRESET, PRESETS, RULE_TIERS, orList, } from "./vocabulary.js";
|
|
4
|
-
export { RuleDeclarationError, RuleLoadError, RuleNotLoadedError, loadAllRules, loadRules, } from "./lazy.js";
|
|
7
|
+
export { RuleDeclarationError, RuleLoadError, RuleNotLoadedError, RuleReadsError, loadAllRules, loadRules, } from "./lazy.js";
|
|
5
8
|
export { addonNames, groupIds, ruleIds, ruleIsOn, ruleSetting } from "./severity.js";
|
|
6
9
|
export { displayPath, slashed } from "./display-path.js";
|
|
7
10
|
export type { PathModule } from "./display-path.js";
|
|
@@ -13,7 +16,7 @@ export { advance, buildPlan, describeNotChecked, describeTurnOn, isClean } from
|
|
|
13
16
|
export type { Advance, Plan, PlanRow } from "./plan.js";
|
|
14
17
|
export { findConfigFile, findConfigUpward, loadConfig, loadConfigFile, reloadsLocalImports, } from "./config-file.js";
|
|
15
18
|
export { LOOSE_NULLS_FIX, MAX_FINDINGS_PER_RULE_PER_FILE, STRICT_NULLS_REMEDY, activeRuleIds, compareFindings, explain, limitFindings, } from "./engine.js";
|
|
16
|
-
export type { CheckProgress } from "./engine.js";
|
|
19
|
+
export type { CheckerSlicing, CheckProgress } from "./engine.js";
|
|
17
20
|
export { SLICE_MS } from "./checker.js";
|
|
18
21
|
export { counted, describeStatus, guaranteeAt, proveGuarantees } from "./guarantees.js";
|
|
19
22
|
export { STATED_RULE_ID } from "./stated.js";
|
|
@@ -24,16 +27,20 @@ export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js"
|
|
|
24
27
|
export type { CacheSnapshot, ResultCache } from "./cache.js";
|
|
25
28
|
export { stronglyConnectedComponents } from "./graph.js";
|
|
26
29
|
export { computeImplementationId, configLocalImports, implementationId } from "./implementation.js";
|
|
27
|
-
export {
|
|
28
|
-
export type { PackageCacheClean, PackageCacheStats } from "./package-cache.js";
|
|
30
|
+
export { statewardVersion } from "./disk-cache.js";
|
|
29
31
|
export { NothingToCheckError, TsconfigError, TypeScriptLibMissingError, missingDefaultLib, toTypeScriptPath, tsconfigDirectory, } from "./backend/typescript6.js";
|
|
30
32
|
export { createTimingRecorder } from "./timing.js";
|
|
31
33
|
export { cacheEntries, dropLeastRecentlyUsed, limitBytes, markUsed } from "./disk-limits.js";
|
|
32
34
|
export { CACHE_SUBDIR, PROJECT_CACHE_DIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, userCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
|
|
33
|
-
export type { DiskCache, ResultsCacheStats } from "./disk-cache.js";
|
|
35
|
+
export type { DiskCache, ResultsCacheStats, SaveOutcome } from "./disk-cache.js";
|
|
36
|
+
export { journalProgress } from "./journal.js";
|
|
34
37
|
export type { CacheEntry } from "./disk-limits.js";
|
|
35
38
|
export type { RuleCost, RunTiming, TimingRecorder } from "./timing.js";
|
|
36
39
|
export { hintLines, hintWithoutExamples, laidOutHint } from "./hint-lines.js";
|
|
37
40
|
export type { HintLine } from "./hint-lines.js";
|
|
38
|
-
export { renameNotice, renamedIdsIn, renamedRule } from "./renamed.js";
|
|
41
|
+
export { quotedIdLine, removedNotice, removedOf, renameNotice, renamedIdsIn, renamedRule, renamesOf, } from "./renamed.js";
|
|
42
|
+
export type { Renames } from "./renamed.js";
|
|
43
|
+
export { MemoryBudgetError, describePlan, planMemory } from "./memory-plan.js";
|
|
44
|
+
export type { MemoryPlan, ProjectPlan } from "./memory-plan.js";
|
|
45
|
+
export type { MemoryBudget } from "./checker.js";
|
|
39
46
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
//. It holds the public API too, so one import is enough.
|
|
4
4
|
export * from "./index.js";
|
|
5
5
|
export { isMaxMemory, isPreset, MIN_MAX_MEMORY } from "./config.js";
|
|
6
|
+
export { FACT_CHOICES, applyConfigEdit, factChoiceTitle, factLineEdit, factLineFixes, factValueText, } from "./fact-lines.js";
|
|
7
|
+
export { PLACEHOLDER_CLASS } from "./package-facts.js";
|
|
6
8
|
export { CONFIG_FILE_NAMES, CONFIG_FILE_PATTERN, DEFAULT_CONFIG_FILE, DEFAULT_PRESET, PRESETS, RULE_TIERS, orList, } from "./vocabulary.js";
|
|
7
|
-
export { RuleDeclarationError, RuleLoadError, RuleNotLoadedError, loadAllRules, loadRules, } from "./lazy.js";
|
|
9
|
+
export { RuleDeclarationError, RuleLoadError, RuleNotLoadedError, RuleReadsError, loadAllRules, loadRules, } from "./lazy.js";
|
|
8
10
|
export { addonNames, groupIds, ruleIds, ruleIsOn, ruleSetting } from "./severity.js";
|
|
9
11
|
export { displayPath, slashed } from "./display-path.js";
|
|
10
12
|
export { matchingOverrides } from "./overrides.js";
|
|
@@ -20,11 +22,13 @@ export { IGNORE_FIX_TITLE, IGNORE_RULE_ID, ignoreFix } from "./ignores.js";
|
|
|
20
22
|
export { CACHE_FORMAT, emptyCache, parseSnapshot, toSnapshot } from "./cache.js";
|
|
21
23
|
export { stronglyConnectedComponents } from "./graph.js";
|
|
22
24
|
export { computeImplementationId, configLocalImports, implementationId } from "./implementation.js";
|
|
23
|
-
export {
|
|
25
|
+
export { statewardVersion } from "./disk-cache.js";
|
|
24
26
|
export { NothingToCheckError, TsconfigError, TypeScriptLibMissingError, missingDefaultLib, toTypeScriptPath, tsconfigDirectory, } from "./backend/typescript6.js";
|
|
25
27
|
export { createTimingRecorder } from "./timing.js";
|
|
26
28
|
export { cacheEntries, dropLeastRecentlyUsed, limitBytes, markUsed } from "./disk-limits.js";
|
|
27
29
|
export { CACHE_SUBDIR, PROJECT_CACHE_DIR, RESULTS_CACHE_DEFAULT_MB, cleanResultsCache, defaultCacheDir, userCacheDir, openDiskCache, resultsCacheLimit, resultsCacheStats, } from "./disk-cache.js";
|
|
30
|
+
export { journalProgress } from "./journal.js";
|
|
28
31
|
export { hintLines, hintWithoutExamples, laidOutHint } from "./hint-lines.js";
|
|
29
|
-
export { renameNotice, renamedIdsIn, renamedRule } from "./renamed.js";
|
|
32
|
+
export { quotedIdLine, removedNotice, removedOf, renameNotice, renamedIdsIn, renamedRule, renamesOf, } from "./renamed.js";
|
|
33
|
+
export { MemoryBudgetError, describePlan, planMemory } from "./memory-plan.js";
|
|
30
34
|
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FileEntry, ResultCache } from "./cache.js";
|
|
2
|
+
/** What a journal belongs to: the cache file's head, and the cache format of its entries. */
|
|
3
|
+
export type JournalOwner = {
|
|
4
|
+
readonly version: string;
|
|
5
|
+
readonly implementation: string;
|
|
6
|
+
readonly project: string;
|
|
7
|
+
};
|
|
8
|
+
/** What a journal holds: the results of finished files, and the file the run was on when it ended. */
|
|
9
|
+
export type JournalContents = {
|
|
10
|
+
readonly entries: ReadonlyMap<string, FileEntry>;
|
|
11
|
+
/** The last file started and not finished; undefined when the run was between files. */
|
|
12
|
+
readonly inProgress: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Reads the journal `file` of `owner`'s cache; undefined when there is none, or its head is
|
|
16
|
+
* another's (another version, implementation, project or cache format).
|
|
17
|
+
*/
|
|
18
|
+
export declare function readJournal(file: string, owner: JournalOwner): JournalContents | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* How far the run that wrote the journal `file` got, for a message: the files it finished and the
|
|
21
|
+
* file it was on. Read without its owner (another process asks); undefined when there is none.
|
|
22
|
+
*/
|
|
23
|
+
export declare function journalProgress(file: string): {
|
|
24
|
+
readonly finished: number;
|
|
25
|
+
readonly inProgress: string | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
/** An open journal: it appends what `cache.progress` is told, until `close`. */
|
|
28
|
+
export type OpenJournal = {
|
|
29
|
+
close(): void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Starts appending `cache`'s progress to `file`: after the lines already there when its head is
|
|
33
|
+
* `owner`'s, else in a new journal. A file whose results are the ones the cache already holds is
|
|
34
|
+
* not written again (a warm run writes little more than the `started` lines). A failed write ends
|
|
35
|
+
* the journal (`onError`); the check goes on, and its results are saved at the end as usual.
|
|
36
|
+
*/
|
|
37
|
+
export declare function openJournal(file: string, owner: JournalOwner, cache: ResultCache, onError: (error: Error) => void): OpenJournal;
|
|
38
|
+
/** Removes the journal `file`, once the cache holds what it held; a failure leaves it to be read again. */
|
|
39
|
+
export declare function removeJournal(file: string): void;
|
|
40
|
+
//# sourceMappingURL=journal.d.ts.map
|
package/dist/journal.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { closeSync, existsSync, openSync, readSync, rmSync, writeSync } from "node:fs";
|
|
2
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
|
+
import { CACHE_FORMAT, fileSnapshot, parseFileEntry } from "./cache.js";
|
|
4
|
+
/**
|
|
5
|
+
* The check's journal: one line per file whose results the run finished, appended as it goes, next
|
|
6
|
+
* to the results cache it belongs to (disk-cache.ts). A run that dies (out of memory) leaves it;
|
|
7
|
+
* the next run that opens the cache folds it in, so it checks again only what was not finished.
|
|
8
|
+
* The cache's own file is written only at the end, never during the check: rewriting a cache of a
|
|
9
|
+
* few hundred MB per batch of files would cost more than the check.
|
|
10
|
+
*
|
|
11
|
+
* Format, one JSON value per line:
|
|
12
|
+
* - first, the head: `{"journal":1,"stateward":…,"implementation":…,"project":…,"format":…}`; a
|
|
13
|
+
* journal with another head is not read;
|
|
14
|
+
* - `{"started":"<file>"}` when the file phase starts a file;
|
|
15
|
+
* - `{"file":"<file>","entry":{…}}` when its results are final (`fileSnapshot`).
|
|
16
|
+
*
|
|
17
|
+
* Each line is read on its own, field by field: a line that does not parse (the last one, torn by
|
|
18
|
+
* the process dying while it wrote) is left out, and the lines after it still count.
|
|
19
|
+
*/
|
|
20
|
+
/** Bumped when the lines change. */
|
|
21
|
+
const JOURNAL_FORMAT = 1;
|
|
22
|
+
function headOf(owner) {
|
|
23
|
+
return JSON.stringify({
|
|
24
|
+
journal: JOURNAL_FORMAT,
|
|
25
|
+
stateward: owner.version,
|
|
26
|
+
implementation: owner.implementation,
|
|
27
|
+
project: owner.project,
|
|
28
|
+
format: CACHE_FORMAT,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Each whole line of `file`, in order, without its newline; a last line with no newline is torn. */
|
|
32
|
+
function* linesOf(file) {
|
|
33
|
+
let fd;
|
|
34
|
+
try {
|
|
35
|
+
fd = openSync(file, "r");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// No journal: nothing to read.
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const decoder = new StringDecoder("utf8");
|
|
43
|
+
const buffer = Buffer.alloc(1024 * 1024);
|
|
44
|
+
let pending = "";
|
|
45
|
+
for (;;) {
|
|
46
|
+
const read = readSync(fd, buffer, 0, buffer.length, null);
|
|
47
|
+
if (read === 0)
|
|
48
|
+
return;
|
|
49
|
+
pending += decoder.write(buffer.subarray(0, read));
|
|
50
|
+
let end = pending.indexOf("\n");
|
|
51
|
+
while (end !== -1) {
|
|
52
|
+
yield pending.slice(0, end);
|
|
53
|
+
pending = pending.slice(end + 1);
|
|
54
|
+
end = pending.indexOf("\n");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
closeSync(fd);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** A line's JSON value; undefined when it does not parse (a torn line). */
|
|
63
|
+
function parsedLine(line) {
|
|
64
|
+
try {
|
|
65
|
+
const value = JSON.parse(line);
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads the journal `file` of `owner`'s cache; undefined when there is none, or its head is
|
|
74
|
+
* another's (another version, implementation, project or cache format).
|
|
75
|
+
*/
|
|
76
|
+
export function readJournal(file, owner) {
|
|
77
|
+
const entries = new Map();
|
|
78
|
+
let inProgress;
|
|
79
|
+
let first = true;
|
|
80
|
+
for (const line of linesOf(file)) {
|
|
81
|
+
if (first) {
|
|
82
|
+
if (line !== headOf(owner))
|
|
83
|
+
return undefined;
|
|
84
|
+
first = false;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const value = parsedLine(line);
|
|
88
|
+
if (typeof value !== "object" || value === null)
|
|
89
|
+
continue;
|
|
90
|
+
const started = Reflect.get(value, "started");
|
|
91
|
+
if (typeof started === "string") {
|
|
92
|
+
inProgress = started;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const name = Reflect.get(value, "file");
|
|
96
|
+
const entry = parseFileEntry(Reflect.get(value, "entry"));
|
|
97
|
+
if (typeof name !== "string" || entry === undefined)
|
|
98
|
+
continue;
|
|
99
|
+
entries.set(name, entry);
|
|
100
|
+
if (inProgress === name)
|
|
101
|
+
inProgress = undefined;
|
|
102
|
+
}
|
|
103
|
+
return first ? undefined : { entries, inProgress };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* How far the run that wrote the journal `file` got, for a message: the files it finished and the
|
|
107
|
+
* file it was on. Read without its owner (another process asks); undefined when there is none.
|
|
108
|
+
*/
|
|
109
|
+
export function journalProgress(file) {
|
|
110
|
+
const finished = new Set();
|
|
111
|
+
let inProgress;
|
|
112
|
+
let lines = 0;
|
|
113
|
+
for (const line of linesOf(file)) {
|
|
114
|
+
lines += 1;
|
|
115
|
+
if (lines === 1)
|
|
116
|
+
continue;
|
|
117
|
+
const value = parsedLine(line);
|
|
118
|
+
if (typeof value !== "object" || value === null)
|
|
119
|
+
continue;
|
|
120
|
+
const started = Reflect.get(value, "started");
|
|
121
|
+
const name = Reflect.get(value, "file");
|
|
122
|
+
if (typeof started === "string")
|
|
123
|
+
inProgress = started;
|
|
124
|
+
else if (typeof name === "string") {
|
|
125
|
+
finished.add(name);
|
|
126
|
+
if (inProgress === name)
|
|
127
|
+
inProgress = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return lines === 0 ? undefined : { finished: finished.size, inProgress };
|
|
131
|
+
}
|
|
132
|
+
/** Whether `next` is `before` again: the same fingerprint, the same result objects and reads. */
|
|
133
|
+
function unchanged(before, next) {
|
|
134
|
+
if (before?.fingerprint !== next.fingerprint)
|
|
135
|
+
return false;
|
|
136
|
+
if (before.rules.size !== next.rules.size || before.reads.size !== next.reads.size)
|
|
137
|
+
return false;
|
|
138
|
+
for (const [key, result] of next.rules)
|
|
139
|
+
if (before.rules.get(key) !== result)
|
|
140
|
+
return false;
|
|
141
|
+
for (const [key, hash] of next.reads)
|
|
142
|
+
if (before.reads.get(key) !== hash)
|
|
143
|
+
return false;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Starts appending `cache`'s progress to `file`: after the lines already there when its head is
|
|
148
|
+
* `owner`'s, else in a new journal. A file whose results are the ones the cache already holds is
|
|
149
|
+
* not written again (a warm run writes little more than the `started` lines). A failed write ends
|
|
150
|
+
* the journal (`onError`); the check goes on, and its results are saved at the end as usual.
|
|
151
|
+
*/
|
|
152
|
+
export function openJournal(file, owner, cache, onError) {
|
|
153
|
+
const head = headOf(owner);
|
|
154
|
+
// Only the head is read: what follows is the earlier start's, kept as it is.
|
|
155
|
+
const [first] = linesOf(file);
|
|
156
|
+
const keep = first === head;
|
|
157
|
+
let fd = openSync(file, keep ? "a" : "w");
|
|
158
|
+
const close = () => {
|
|
159
|
+
if (fd === undefined)
|
|
160
|
+
return;
|
|
161
|
+
cache.progress = undefined;
|
|
162
|
+
closeSync(fd);
|
|
163
|
+
fd = undefined;
|
|
164
|
+
};
|
|
165
|
+
const append = (line) => {
|
|
166
|
+
if (fd === undefined)
|
|
167
|
+
return;
|
|
168
|
+
try {
|
|
169
|
+
writeSync(fd, `${line}\n`);
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
close();
|
|
173
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
// A new journal starts with its head; a kept one with a line break, which ends a line the
|
|
177
|
+
// earlier start tore (an empty line reads as nothing).
|
|
178
|
+
append(keep ? "" : head);
|
|
179
|
+
const progress = {
|
|
180
|
+
started(name) {
|
|
181
|
+
append(JSON.stringify({ started: name }));
|
|
182
|
+
},
|
|
183
|
+
finished(name, entry) {
|
|
184
|
+
if (unchanged(cache.files.get(name), entry))
|
|
185
|
+
return;
|
|
186
|
+
append(`{"file":${JSON.stringify(name)},"entry":${JSON.stringify(fileSnapshot(entry))}}`);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
cache.progress = progress;
|
|
190
|
+
return { close };
|
|
191
|
+
}
|
|
192
|
+
/** Removes the journal `file`, once the cache holds what it held; a failure leaves it to be read again. */
|
|
193
|
+
export function removeJournal(file) {
|
|
194
|
+
if (existsSync(file))
|
|
195
|
+
rmSync(file, { force: true });
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=journal.js.map
|
package/dist/lazy.d.ts
CHANGED
|
@@ -28,6 +28,13 @@ export declare class RuleNotLoadedError extends Error {
|
|
|
28
28
|
export declare class RuleDeclarationError extends Error {
|
|
29
29
|
constructor(ruleId: string, what: string);
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* A rule's `reads` is malformed, or names an analysis that the publisher in the config does not
|
|
33
|
+
* publish: what the config check says of a rule given directly, found once a lazy rule's code loads.
|
|
34
|
+
*/
|
|
35
|
+
export declare class RuleReadsError extends Error {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
31
38
|
/** A rule's module could not be imported (a broken install). */
|
|
32
39
|
export declare class RuleLoadError extends Error {
|
|
33
40
|
constructor(ruleId: string, reason: string);
|
|
@@ -36,7 +43,7 @@ export declare class RuleLoadError extends Error {
|
|
|
36
43
|
export declare function codeOf(ruleId: string, rule: PluginRule): Rule;
|
|
37
44
|
/** Loads one lazy rule and checks it against its declaration. */
|
|
38
45
|
export declare function loadRule(ruleId: string, rule: PluginRule): Promise<Rule>;
|
|
39
|
-
type Settings = Pick<Config, "plugins" | "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides">>;
|
|
46
|
+
type Settings = Pick<Config, "plugins" | "preset" | "addons" | "rules" | "groups"> & Partial<Pick<Config, "overrides" | "conventions">>;
|
|
40
47
|
/**
|
|
41
48
|
* Loads the code of every lazy rule that is on somewhere (in the config or in an override), so a
|
|
42
49
|
* check can run them. A rule that is off everywhere is not loaded. Rejects with a `RuleLoadError`
|
package/dist/lazy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { readTarget, readsProblem, unpublishedRead } from "./analyses.js";
|
|
2
3
|
import { ruleIsOn } from "./severity.js";
|
|
3
4
|
/** Wraps a dynamic `import()`. A failed import is not kept: the next `load` tries again. */
|
|
4
5
|
export function moduleLoader(importModule) {
|
|
@@ -55,6 +56,16 @@ export class RuleDeclarationError extends Error {
|
|
|
55
56
|
this.name = "RuleDeclarationError";
|
|
56
57
|
}
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* A rule's `reads` is malformed, or names an analysis that the publisher in the config does not
|
|
61
|
+
* publish: what the config check says of a rule given directly, found once a lazy rule's code loads.
|
|
62
|
+
*/
|
|
63
|
+
export class RuleReadsError extends Error {
|
|
64
|
+
constructor(message) {
|
|
65
|
+
super(message);
|
|
66
|
+
this.name = "RuleReadsError";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
58
69
|
/** A rule's module could not be imported (a broken install). */
|
|
59
70
|
export class RuleLoadError extends Error {
|
|
60
71
|
constructor(ruleId, reason) {
|
|
@@ -78,6 +89,10 @@ function verify(ruleId, declared, rule) {
|
|
|
78
89
|
const differs = keys.filter((key) => !isDeepStrictEqual(before.get(key), after.get(key)));
|
|
79
90
|
if (differs.length > 0)
|
|
80
91
|
throw new RuleDeclarationError(ruleId, `meta.${differs.join(", meta.")}`);
|
|
92
|
+
// A loaded rule's `reads` was not seen by the config check: checked here, as `parseRule` does.
|
|
93
|
+
const reads = rule.kind === "project" ? readsProblem(rule.reads) : undefined;
|
|
94
|
+
if (reads !== undefined)
|
|
95
|
+
throw new RuleReadsError(`${ruleId}: ${reads}`);
|
|
81
96
|
verified.add(rule);
|
|
82
97
|
return rule;
|
|
83
98
|
}
|
|
@@ -109,9 +124,19 @@ export async function loadRule(ruleId, rule) {
|
|
|
109
124
|
* or a `RuleDeclarationError`.
|
|
110
125
|
*/
|
|
111
126
|
export async function loadRules(config) {
|
|
112
|
-
|
|
127
|
+
const loads = config.plugins.flatMap((plugin) => Object.entries(plugin.rules)
|
|
113
128
|
.filter(([key, rule]) => rule.kind === "lazy" && ruleIsOn(config, plugin.name, key, rule.meta))
|
|
114
|
-
.map(([key, rule]) =>
|
|
129
|
+
.map(async ([key, rule]) => {
|
|
130
|
+
const loaded = await loadRule(`${plugin.name}/${key}`, rule);
|
|
131
|
+
// As the config check of a rule given directly (config.ts `unpublishedReads`).
|
|
132
|
+
for (const id of loaded.kind === "project" ? (loaded.reads ?? []) : []) {
|
|
133
|
+
const target = readTarget(config.plugins, id);
|
|
134
|
+
if (target.kind === "no-analysis") {
|
|
135
|
+
throw new RuleReadsError(unpublishedRead(plugin.name, key, id, target.plugin));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
await Promise.all(loads);
|
|
115
140
|
}
|
|
116
141
|
/** Loads every rule of the plugins, on or off: for the docs and for tests. */
|
|
117
142
|
export async function loadAllRules(plugins) {
|
package/dist/ledger.d.ts
CHANGED
|
@@ -52,8 +52,8 @@ export declare function withRule(ruleId: string, marks: readonly RuleMark[]): Le
|
|
|
52
52
|
/** Why a place past where the file's scan stopped is not checked: the uses after it are not read. */
|
|
53
53
|
export declare function stoppedReason(ref: LedgerRef): string;
|
|
54
54
|
/**
|
|
55
|
-
* "`w =
|
|
56
|
-
* for `
|
|
55
|
+
* "`w = settings` (another name for it) is a use of `settings` that stateward does not read
|
|
56
|
+
* for `Owned`: write it the way `stateward explain ownership/state-written-outside-owner` shows".
|
|
57
57
|
*/
|
|
58
58
|
export declare function unreadReason(ref: LedgerRef, ruleId: string): string;
|
|
59
59
|
/** The ledger as a proof reads it: the references of each declaration, and the marks on each. */
|
package/dist/ledger.js
CHANGED
|
@@ -282,8 +282,8 @@ export function stoppedReason(ref) {
|
|
|
282
282
|
return `the file is too large to read past \`${ref.text}\`, so the uses of \`${ref.name}\` after it are not checked: split the file`;
|
|
283
283
|
}
|
|
284
284
|
/**
|
|
285
|
-
* "`w =
|
|
286
|
-
* for `
|
|
285
|
+
* "`w = settings` (another name for it) is a use of `settings` that stateward does not read
|
|
286
|
+
* for `Owned`: write it the way `stateward explain ownership/state-written-outside-owner` shows".
|
|
287
287
|
*/
|
|
288
288
|
export function unreadReason(ref, ruleId) {
|
|
289
289
|
return `\`${ref.text}\` (${FORM_WORDS[ref.form]}) is a use of \`${ref.name}\` that stateward does not read for \`${ref.marker}\`: ${shownBy(ruleId)}`;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ProgramSize } from "./backend/program-size.js";
|
|
2
|
+
/**
|
|
3
|
+
* How much memory a check needs, estimated from its input before anything is built (the text of
|
|
4
|
+
* each program and of its own files), never from the live heap: the same input gives the same
|
|
5
|
+
* plan on every machine and run (SW5).
|
|
6
|
+
*
|
|
7
|
+
* The estimate, in MB, while a project is checked:
|
|
8
|
+
*
|
|
9
|
+
* BASE
|
|
10
|
+
* + PARSED_BASE + PARSED_BYTES_PER_CODE_CHAR × its program's code (its text without comments
|
|
11
|
+
* and white space) + PARSED_BYTES_PER_FILE × its files (syntax trees, binder; not sliced)
|
|
12
|
+
* + RESULT_BYTES_PER_OWN_CHAR × every project's own text (findings and summaries kept to the end)
|
|
13
|
+
* + CHECKER_BASE + the least of
|
|
14
|
+
* CHECKER_BYTES_PER_OWN_CHAR × the own text one type checker checks (a small slice), and
|
|
15
|
+
* WIDE_CHECKER_MB + WIDE_CHECKER_BYTES_PER_OWN_CHAR × that text (a large one)
|
|
16
|
+
*
|
|
17
|
+
* plus, when the programs are kept (fixes are tried), the other projects' programs and checkers.
|
|
18
|
+
* It must stay within USABLE_SHARE of the budget: V8 collects at length, then fails, when the live
|
|
19
|
+
* heap nears its limit.
|
|
20
|
+
*
|
|
21
|
+
* Measured on 2026-12-02 (all eight packs, `recommended`, results cache on), the live heap read
|
|
22
|
+
* after a forced collection every 1 to 3 s by a rule that samples it, with a new checker every
|
|
23
|
+
* 139 to 555 files (the smaller app) and every 676 to 10,822 files (the larger):
|
|
24
|
+
*
|
|
25
|
+
* - a React app of 21,016 files, 95.2 M characters (the walk counts 96.9 M), 10,822 own files of
|
|
26
|
+
* 35.4 M: 2,303 MB once parsed and bound (23.3 bytes a character over the 47 MB at start);
|
|
27
|
+
* about 407 MB of results after 10,141 files (12.1 bytes an own character); one checker for
|
|
28
|
+
* all files 1,060 MB (30 bytes an own character); slices of 676 files 200 to 490 MB, the
|
|
29
|
+
* densest near 110 bytes an own character;
|
|
30
|
+
* - a React app of 1,549 files, 18.9 M characters, 555 own files of 6.6 M: 466 MB parsed and bound
|
|
31
|
+
* (22.2 bytes a character); 68 MB of results after 438 files (13 bytes an own character); one
|
|
32
|
+
* checker 268 MB (40 bytes), slices of 139 files about 130 MB (79 bytes).
|
|
33
|
+
*
|
|
34
|
+
* Parsing and binding, measured on 2026-12-03 apart from the check (a program built as stateward
|
|
35
|
+
* builds it, its checker created, the heap read after a forced collection), on seven projects:
|
|
36
|
+
* the two apps above (2,216 and 406 MB), a server of 25,785 files whose 295 M characters are
|
|
37
|
+
* mostly the documentation comments of a library's declaration files (105 M of code: 3,620 MB),
|
|
38
|
+
* two libraries of 4,226 and 2,889 files (604 and 269 MB), 40,000 own files of two lines each
|
|
39
|
+
* (359 MB) and a small example (126 MB). 35 bytes a character of code, 3.5 KB a file and 100 MB
|
|
40
|
+
* fit all seven within 12% but the smallest (37% over); per character of text they range from
|
|
41
|
+
* 6.5 to 70 bytes. On the server, a budget of 5,120 MB in 9 slices was measured at 4,794 MB of
|
|
42
|
+
* live heap; this estimate puts that plan at 5,133.
|
|
43
|
+
*
|
|
44
|
+
* The checker's cost per character varies fourfold between slices of one project, so the
|
|
45
|
+
* constant is near the densest measured; the others are rounded up. One checker for all files
|
|
46
|
+
* costs less per character (they share their types): 30 bytes for all 10,822 files, 40 for all
|
|
47
|
+
* 555. So a second line bounds it, above both: 400 MB + 40 bytes an own character (1,816 MB
|
|
48
|
+
* against the 1,060 measured; 652 against 268). A slice keeps the first line (`checkerMb`).
|
|
49
|
+
*/
|
|
50
|
+
export declare const MEMORY_MODEL: {
|
|
51
|
+
/** Node, TypeScript and stateward's code, before any project (MB). */
|
|
52
|
+
baseMb: number;
|
|
53
|
+
/** Syntax trees, binder, module resolution: what any program costs (MB). */
|
|
54
|
+
parsedBaseMb: number;
|
|
55
|
+
/** The same, per character of the program's code (its text without comments and white space). */
|
|
56
|
+
parsedBytesPerCodeChar: number;
|
|
57
|
+
/** The same, per file of the program. */
|
|
58
|
+
parsedBytesPerFile: number;
|
|
59
|
+
/** What the run keeps to its end (findings, summaries, the results cache): per own character. */
|
|
60
|
+
resultBytesPerOwnChar: number;
|
|
61
|
+
/** What any type checker computes first (MB), paid again by each new one. */
|
|
62
|
+
checkerBaseMb: number;
|
|
63
|
+
/** What a type checker adds per character of the own files it checks, in a small slice. */
|
|
64
|
+
checkerBytesPerOwnChar: number;
|
|
65
|
+
/** A large checker's cost (MB), before its share per character (`wideCheckerBytesPerOwnChar`). */
|
|
66
|
+
wideCheckerMb: number;
|
|
67
|
+
/** What a type checker adds per character of the own files it checks, in a large slice. */
|
|
68
|
+
wideCheckerBytesPerOwnChar: number;
|
|
69
|
+
/** The share of the budget the estimate may fill. */
|
|
70
|
+
usableShare: number;
|
|
71
|
+
/** The fewest files a type checker is started for; a budget that allows fewer is too small. */
|
|
72
|
+
minFilesPerChecker: number;
|
|
73
|
+
};
|
|
74
|
+
/** One project's part of the plan. */
|
|
75
|
+
export type ProjectPlan = {
|
|
76
|
+
readonly tsconfig: string;
|
|
77
|
+
/** Its own files. */
|
|
78
|
+
readonly files: number;
|
|
79
|
+
/** How many type checkers share them, one after the other (1: one for all). */
|
|
80
|
+
readonly slices: number;
|
|
81
|
+
/** The files of each, the last one's fewer. */
|
|
82
|
+
readonly filesPerChecker: number;
|
|
83
|
+
};
|
|
84
|
+
export type MemoryPlan = {
|
|
85
|
+
readonly kind: "fits";
|
|
86
|
+
readonly budgetMb: number;
|
|
87
|
+
readonly projects: readonly ProjectPlan[];
|
|
88
|
+
} | {
|
|
89
|
+
readonly kind: "below-floor";
|
|
90
|
+
readonly budgetMb: number;
|
|
91
|
+
/** The least budget the plan fits in, rounded up to 256 MB. */
|
|
92
|
+
readonly neededMb: number;
|
|
93
|
+
/** Files and text of the project that needs it. */
|
|
94
|
+
readonly tsconfig: string;
|
|
95
|
+
readonly size: ProgramSize;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The plan for a check of `projects` (in the order the file phase reaches them) within `budgetMb`:
|
|
99
|
+
* how many own files of each project share one type checker. `keepsPrograms`: the programs stay
|
|
100
|
+
* built to the end (fixes are tried), so every program counts at once; otherwise one at a time.
|
|
101
|
+
*/
|
|
102
|
+
export declare function planMemory(budgetMb: number, projects: readonly {
|
|
103
|
+
readonly tsconfig: string;
|
|
104
|
+
readonly size: ProgramSize;
|
|
105
|
+
}[], keepsPrograms: boolean): MemoryPlan;
|
|
106
|
+
/**
|
|
107
|
+
* The plan as stateward prints it once, before the check: "memory budget 3,072 MB: 4 slices of
|
|
108
|
+
* about 900 files". Undefined when every project keeps one type checker (nothing to say).
|
|
109
|
+
* `shown` names a project's tsconfig as the reader would type it.
|
|
110
|
+
*/
|
|
111
|
+
export declare function describePlan(plan: Extract<MemoryPlan, {
|
|
112
|
+
kind: "fits";
|
|
113
|
+
}>, shown: (tsconfig: string) => string): string | undefined;
|
|
114
|
+
/** The budget is below what parsing and binding the project needs: the check does not start. */
|
|
115
|
+
export declare class MemoryBudgetError extends Error {
|
|
116
|
+
readonly hint: string;
|
|
117
|
+
constructor(plan: Extract<MemoryPlan, {
|
|
118
|
+
kind: "below-floor";
|
|
119
|
+
}>, shown: string);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=memory-plan.d.ts.map
|