@dcaldeira/tooling 0.0.0-stage → 0.2.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 (56) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +33 -2
  3. package/checks/a11y.mjs +206 -0
  4. package/checks/architecture.mjs +137 -0
  5. package/checks/audit.mjs +121 -0
  6. package/checks/bundle.mjs +126 -0
  7. package/checks/dependencies.mjs +277 -0
  8. package/checks/duplication.mjs +135 -0
  9. package/checks/lint-scss.mjs +363 -0
  10. package/checks/package.mjs +30 -0
  11. package/checks/playwright-summary.mjs +53 -0
  12. package/checks/sass.mjs +67 -0
  13. package/checks/scan-secrets.mjs +58 -0
  14. package/checks/shared.mjs +86 -0
  15. package/checks/style-property-order.json +498 -0
  16. package/checks/translations.mjs +55 -0
  17. package/checks/visual-compare.mjs +148 -0
  18. package/checks/visual-report-html.mjs +470 -0
  19. package/checks/visual-report.mjs +13 -0
  20. package/config.schema.json +977 -0
  21. package/configs/eslint.mjs +27 -0
  22. package/configs/knip.json +11 -0
  23. package/configs/playwright.mjs +15 -0
  24. package/configs/prettier.mjs +1 -0
  25. package/configs/tsconfig.json +16 -0
  26. package/configs/vitest.mjs +16 -0
  27. package/package.json +103 -4
  28. package/release/evidence.mjs +62 -0
  29. package/release/finalize.mjs +65 -0
  30. package/release/gh.mjs +25 -0
  31. package/release/github.mjs +64 -0
  32. package/release/prepare.mjs +30 -0
  33. package/runner/browsers.mjs +73 -0
  34. package/runner/cache.mjs +121 -0
  35. package/runner/ci-plan.mjs +54 -0
  36. package/runner/cli.mjs +251 -0
  37. package/runner/config.mjs +148 -0
  38. package/runner/docs-install.mjs +93 -0
  39. package/runner/execute.mjs +298 -0
  40. package/runner/generate.mjs +122 -0
  41. package/runner/git.mjs +122 -0
  42. package/runner/graph.mjs +250 -0
  43. package/runner/index.mjs +4 -0
  44. package/runner/insights.mjs +313 -0
  45. package/runner/provision.mjs +53 -0
  46. package/runner/repo-standard.mjs +104 -0
  47. package/runner/report.mjs +35 -0
  48. package/runner/serve-static.mjs +76 -0
  49. package/runner/setup.mjs +241 -0
  50. package/runner/summary.mjs +112 -0
  51. package/runner/watch.mjs +82 -0
  52. package/templates/ci.yml +25 -0
  53. package/templates/dependabot-merge.yml +13 -0
  54. package/templates/dependabot.yml +26 -0
  55. package/templates/pre-push +13 -0
  56. package/templates/release.yml +23 -0
