@typeonce/ritmo-devtools 0.13.0 → 0.15.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 (92) hide show
  1. package/CHANGELOG.md +312 -0
  2. package/README.md +336 -58
  3. package/dist/Desync.d.ts +49 -0
  4. package/dist/Desync.d.ts.map +1 -0
  5. package/dist/Desync.js +51 -0
  6. package/dist/Desync.js.map +1 -0
  7. package/dist/Determinism.d.ts +17 -6
  8. package/dist/Determinism.d.ts.map +1 -1
  9. package/dist/Determinism.js +11 -3
  10. package/dist/Determinism.js.map +1 -1
  11. package/dist/Format.d.ts +43 -8
  12. package/dist/Format.d.ts.map +1 -1
  13. package/dist/Format.js +63 -31
  14. package/dist/Format.js.map +1 -1
  15. package/dist/Fuzz.d.ts +268 -0
  16. package/dist/Fuzz.d.ts.map +1 -0
  17. package/dist/Fuzz.js +355 -0
  18. package/dist/Fuzz.js.map +1 -0
  19. package/dist/Invariant.d.ts +6 -2
  20. package/dist/Invariant.d.ts.map +1 -1
  21. package/dist/Invariant.js.map +1 -1
  22. package/dist/Lint.d.ts +9 -3
  23. package/dist/Lint.d.ts.map +1 -1
  24. package/dist/Lint.js.map +1 -1
  25. package/dist/PlaywrightEngine.d.ts +29 -0
  26. package/dist/PlaywrightEngine.d.ts.map +1 -0
  27. package/dist/PlaywrightEngine.js +193 -0
  28. package/dist/PlaywrightEngine.js.map +1 -0
  29. package/dist/Replay.d.ts +43 -34
  30. package/dist/Replay.d.ts.map +1 -1
  31. package/dist/Replay.js +27 -33
  32. package/dist/Replay.js.map +1 -1
  33. package/dist/Session.d.ts +214 -17
  34. package/dist/Session.d.ts.map +1 -1
  35. package/dist/Session.js +563 -57
  36. package/dist/Session.js.map +1 -1
  37. package/dist/Verify.d.ts +147 -0
  38. package/dist/Verify.d.ts.map +1 -0
  39. package/dist/Verify.js +151 -0
  40. package/dist/Verify.js.map +1 -0
  41. package/dist/cli.js +136 -8
  42. package/dist/cli.js.map +1 -1
  43. package/dist/index.d.ts +4 -2
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -2
  46. package/dist/index.js.map +1 -1
  47. package/dist/internal/dependencyScan.d.ts +44 -0
  48. package/dist/internal/dependencyScan.d.ts.map +1 -0
  49. package/dist/internal/dependencyScan.js +313 -0
  50. package/dist/internal/dependencyScan.js.map +1 -0
  51. package/dist/internal/fuzzNetwork.d.ts +56 -0
  52. package/dist/internal/fuzzNetwork.d.ts.map +1 -0
  53. package/dist/internal/fuzzNetwork.js +96 -0
  54. package/dist/internal/fuzzNetwork.js.map +1 -0
  55. package/dist/internal/values.d.ts +9 -1
  56. package/dist/internal/values.d.ts.map +1 -1
  57. package/dist/internal/values.js +11 -1
  58. package/dist/internal/values.js.map +1 -1
  59. package/dist/internal/verifyRunner.d.ts +19 -0
  60. package/dist/internal/verifyRunner.d.ts.map +1 -0
  61. package/dist/internal/verifyRunner.js +47 -0
  62. package/dist/internal/verifyRunner.js.map +1 -0
  63. package/dist/internal/version.d.ts +1 -1
  64. package/dist/internal/version.js +1 -1
  65. package/package.json +28 -3
  66. package/src/Desync.ts +100 -0
  67. package/src/Determinism.ts +46 -11
  68. package/src/Format.ts +99 -34
  69. package/src/Fuzz.ts +544 -0
  70. package/src/Invariant.ts +6 -2
  71. package/src/Lint.ts +9 -3
  72. package/src/PlaywrightEngine.ts +229 -0
  73. package/src/Replay.ts +98 -74
  74. package/src/Session.ts +806 -72
  75. package/src/Verify.ts +273 -0
  76. package/src/cli.ts +131 -8
  77. package/src/index.ts +4 -2
  78. package/src/internal/dependencyScan.ts +356 -0
  79. package/src/internal/fuzzNetwork.ts +130 -0
  80. package/src/internal/values.ts +20 -1
  81. package/src/internal/verifyRunner.ts +46 -0
  82. package/src/internal/version.ts +1 -1
  83. package/dist/Monitor.d.ts +0 -101
  84. package/dist/Monitor.d.ts.map +0 -1
  85. package/dist/Monitor.js +0 -602
  86. package/dist/Monitor.js.map +0 -1
  87. package/dist/internal/monitor.d.ts +0 -126
  88. package/dist/internal/monitor.d.ts.map +0 -1
  89. package/dist/internal/monitor.js +0 -279
  90. package/dist/internal/monitor.js.map +0 -1
  91. package/src/Monitor.ts +0 -713
  92. package/src/internal/monitor.ts +0 -370
