@reventlessdev/reventless-gwt 1.0.0-alpha.114 → 1.0.0-alpha.116

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 (88) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +5 -12
  3. package/rescript.json +0 -1
  4. package/src/JestBind.res +21 -22
  5. package/src/JestBind.res.mjs +15 -11
  6. package/src/RunnerHook.res +38 -0
  7. package/src/RunnerHook.res.mjs +26 -0
  8. package/bin/reventless-dev.mjs +0 -21
  9. package/src/Bind.res +0 -29
  10. package/src/Bind.res.mjs +0 -22
  11. package/src/BuildClassifier.res +0 -147
  12. package/src/BuildClassifier.res.mjs +0 -136
  13. package/src/Cancellation.res +0 -37
  14. package/src/Cancellation.res.mjs +0 -46
  15. package/src/ChildProcess.res +0 -102
  16. package/src/ChildProcess.res.mjs +0 -107
  17. package/src/Cli.res +0 -905
  18. package/src/Cli.res.mjs +0 -952
  19. package/src/Collector.res +0 -212
  20. package/src/Collector.res.mjs +0 -218
  21. package/src/ComponentMeta.res +0 -77
  22. package/src/ComponentMeta.res.mjs +0 -91
  23. package/src/ComponentScan.res +0 -103
  24. package/src/ComponentScan.res.mjs +0 -105
  25. package/src/Discovery.res +0 -105
  26. package/src/Discovery.res.mjs +0 -99
  27. package/src/DomainDeadCode.res +0 -98
  28. package/src/DomainDeadCode.res.mjs +0 -72
  29. package/src/DomainGraph.res +0 -0
  30. package/src/DomainGraph.res.mjs +0 -0
  31. package/src/Filter.res +0 -45
  32. package/src/Filter.res.mjs +0 -47
  33. package/src/FormatterHuman.res +0 -109
  34. package/src/FormatterHuman.res.mjs +0 -115
  35. package/src/FormatterJson.res +0 -264
  36. package/src/FormatterJson.res.mjs +0 -322
  37. package/src/FormatterJunit.res +0 -93
  38. package/src/FormatterJunit.res.mjs +0 -90
  39. package/src/FormatterTap.res +0 -100
  40. package/src/FormatterTap.res.mjs +0 -131
  41. package/src/FormatterVsCode.res +0 -352
  42. package/src/FormatterVsCode.res.mjs +0 -546
  43. package/src/Loader.res +0 -24
  44. package/src/Loader.res.mjs +0 -23
  45. package/src/PackageScan.res +0 -80
  46. package/src/PackageScan.res.mjs +0 -81
  47. package/src/PlatformRunner.res +0 -191
  48. package/src/PlatformRunner.res.mjs +0 -178
  49. package/src/PlatformScan.res +0 -142
  50. package/src/PlatformScan.res.mjs +0 -132
  51. package/src/ProcessManager.res +0 -135
  52. package/src/ProcessManager.res.mjs +0 -119
  53. package/src/RunWorker.res +0 -24
  54. package/src/RunWorker.res.mjs +0 -16
  55. package/src/RunnerTypes.res +0 -68
  56. package/src/RunnerTypes.res.mjs +0 -60
  57. package/src/Watch.res +0 -108
  58. package/src/Watch.res.mjs +0 -85
  59. package/src/WatcherProbe.res +0 -56
  60. package/src/WatcherProbe.res.mjs +0 -59
  61. package/src/Worker.res +0 -24
  62. package/src/Worker.res.mjs +0 -9
  63. package/tests/BuildClassifierTest.res +0 -133
  64. package/tests/BuildClassifierTest.res.mjs +0 -176
  65. package/tests/CliRunEntryTest.res +0 -57
  66. package/tests/CliRunEntryTest.res.mjs +0 -65
  67. package/tests/CliWatchScopeTest.res +0 -62
  68. package/tests/CliWatchScopeTest.res.mjs +0 -95
  69. package/tests/ComponentMetaTest.res +0 -67
  70. package/tests/ComponentMetaTest.res.mjs +0 -71
  71. package/tests/DiscoveryTest.res +0 -42
  72. package/tests/DiscoveryTest.res.mjs +0 -43
  73. package/tests/DomainDeadCodeTest.res +0 -119
  74. package/tests/DomainDeadCodeTest.res.mjs +0 -158
  75. package/tests/DomainGraphTest.res +0 -448
  76. package/tests/DomainGraphTest.res.mjs +0 -505
  77. package/tests/FormatterGoldenTest.res +0 -125
  78. package/tests/FormatterGoldenTest.res.mjs +0 -162
  79. package/tests/FormatterVsCodeMessageTest.res +0 -41
  80. package/tests/FormatterVsCodeMessageTest.res.mjs +0 -42
  81. package/tests/PlatformRunnerTest.res +0 -66
  82. package/tests/PlatformRunnerTest.res.mjs +0 -85
  83. package/tests/PlatformScanTest.res +0 -61
  84. package/tests/PlatformScanTest.res.mjs +0 -56
  85. package/tests/RunnerUnitTest.res +0 -219
  86. package/tests/RunnerUnitTest.res.mjs +0 -244
  87. package/tests/WatchDebounceTest.res +0 -106
  88. package/tests/WatchDebounceTest.res.mjs +0 -128
