@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.
Files changed (75) hide show
  1. package/dist/analyses.d.ts +37 -0
  2. package/dist/analyses.js +57 -0
  3. package/dist/backend/fingerprints.d.ts +3 -1
  4. package/dist/backend/fingerprints.js +198 -9
  5. package/dist/backend/program-record.d.ts +7 -0
  6. package/dist/backend/program-size.d.ts +32 -0
  7. package/dist/backend/program-size.js +166 -0
  8. package/dist/backend/typescript6.d.ts +62 -32
  9. package/dist/backend/typescript6.js +1615 -164
  10. package/dist/baseline.d.ts +1 -1
  11. package/dist/baseline.js +14 -10
  12. package/dist/cache.d.ts +92 -4
  13. package/dist/cache.js +257 -68
  14. package/dist/checker.d.ts +28 -3
  15. package/dist/checker.js +42 -8
  16. package/dist/class-id.d.ts +34 -0
  17. package/dist/class-id.js +93 -0
  18. package/dist/code-text.d.ts +8 -0
  19. package/dist/code-text.js +66 -0
  20. package/dist/config-file.js +7 -5
  21. package/dist/config.d.ts +10 -2
  22. package/dist/config.js +490 -48
  23. package/dist/define.d.ts +8 -2
  24. package/dist/disk-cache.d.ts +34 -2
  25. package/dist/disk-cache.js +82 -15
  26. package/dist/engine.d.ts +64 -3
  27. package/dist/engine.js +474 -59
  28. package/dist/fact-lines.d.ts +31 -0
  29. package/dist/fact-lines.js +197 -0
  30. package/dist/facts-versions.d.ts +27 -0
  31. package/dist/facts-versions.js +99 -0
  32. package/dist/fixes.js +4 -1
  33. package/dist/ignores.d.ts +11 -0
  34. package/dist/ignores.js +74 -27
  35. package/dist/implementation.d.ts +0 -6
  36. package/dist/implementation.js +0 -17
  37. package/dist/index.d.ts +9 -9
  38. package/dist/index.js +12 -7
  39. package/dist/internal.d.ts +13 -6
  40. package/dist/internal.js +7 -3
  41. package/dist/journal.d.ts +40 -0
  42. package/dist/journal.js +197 -0
  43. package/dist/lazy.d.ts +8 -1
  44. package/dist/lazy.js +27 -2
  45. package/dist/ledger.d.ts +2 -2
  46. package/dist/ledger.js +2 -2
  47. package/dist/memory-plan.d.ts +121 -0
  48. package/dist/memory-plan.js +174 -0
  49. package/dist/off-by-default.d.ts +13 -0
  50. package/dist/off-by-default.js +15 -0
  51. package/dist/options.d.ts +21 -5
  52. package/dist/options.js +22 -7
  53. package/dist/package-facts.d.ts +211 -17
  54. package/dist/package-facts.js +520 -38
  55. package/dist/plan.d.ts +1 -1
  56. package/dist/plan.js +7 -2
  57. package/dist/release.d.ts +12 -21
  58. package/dist/release.js +26 -38
  59. package/dist/renamed.d.ts +22 -3
  60. package/dist/renamed.js +50 -16
  61. package/dist/rollout.js +7 -4
  62. package/dist/severity.d.ts +1 -1
  63. package/dist/severity.js +17 -3
  64. package/dist/test-runner.d.ts +18 -0
  65. package/dist/test-runner.js +483 -0
  66. package/dist/testing.d.ts +3 -3
  67. package/dist/testing.js +5 -5
  68. package/dist/timing.d.ts +17 -7
  69. package/dist/timing.js +60 -38
  70. package/dist/types.d.ts +704 -20
  71. package/dist/unread.d.ts +90 -0
  72. package/dist/unread.js +405 -0
  73. package/dist/vocabulary.d.ts +1 -1
  74. package/dist/vocabulary.js +1 -1
  75. package/package.json +4 -2