package/dist/cli.js CHANGED
@@ -11,8 +11,10 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
11
11
  * `ritmo-devtools`: devtools from the command line.
12
12
  *
13
13
  * ritmo-devtools lint <entry>
14
+ * ritmo-devtools verify <entry> <replay> [--engines node,chromium,webkit,firefox] [--json]
15
+ * ritmo-devtools scan <entry> [--json]
14
16
  *
15
- * Imports `<entry>` (a module exporting `lintTarget`, see the `Lint` module),
17
+ * `lint` imports `<entry>` (a module exporting `lintTarget`, see the `Lint` module),
16
18
  * prints every lint of its schedules with its fix, and exits with 1 when one
17
19
  * is a warning. Info-level lints are printed and do not fail.
18
20
  *
@@ -27,18 +29,51 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
27
29
  * A missing or unreadable config, one with `extends`, or one that never turns
28
30
  * the rule on prints why the check was skipped and does not fail.
29
31
  *
30
- * Exit codes: 0 ok, 1 lint warning or uncovered module, 2 usage error.
32
+ * `verify` imports `<entry>` (a module exporting `replayTarget`, the
33
+ * `make(playback)` factory `Replay.session` takes), plays the replay file in
34
+ * Node and in each listed browser engine, and prints the first tick whose
35
+ * checksum differs from Node's, with every value that differs there (see the
36
+ * `Verify` module). Node always runs, as the reference; `--engines node` (the
37
+ * default) needs no other dependency. Browser engines need `playwright` and
38
+ * `vite` (see the `PlaywrightEngine` module); one that is not installed is
39
+ * printed with its install command and fails the check. `--json` prints the
40
+ * result as JSON instead of text.
41
+ *
42
+ * `scan` resolves every file `<entry>` (the simulation entry) imports,
43
+ * `node_modules` included, and runs the oxlint rules `ritmo/use-ops-for-math`,
44
+ * `ritmo/use-clock-for-time`, and `ritmo/use-random-for-randomness` over them,
45
+ * so a dependency that calls `Math.sin`, `Date.now`, or `Math.random` shows
46
+ * before a desync does. Findings are printed per package with what to do next;
47
+ * `--json` prints them as JSON instead. It is a hint, not a verdict: it exits
48
+ * with 0 with or without findings. It needs `rolldown` (Vite 8 includes it)
49
+ * and the game's `oxlint` with `@typeonce/oxlint-plugin-ritmo`; a missing one
50
+ * is printed with its install command and exits with 2.
51
+ *
52
+ * Exit codes: 0 ok (and every `scan` that ran), 1 lint warning, uncovered
53
+ * module, or an engine that differs or did not run, 2 usage error (for `scan`
54
+ * also an unreadable entry, an import that does not resolve, or a missing tool).
31
55
  * Requires Node 22.15 or later for `module.registerHooks`; on older Node it
32
56
  * prints that coverage was not checked.
33
57
  *
34
58
  * @module cli
35
59
  * @docGroup devtools
36
60
  */
61
+ import { readFileSync } from "node:fs";
37
62
  import { resolve } from "node:path";
38
63
  import { pathToFileURL } from "node:url";
64
+ import * as DependencyScan from "./internal/dependencyScan.js";
39
65
  import * as SimulationCoverage from "./internal/simulationCoverage.js";
40
66
  import * as Lint from "./Lint.js";
41
- const usage = "usage: ritmo-devtools lint <entry>\n <entry> exports lintTarget: () => { runtime, schedules, describe?, hostEvents? } (see the Lint module)";
67
+ import * as Replay from "./Replay.js";
68
+ import * as Verify from "./Verify.js";
69
+ const usage = [
70
+ "usage: ritmo-devtools lint <entry>",
71
+ " ritmo-devtools verify <entry> <replay> [--engines node,chromium,webkit,firefox] [--json]",
72
+ " ritmo-devtools scan <entry> [--json]",
73
+ " lint: <entry> exports lintTarget: () => { runtime, schedules, describe?, hostEvents? } (see the Lint module)",
74
+ " verify: <entry> exports replayTarget: (playback) => { runtime, schedules, hostClock } (see the Verify module)",
75
+ " scan: <entry> is the simulation's entry module; every file it imports, node_modules included, is checked for Math, clock, and randomness calls"
76
+ ].join("\n");
42
77
  const isRecord = (value) => typeof value === "object" && value !== null;