@@ -1,546 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Nodefs from "node:fs";
4
- import * as Nodepath from "node:path";
5
- import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
- import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
7
- import * as Hint$ReventlessGwt from "./Hint.res.mjs";
8
- import * as Outcome$ReventlessGwt from "./Outcome.res.mjs";
9
- import * as ComponentMeta$ReventlessGwt from "./ComponentMeta.res.mjs";
10
- import * as RenderRescript$ReventlessGwt from "./RenderRescript.res.mjs";
11
- import * as Protocol$ReventlessDomainProtocol from "@reventlessdev/reventless-domain-protocol/src/Protocol.res.mjs";
12
-
13
- function write(s) {
14
- process.stdout.write(s);
15
- }
16
-
17
- function writeLine(s) {
18
- process.stdout.write(s + "\n");
19
- }
20
-
21
- function emit(e) {
22
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
23
- process.stdout.write(s + "\n");
24
- }
25
-
26
- function uriOf(path) {
27
- return "file://" + path;
28
- }
29
-
30
- function fileLabelOf(abs) {
31
- let base = Nodepath.basename(abs);
32
- if (base.endsWith(".res.mjs")) {
33
- return base.slice(0, base.length - 8 | 0);
34
- } else {
35
- return base;
36
- }
37
- }
38
-
39
- function relativeToCwd(abs) {
40
- return Nodepath.relative(process.cwd(), abs);
41
- }
42
-
43
- let sourceLineCache = {};
44
-
45
- function mjsToRes(mjsPath) {
46
- if (mjsPath.endsWith(".res.mjs")) {
47
- return mjsPath.slice(0, mjsPath.length - 4 | 0);
48
- }
49
- }
50
-
51
- function readLinesCached(resPath) {
52
- let v = sourceLineCache[resPath];
53
- if (v !== undefined) {
54
- return Primitive_option.valFromOption(v);
55
- }
56
- let v$1;
57
- try {
58
- v$1 = Nodefs.existsSync(resPath) ? Nodefs.readFileSync(resPath, "utf8").split("\n") : undefined;
59
- } catch (exn) {
60
- v$1 = undefined;
61
- }
62
- sourceLineCache[resPath] = v$1;
63
- return v$1;
64
- }
65
-
66
- function escapeForDouble(s) {
67
- return s.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
68
- }
69
-
70
- function escapeForSingle(s) {
71
- return s.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
72
- }
73
-
74
- function locateInSource(mjsPath, label) {
75
- let resPath = mjsToRes(mjsPath);
76
- if (resPath === undefined) {
77
- return;
78
- }
79
- let lines = readLinesCached(resPath);
80
- if (lines === undefined) {
81
- return;
82
- }
83
- let needleD = "\"" + escapeForDouble(label) + "\"";
84
- let needleS = "'" + escapeForSingle(label) + "'";
85
- let total = lines.length;
86
- let _i = 0;
87
- while (true) {
88
- let i = _i;
89
- if (i >= total) {
90
- return;
91
- }
92
- let line = lines[i];
93
- let idxD = line.indexOf(needleD);
94
- let idxS = line.indexOf(needleS);
95
- let col = idxD !== -1 ? (
96
- idxS !== -1 ? (
97
- idxD < idxS ? idxD : idxS
98
- ) + 1 | 0 : idxD + 1 | 0
99
- ) : (
100
- idxS !== -1 ? idxS + 1 | 0 : -1
101
- );
102
- if (col >= 0) {
103
- return {
104
- file: resPath,
105
- line: i + 1 | 0,
106
- column: col
107
- };
108
- }
109
- _i = i + 1 | 0;
110
- continue;
111
- };
112
- }
113
-
114
- function rangeOf(loc) {
115
- let pos_line = loc.line - 1 | 0;
116
- let pos_character = loc.column - 1 | 0;
117
- let pos = {
118
- line: pos_line,
119
- character: pos_character
120
- };
121
- return {
122
- start: pos,
123
- end: pos
124
- };
125
- }
126
-
127
- function locationOf(loc) {
128
- return {
129
- uri: "file://" + loc.file,
130
- range: rangeOf(loc)
131
- };
132
- }
133
-
134
- function hello() {
135
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
136
- event: "hello",
137
- protocol: Protocol$ReventlessDomainProtocol.protocolVersion
138
- });
139
- process.stdout.write(s + "\n");
140
- }
141
-
142
- function discoverStart() {
143
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
144
- event: "discoverStart"
145
- });
146
- process.stdout.write(s + "\n");
147
- }
148
-
149
- function emitDiscoveryItems(files) {
150
- files.forEach(param => {
151
- let path = param[0];
152
- let resPath = mjsToRes(path);
153
- let fileUri = resPath !== undefined ? (
154
- Nodefs.existsSync(resPath) ? "file://" + resPath : "file://" + path
155
- ) : "file://" + path;
156
- let component = Stdlib_Option.map(ComponentMeta$ReventlessGwt.componentOfTestFile(path), c => ({
157
- kind: c.kind,
158
- name: c.name
159
- }));
160
- let e_3 = fileLabelOf(path);
161
- let e_4 = Nodepath.relative(process.cwd(), path);
162
- let e_5 = fileUri;
163
- let e = {
164
- event: "item",
165
- id: path,
166
- kind: "File",
167
- label: e_3,
168
- description: e_4,
169
- uri: e_5,
170
- component: component
171
- };
172
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
173
- process.stdout.write(s + "\n");
174
- let seenDescribes = {};
175
- param[1].forEach(t => {
176
- let stack = {
177
- contents: []
178
- };
179
- t.describePath.forEach(label => {
180
- let parent = stack.contents.length === 0 ? path : path + "::" + stack.contents.join("::");
181
- stack.contents = stack.contents.concat([label]);
182
- let id = path + "::" + stack.contents.join("::");
183
- let match = seenDescribes[id];
184
- if (match !== undefined) {
185
- return;
186
- }
187
- seenDescribes[id] = true;
188
- let loc = locateInSource(path, label);
189
- let e_1 = parent;
190
- let e_5 = Stdlib_Option.map(loc, l => "file://" + l.file);
191
- let e_6 = Stdlib_Option.map(loc, rangeOf);
192
- let e = {
193
- event: "item",
194
- id: id,
195
- parent: e_1,
196
- kind: "Suite",
197
- label: label,
198
- uri: e_5,
199
- range: e_6
200
- };
201
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
202
- process.stdout.write(s + "\n");
203
- });
204
- let parent = t.describePath.length === 0 ? path : path + "::" + t.describePath.join("::");
205
- let testId = path + "::" + t.id;
206
- let resLoc = locateInSource(path, t.name);
207
- let match = t.location;
208
- let loc = resLoc !== undefined ? resLoc : (
209
- match !== undefined ? match : undefined
210
- );
211
- let e_1 = parent;
212
- let e_3 = t.name;
213
- let e_5 = Stdlib_Option.map(loc, l => "file://" + l.file);
214
- let e_6 = Stdlib_Option.map(loc, rangeOf);
215
- let e = {
216
- event: "item",
217
- id: testId,
218
- parent: e_1,
219
- kind: "Test",
220
- label: e_3,
221
- uri: e_5,
222
- range: e_6
223
- };
224
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
225
- process.stdout.write(s + "\n");
226
- });
227
- });
228
- }
229
-
230
- function discoverEnd(total) {
231
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
232
- event: "discoverEnd",
233
- total: total
234
- });
235
- process.stdout.write(s + "\n");
236
- }
237
-
238
- function packages(pkgs) {
239
- let e = {
240
- event: "packages",
241
- packages: pkgs.map(p => ({
242
- name: p.name,
243
- dir: p.dir,
244
- build: p.build
245
- }))
246
- };
247
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
248
- process.stdout.write(s + "\n");
249
- }
250
-
251
- function components(comps) {
252
- let e = {
253
- event: "components",
254
- components: comps.map(c => ({
255
- kind: c.kind,
256
- name: c.name,
257
- dir: c.dir,
258
- files: c.files
259
- }))
260
- };
261
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
262
- process.stdout.write(s + "\n");
263
- }
264
-
265
- function deadCode(findings) {
266
- let e = {
267
- event: "deadCode",
268
- findings: findings.map(f => ({
269
- kind: f.kind,
270
- plugin: f.pluginName,
271
- component: f.componentName,
272
- detail: f.detail
273
- }))
274
- };
275
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
276
- process.stdout.write(s + "\n");
277
- }
278
-
279
- function graph(g) {
280
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
281
- event: "graph",
282
- nodes: g.nodes,
283
- edges: g.edges
284
- });
285
- process.stdout.write(s + "\n");
286
- }
287
-
288
- function definitions(entries) {
289
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
290
- event: "definitions",
291
- entries: entries
292
- });
293
- process.stdout.write(s + "\n");
294
- }
295
-
296
- function buildStart(pkg) {
297
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
298
- event: "buildStart",
299
- package: pkg
300
- });
301
- process.stdout.write(s + "\n");
302
- }
303
-
304
- function buildOk(pkg, durationMs) {
305
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
306
- event: "buildOk",
307
- package: pkg,
308
- durationMs: durationMs
309
- });
310
- process.stdout.write(s + "\n");
311
- }
312
-
313
- function buildFail(pkg, message) {
314
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
315
- event: "buildFail",
316
- package: pkg,
317
- message: message
318
- });
319
- process.stdout.write(s + "\n");
320
- }
321
-
322
- function buildExternal(pkg) {
323
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
324
- event: "buildExternal",
325
- package: pkg
326
- });
327
- process.stdout.write(s + "\n");
328
- }
329
-
330
- function platformStart($$package, dir, domainPort, platformPort) {
331
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
332
- event: "platformStart",
333
- package: $$package,
334
- dir: dir,
335
- domainPort: domainPort,
336
- platformPort: platformPort
337
- });
338
- process.stdout.write(s + "\n");
339
- }
340
-
341
- function platformReady(domainEndpoint) {
342
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
343
- event: "platformReady",
344
- domainEndpoint: domainEndpoint
345
- });
346
- process.stdout.write(s + "\n");
347
- }
348
-
349
- function domainEvent(payload) {
350
- let s = JSON.stringify(payload);
351
- process.stdout.write(s + "\n");
352
- }
353
-
354
- function platformLog(line) {
355
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
356
- event: "platformLog",
357
- line: line
358
- });
359
- process.stdout.write(s + "\n");
360
- }
361
-
362
- function platformStop(code) {
363
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
364
- event: "platformStop",
365
- code: code
366
- });
367
- process.stdout.write(s + "\n");
368
- }
369
-
370
- function runStart(total, filter) {
371
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
372
- event: "runStart",
373
- total: total,
374
- filter: filter
375
- });
376
- process.stdout.write(s + "\n");
377
- }
378
-
379
- function testStart(id) {
380
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
381
- event: "testStart",
382
- id: id
383
- });
384
- process.stdout.write(s + "\n");
385
- }
386
-
387
- function testPass(id, durationMs) {
388
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
389
- event: "testPass",
390
- id: id,
391
- durationMs: durationMs
392
- });
393
- process.stdout.write(s + "\n");
394
- }
395
-
396
- function testSkip(id, reason) {
397
- let s = Protocol$ReventlessDomainProtocol.toJsonLine({
398
- event: "testSkip",
399
- id: id,
400
- reason: reason
401
- });
402
- process.stdout.write(s + "\n");
403
- }
404
-
405
- function messagePayload(t) {
406
- let m = t.mismatch;
407
- if (m === undefined) {
408
- return {
409
- message: "failed"
410
- };
411
- }
412
- let hint = Hint$ReventlessGwt.forMismatch(t.slice, m);
413
- let match;
414
- switch (m.TAG) {
415
- case "ErrorMismatch" :
416
- let actual = m.actual;
417
- let actStr = actual !== undefined ? "Error(" + RenderRescript$ReventlessGwt.render(undefined, actual) + ")" : "Ok(" + RenderRescript$ReventlessGwt.renderMany(m.actualEvents) + ")";
418
- match = [
419
- "Error(" + RenderRescript$ReventlessGwt.render(undefined, m.expected) + ")",
420
- actStr
421
- ];
422
- break;
423
- case "StateMismatch" :
424
- match = [
425
- RenderRescript$ReventlessGwt.renderOption(m.expected),
426
- RenderRescript$ReventlessGwt.renderOption(m.actual)
427
- ];
428
- break;
429
- case "NoEventExpected" :
430
- match = [
431
- "[]",
432
- RenderRescript$ReventlessGwt.renderMany(m.actual)
433
- ];
434
- break;
435
- case "TodoMismatch" :
436
- match = [
437
- Outcome$ReventlessGwt.format(m),
438
- ""
439
- ];
440
- break;
441
- case "AppendConditionMismatch" :
442
- match = [
443
- RenderRescript$ReventlessGwt.render(undefined, m.expected),
444
- RenderRescript$ReventlessGwt.render(undefined, m.actual)
445
- ];
446
- break;
447
- case "TranslateError" :
448
- match = [
449
- m.expected,
450
- Stdlib_Option.getOr(m.actual, "(none)")
451
- ];
452
- break;
453
- case "Throw" :
454
- match = [
455
- "",
456
- m.error
457
- ];
458
- break;
459
- default:
460
- match = [
461
- RenderRescript$ReventlessGwt.renderMany(m.expected),
462
- RenderRescript$ReventlessGwt.renderMany(m.actual)
463
- ];
464
- }
465
- let location = Stdlib_Option.map(t.location, loc => locationOf(Stdlib_Option.getOr(locateInSource(loc.file, t.name), loc)));
466
- return {
467
- message: hint.message,
468
- kind: Outcome$ReventlessGwt.kindName(m),
469
- expected: match[0],
470
- actual: match[1],
471
- location: location
472
- };
473
- }
474
-
475
- function testFail(t, id) {
476
- let e_1 = t.durationMs;
477
- let e_2 = [messagePayload(t)];
478
- let e = {
479
- event: "testFail",
480
- id: id,
481
- durationMs: e_1,
482
- messages: e_2
483
- };
484
- let s = Protocol$ReventlessDomainProtocol.toJsonLine(e);
485
- process.stdout.write(s + "\n");
486
- }
487
-
488
- function runEnd(s) {
489
- let s$1 = Protocol$ReventlessDomainProtocol.toJsonLine({
490
- event: "runEnd",
491
- passed: s.passed,
492
- failed: s.failed,
493
- skipped: s.skipped,
494
- durationMs: s.durationMs
495
- });
496
- process.stdout.write(s$1 + "\n");
497
- }
498
-
499
- let P;
500
-
501
- let protocolVersion = Protocol$ReventlessDomainProtocol.protocolVersion;
502
-
503
- export {
504
- P,
505
- write,
506
- writeLine,
507
- emit,
508
- uriOf,
509
- fileLabelOf,
510
- relativeToCwd,
511
- sourceLineCache,
512
- mjsToRes,
513
- readLinesCached,
514
- escapeForDouble,
515
- escapeForSingle,
516
- locateInSource,
517
- rangeOf,
518
- locationOf,
519
- protocolVersion,
520
- hello,
521
- discoverStart,
522
- emitDiscoveryItems,
523
- discoverEnd,
524
- packages,
525
- components,
526
- deadCode,
527
- graph,
528
- definitions,
529
- buildStart,
530
- buildOk,
531
- buildFail,
532
- buildExternal,
533
- platformStart,
534
- platformReady,
535
- domainEvent,
536
- platformLog,
537
- platformStop,
538
- runStart,
539
- testStart,
540
- testPass,
541
- testSkip,
542
- messagePayload,
543
- testFail,
544
- runEnd,
545
- }
546
- /* node:fs Not a pure module */
package/src/Loader.res DELETED
@@ -1,24 +0,0 @@
1
- // Dynamic-import wrapper. Each GWT test file registers describe/test at
2
- // import time, so the caller must `Collector.activate()` before invoking
3
- // `loadFile` and drain after. The loader converts the absolute path into
4
- // a `file://` URL so Node's ESM loader accepts it.
5
- //
6
- // A monotonic cache-busting query (`?t=N`) is appended so every load
7
- // re-executes the module's top-level registration. Node's ESM cache is keyed
8
- // by URL (not mtime), so without this a second load in the same process — the
9
- // `discover`-then-run within `watch`, and every re-run after a recompile —
10
- // would hit the cache, skip registration, and drain zero tests. The `?t=`
11
- // query is stripped from captured stack frames in `Collector.parseFrame`.
12
-
13
- @module("node:url") external pathToFileURL: string => {"href": string} = "pathToFileURL"
14
-
15
- let dynamicImport: string => promise<'a> = %raw(`(u) => import(u)`)
16
-
17
- let counter = ref(0)
18
-
19
- let loadFile = async (absolutePath: string): unit => {
20
- counter := counter.contents + 1
21
- let url = pathToFileURL(absolutePath)
22
- let busted = url["href"] ++ "?t=" ++ Int.toString(counter.contents)
23
- let _: 'a = await dynamicImport(busted)
24
- }
@@ -1,23 +0,0 @@
1
- // Generated by ReScript, PLEASE EDIT WITH CARE
2
-
3
- import * as Nodeurl from "node:url";
4
-
5
- let dynamicImport = ((u) => import(u));
6
-
7
- let counter = {
8
- contents: 0
9
- };
10
-
11
- async function loadFile(absolutePath) {
12
- counter.contents = counter.contents + 1 | 0;
13
- let url = Nodeurl.pathToFileURL(absolutePath);
14
- let busted = url.href + "?t=" + counter.contents.toString();
15
- await dynamicImport(busted);
16
- }
17
-
18
- export {
19
- dynamicImport,
20
- counter,
21
- loadFile,
22
- }
23
- /* node:url Not a pure module */
@@ -1,80 +0,0 @@
1
- // Derives the set of workspace packages that own GWT test files, so a watch
2
- // session knows which packages to keep compiling (`pnpm run start` →
3
- // `rescript build -w`). Given the absolute test-file paths from `Discovery`,
4
- // each is mapped to its nearest ancestor `package.json` that declares a
5
- // `start` script; results are deduplicated by directory.
6
- //
7
- // This is the input both the `packages` NDJSON event (FormatterVsCode) and the
8
- // watch-mode build manager (ProcessManager) consume — computed fresh per run so
9
- // it never drifts when a plugin is added or removed.
10
-
11
- type pkg = {
12
- // Package name from package.json (may be "" if absent).
13
- name: string,
14
- // Absolute directory containing the owning package.json.
15
- dir: string,
16
- // The `start` script's command (the ReScript watch command), informational.
17
- build: string,
18
- }
19
-
20
- @module("node:fs") external _existsSync: string => bool = "existsSync"
21
- @module("node:fs") external _readFileSync: (string, string) => string = "readFileSync"
22
- @module("node:path") external dirname: string => string = "dirname"
23
- @module("node:path") external join: (string, string) => string = "join"
24
-
25
- // Reads name + `start` command from a package.json, if it declares one.
26
- let readPackage = (pkgJsonPath: string): option<(string, string)> =>
27
- try {
28
- let json = JSON.parseOrThrow(_readFileSync(pkgJsonPath, "utf8"))
29
- switch json {
30
- | Object(obj) =>
31
- let name = switch obj->Dict.get("name") {
32
- | Some(String(n)) => n
33
- | _ => ""
34
- }
35
- switch obj->Dict.get("scripts") {
36
- | Some(Object(scripts)) =>
37
- switch scripts->Dict.get("start") {
38
- | Some(String(cmd)) => Some((name, cmd))
39
- | _ => None
40
- }
41
- | _ => None
42
- }
43
- | _ => None
44
- }
45
- } catch {
46
- | _ => None
47
- }
48
-
49
- // Walks up from `dir` to the nearest package.json declaring a `start` script.
50
- let rec findOwning = (dir: string): option<pkg> => {
51
- let pkgJson = join(dir, "package.json")
52
- let here = _existsSync(pkgJson) ? readPackage(pkgJson) : None
53
- switch here {
54
- | Some((name, build)) => Some({name, dir, build})
55
- | None => {
56
- let parent = dirname(dir)
57
- parent == dir ? None : findOwning(parent)
58
- }
59
- }
60
- }
61
-
62
- // Maps test files → deduplicated owning packages (declaration order preserved).
63
- let scan = (testFiles: array<string>): array<pkg> => {
64
- let seen = Dict.make()
65
- let out = []
66
- testFiles->Array.forEach(file =>
67
- switch findOwning(dirname(file)) {
68
- | Some(pkg) =>
69
- switch seen->Dict.get(pkg.dir) {
70
- | Some(_) => ()
71
- | None => {
72
- seen->Dict.set(pkg.dir, true)
73
- out->Array.push(pkg)
74
- }
75
- }
76
- | None => ()
77
- }
78
- )
79
- out
80
- }