package/dist/timing.js CHANGED
@@ -1,14 +1,40 @@
1
- import { getHeapStatistics } from "node:v8";
2
- const usedHeap = () => getHeapStatistics().used_heap_size;
1
+ import { getHeapStatistics, setFlagsFromString } from "node:v8";
2
+ import { runInNewContext } from "node:vm";
3
+ /**
4
+ * A function that runs a full garbage collection, or undefined when none can be had. Node gives
5
+ * one only to a process started with `--expose-gc`; the flag set now takes effect for a new
6
+ * context, which hands out its `gc`, and is unset again. Asked for only under `--timing`.
7
+ */
8
+ function fullCollection() {
9
+ try {
10
+ setFlagsFromString("--expose-gc");
11
+ const found = runInNewContext("gc");
12
+ // Back as it was: later contexts of the process get no `gc`.
13
+ setFlagsFromString("--no-expose-gc");
14
+ if (typeof found !== "function")
15
+ return undefined;
16
+ return () => {
17
+ Reflect.apply(found, undefined, []);
18
+ };
19
+ }
20
+ catch {
21
+ // A runtime without V8 flags: the live heap is not measured.
22
+ return undefined;
23
+ }
24
+ }
25
+ /**
26
+ * The recorder holds one record per rule and a few totals, whatever the size of the project: a
27
+ * type question adds its time to the rule that asked it and keeps nothing.
28
+ */
3
29
  export function createTimingRecorder({ secondPass = false, } = {}) {
4
30
  const rules = new Map();
5
31
  let started = performance.now();
6
32
  let programMs = 0;
7
33
  let fingerprintMs = 0;
8
34
  let ledgerMs = 0;
35
+ let liveHeapBytes;
9
36
  /** The type time of the rule that is running; undefined between rules. */
10
37
  let current;
11
- const wrapped = new WeakMap();
12
38
  const costOf = (ruleId, kind) => {
13
39
  let found = rules.get(ruleId);
14
40
  if (found === undefined) {
@@ -22,7 +48,6 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
22
48
  typeMs: 0,
23
49
  files: 0,
24
50
  reused: 0,
25
- allocatedBytes: 0,
26
51
  };
27
52
  rules.set(ruleId, found);
28
53
  }
@@ -35,16 +60,12 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
35
60
  const outerSide = typeSide;
36
61
  current = cost;
37
62
  typeSide = side === "warmMs" ? "warmTypeMs" : "typeMs";
38
- const heap = usedHeap();
39
63
  const at = performance.now();
40
64
  try {
41
65
  return run();
42
66
  }
43
67
  finally {
44
68
  cost[side] += performance.now() - at;
45
- // The heap is the check's own: the second pass's growth is not added.
46
- if (side !== "warmMs")
47
- cost.allocatedBytes += Math.max(0, usedHeap() - heap);
48
69
  current = outer;
49
70
  typeSide = outerSide;
50
71
  }
@@ -71,46 +92,46 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
71
92
  reused(ruleId, kind) {
72
93
  costOf(ruleId, kind).reused += 1;
73
94
  },
95
+ filesDone() {
96
+ const collect = fullCollection();
97
+ if (collect === undefined)
98
+ return;
99
+ // Not part of the check's time: the collection is the recorder's own.
100
+ const at = performance.now();
101
+ collect();
102
+ liveHeapBytes = Math.max(liveHeapBytes ?? 0, getHeapStatistics().used_heap_size);
103
+ started += performance.now() - at;
104
+ },
74
105
  projectSide(ruleId, run) {
75
106
  return measure(costOf(ruleId, "project"), "projectMs", run);
76
107
  },
77
108
  timedTypes(types) {
78
- const known = wrapped.get(types);
79
- if (known !== undefined)
80
- return known;
81
- const methods = new Map();
82
- const proxy = new Proxy(types, {
109
+ // A new proxy per call, held by nobody once the rule has run: nothing grows with the project.
110
+ return new Proxy(types, {
83
111
  get(target, key, receiver) {
84
112
  const value = Reflect.get(target, key, receiver);
85
113
  if (typeof value !== "function")
86
114
  return value;
87
- let method = methods.get(key);
88
- if (method === undefined) {
89
- method = (...args) => {
90
- const cost = current;
91
- if (cost === undefined) {
92
- const untimed = Reflect.apply(value, target, args);
93
- return untimed;
94
- }
95
- // A question asked inside another (none today) is counted once, by the outer one.
96
- current = undefined;
97
- const at = performance.now();
98
- try {
99
- const answer = Reflect.apply(value, target, args);
100
- return answer;
101
- }
102
- finally {
103
- cost[typeSide] += performance.now() - at;
104
- current = cost;
105
- }
106
- };
107
- methods.set(key, method);
108
- }
109
- return method;
115
+ return (...args) => {
116
+ const cost = current;
117
+ if (cost === undefined) {
118
+ const untimed = Reflect.apply(value, target, args);
119
+ return untimed;
120
+ }
121
+ // A question asked inside another (none today) is counted once, by the outer one.
122
+ current = undefined;
123
+ const at = performance.now();
124
+ try {
125
+ const answer = Reflect.apply(value, target, args);
126
+ return answer;
127
+ }
128
+ finally {
129
+ cost[typeSide] += performance.now() - at;
130
+ current = cost;
131
+ }
132
+ };
110
133
  },
111
134
  });
112
- wrapped.set(types, proxy);
113
- return proxy;
114
135
  },
115
136
  start() {
116
137
  started = performance.now();
@@ -134,6 +155,7 @@ export function createTimingRecorder({ secondPass = false, } = {}) {
134
155
  totalMs,
135
156
  programMs,
136
157
  typeMs,
158
+ liveHeapBytes,
137
159
  fingerprintMs,
138
160
  ledgerMs,
139
161
  otherMs: Math.max(0, totalMs - programMs - fingerprintMs - ledgerMs - ruleMs),