43
78
  /** Checks at runtime what the type of `lintTarget`'s result promises, so a wrong entry fails with a message. */
44
79
  const isTarget = (value) => isRecord(value)
@@ -49,11 +84,17 @@ const isTarget = (value) => isRecord(value)
49
84
  && (value["describe"] === undefined || isRecord(value["describe"]))
50
85
  && (value["hostEvents"] === undefined || Array.isArray(value["hostEvents"]));
51
86
  const main = async (args) => {
52
- const [command, entry] = args;
53
- if (command !== "lint" || entry === undefined) {
54
- console.error(usage);
55
- return 2;
56
- }
87
+ const [command, ...rest] = args;
88
+ if (command === "lint" && rest.length === 1)
89
+ return lint(rest[0]);
90
+ if (command === "verify")
91
+ return verify(rest);
92
+ if (command === "scan")
93
+ return scan(rest);
94
+ console.error(usage);
95
+ return 2;
96
+ };
97
+ const lint = async (entry) => {
57
98
  const loads = SimulationCoverage.recordLoads();
58
99
  const loaded = await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(entry)).href));
59
100
  // Snapshot before lintTarget runs: modules it imports (render schedules to describe) are host code.
@@ -80,5 +121,92 @@ const main = async (args) => {
80
121
  console.log(text);
81
122
  return report.data.ok && (!coverage.checked || coverage.uncovered.length === 0) ? 0 : 1;
82
123
  };
124
+ const engineNames = ["node", "chromium", "webkit", "firefox"];
125
+ const verify = async (args) => {
126
+ const positional = [];
127
+ let engines = ["node"];
128
+ let json = false;
129
+ for (let index = 0; index < args.length; index++) {
130
+ const arg = args[index];
131
+ if (arg === "--json")
132
+ json = true;
133
+ else if (arg === "--engines")
134
+ engines = (args[++index] ?? "").split(",").filter((name) => name !== "");
135
+ else if (arg.startsWith("--engines="))
136
+ engines = arg.slice("--engines=".length).split(",").filter((name) => name !== "");
137
+ else
138
+ positional.push(arg);
139
+ }
140
+ const [entry, replay] = positional;
141
+ if (entry === undefined || replay === undefined || positional.length !== 2) {
142
+ console.error(usage);
143
+ return 2;
144
+ }
145
+ const unknown = engines.filter((name) => !engineNames.includes(name));
146
+ if (engines.length === 0 || unknown.length > 0) {
147
+ console.error(`--engines takes a comma-separated list of ${engineNames.join(", ")}${unknown.length > 0 ? `; unknown: ${unknown.join(", ")}` : ""}`);
148
+ return 2;
149
+ }
150
+ let data;
151
+ try {
152
+ data = JSON.parse(readFileSync(resolve(replay), "utf8"));
153
+ }
154
+ catch (error) {
155
+ console.error(`${replay} could not be read as JSON: ${error instanceof Error ? error.message : String(error)}`);
156
+ return 2;
157
+ }
158
+ const file = Replay.parse(data);
159
+ if (!file.ok) {
160
+ console.error(`${replay} is not a replay file: ${file.error._tag === "InvalidReplay" ? file.error.message : file.error._tag}`);
161
+ return 2;
162
+ }
163
+ const loaded = await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(entry)).href));
164
+ const make = isRecord(loaded) ? loaded["replayTarget"] : undefined;
165
+ if (typeof make !== "function") {
166
+ console.error(`${entry} must export replayTarget: (playback) => { runtime, schedules, hostClock } (see the Verify module)`);
167
+ return 2;
168
+ }
169
+ // The browser adapter, and with it playwright and vite, loads only when a browser is listed.
170
+ const browsers = engines.filter((name) => name !== "node");
171
+ const PlaywrightEngine = browsers.length > 0 ? await import("./PlaywrightEngine.js") : undefined;
172
+ const playwright = PlaywrightEngine?.make({ entry, browsers: browsers.filter(PlaywrightEngine.isBrowser) });
173
+ let result;
174
+ try {
175
+ // The entry's type is checked where it is written; here only its shape is known.
176
+ result = await Verify.acrossEngines(make, file.value, { engines: playwright?.engines ?? [] });
177
+ }
178
+ catch (error) {
179
+ console.error(`replayTarget in ${entry} threw: ${error instanceof Error ? error.stack ?? error.message : String(error)}`);
180
+ return 2;
181
+ }
182
+ finally {
183
+ await playwright?.close();
184
+ }
185
+ console.log(json ? JSON.stringify(result.ok ? { ok: true, ...result.value.data } : { ok: false, ...withoutText(result.error) }, null, 2) : result.ok ? result.value.text : result.error.text);
186
+ return result.ok ? 0 : 1;
187
+ };
188
+ const scan = async (args) => {
189
+ const json = args.includes("--json");
190
+ const positional = args.filter((arg) => arg !== "--json");
191
+ if (positional.length !== 1 || positional[0].startsWith("-")) {
192
+ console.error(usage);
193
+ return 2;
194
+ }
195
+ const result = await DependencyScan.run(positional[0], process.cwd());
196
+ if (!result.ok) {
197
+ const error = result.error;
198
+ console.error(error._tag === "ToolMissing"
199
+ ? `scan needs ${error.tool}, which is not installed: ${error.install}`
200
+ : error._tag === "ResolveFailed"
201
+ ? `the imports of ${positional[0]} could not be resolved: ${error.message}`
202
+ : error._tag === "LintFailed"
203
+ ? `oxlint did not run: ${error.message}`
204
+ : error.message);
205
+ return 2;
206
+ }
207
+ console.log(json ? JSON.stringify(result.value, null, 2) : DependencyScan.format(result.value));
208
+ return 0;
209
+ };
210
+ const withoutText = ({ text: _text, ...error }) => error;
83
211
  process.exitCode = await main(process.argv.slice(2));