@@ -0,0 +1,498 @@
1
+ [
2
+ "composes",
3
+ "all",
4
+ "position",
5
+ "inset",
6
+ "inset-block",
7
+ "inset-block-start",
8
+ "inset-block-end",
9
+ "inset-inline",
10
+ "inset-inline-start",
11
+ "inset-inline-end",
12
+ "top",
13
+ "right",
14
+ "bottom",
15
+ "left",
16
+ "z-index",
17
+ "float",
18
+ "clear",
19
+ "box-sizing",
20
+ "display",
21
+ "visibility",
22
+ "columns",
23
+ "column-width",
24
+ "column-count",
25
+ "column-height",
26
+ "column-wrap",
27
+ "column-span",
28
+ "column-fill",
29
+ "flex",
30
+ "flex-grow",
31
+ "flex-shrink",
32
+ "flex-basis",
33
+ "flex-flow",
34
+ "flex-direction",
35
+ "flex-wrap",
36
+ "-webkit-box-orient",
37
+ "grid",
38
+ "grid-area",
39
+ "grid-template",
40
+ "grid-template-areas",
41
+ "grid-template-rows",
42
+ "grid-template-columns",
43
+ "grid-row",
44
+ "grid-row-start",
45
+ "grid-row-end",
46
+ "grid-column",
47
+ "grid-column-start",
48
+ "grid-column-end",
49
+ "grid-auto-rows",
50
+ "grid-auto-columns",
51
+ "grid-auto-flow",
52
+ "grid-gap",
53
+ "grid-row-gap",
54
+ "grid-column-gap",
55
+ "gap",
56
+ "row-gap",
57
+ "column-gap",
58
+ "column-rule",
59
+ "column-rule-width",
60
+ "column-rule-style",
61
+ "column-rule-color",
62
+ "place-content",
63
+ "place-items",
64
+ "place-self",
65
+ "align-content",
66
+ "align-items",
67
+ "align-self",
68
+ "justify-content",
69
+ "justify-items",
70
+ "justify-self",
71
+ "order",
72
+ "inline-size",
73
+ "min-inline-size",
74
+ "max-inline-size",
75
+ "width",
76
+ "min-width",
77
+ "max-width",
78
+ "block-size",
79
+ "min-block-size",
80
+ "max-block-size",
81
+ "height",
82
+ "min-height",
83
+ "max-height",
84
+ "aspect-ratio",
85
+ "contain-intrinsic-inline-size",
86
+ "contain-intrinsic-block-size",
87
+ "contain-intrinsic-size",
88
+ "contain-intrinsic-width",
89
+ "contain-intrinsic-height",
90
+ "padding",
91
+ "padding-block",
92
+ "padding-block-start",
93
+ "padding-block-end",
94
+ "padding-inline",
95
+ "padding-inline-start",
96
+ "padding-inline-end",
97
+ "padding-top",
98
+ "padding-right",
99
+ "padding-bottom",
100
+ "padding-left",
101
+ "margin",
102
+ "margin-block",
103
+ "margin-block-start",
104
+ "margin-block-end",
105
+ "margin-inline",
106
+ "margin-inline-start",
107
+ "margin-inline-end",
108
+ "margin-top",
109
+ "margin-right",
110
+ "margin-bottom",
111
+ "margin-left",
112
+ "anchor-name",
113
+ "anchor-scope",
114
+ "position-area",
115
+ "position-anchor",
116
+ "position-try",
117
+ "position-try-order",
118
+ "position-try-fallbacks",
119
+ "position-visibility",
120
+ "contain",
121
+ "container",
122
+ "container-name",
123
+ "container-type",
124
+ "content-visibility",
125
+ "overflow",
126
+ "overflow-inline",
127
+ "overflow-block",
128
+ "overflow-x",
129
+ "overflow-y",
130
+ "scrollbar-gutter",
131
+ "-webkit-overflow-scrolling",
132
+ "-ms-overflow-x",
133
+ "-ms-overflow-y",
134
+ "-ms-overflow-style",
135
+ "text-overflow",
136
+ "-webkit-line-clamp",
137
+ "line-clamp",
138
+ "scroll-behavior",
139
+ "overscroll-behavior",
140
+ "overscroll-behavior-inline",
141
+ "overscroll-behavior-block",
142
+ "overscroll-behavior-x",
143
+ "overscroll-behavior-y",
144
+ "font",
145
+ "font-family",
146
+ "font-size",
147
+ "font-size-adjust",
148
+ "font-variation-settings",
149
+ "font-style",
150
+ "font-weight",
151
+ "font-optical-sizing",
152
+ "font-stretch",
153
+ "font-feature-settings",
154
+ "font-kerning",
155
+ "font-variant",
156
+ "font-variant-ligatures",
157
+ "font-variant-caps",
158
+ "font-variant-alternates",
159
+ "font-variant-numeric",
160
+ "font-variant-east-asian",
161
+ "font-variant-position",
162
+ "-webkit-font-smoothing",
163
+ "-moz-osx-font-smoothing",
164
+ "font-smooth",
165
+ "font-synthesis",
166
+ "font-synthesis-weight",
167
+ "font-synthesis-style",
168
+ "font-synthesis-small-caps",
169
+ "line-height",
170
+ "vertical-align",
171
+ "alignment-baseline",
172
+ "baseline-shift",
173
+ "dominant-baseline",
174
+ "base-palette",
175
+ "override-colors",
176
+ "font-palette",
177
+ "color",
178
+ "-webkit-text-fill-color",
179
+ "-webkit-text-stroke",
180
+ "-webkit-text-stroke-width",
181
+ "-webkit-text-stroke-color",
182
+ "text-align",
183
+ "text-align-last",
184
+ "text-justify",
185
+ "text-indent",
186
+ "text-transform",
187
+ "word-spacing",
188
+ "letter-spacing",
189
+ "hyphens",
190
+ "hyphenate-character",
191
+ "line-break",
192
+ "word-break",
193
+ "text-wrap",
194
+ "text-wrap-mode",
195
+ "text-wrap-style",
196
+ "word-wrap",
197
+ "overflow-wrap",
198
+ "tab-size",
199
+ "white-space",
200
+ "white-space-collapse",
201
+ "text-emphasis",
202
+ "text-emphasis-color",
203
+ "text-emphasis-style",
204
+ "text-emphasis-position",
205
+ "text-decoration",
206
+ "text-decoration-line",
207
+ "text-decoration-thickness",
208
+ "text-decoration-style",
209
+ "text-decoration-color",
210
+ "text-decoration-skip-ink",
211
+ "text-underline-position",
212
+ "text-underline-offset",
213
+ "text-shadow",
214
+ "ruby-position",
215
+ "ruby-align",
216
+ "src",
217
+ "font-display",
218
+ "unicode-range",
219
+ "size-adjust",
220
+ "ascent-override",
221
+ "descent-override",
222
+ "line-gap-override",
223
+ "appearance",
224
+ "accent-color",
225
+ "pointer-events",
226
+ "-ms-touch-action",
227
+ "touch-action",
228
+ "cursor",
229
+ "caret-color",
230
+ "zoom",
231
+ "resize",
232
+ "user-select",
233
+ "-webkit-user-select",
234
+ "nav-index",
235
+ "nav-up",
236
+ "nav-right",
237
+ "nav-down",
238
+ "nav-left",
239
+ "outline",
240
+ "outline-width",
241
+ "outline-style",
242
+ "outline-color",
243
+ "outline-offset",
244
+ "color-scheme",
245
+ "forced-color-adjust",
246
+ "print-color-adjust",
247
+ "table-layout",
248
+ "empty-cells",
249
+ "caption-side",
250
+ "border-spacing",
251
+ "border-collapse",
252
+ "content",
253
+ "quotes",
254
+ "list-style",
255
+ "list-style-position",
256
+ "list-style-type",
257
+ "list-style-image",
258
+ "counter-reset",
259
+ "counter-set",
260
+ "counter-increment",
261
+ "scroll-snap-type",
262
+ "scroll-snap-align",
263
+ "scroll-snap-stop",
264
+ "scroll-padding",
265
+ "scroll-padding-block",
266
+ "scroll-padding-block-start",
267
+ "scroll-padding-block-end",
268
+ "scroll-padding-inline",
269
+ "scroll-padding-inline-start",
270
+ "scroll-padding-inline-end",
271
+ "scroll-padding-top",
272
+ "scroll-padding-right",
273
+ "scroll-padding-bottom",
274
+ "scroll-padding-left",
275
+ "scroll-margin",
276
+ "scroll-margin-block",
277
+ "scroll-margin-block-start",
278
+ "scroll-margin-block-end",
279
+ "scroll-margin-inline",
280
+ "scroll-margin-inline-start",
281
+ "scroll-margin-inline-end",
282
+ "scroll-margin-top",
283
+ "scroll-margin-right",
284
+ "scroll-margin-bottom",
285
+ "scroll-margin-left",
286
+ "scrollbar-color",
287
+ "scrollbar-width",
288
+ "object-fit",
289
+ "object-position",
290
+ "-ms-interpolation-mode",
291
+ "image-orientation",
292
+ "image-rendering",
293
+ "image-resolution",
294
+ "background",
295
+ "background-color",
296
+ "background-image",
297
+ "-ms-filter:\\'progid:DXImageTransform.Microsoft.gradient",
298
+ "filter:progid:DXImageTransform.Microsoft.gradient",
299
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader",
300
+ "background-repeat",
301
+ "background-attachment",
302
+ "background-position",
303
+ "background-position-x",
304
+ "background-position-y",
305
+ "background-clip",
306
+ "background-origin",
307
+ "background-size",
308
+ "border",
309
+ "border-color",
310
+ "border-style",
311
+ "border-width",
312
+ "border-block",
313
+ "border-block-start",
314
+ "border-block-start-color",
315
+ "border-block-start-style",
316
+ "border-block-start-width",
317
+ "border-block-end",
318
+ "border-block-end-color",
319
+ "border-block-end-style",
320
+ "border-block-end-width",
321
+ "border-inline",
322
+ "border-inline-start",
323
+ "border-inline-start-color",
324
+ "border-inline-start-style",
325
+ "border-inline-start-width",
326
+ "border-inline-end",
327
+ "border-inline-end-color",
328
+ "border-inline-end-style",
329
+ "border-inline-end-width",
330
+ "border-top",
331
+ "border-top-color",
332
+ "border-top-style",
333
+ "border-top-width",
334
+ "border-right",
335
+ "border-right-color",
336
+ "border-right-style",
337
+ "border-right-width",
338
+ "border-bottom",
339
+ "border-bottom-color",
340
+ "border-bottom-style",
341
+ "border-bottom-width",
342
+ "border-left",
343
+ "border-left-color",
344
+ "border-left-style",
345
+ "border-left-width",
346
+ "corner",
347
+ "corner-block-start",
348
+ "corner-block-end",
349
+ "corner-inline-start",
350
+ "corner-inline-end",
351
+ "corner-start-start",
352
+ "corner-start-end",
353
+ "corner-end-start",
354
+ "corner-end-end",
355
+ "corner-top",
356
+ "corner-right",
357
+ "corner-bottom",
358
+ "corner-left",
359
+ "corner-top-left",
360
+ "corner-top-right",
361
+ "corner-bottom-right",
362
+ "corner-bottom-left",
363
+ "border-radius",
364
+ "border-start-start-radius",
365
+ "border-start-end-radius",
366
+ "border-end-start-radius",
367
+ "border-end-end-radius",
368
+ "border-top-left-radius",
369
+ "border-top-right-radius",
370
+ "border-bottom-right-radius",
371
+ "border-bottom-left-radius",
372
+ "corner-shape",
373
+ "corner-block-start-shape",
374
+ "corner-block-end-shape",
375
+ "corner-inline-start-shape",
376
+ "corner-inline-end-shape",
377
+ "corner-start-start-shape",
378
+ "corner-start-end-shape",
379
+ "corner-end-start-shape",
380
+ "corner-end-end-shape",
381
+ "corner-top-shape",
382
+ "corner-right-shape",
383
+ "corner-bottom-shape",
384
+ "corner-left-shape",
385
+ "corner-top-left-shape",
386
+ "corner-top-right-shape",
387
+ "corner-bottom-right-shape",
388
+ "corner-bottom-left-shape",
389
+ "border-image",
390
+ "border-image-source",
391
+ "border-image-slice",
392
+ "border-image-width",
393
+ "border-image-outset",
394
+ "border-image-repeat",
395
+ "box-shadow",
396
+ "background-blend-mode",
397
+ "isolation",
398
+ "mix-blend-mode",
399
+ "filter:progid:DXImageTransform.Microsoft.Alpha(Opacity",
400
+ "-ms-filter:\\'progid:DXImageTransform.Microsoft.Alpha",
401
+ "opacity",
402
+ "filter",
403
+ "backdrop-filter",
404
+ "clip",
405
+ "clip-path",
406
+ "clip-rule",
407
+ "mask-border",
408
+ "mask-border-source",
409
+ "mask-border-slice",
410
+ "mask-border-width",
411
+ "mask-border-outset",
412
+ "mask-border-repeat",
413
+ "mask-border-mode",
414
+ "mask",
415
+ "mask-image",
416
+ "mask-mode",
417
+ "mask-repeat",
418
+ "mask-position",
419
+ "mask-clip",
420
+ "mask-origin",
421
+ "mask-size",
422
+ "mask-composite",
423
+ "mask-type",
424
+ "shape-outside",
425
+ "shape-image-threshold",
426
+ "shape-margin",
427
+ "direction",
428
+ "unicode-bidi",
429
+ "writing-mode",
430
+ "text-orientation",
431
+ "text-combine-upright",
432
+ "text-anchor",
433
+ "fill",
434
+ "fill-rule",
435
+ "fill-opacity",
436
+ "stroke",
437
+ "stroke-opacity",
438
+ "stroke-width",
439
+ "stroke-linecap",
440
+ "stroke-linejoin",
441
+ "stroke-miterlimit",
442
+ "stroke-dasharray",
443
+ "stroke-dashoffset",
444
+ "color-interpolation",
445
+ "color-interpolation-filters",
446
+ "flood-color",
447
+ "flood-opacity",
448
+ "lighting-color",
449
+ "marker",
450
+ "marker-start",
451
+ "marker-mid",
452
+ "marker-end",
453
+ "stop-color",
454
+ "stop-opacity",
455
+ "paint-order",
456
+ "shape-rendering",
457
+ "text-rendering",
458
+ "transform",
459
+ "transform-origin",
460
+ "transform-box",
461
+ "transform-style",
462
+ "rotate",
463
+ "scale",
464
+ "translate",
465
+ "perspective",
466
+ "perspective-origin",
467
+ "backface-visibility",
468
+ "transition",
469
+ "transition-delay",
470
+ "transition-timing-function",
471
+ "transition-duration",
472
+ "transition-property",
473
+ "transition-behavior",
474
+ "view-transition-name",
475
+ "view-transition-class",
476
+ "animation",
477
+ "animation-name",
478
+ "animation-duration",
479
+ "animation-timing-function",
480
+ "animation-delay",
481
+ "animation-iteration-count",
482
+ "animation-direction",
483
+ "animation-fill-mode",
484
+ "animation-play-state",
485
+ "animation-composition",
486
+ "offset",
487
+ "offset-position",
488
+ "offset-path",
489
+ "offset-distance",
490
+ "offset-rotate",
491
+ "offset-anchor",
492
+ "will-change",
493
+ "break-before",
494
+ "break-after",
495
+ "break-inside",
496
+ "widows",
497
+ "orphans"
498
+ ]
@@ -0,0 +1,55 @@
1
+ import { readFileSync, readdirSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { loadConfig, inside } from '../runner/config.mjs';
5
+
6
+ export const flatten = (value, prefix = '') =>
7
+ Object.entries(value).flatMap(([key, child]) => {
8
+ const path = prefix ? `${prefix}.${key}` : key;
9
+ return child && typeof child === 'object' ? flatten(child, path) : [[path, child]];
10
+ });
11
+ const placeholders = (value) =>
12
+ [...String(value).matchAll(/\{\{\s*(-?\s*[\w.]+)(?:\s*,[^}]*)?\s*\}\}/g)]
13
+ .map((m) => m[1].trim())
14
+ .sort()
15
+ .join(',');
16
+
17
+ export function validateCatalogues(catalogues, source, { pluralExceptions = [] } = {}) {
18
+ const errors = [];
19
+ const base = new Map(flatten(catalogues[source]));
20
+ for (const [locale, catalogue] of Object.entries(catalogues)) {
21
+ const entries = new Map(flatten(catalogue));
22
+ for (const [key, value] of entries) {
23
+ if (typeof value !== 'string' || !value.trim())
24
+ errors.push(`${locale}: ${key} must be a non-empty string`);
25
+ if (!base.has(key)) errors.push(`${locale}: extra key ${key}`);
26
+ else if (placeholders(value) !== placeholders(base.get(key)))
27
+ errors.push(`${locale}: ${key} interpolation differs from ${source}`);
28
+ const plural = key.match(/^(.*)_(zero|one|two|few|many|other)$/);
29
+ if (plural && !pluralExceptions.includes(plural[1]) && !entries.has(`${plural[1]}_other`))
30
+ errors.push(`${locale}: ${plural[1]}_other is missing`);
31
+ }
32
+ for (const key of base.keys())
33
+ if (!entries.has(key)) errors.push(`${locale}: missing key ${key}`);
34
+ }
35
+ return errors;
36
+ }
37
+
38
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
39
+ const root = process.env.TOOLING_ROOT ?? process.cwd();
40
+ const { config } = loadConfig(root);
41
+ if (!config.translations?.directory || !config.translations?.source)
42
+ throw new Error('Configure translations.directory and translations.source');
43
+ const directory = inside(root, config.translations.directory);
44
+ const catalogues = Object.fromEntries(
45
+ readdirSync(directory)
46
+ .filter((name) => name.endsWith('.json'))
47
+ .map((name) => [name.slice(0, -5), JSON.parse(readFileSync(join(directory, name), 'utf8'))]),
48
+ );
49
+ if (!catalogues[config.translations.source]) throw new Error('Authoritative catalogue not found');
50
+ const errors = validateCatalogues(catalogues, config.translations.source, config.translations);
51
+ if (errors.length) {
52
+ console.error(errors.join('\n'));
53
+ process.exitCode = 1;
54
+ } else console.log(`Translation parity passed (${Object.keys(catalogues).length} catalogues)`);
55
+ }
@@ -0,0 +1,148 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ readFileSync,
6
+ readdirSync,
7
+ rmSync,
8
+ writeFileSync,
9
+ } from 'node:fs';
10
+ import { basename, dirname, isAbsolute, join, relative } from 'node:path';
11
+
12
+ import { buildHtml } from './visual-report-html.mjs';
13
+ import { inside } from '../runner/config.mjs';
14
+
15
+ const [baseRef, outDir = 'visual-diff', snapshotDir, resultsDir = 'test-results'] = process.argv.slice(2);
16
+
17
+ if (!baseRef || !snapshotDir || process.argv.length > 6) {
18
+ process.stderr.write('Usage: visual-compare.mjs <baseRef> <outDir> <snapshotDir> [resultsDir]\n');
19
+ process.exit(1);
20
+ }
21
+
22
+ const root = process.cwd();
23
+ const output = inside(root, outDir);
24
+ const snapshots = inside(root, snapshotDir);
25
+ const results = inside(root, resultsDir);
26
+ const overlaps = (a, b) => {
27
+ const rel = relative(a, b).replaceAll(String.fromCharCode(92), '/');
28
+ return rel === '' || (rel !== '..' && !rel.startsWith('../') && !isAbsolute(rel));
29
+ };
30
+ if (output === root || overlaps(output, snapshots) || overlaps(snapshots, output) ||
31
+ overlaps(output, results) || overlaps(results, output))
32
+ throw new Error('Report output must be separate from source snapshots and test results');
33
+
34
+ const git = (...args) =>
35
+ execFileSync('git', args, { maxBuffer: 256 * 1024 * 1024 });
36
+
37
+ // Paths relative to the snapshot directory, e.g. `desktop/blocks-table--default--light.png`.
38
+ const listBase = () =>
39
+ git('ls-tree', '-r', '--name-only', baseRef, '--', `./${snapshotDir}`)
40
+ .toString()
41
+ .split('\n')
42
+ .map((file) => file.trim())
43
+ .filter((file) => file.endsWith('.png'))
44
+ .map((file) =>
45
+ file.slice(file.indexOf(snapshotDir) + snapshotDir.length + 1)
46
+ );
47
+
48
+ const listHead = (dir = '') => {
49
+ const root = join(snapshotDir, dir);
50
+ if (!existsSync(root)) return [];
51
+ return readdirSync(root, { withFileTypes: true }).flatMap((entry) => {
52
+ const path = dir ? `${dir}/${entry.name}` : entry.name;
53
+ if (entry.isDirectory()) return listHead(path);
54
+ return entry.name.endsWith('.png') ? [path] : [];
55
+ });
56
+ };
57
+
58
+ const baseFiles = new Set(listBase());
59
+ const headFiles = new Set(listHead());
60
+
61
+ const readBase = (file) => git('show', `${baseRef}:./${snapshotDir}/${file}`);
62
+ const readHead = (file) => readFileSync(join(snapshotDir, file));
63
+
64
+ const changes = [];
65
+
66
+ for (const file of [...new Set([...baseFiles, ...headFiles])].sort()) {
67
+ const inBase = baseFiles.has(file);
68
+ const inHead = headFiles.has(file);
69
+
70
+ if (inBase && inHead) {
71
+ if (!readBase(file).equals(readHead(file)))
72
+ changes.push({ file, status: 'changed' });
73
+ } else {
74
+ changes.push({ file, status: inHead ? 'added' : 'removed' });
75
+ }
76
+ }
77
+
78
+ // Failing tests leave `<test folder>-<project>/<name>-actual.png` next to the baseline they missed.
79
+ const listFailures = (dir = resultsDir) => {
80
+ if (!existsSync(dir)) return [];
81
+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
82
+ const path = join(dir, entry.name);
83
+ if (entry.isDirectory()) return listFailures(path);
84
+ return entry.name.endsWith('-actual.png') ? [path] : [];
85
+ });
86
+ };
87
+
88
+ const known = new Set(changes.map(({ file }) => file));
89
+ const projects = [...new Set([...headFiles].map((file) => file.split('/')[0]))]
90
+ .sort((a, b) => b.length - a.length);
91
+
92
+ for (const actual of listFailures()) {
93
+ const folder = basename(dirname(actual));
94
+ const project = projects.find((name) => folder.endsWith('-' + name));
95
+ if (!project) continue;
96
+ const file = `${project}/${basename(actual).replace(/-actual\.png$/, '.png')}`;
97
+ if (known.has(file) || !headFiles.has(file)) continue;
98
+ changes.push({ file, status: 'changed', failure: actual });
99
+ }
100
+
101
+ rmSync(outDir, { recursive: true, force: true });
102
+
103
+ if (changes.length === 0) {
104
+ process.stdout.write('No visual snapshot changes.\n');
105
+ process.exit(0);
106
+ }
107
+
108
+ const counts = { added: 0, changed: 0, removed: 0 };
109
+ for (const { status } of changes) counts[status] += 1;
110
+
111
+ mkdirSync(outDir, { recursive: true });
112
+
113
+ // A failing test compares the committed baseline with the image the test produced.
114
+ const beforeOf = ({ file, status, failure }) => {
115
+ if (failure) return readHead(file);
116
+ return status === 'added' ? null : readBase(file);
117
+ };
118
+
119
+ const afterOf = ({ file, status, failure }) => {
120
+ if (failure) return readFileSync(failure);
121
+ return status === 'removed' ? null : readHead(file);
122
+ };
123
+
124
+ const entries = changes.map((change) => ({
125
+ file: change.file,
126
+ status: change.status,
127
+ failure: Boolean(change.failure),
128
+ before: beforeOf(change),
129
+ after: afterOf(change),
130
+ }));
131
+ writeFileSync(
132
+ join(outDir, 'index.html'),
133
+ buildHtml({ entries, counts, baseRef })
134
+ );
135
+
136
+ const summary = `${counts.added} new (no previous snapshot), ${counts.changed} changed, ${counts.removed} removed.`;
137
+
138
+ // Short PR comment: counts only. Images live in the interactive report, not in the comment.
139
+ writeFileSync(
140
+ join(outDir, 'comment.md'),
141
+ ['<!-- visual-snapshots -->', '## Visual snapshots', '', summary, ''].join(
142
+ '\n'
143
+ )
144
+ );
145
+
146
+ process.stdout.write(
147
+ `${counts.added} new, ${counts.changed} changed, ${counts.removed} removed. Report: ${join(outDir, 'index.html')}\n`
148
+ );