@ngbracket/a11y-devtools 0.14.1 → 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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
3
3
  All notable changes to `@ngbracket/a11y-devtools` are documented here.
4
4
  This project adheres to [Semantic Versioning](https://semver.org/).
5
5
 
6
+ ## 0.15.0
7
+
8
+ ### Added
9
+
10
+ - **Re-render a saved report without scanning.** `--from <report.json>` reads
11
+ a previous run's JSON report (from `--out`) and writes it in whatever
12
+ `--format`s you ask for, so you can add an HTML report or an ACR worksheet
13
+ later without running the scan again. `--baseline` and `--fail-on` work as
14
+ usual; scan options such as `--route` or `--keyboard` are refused. The
15
+ output is byte-for-byte what the original scan would have written. For the
16
+ ACR worksheet, it notes when the report's axe-core version differs from the
17
+ installed one, or when the report predates `checks` (0.14.0).
18
+ From code: `parseReport()`, plus `axeVersion()` for the installed axe-core.
19
+
20
+ ### Changed
21
+
22
+ - Type-checking: the specs are now type-checked in CI, and the browser source
23
+ compiles without Node types (report mode has its own tsconfig). No change to
24
+ the published output.
25
+
6
26
  ## 0.14.1
7
27
 
8
28
  ### Fixed
package/README.md CHANGED
@@ -67,7 +67,8 @@ npx ngbr-a11y-report --serve "npx ng serve" --route / --route /settings \
67
67
  ```
68
68
 
69
69
  Preparing a VPAT/ACR? `--format acr` adds an evaluation worksheet: the results by WCAG 2.2
70
- A/AA criterion, with the conformance columns left for a person to fill in.
70
+ A/AA criterion, with the conformance columns left for a person to fill in. Already scanned?
71
+ `--from a11y.json --out a11y --format acr` writes it from the saved JSON report.
71
72
 
72
73
  Next steps, in the docs:
73
74
  [Your first scan](https://ngbracket.com/tools/a11y-devtools/docs/first-scan) ·
@@ -135,3 +136,4 @@ ever becomes reachable through a static import.
135
136
  - Real-browser E2E tests, including component attribution in a real Angular app.
136
137
  - Report mode can start the dev server (`--serve`).
137
138
  - ACR evaluation worksheet by WCAG 2.2 A/AA criterion (`--format acr`).
139
+ - Re-render a saved JSON report in any format without scanning (`--from`).
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync, writeFileSync } from 'node:fs';
3
3
  import {
4
+ axeVersion,
4
5
  diffAgainstBaseline,
5
6
  parseBaseline,
7
+ parseReport,
6
8
  scanPages,
7
9
  startDevServer,
8
10
  toAcrHtml,
@@ -17,6 +19,7 @@ const USAGE = `ngbr-a11y-report — component-attributed a11y scan of a running
17
19
  Usage:
18
20
  ngbr-a11y-report --base <url> --route <path> [--route <path> ...] [options]
19
21
  ngbr-a11y-report --serve "<command>" --route <path> [...] [options]
22
+ ngbr-a11y-report --from <report.json> [--out <prefix>] [--format <list>] [--baseline <file>] [--fail-on <impact>]
20
23
 
21
24
  Options:
22
25
  --base <url> Origin of the running dev server (e.g. http://localhost:4200).
@@ -27,6 +30,10 @@ Options:
27
30
  --serve-timeout <s>
28
31
  Seconds to wait for --serve to answer (default 180)
29
32
  --route <path> Route to scan; repeat for multiple routes
33
+ --from <file> Don't scan: read a previous run's JSON report (from --out)
34
+ and write it in the --format(s) asked for — e.g. add an
35
+ HTML report or ACR worksheet later. --baseline and
36
+ --fail-on work as usual; the scan options don't apply
30
37
  --tags <list> Comma-separated axe tags to scope the ruleset (e.g. wcag22aa,best-practice)
31
38
  --out <prefix> Write <prefix>.md / .json / .html (default: print Markdown to stdout)
32
39
  --format <list> Comma-separated: md, json, html — or both (= md,json) or all
@@ -79,6 +86,7 @@ function parseArgs(argv) {
79
86
  case '--serve': opts.serve = next(); break;
80
87
  case '--serve-timeout': opts.serveTimeout = Number(next()); break;
81
88
  case '--route': opts.routes.push(next()); break;
89
+ case '--from': opts.from = next(); break;
82
90
  case '--tags': opts.tags = next().split(',').map((s) => s.trim()).filter(Boolean); break;
83
91
  case '--out': opts.out = next(); break;
84
92
  case '--format': opts.format = next(); break;
@@ -105,7 +113,25 @@ function parseArgs(argv) {
105
113
  const opts = parseArgs(process.argv.slice(2));
106
114
  if (opts.serve && !opts.base) opts.base = 'http://localhost:4200';
107
115
 
108
- if (opts.help || !opts.base || opts.routes.length === 0) {
116
+ // Options that only mean something when scanning — refused with --from, rather
117
+ // than silently ignored.
118
+ const SCAN_ONLY = {
119
+ base: '--base', serve: '--serve', serveTimeout: '--serve-timeout', routes: '--route', tags: '--tags',
120
+ wait: '--wait', frameworkPrefixes: '--framework-prefixes / --no-skip-primitives', keyboard: '--keyboard',
121
+ focusTraps: '--focus-traps', colorScheme: '--color-scheme', darkClass: '--dark-class',
122
+ darkAttribute: '--dark-attribute', headed: '--headed',
123
+ };
124
+ if (opts.from && !opts.help) {
125
+ const clash = Object.keys(SCAN_ONLY).filter((k) => (k === 'routes' ? opts.routes.length > 0 : opts[k] !== undefined));
126
+ if (clash.length > 0) {
127
+ process.stderr.write(
128
+ `--from re-renders a saved report without scanning, so ${clash.map((k) => SCAN_ONLY[k]).join(', ')} can't be used with it.\n`,
129
+ );
130
+ process.exit(2);
131
+ }
132
+ }
133
+
134
+ if (opts.help || (!opts.from && (!opts.base || opts.routes.length === 0))) {
109
135
  process.stderr.write(USAGE);
110
136
  process.exit(opts.help ? 0 : 1);
111
137
  }
@@ -146,6 +172,29 @@ if (opts.darkAttribute) {
146
172
  darkAttribute = { name: opts.darkAttribute.slice(0, eq), value: opts.darkAttribute.slice(eq + 1) };
147
173
  }
148
174
 
175
+ let saved;
176
+ if (opts.from) {
177
+ try {
178
+ saved = parseReport(readFileSync(opts.from, 'utf8'));
179
+ } catch (err) {
180
+ process.stderr.write(`Can't use --from ${opts.from}: ${err.message}\n`);
181
+ process.exit(2);
182
+ }
183
+ if (formats.has('acr') || formats.has('acr-md')) {
184
+ // The worksheet lists which rules checked each criterion from the installed
185
+ // axe-core, so say when that isn't the version the scan ran.
186
+ if (!saved.checks) {
187
+ process.stderr.write(
188
+ `Note: ${opts.from} doesn't record what was checked (reports from before 0.14.0 don't), so the worksheet counts a rule as run only where it found something.\n`,
189
+ );
190
+ } else if (saved.checks.axeVersion !== axeVersion()) {
191
+ process.stderr.write(
192
+ `Note: the scan ran axe-core ${saved.checks.axeVersion}; the worksheet's rule lists come from the installed axe-core ${axeVersion()}.\n`,
193
+ );
194
+ }
195
+ }
196
+ }
197
+
149
198
  // Read the baseline before the (slow) scan, so a bad path fails fast.
150
199
  let baseline;
151
200
  if (opts.baseline) {
@@ -182,31 +231,35 @@ if (opts.serve) {
182
231
  );
183
232
  }
184
233
 
185
- let report;
186
- try {
187
- report = await scanPages({
188
- baseUrl: opts.base,
189
- routes: opts.routes,
190
- tags: opts.tags,
191
- waitMs: opts.wait,
192
- headed: opts.headed,
193
- frameworkPrefixes: opts.frameworkPrefixes,
194
- keyboard: opts.keyboard,
195
- focusTraps: opts.focusTraps,
196
- colorScheme: opts.colorScheme,
197
- darkClass: opts.darkClass,
198
- darkAttribute,
199
- });
200
- } finally {
201
- if (server && !server.reused) {
202
- await server.stop();
203
- process.stderr.write('Stopped the dev server.\n');
234
+ let report = saved;
235
+ if (!report) {
236
+ try {
237
+ report = await scanPages({
238
+ baseUrl: opts.base,
239
+ routes: opts.routes,
240
+ tags: opts.tags,
241
+ waitMs: opts.wait,
242
+ headed: opts.headed,
243
+ frameworkPrefixes: opts.frameworkPrefixes,
244
+ keyboard: opts.keyboard,
245
+ focusTraps: opts.focusTraps,
246
+ colorScheme: opts.colorScheme,
247
+ darkClass: opts.darkClass,
248
+ darkAttribute,
249
+ });
250
+ } finally {
251
+ if (server && !server.reused) {
252
+ await server.stop();
253
+ process.stderr.write('Stopped the dev server.\n');
254
+ }
204
255
  }
205
256
  }
206
257
 
207
258
  const allFindings = report.pages.flatMap((p) => p.findings);
208
259
  process.stderr.write(
209
- `Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
260
+ saved
261
+ ? `Read ${report.pages.length} route(s) · ${allFindings.length} node-instance(s) from ${opts.from} (scanned ${report.generatedAt}).\n`
262
+ : `Scanned ${report.pages.length} route(s) · ${allFindings.length} node-instance(s).\n`,
210
263
  );
211
264
  const diff = baseline ? diffAgainstBaseline(report, baseline) : undefined;
212
265
  if (diff) {
@@ -76,6 +76,13 @@ export declare function impactRank(impact: Impact): number;
76
76
  * output stays a valid baseline for the next run.
77
77
  */
78
78
  export declare function toJson(report: ScanReport, diff?: BaselineDiff): string;
79
+ /**
80
+ * Read a report back from its JSON text (a `toJson` report), so it can be
81
+ * rendered in another format without scanning again. The derived fields
82
+ * (`summary`, per-page counts, `scope`, `baseline`) are dropped — every format
83
+ * recomputes them. Throws a readable error for anything that isn't a report.
84
+ */
85
+ export declare function parseReport(json: string): ScanReport;
79
86
  /** UI primitives and directives a finding came through, for a "via …" note. */
80
87
  export declare function viaNames(finding: A11yFinding): string[];
81
88
  /** Findings sorted most severe first (stable within an impact level). */
@@ -86,6 +86,40 @@ export function toJson(report, diff) {
86
86
  })),
87
87
  }, null, 2);
88
88
  }
89
+ /**
90
+ * Read a report back from its JSON text (a `toJson` report), so it can be
91
+ * rendered in another format without scanning again. The derived fields
92
+ * (`summary`, per-page counts, `scope`, `baseline`) are dropped — every format
93
+ * recomputes them. Throws a readable error for anything that isn't a report.
94
+ */
95
+ export function parseReport(json) {
96
+ let data;
97
+ try {
98
+ data = JSON.parse(json);
99
+ }
100
+ catch {
101
+ throw new Error('not valid JSON — pass a report written by `--out` (the .json file).');
102
+ }
103
+ const { generatedAt, checks, pages } = (data ?? {});
104
+ const isPage = (p) => typeof p?.label === 'string' &&
105
+ typeof p.url === 'string' &&
106
+ Array.isArray(p.findings);
107
+ if (typeof generatedAt !== 'string' || !Array.isArray(pages) || !pages.every(isPage)) {
108
+ throw new Error('not a report-mode JSON report — pass a report written by `--out` (the .json file).');
109
+ }
110
+ return {
111
+ generatedAt,
112
+ ...(checks && { checks }),
113
+ pages: pages.map((p) => ({
114
+ label: p.label,
115
+ url: p.url,
116
+ findings: p.findings,
117
+ ...(p.error !== undefined && { error: p.error }),
118
+ ...(p.colorScheme && { colorScheme: p.colorScheme }),
119
+ ...(p.darkOnly && { darkOnly: true }),
120
+ })),
121
+ };
122
+ }
89
123
  /** UI primitives and directives a finding came through, for a "via …" note. */
90
124
  export function viaNames(finding) {
91
125
  // e.g. an `<button nbButton>` shows as "via NbButtonComponent" under its app owner.
@@ -88,3 +88,5 @@ export interface ScanPagesOptions {
88
88
  * to the component that rendered it — with no change to the target app.
89
89
  */
90
90
  export declare function scanPages(options: ScanPagesOptions): Promise<ScanReport>;
91
+ /** Version of the installed axe-core — the one a scan run now would use. */
92
+ export declare function axeVersion(): string;
@@ -179,6 +179,7 @@ export async function scanPages(options) {
179
179
  };
180
180
  return { generatedAt: new Date().toISOString(), checks, pages };
181
181
  }
182
- function axeVersion() {
182
+ /** Version of the installed axe-core — the one a scan run now would use. */
183
+ export function axeVersion() {
183
184
  return createRequire(import.meta.url)('axe-core/package.json').version;
184
185
  }
@@ -1,5 +1,5 @@
1
- export { scanPages, type ColorScheme, type ScanPagesOptions, type ThemeContext, } from './headless.js';
2
- export { groupByComponent, distinctRuleCount, toJson, toMarkdown, DARK_ONLY_NOTE, type PageReport, type ScanChecks, type ScanReport, } from './format.js';
1
+ export { axeVersion, scanPages, type ColorScheme, type ScanPagesOptions, type ThemeContext, } from './headless.js';
2
+ export { groupByComponent, distinctRuleCount, parseReport, toJson, toMarkdown, DARK_ONLY_NOTE, type PageReport, type ScanChecks, type ScanReport, } from './format.js';
3
3
  export { toHtml } from './html.js';
4
4
  export { diffAgainstBaseline, findingKey, findingsNotIn, parseBaseline, type BaselineDiff, type BaselineReport, type NewFinding, } from './baseline.js';
5
5
  export { isServing, startDevServer, type DevServer, type DevServerOptions } from './serve.js';
@@ -1,5 +1,5 @@
1
- export { scanPages, } from './headless.js';
2
- export { groupByComponent, distinctRuleCount, toJson, toMarkdown, DARK_ONLY_NOTE, } from './format.js';
1
+ export { axeVersion, scanPages, } from './headless.js';
2
+ export { groupByComponent, distinctRuleCount, parseReport, toJson, toMarkdown, DARK_ONLY_NOTE, } from './format.js';
3
3
  export { toHtml } from './html.js';
4
4
  export { diffAgainstBaseline, findingKey, findingsNotIn, parseBaseline, } from './baseline.js';
5
5
  export { isServing, startDevServer } from './serve.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "description": "Dev-only in-app accessibility auditing for Angular that maps each axe violation back to the component that rendered it — the attribution React overlay tools can't do.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",
@@ -48,8 +48,9 @@
48
48
  "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
49
49
  },
50
50
  "scripts": {
51
- "build": "tsc -p tsconfig.json && node scripts/build-inpage.mjs",
51
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.report.json && node scripts/build-inpage.mjs",
52
52
  "test": "vitest run",
53
+ "typecheck": "tsc -p tsconfig.spec.json --noEmit",
53
54
  "test:watch": "vitest",
54
55
  "demo:console": "vitest run --config vitest.demo.config.ts --disableConsoleIntercept",
55
56
  "prepublishOnly": "npm run build"