84
212
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,KAAK,kBAAkB,MAAM,kCAAkC,CAAA;AACtE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,MAAM,KAAK,GAAG,8IAA8I,CAAA;AAE5J,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAElH,gHAAgH;AAChH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAkC,EAAE,CAClE,QAAQ,CAAC,KAAK,CAAC;OACZ,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;OAC1B,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC;OACnC,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC,KAAK,UAAU;OAC3D,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;OAC5B,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,SAAS,IAAI,QAAQ,C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CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAC/F,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,MAAM,WAAW,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,EAAsB,EAAE,EAAE,CAAC,KAAK,CAAA;AAE5E,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- /** Debug sessions, trace history, text reports, and a live browser monitor for ritmo runtimes. */
1
+ /** Headless debug sessions, trace history, text reports, replays, and fuzzing for ritmo runtimes. */
2
2
  export * as Format from "./Format.ts";
3
+ export * as Fuzz from "./Fuzz.ts";
4
+ export * as Desync from "./Desync.ts";
3
5
  export * as Determinism from "./Determinism.ts";
4
6
  export * as Invariant from "./Invariant.ts";
5
7
  export * as Lint from "./Lint.ts";
6
- export * as Monitor from "./Monitor.ts";
7
8
  export * as Replay from "./Replay.ts";
8
9
  export * as Rendered from "./Rendered.ts";
9
10
  export * as Session from "./Session.ts";
11
+ export * as Verify from "./Verify.ts";
10
12
  /** The package's identifier. */
11
13
  export declare const packageTag: "devtools";
12
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAG,UAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,gCAAgC;AAChC,eAAO,MAAM,UAAU,EAAG,UAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
- /** Debug sessions, trace history, text reports, and a live browser monitor for ritmo runtimes. */
1
+ /** Headless debug sessions, trace history, text reports, replays, and fuzzing for ritmo runtimes. */
2
2
  export * as Format from "./Format.js";
3
+ export * as Fuzz from "./Fuzz.js";
4
+ export * as Desync from "./Desync.js";
3
5
  export * as Determinism from "./Determinism.js";
4
6
  export * as Invariant from "./Invariant.js";
5
7
  export * as Lint from "./Lint.js";
6
- export * as Monitor from "./Monitor.js";
7
8
  export * as Replay from "./Replay.js";
8
9
  export * as Rendered from "./Rendered.js";
9
10
  export * as Session from "./Session.js";
11
+ export * as Verify from "./Verify.js";
10
12
  /** The package's identifier. */
11
13
  export const packageTag = "devtools";
12
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,gCAAgC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,gCAAgC;AAChC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAmB,CAAA"}
@@ -0,0 +1,44 @@
1
+ import * as Result from "@typeonce/ritmo/Result";
2
+ /** The rules the scan runs: the determinism rules a dependency can break. */
3
+ export declare const rules: readonly ["ritmo/use-ops-for-math", "ritmo/use-clock-for-time", "ritmo/use-random-for-randomness"];
4
+ export type Rule = (typeof rules)[number];
5
+ /** One report of a rule, at a 1-based line and column (UTF-16) in a file relative to the working directory. */
6
+ export interface Finding {
7
+ readonly file: string;
8
+ readonly line: number;
9
+ readonly column: number;
10
+ readonly rule: Rule;
11
+ /** The flagged source (`Math.sin`, `x ** 3`, `Date.now`), shortened to one line. */
12
+ readonly snippet: string;
13
+ }
14
+ /** Findings of the files that belong to one package (nearest `package.json` with a `name`). */
15
+ export interface PackageReport {
16
+ readonly name: string;
17
+ readonly files: number;
18
+ readonly findings: ReadonlyArray<Finding>;
19
+ }
20
+ /** The scan result; `packages` starts with the entry's own package, then the rest by name. */
21
+ export interface Report {
22
+ readonly entry: string;
23
+ readonly files: number;
24
+ readonly packages: ReadonlyArray<PackageReport>;
25
+ }
26
+ export type ScanError = {
27
+ readonly _tag: "EntryUnreadable";
28
+ readonly message: string;
29
+ } | {
30
+ readonly _tag: "ToolMissing";
31
+ readonly tool: string;
32
+ readonly install: string;
33
+ } | {
34
+ readonly _tag: "ResolveFailed";
35
+ readonly message: string;
36
+ } | {
37
+ readonly _tag: "LintFailed";
38
+ readonly message: string;
39
+ };
40
+ /** Scans the import closure of `entry`; paths in the report are relative to `cwd`. */
41
+ export declare const run: (entry: string, cwd: string) => Promise<Result.Result<Report, ScanError>>;
42
+ /** The text report: findings grouped by package, a summary line, and what to do next. */
43
+ export declare const format: (report: Report) => string;
44
+ //# sourceMappingURL=dependencyScan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencyScan.d.ts","sourceRoot":"","sources":["../../src/internal/dependencyScan.ts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,MAAM,MAAM,wBAAwB,CAAA;AAEhD,6EAA6E;AAC7E,eAAO,MAAM,KAAK,YAAI,wBAAwB,EAAE,0BAA0B,EAAE,iCAAiC,CAAU,CAAA;AAEvH,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAA;AAEzC,+GAA+G;AAC/G,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,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,WAAY,MAAM,KAAG,MAgBvC,CAAA"}
@@ -0,0 +1,313 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ /**
10
+ * The dependency determinism scan behind `ritmo-devtools scan <entry>` (Node
11
+ * only): every file the simulation entry imports, `node_modules` included,
12
+ * checked with the oxlint rules `ritmo/use-ops-for-math`,
13
+ * `ritmo/use-clock-for-time`, and `ritmo/use-random-for-randomness`.
14
+ *
15
+ * The import closure comes from rolldown: a real bundler resolves exactly
16
+ * what a game's build resolves (package `exports`, `browser` fields, CJS and
17
+ * ESM, TypeScript with type-only imports erased), and its module graph
18
+ * (`this.getModuleIds()`) lists every loaded file, including ones tree-shaking
19
+ * would drop. Rolldown is what Vite 8 builds with, so a game with Vite 8 needs
20
+ * nothing new: it is found as Vite's own dependency when the game does not
21
+ * install it directly. esbuild (through tsx) was the alternative, but Vite 8
22
+ * no longer depends on it, so fewer games would have it.
23
+ *
24
+ * The files are checked by spawning the game's own `oxlint` with
25
+ * `@typeonce/oxlint-plugin-ritmo` (both are in every game's setup) and a
26
+ * generated config that turns on only those three rules. Running the rules
27
+ * themselves, not a scanner that mirrors them, keeps one definition of what is
28
+ * flagged: the scan reports exactly what the lint would report if the
29
+ * dependency were the game's code, and what `oxlint --fix` fixes after the
30
+ * dependency is vendored.
31
+ *
32
+ * Each tool is looked up from the entry's directory first, then from devtools
33
+ * (`oxlint` and `rolldown` are optional peer dependencies).
34
+ *
35
+ * @internal
36
+ */
37
+ import { spawnSync } from "node:child_process";
38
+ import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
39
+ import { tmpdir } from "node:os";
40
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
41
+ import { fileURLToPath, pathToFileURL } from "node:url";
42
+ import * as Result from "@typeonce/ritmo/Result";
43
+ /** The rules the scan runs: the determinism rules a dependency can break. */
44
+ export const rules = ["ritmo/use-ops-for-math", "ritmo/use-clock-for-time", "ritmo/use-random-for-randomness"];
45
+ const sourceFile = /\.(?:[cm]?[jt]s|[jt]sx)$/;
46
+ const chunkSize = 400;
47
+ const unnamed = "(no package)";
48
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
49
+ const readJson = (path) => {
50
+ try {
51
+ return JSON.parse(readFileSync(path, "utf8"));
52
+ }
53
+ catch {
54
+ return undefined;
55
+ }
56
+ };
57
+ /** The real directory of the installed package `name`, looked up through `node_modules` from `from` upward. */
58
+ const findPackage = (name, from) => {
59
+ for (let directory = from;; directory = dirname(directory)) {
60
+ const candidate = join(directory, "node_modules", name);
61
+ if (existsSync(join(candidate, "package.json")))
62
+ return realpathSync(candidate);
63
+ if (dirname(directory) === directory)
64
+ return undefined;
65
+ }
66
+ };
67
+ const exportTarget = (value) => {
68
+ if (typeof value === "string")
69
+ return value;
70
+ if (Array.isArray(value))
71
+ return exportTarget(value[0]);
72
+ if (!isRecord(value))
73
+ return undefined;
74
+ for (const [condition, target] of Object.entries(value)) {
75
+ if (condition === "import" || condition === "node" || condition === "default") {
76
+ const found = exportTarget(target);
77
+ if (found !== undefined)
78
+ return found;
79
+ }
80
+ }
81
+ return undefined;
82
+ };
83
+ /** The file the package's main entry imports (`exports["."]` with `import`/`node`/`default`, then `module`, `main`). */
84
+ const packageEntry = (directory) => {
85
+ const manifest = readJson(join(directory, "package.json"));
86
+ const record = isRecord(manifest) ? manifest : {};
87
+ const exports = record["exports"];
88
+ const main = isRecord(exports) && "." in exports ? exports["."] : exports;
89
+ const target = exportTarget(main)
90
+ ?? (typeof record["module"] === "string" ? record["module"] : undefined)
91
+ ?? (typeof record["main"] === "string" ? record["main"] : "index.js");
92
+ return join(directory, target);
93
+ };
94
+ const devtoolsDirectory = dirname(fileURLToPath(import.meta.url));
95
+ const locate = (name, from) => findPackage(name, from) ?? findPackage(name, devtoolsDirectory);
96
+ /** Rolldown, installed directly or as Vite 8's dependency. */
97
+ const loadRolldown = async (from) => {
98
+ const vite = locate("vite", from);
99
+ const directory = locate("rolldown", from) ?? (vite === undefined ? undefined : findPackage("rolldown", vite));
100
+ if (directory === undefined)
101
+ return undefined;
102
+ const loaded = await import(__rewriteRelativeImportExtension(pathToFileURL(packageEntry(directory)).href));
103
+ const rolldown = isRecord(loaded) ? loaded["rolldown"] : undefined;
104
+ // The module is untyped here (an optional peer); only its shape was checked.
105
+ return typeof rolldown === "function" ? rolldown : undefined;
106
+ };
107
+ /** Every source file the entry imports, itself included, as real absolute paths. */
108
+ const closure = async (rolldown, entry) => {
109
+ let ids = [];
110
+ const bundle = await rolldown({
111
+ input: entry,
112
+ cwd: dirname(entry),
113
+ // The build that ships to players; Node builtins stay external.
114
+ platform: "browser",
115
+ treeshake: false,
116
+ logLevel: "silent",
117
+ plugins: [{
118
+ name: "ritmo-devtools-scan",
119
+ buildEnd() {
120
+ ids = [...this.getModuleIds()];
121
+ }
122
+ }]
123
+ });
124
+ try {
125
+ await bundle.generate({});
126
+ }
127
+ finally {
128
+ await bundle.close();
129
+ }
130
+ return [...new Set(ids.filter((id) => isAbsolute(id) && sourceFile.test(id) && existsSync(id)).map((id) => realpathSync(id)))].sort();
131
+ };
132
+ const parseDiagnostics = (stdout) => {
133
+ let parsed;
134
+ try {
135
+ parsed = JSON.parse(stdout);
136
+ }
137
+ catch {
138
+ return undefined;
139
+ }
140
+ if (!isRecord(parsed) || !Array.isArray(parsed["diagnostics"]))
141
+ return undefined;
142
+ const out = [];
143
+ for (const diagnostic of parsed["diagnostics"]) {
144
+ if (!isRecord(diagnostic) || typeof diagnostic["code"] !== "string" || typeof diagnostic["filename"] !== "string")
145
+ continue;
146
+ const rule = diagnostic["code"].replace(/^ritmo\((.*)\)$/, "ritmo/$1");
147
+ const label = Array.isArray(diagnostic["labels"]) ? diagnostic["labels"][0] : undefined;
148
+ const span = isRecord(label) && isRecord(label["span"]) ? label["span"] : undefined;
149
+ if (!rules.includes(rule) || span === undefined)
150
+ continue;
151
+ if (typeof span["offset"] !== "number" || typeof span["length"] !== "number")
152
+ continue;
153
+ out.push({ file: diagnostic["filename"], rule: rule, offset: span["offset"], length: span["length"] });
154
+ }
155
+ return out;
156
+ };
157
+ const lint = (oxlint, plugin, files) => {
158
+ const directory = mkdtempSync(join(tmpdir(), "ritmo-scan-"));
159
+ try {
160
+ const config = join(directory, "oxlintrc.json");
161
+ writeFileSync(config, JSON.stringify({
162
+ jsPlugins: [plugin],
163
+ categories: { correctness: "off" },
164
+ rules: Object.fromEntries(rules.map((rule) => [rule, "error"])),
165
+ ignorePatterns: []
166
+ }));
167
+ const diagnostics = [];
168
+ for (let start = 0; start < files.length; start += chunkSize) {
169
+ const run = spawnSync(process.execPath, [oxlint, "-c", config, "--format", "json", "--no-ignore", "--disable-nested-config", ...files.slice(start, start + chunkSize)], { encoding: "utf8", maxBuffer: 1024 * 1024 * 1024 });
170
+ const parsed = parseDiagnostics(run.stdout ?? "");
171
+ if (parsed === undefined) {
172
+ return Result.failure({ _tag: "LintFailed", message: (run.stderr || run.stdout || run.error?.message || "no output").trim() });
173
+ }
174
+ diagnostics.push(...parsed);
175
+ }
176
+ return Result.success(diagnostics);
177
+ }
178
+ finally {
179
+ rmSync(directory, { recursive: true, force: true });
180
+ }
181
+ };
182
+ const shorten = (text) => {
183
+ const line = text.replace(/\s+/g, " ").trim();
184
+ return line.length > 60 ? `${line.slice(0, 59)}…` : line;
185
+ };
186
+ /** Line, column (UTF-16), and snippet of each byte span (oxlint reports UTF-8 offsets), walking the file once. */
187
+ const locateSpans = (path, cwd, found) => {
188
+ const bytes = readFileSync(path);
189
+ const file = relative(cwd, path);
190
+ const sorted = [...found].sort((a, b) => a.offset - b.offset);
191
+ const out = [];
192
+ let cursor = 0;
193
+ let line = 1;
194
+ let column = 1;
195
+ for (const diagnostic of sorted) {
196
+ const end = Math.min(diagnostic.offset, bytes.length);
197
+ let lineStart = cursor;
198
+ for (let index = cursor; index < end; index++) {
199
+ if (bytes[index] === 0x0a) {
200
+ line++;
201
+ column = 1;
202
+ lineStart = index + 1;
203
+ }
204
+ }
205
+ column += bytes.subarray(lineStart, end).toString("utf8").length;
206
+ cursor = end;
207
+ out.push({
208
+ file,
209
+ line,
210
+ column,
211
+ rule: diagnostic.rule,
212
+ snippet: shorten(bytes.subarray(diagnostic.offset, diagnostic.offset + diagnostic.length).toString("utf8"))
213
+ });
214
+ }
215
+ return out;
216
+ };
217
+ /** The `name` of the nearest `package.json` above `file` that has one. */
218
+ const packageOf = (cache, file) => {
219
+ const visited = [];
220
+ let name;
221
+ for (let directory = dirname(file);; directory = dirname(directory)) {
222
+ if (cache.has(directory)) {
223
+ name = cache.get(directory);
224
+ break;
225
+ }
226
+ visited.push(directory);
227
+ const manifest = readJson(join(directory, "package.json"));
228
+ if (isRecord(manifest) && typeof manifest["name"] === "string" && manifest["name"] !== "") {
229
+ name = manifest["name"];
230
+ break;
231
+ }
232
+ if (dirname(directory) === directory)
233
+ break;
234
+ }
235
+ for (const directory of visited)
236
+ cache.set(directory, name);
237
+ return name;
238
+ };
239
+ /** Scans the import closure of `entry`; paths in the report are relative to `cwd`. */
240
+ export const run = async (entry, cwd) => {
241
+ const absolute = resolve(cwd, entry);
242
+ try {
243
+ if (!statSync(absolute).isFile())
244
+ return Result.failure({ _tag: "EntryUnreadable", message: `${entry} is not a file` });
245
+ readFileSync(absolute);
246
+ }
247
+ catch (error) {
248
+ return Result.failure({ _tag: "EntryUnreadable", message: `${entry} could not be read: ${error instanceof Error ? error.message : String(error)}` });
249
+ }
250
+ const from = dirname(realpathSync(absolute));
251
+ const rolldown = await loadRolldown(from);
252
+ if (rolldown === undefined) {
253
+ return Result.failure({ _tag: "ToolMissing", tool: "rolldown (or vite 8, which includes it)", install: "npm install --save-dev rolldown" });
254
+ }
255
+ const oxlint = locate("oxlint", from);
256
+ const plugin = locate("@typeonce/oxlint-plugin-ritmo", from);
257
+ if (oxlint === undefined || plugin === undefined) {
258
+ return Result.failure({ _tag: "ToolMissing", tool: "oxlint with @typeonce/oxlint-plugin-ritmo", install: "npm install --save-dev oxlint @typeonce/oxlint-plugin-ritmo" });
259
+ }
260
+ const manifest = readJson(join(oxlint, "package.json"));
261
+ const bin = isRecord(manifest) ? manifest["bin"] : undefined;
262
+ const oxlintBin = join(oxlint, typeof bin === "string" ? bin : isRecord(bin) && typeof bin["oxlint"] === "string" ? bin["oxlint"] : "bin/oxlint");
263
+ let files;
264
+ try {
265
+ files = await closure(rolldown, realpathSync(absolute));
266
+ }
267
+ catch (error) {
268
+ return Result.failure({ _tag: "ResolveFailed", message: error instanceof Error ? error.message : String(error) });
269
+ }
270
+ const diagnostics = lint(oxlintBin, packageEntry(plugin), files);
271
+ if (!diagnostics.ok)
272
+ return diagnostics;
273
+ const base = realpathSync(cwd);
274
+ const byFile = new Map();
275
+ for (const diagnostic of diagnostics.value) {
276
+ const path = realpathSync(diagnostic.file);
277
+ byFile.set(path, [...(byFile.get(path) ?? []), diagnostic]);
278
+ }
279
+ const cache = new Map();
280
+ const own = packageOf(cache, realpathSync(absolute)) ?? unnamed;
281
+ const groups = new Map([[own, { files: 0, findings: [] }]]);
282
+ for (const file of files) {
283
+ const name = packageOf(cache, file) ?? unnamed;
284
+ const group = groups.get(name) ?? { files: 0, findings: [] };
285
+ group.files++;
286
+ group.findings.push(...locateSpans(file, base, byFile.get(file) ?? []));
287
+ groups.set(name, group);
288
+ }
289
+ const packages = [...groups]
290
+ .sort(([a], [b]) => a === own ? -1 : b === own ? 1 : a.localeCompare(b))
291
+ .map(([name, group]) => ({ name, files: group.files, findings: group.findings }));
292
+ return Result.success({ entry: relative(base, realpathSync(absolute)), files: files.length, packages });
293
+ };
294
+ const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
295
+ /** The text report: findings grouped by package, a summary line, and what to do next. */
296
+ export const format = (report) => {
297
+ const flagged = report.packages.filter((entry) => entry.findings.length > 0);
298
+ const total = flagged.reduce((sum, entry) => sum + entry.findings.length, 0);
299
+ const lines = [];
300
+ for (const entry of flagged) {
301
+ lines.push(`${entry.name} (${plural(entry.findings.length, "finding")})`);
302
+ for (const finding of entry.findings) {
303
+ lines.push(` ${finding.file}:${finding.line}:${finding.column} ${finding.rule} ${finding.snippet}`);
304
+ }
305
+ lines.push("");
306
+ }
307
+ lines.push(`scanned ${plural(report.files, "file")} in ${plural(report.packages.length, "package")} imported by ${report.entry}: ${plural(total, "finding")} in ${plural(flagged.length, "package")}`);
308
+ lines.push(total > 0
309
+ ? "These are hints: code the simulation never calls is fine. For a dependency the simulation calls, vendor it into your source and run `oxlint --fix` with these rules on, or replace it; then confirm with Verify.acrossEngines (`ritmo-devtools verify`) or Netcode.syncTest."
310
+ : "No dependency uses the Math functions, clock, or randomness these rules flag; confirm the whole run with Verify.acrossEngines (`ritmo-devtools verify`) or Netcode.syncTest.");
311
+ return lines.join("\n");
312
+ };
313
+ //# sourceMappingURL=dependencyScan.js.map