@ngbracket/a11y-devtools 0.12.2 → 0.13.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 +36 -0
- package/README.md +2 -2
- package/bin/ngbr-a11y-report.mjs +58 -14
- package/dist/inpage.global.js +1 -0
- package/dist/overlay.js +6 -0
- package/dist/report/format.d.ts +14 -0
- package/dist/report/format.js +20 -2
- package/dist/report/html.js +8 -5
- package/dist/report/index.d.ts +1 -0
- package/dist/report/index.js +1 -0
- package/dist/report/serve.d.ts +33 -0
- package/dist/report/serve.js +117 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,42 @@
|
|
|
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.13.0
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **Report mode can start your dev server.** `--serve "<command>"` runs the
|
|
11
|
+
command (for example `--serve "npx ng serve"`), waits until `--base` answers,
|
|
12
|
+
scans, then stops the server and everything it started — even on Ctrl+C or a
|
|
13
|
+
cancelled CI job. `--base` defaults to `http://localhost:4200` with `--serve`.
|
|
14
|
+
If something already answers at `--base`, that server is scanned and nothing is
|
|
15
|
+
started, so the same command works locally with `ng serve` already running.
|
|
16
|
+
`--serve-timeout <seconds>` (default 180) sets how long to wait. If the command
|
|
17
|
+
exits early or never answers, the CLI exits with code `2` and prints the last
|
|
18
|
+
lines of its output. From code: `startDevServer()` and `isServing()` from
|
|
19
|
+
`@ngbracket/a11y-devtools/report`.
|
|
20
|
+
|
|
21
|
+
## 0.12.3
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **Reports say what they aren't.** The Markdown and HTML reports are now titled
|
|
26
|
+
"Automated accessibility scan" (was "Accessibility report") and open with a
|
|
27
|
+
scope note: automated checks cover only part of WCAG, and the report is not a
|
|
28
|
+
conformance report or a VPAT/ACR. The note links to
|
|
29
|
+
[What it checks (and what it can't)](https://ngbracket.com/tools/a11y-devtools/docs/coverage).
|
|
30
|
+
JSON reports carry the same note as a top-level `scope` field. A clean page now
|
|
31
|
+
reads "No automated violations found." The in-app **Download report** gets the
|
|
32
|
+
same changes.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
|
|
36
|
+
- **The overlay no longer adds text to the page's accessibility tree.** Finding
|
|
37
|
+
labels, tab-order numbers and the accessibility-tree preview panel were exposed
|
|
38
|
+
to screen readers, mixing rule ids and badge numbers into the app being tested.
|
|
39
|
+
The overlay layer is now `aria-hidden`. The on/off pill and its menu are in a
|
|
40
|
+
separate layer and stay fully accessible.
|
|
41
|
+
|
|
6
42
|
## 0.12.2
|
|
7
43
|
|
|
8
44
|
### Changed
|
package/README.md
CHANGED
|
@@ -59,10 +59,10 @@ finding highlights labelled with their owning component (including the ngbr/*
|
|
|
59
59
|
keyboard findings), and the focus-follow accessibility-tree panel showing the
|
|
60
60
|
focused button's computed role, name and states.](./demo/keyboard-layer-2026-09.png)
|
|
61
61
|
|
|
62
|
-
In CI
|
|
62
|
+
In CI (`--serve` starts `ng serve`, waits for it, and stops it after the scan):
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
|
-
npx ngbr-a11y-report --
|
|
65
|
+
npx ngbr-a11y-report --serve "npx ng serve" --route / --route /settings \
|
|
66
66
|
--keyboard --baseline a11y-baseline.json --fail-on serious --out a11y --format all
|
|
67
67
|
```
|
|
68
68
|
|
package/bin/ngbr-a11y-report.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
diffAgainstBaseline,
|
|
5
5
|
parseBaseline,
|
|
6
6
|
scanPages,
|
|
7
|
+
startDevServer,
|
|
7
8
|
toHtml,
|
|
8
9
|
toJson,
|
|
9
10
|
toMarkdown,
|
|
@@ -13,9 +14,16 @@ const USAGE = `ngbr-a11y-report — component-attributed a11y scan of a running
|
|
|
13
14
|
|
|
14
15
|
Usage:
|
|
15
16
|
ngbr-a11y-report --base <url> --route <path> [--route <path> ...] [options]
|
|
17
|
+
ngbr-a11y-report --serve "<command>" --route <path> [...] [options]
|
|
16
18
|
|
|
17
19
|
Options:
|
|
18
|
-
--base <url> Origin of the running dev server (e.g. http://localhost:4200)
|
|
20
|
+
--base <url> Origin of the running dev server (e.g. http://localhost:4200).
|
|
21
|
+
With --serve, defaults to http://localhost:4200
|
|
22
|
+
--serve <command> Start the dev server with this command, wait until --base
|
|
23
|
+
answers, scan, then stop it — e.g. --serve "npx ng serve".
|
|
24
|
+
If --base already answers, that server is used as-is
|
|
25
|
+
--serve-timeout <s>
|
|
26
|
+
Seconds to wait for --serve to answer (default 180)
|
|
19
27
|
--route <path> Route to scan; repeat for multiple routes
|
|
20
28
|
--tags <list> Comma-separated axe tags to scope the ruleset (e.g. wcag22aa,best-practice)
|
|
21
29
|
--out <prefix> Write <prefix>.md / .json / .html (default: print Markdown to stdout)
|
|
@@ -63,6 +71,8 @@ function parseArgs(argv) {
|
|
|
63
71
|
const next = () => argv[++i];
|
|
64
72
|
switch (arg) {
|
|
65
73
|
case '--base': opts.base = next(); break;
|
|
74
|
+
case '--serve': opts.serve = next(); break;
|
|
75
|
+
case '--serve-timeout': opts.serveTimeout = Number(next()); break;
|
|
66
76
|
case '--route': opts.routes.push(next()); break;
|
|
67
77
|
case '--tags': opts.tags = next().split(',').map((s) => s.trim()).filter(Boolean); break;
|
|
68
78
|
case '--out': opts.out = next(); break;
|
|
@@ -88,6 +98,7 @@ function parseArgs(argv) {
|
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
const opts = parseArgs(process.argv.slice(2));
|
|
101
|
+
if (opts.serve && !opts.base) opts.base = 'http://localhost:4200';
|
|
91
102
|
|
|
92
103
|
if (opts.help || !opts.base || opts.routes.length === 0) {
|
|
93
104
|
process.stderr.write(USAGE);
|
|
@@ -129,19 +140,52 @@ if (opts.baseline) {
|
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (opts.serveTimeout !== undefined && !(opts.serveTimeout > 0)) {
|
|
144
|
+
process.stderr.write('Invalid --serve-timeout (use a number of seconds, e.g. 300)\n');
|
|
145
|
+
process.exit(2);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let server;
|
|
149
|
+
if (opts.serve) {
|
|
150
|
+
process.stderr.write(`Starting dev server: ${opts.serve}\n`);
|
|
151
|
+
try {
|
|
152
|
+
server = await startDevServer({
|
|
153
|
+
command: opts.serve,
|
|
154
|
+
url: opts.base,
|
|
155
|
+
timeoutMs: opts.serveTimeout === undefined ? undefined : opts.serveTimeout * 1000,
|
|
156
|
+
});
|
|
157
|
+
} catch (err) {
|
|
158
|
+
process.stderr.write(`${err.message}\n`);
|
|
159
|
+
process.exit(2);
|
|
160
|
+
}
|
|
161
|
+
process.stderr.write(
|
|
162
|
+
server.reused
|
|
163
|
+
? `${opts.base} is already serving; scanning that (nothing started).\n`
|
|
164
|
+
: `Dev server is up at ${opts.base}.\n`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let report;
|
|
169
|
+
try {
|
|
170
|
+
report = await scanPages({
|
|
171
|
+
baseUrl: opts.base,
|
|
172
|
+
routes: opts.routes,
|
|
173
|
+
tags: opts.tags,
|
|
174
|
+
waitMs: opts.wait,
|
|
175
|
+
headed: opts.headed,
|
|
176
|
+
frameworkPrefixes: opts.frameworkPrefixes,
|
|
177
|
+
keyboard: opts.keyboard,
|
|
178
|
+
focusTraps: opts.focusTraps,
|
|
179
|
+
colorScheme: opts.colorScheme,
|
|
180
|
+
darkClass: opts.darkClass,
|
|
181
|
+
darkAttribute,
|
|
182
|
+
});
|
|
183
|
+
} finally {
|
|
184
|
+
if (server && !server.reused) {
|
|
185
|
+
await server.stop();
|
|
186
|
+
process.stderr.write('Stopped the dev server.\n');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
145
189
|
|
|
146
190
|
const allFindings = report.pages.flatMap((p) => p.findings);
|
|
147
191
|
process.stderr.write(
|
package/dist/inpage.global.js
CHANGED
|
@@ -34321,6 +34321,7 @@
|
|
|
34321
34321
|
const doc = options.document ?? document;
|
|
34322
34322
|
const container = doc.createElement("div");
|
|
34323
34323
|
container.setAttribute(OVERLAY_ATTR, "");
|
|
34324
|
+
container.setAttribute("aria-hidden", "true");
|
|
34324
34325
|
Object.assign(container.style, {
|
|
34325
34326
|
position: "fixed",
|
|
34326
34327
|
inset: "0",
|
package/dist/overlay.js
CHANGED
|
@@ -38,6 +38,12 @@ export function createOverlay(options = {}) {
|
|
|
38
38
|
const doc = options.document ?? document;
|
|
39
39
|
const container = doc.createElement('div');
|
|
40
40
|
container.setAttribute(OVERLAY_ATTR, '');
|
|
41
|
+
// The highlights, badges and preview panel are a visual aid for sighted
|
|
42
|
+
// developers. Hide them from assistive tech so their text (rule ids, tab
|
|
43
|
+
// numbers, panel rows) doesn't pollute the page's own accessibility tree. The
|
|
44
|
+
// on/off pill lives in a separate layer and stays exposed. Nothing in here is
|
|
45
|
+
// focusable, so this can't create an aria-hidden focus trap.
|
|
46
|
+
container.setAttribute('aria-hidden', 'true');
|
|
41
47
|
Object.assign(container.style, {
|
|
42
48
|
position: 'fixed',
|
|
43
49
|
inset: '0',
|
package/dist/report/format.d.ts
CHANGED
|
@@ -24,6 +24,20 @@ export interface PageReport {
|
|
|
24
24
|
}
|
|
25
25
|
/** One-line explanation for a dark-only page, shared by the Markdown and HTML reports. */
|
|
26
26
|
export declare const DARK_ONLY_NOTE = "Dark mode: lists only issues that don\u2019t also appear in light mode on this route.";
|
|
27
|
+
/**
|
|
28
|
+
* Report title, shared by every format. Says "automated scan" on purpose: a file
|
|
29
|
+
* titled "Accessibility report" is easy to hand to procurement as if it were a
|
|
30
|
+
* conformance report.
|
|
31
|
+
*/
|
|
32
|
+
export declare const REPORT_TITLE = "Automated accessibility scan";
|
|
33
|
+
/** Docs page explaining what automated checks cover and what they can't. */
|
|
34
|
+
export declare const COVERAGE_URL = "https://ngbracket.com/tools/a11y-devtools/docs/coverage";
|
|
35
|
+
/**
|
|
36
|
+
* What the report is and isn't, shown under the title in every format (and as
|
|
37
|
+
* `scope` in JSON). Automated checks cover part of WCAG; a clean run is not a
|
|
38
|
+
* conformance claim, and a VPAT/ACR needs a person to judge every criterion.
|
|
39
|
+
*/
|
|
40
|
+
export declare const REPORT_SCOPE_NOTE: string;
|
|
27
41
|
/** A whole report-mode run across one or more pages. */
|
|
28
42
|
export interface ScanReport {
|
|
29
43
|
/** ISO timestamp of the run. */
|
package/dist/report/format.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
/** One-line explanation for a dark-only page, shared by the Markdown and HTML reports. */
|
|
2
2
|
export const DARK_ONLY_NOTE = 'Dark mode: lists only issues that don’t also appear in light mode on this route.';
|
|
3
|
+
/**
|
|
4
|
+
* Report title, shared by every format. Says "automated scan" on purpose: a file
|
|
5
|
+
* titled "Accessibility report" is easy to hand to procurement as if it were a
|
|
6
|
+
* conformance report.
|
|
7
|
+
*/
|
|
8
|
+
export const REPORT_TITLE = 'Automated accessibility scan';
|
|
9
|
+
/** Docs page explaining what automated checks cover and what they can't. */
|
|
10
|
+
export const COVERAGE_URL = 'https://ngbracket.com/tools/a11y-devtools/docs/coverage';
|
|
11
|
+
/**
|
|
12
|
+
* What the report is and isn't, shown under the title in every format (and as
|
|
13
|
+
* `scope` in JSON). Automated checks cover part of WCAG; a clean run is not a
|
|
14
|
+
* conformance claim, and a VPAT/ACR needs a person to judge every criterion.
|
|
15
|
+
*/
|
|
16
|
+
export const REPORT_SCOPE_NOTE = 'Automated checks cover only part of WCAG. This is not a conformance report or a VPAT/ACR: ' +
|
|
17
|
+
'manual keyboard, screen-reader and content review is still required.';
|
|
3
18
|
/**
|
|
4
19
|
* Group findings by the component that rendered them — the readable form the
|
|
5
20
|
* attribution makes possible ("♿ HeaderComponent — 2 issues" beats a list of
|
|
@@ -43,6 +58,7 @@ export function toJson(report, diff) {
|
|
|
43
58
|
const all = report.pages.flatMap((p) => p.findings);
|
|
44
59
|
return JSON.stringify({
|
|
45
60
|
generatedAt: report.generatedAt,
|
|
61
|
+
scope: `${REPORT_SCOPE_NOTE} ${COVERAGE_URL}`,
|
|
46
62
|
summary: {
|
|
47
63
|
pages: report.pages.length,
|
|
48
64
|
distinctRules: distinctRuleCount(all),
|
|
@@ -91,10 +107,12 @@ export function addedBySeverity(diff) {
|
|
|
91
107
|
export function toMarkdown(report, diff) {
|
|
92
108
|
const all = report.pages.flatMap((p) => p.findings);
|
|
93
109
|
const lines = [];
|
|
94
|
-
lines.push(
|
|
110
|
+
lines.push(`# ${REPORT_TITLE}`);
|
|
95
111
|
lines.push('');
|
|
96
112
|
lines.push(`_Generated ${report.generatedAt} · @ngbracket/a11y-devtools report-mode_`);
|
|
97
113
|
lines.push('');
|
|
114
|
+
lines.push(`> ${REPORT_SCOPE_NOTE} [What automated checks cover](${COVERAGE_URL}).`);
|
|
115
|
+
lines.push('');
|
|
98
116
|
// Summary table — distinct rules alongside raw node-instances, so the headline
|
|
99
117
|
// count can't be read as "how bad is it" on its own.
|
|
100
118
|
lines.push('## Summary');
|
|
@@ -131,7 +149,7 @@ export function toMarkdown(report, diff) {
|
|
|
131
149
|
continue;
|
|
132
150
|
}
|
|
133
151
|
if (page.findings.length === 0) {
|
|
134
|
-
lines.push('No violations found. ✅');
|
|
152
|
+
lines.push('No automated violations found. ✅');
|
|
135
153
|
lines.push('');
|
|
136
154
|
continue;
|
|
137
155
|
}
|
package/dist/report/html.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addedBySeverity, DARK_ONLY_NOTE, bySeverity, distinctRuleCount, groupByComponent, viaNames, } from './format.js';
|
|
1
|
+
import { addedBySeverity, COVERAGE_URL, DARK_ONLY_NOTE, REPORT_SCOPE_NOTE, REPORT_TITLE, bySeverity, distinctRuleCount, groupByComponent, viaNames, } from './format.js';
|
|
2
2
|
/**
|
|
3
3
|
* A single self-contained HTML report: inline CSS, no scripts, no external
|
|
4
4
|
* requests — so it can be attached to a CI run, emailed, or opened offline.
|
|
@@ -46,7 +46,9 @@ main { max-width: 960px; margin: 0 auto; padding: 32px 16px 64px; }
|
|
|
46
46
|
h1 { font-size: 1.6rem; margin: 0 0 4px; }
|
|
47
47
|
h2 { font-size: 1.25rem; margin: 40px 0 12px; padding-top: 16px; border-top: 1px solid var(--line); }
|
|
48
48
|
h3 { font-size: 1.05rem; margin: 0 0 4px; }
|
|
49
|
-
.meta { color: var(--muted); margin: 0 0
|
|
49
|
+
.meta { color: var(--muted); margin: 0 0 12px; }
|
|
50
|
+
.scope { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
|
|
51
|
+
margin: 0 0 24px; padding: 10px 14px; }
|
|
50
52
|
a { color: var(--link); }
|
|
51
53
|
code { font: 0.9em/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
|
|
52
54
|
table { border-collapse: collapse; width: 100%; margin: 8px 0 16px; }
|
|
@@ -85,13 +87,14 @@ export function toHtml(report, diff) {
|
|
|
85
87
|
out.push('<head>');
|
|
86
88
|
out.push('<meta charset="utf-8">');
|
|
87
89
|
out.push('<meta name="viewport" content="width=device-width, initial-scale=1">');
|
|
88
|
-
out.push(
|
|
90
|
+
out.push(`<title>${REPORT_TITLE}</title>`);
|
|
89
91
|
out.push(`<style>${STYLES}</style>`);
|
|
90
92
|
out.push('</head>');
|
|
91
93
|
out.push('<body>');
|
|
92
94
|
out.push('<main>');
|
|
93
|
-
out.push(
|
|
95
|
+
out.push(`<h1>${REPORT_TITLE}</h1>`);
|
|
94
96
|
out.push(`<p class="meta">Generated <time datetime="${escapeHtml(report.generatedAt)}">${escapeHtml(report.generatedAt)}</time> · @ngbracket/a11y-devtools report-mode</p>`);
|
|
97
|
+
out.push(`<p class="scope">${escapeHtml(REPORT_SCOPE_NOTE)} <a href="${COVERAGE_URL}">What automated checks cover</a>.</p>`);
|
|
95
98
|
// Summary — distinct rules next to raw node-instances, so the bigger number
|
|
96
99
|
// can't be read on its own as "how bad is it".
|
|
97
100
|
out.push('<section aria-labelledby="summary">');
|
|
@@ -131,7 +134,7 @@ export function toHtml(report, diff) {
|
|
|
131
134
|
return;
|
|
132
135
|
}
|
|
133
136
|
if (page.findings.length === 0) {
|
|
134
|
-
out.push('<p class="ok">No violations found.</p>');
|
|
137
|
+
out.push('<p class="ok">No automated violations found.</p>');
|
|
135
138
|
out.push('</section>');
|
|
136
139
|
return;
|
|
137
140
|
}
|
package/dist/report/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { scanPages, type ColorScheme, type ScanPagesOptions, type ThemeContext,
|
|
|
2
2
|
export { groupByComponent, distinctRuleCount, toJson, toMarkdown, DARK_ONLY_NOTE, type PageReport, 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
|
+
export { isServing, startDevServer, type DevServer, type DevServerOptions } from './serve.js';
|
package/dist/report/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { scanPages, } from './headless.js';
|
|
|
2
2
|
export { groupByComponent, distinctRuleCount, 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
|
+
export { isServing, startDevServer } from './serve.js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface DevServerOptions {
|
|
2
|
+
/** Shell command that starts the dev server, e.g. `npx ng serve admin --port 4300`. */
|
|
3
|
+
command: string;
|
|
4
|
+
/** URL to poll until the server answers, e.g. `http://localhost:4300`. */
|
|
5
|
+
url: string;
|
|
6
|
+
/** Give up if the server hasn't answered after this long (ms). Default 180000. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
/**
|
|
9
|
+
* If something already answers at `url`, scan that and start nothing.
|
|
10
|
+
* Default true — handy locally when `ng serve` is already running.
|
|
11
|
+
*/
|
|
12
|
+
reuseExisting?: boolean;
|
|
13
|
+
/** Working directory for the command. Default `process.cwd()`. */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
/** Called with each line the command prints (stdout and stderr). */
|
|
16
|
+
onOutput?: (line: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface DevServer {
|
|
19
|
+
/** True when an already-running server was reused and nothing was started. */
|
|
20
|
+
reused: boolean;
|
|
21
|
+
/** Stop the server (and everything it spawned). Safe to call more than once. */
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
/** True when something at `url` answers with a non-5xx response. */
|
|
25
|
+
export declare function isServing(url: string): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
28
|
+
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
29
|
+
* command exits first or `timeoutMs` passes; the error includes the last lines
|
|
30
|
+
* of its output. Always `stop()` the result when the scan is done. Until then,
|
|
31
|
+
* SIGINT/SIGTERM stop the server before the process ends.
|
|
32
|
+
*/
|
|
33
|
+
export declare function startDevServer(options: DevServerOptions): Promise<DevServer>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
/** Lines of dev-server output kept for the error message when it fails to start. */
|
|
3
|
+
const OUTPUT_TAIL = 30;
|
|
4
|
+
const POLL_MS = 500;
|
|
5
|
+
/** True when something at `url` answers with a non-5xx response. */
|
|
6
|
+
export async function isServing(url) {
|
|
7
|
+
try {
|
|
8
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(2000), redirect: 'manual' });
|
|
9
|
+
await res.body?.cancel();
|
|
10
|
+
return res.status < 500;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Start a dev server and resolve once `url` answers — for report mode in CI,
|
|
18
|
+
* where nothing is running yet. Rejects (after stopping the process) if the
|
|
19
|
+
* command exits first or `timeoutMs` passes; the error includes the last lines
|
|
20
|
+
* of its output. Always `stop()` the result when the scan is done. Until then,
|
|
21
|
+
* SIGINT/SIGTERM stop the server before the process ends.
|
|
22
|
+
*/
|
|
23
|
+
export async function startDevServer(options) {
|
|
24
|
+
const { command, url, timeoutMs = 180_000, reuseExisting = true } = options;
|
|
25
|
+
if (await isServing(url)) {
|
|
26
|
+
if (reuseExisting)
|
|
27
|
+
return { reused: true, stop: async () => { } };
|
|
28
|
+
throw new Error(`Something is already serving ${url}; stop it or use a different port.`);
|
|
29
|
+
}
|
|
30
|
+
// A process group of its own (POSIX), so stop() also ends what the shell spawned.
|
|
31
|
+
const child = spawn(command, {
|
|
32
|
+
cwd: options.cwd,
|
|
33
|
+
shell: true,
|
|
34
|
+
detached: process.platform !== 'win32',
|
|
35
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
36
|
+
});
|
|
37
|
+
const tail = [];
|
|
38
|
+
const collect = (chunk) => {
|
|
39
|
+
for (const line of chunk.toString().split(/\r?\n/)) {
|
|
40
|
+
if (!line.trim())
|
|
41
|
+
continue;
|
|
42
|
+
options.onOutput?.(line);
|
|
43
|
+
tail.push(line);
|
|
44
|
+
if (tail.length > OUTPUT_TAIL)
|
|
45
|
+
tail.shift();
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
child.stdout?.on('data', collect);
|
|
49
|
+
child.stderr?.on('data', collect);
|
|
50
|
+
let exitCode;
|
|
51
|
+
const exited = new Promise((done) => {
|
|
52
|
+
child.once('exit', (code, signal) => {
|
|
53
|
+
exitCode = code ?? (signal ? -1 : null);
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
child.once('error', (err) => {
|
|
57
|
+
tail.push(err.message);
|
|
58
|
+
exitCode = -1;
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
// The server is in its own process group, so Ctrl+C (or a cancelled CI job)
|
|
63
|
+
// doesn't reach it. Until stop(), pass those signals on, then re-raise them;
|
|
64
|
+
// if the process exits some other way, kill it synchronously.
|
|
65
|
+
const onSignal = (signal) => {
|
|
66
|
+
void stop().then(() => process.kill(process.pid, signal));
|
|
67
|
+
};
|
|
68
|
+
const onExit = () => killTree(child, 'SIGKILL');
|
|
69
|
+
process.once('SIGINT', onSignal);
|
|
70
|
+
process.once('SIGTERM', onSignal);
|
|
71
|
+
process.once('exit', onExit);
|
|
72
|
+
let stopped = false;
|
|
73
|
+
const stop = async () => {
|
|
74
|
+
if (stopped)
|
|
75
|
+
return;
|
|
76
|
+
stopped = true;
|
|
77
|
+
process.off('SIGINT', onSignal);
|
|
78
|
+
process.off('SIGTERM', onSignal);
|
|
79
|
+
process.off('exit', onExit);
|
|
80
|
+
if (exitCode === undefined) {
|
|
81
|
+
killTree(child, 'SIGTERM');
|
|
82
|
+
const forced = setTimeout(() => killTree(child, 'SIGKILL'), 5000);
|
|
83
|
+
await exited;
|
|
84
|
+
clearTimeout(forced);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const withOutput = (message) => new Error(tail.length ? `${message}\nLast output:\n ${tail.join('\n ')}` : message);
|
|
88
|
+
const deadline = Date.now() + timeoutMs;
|
|
89
|
+
while (true) {
|
|
90
|
+
if (exitCode !== undefined) {
|
|
91
|
+
await stop();
|
|
92
|
+
throw withOutput(`Dev server command exited (code ${exitCode}) before ${url} answered: ${command}`);
|
|
93
|
+
}
|
|
94
|
+
if (await isServing(url))
|
|
95
|
+
return { reused: false, stop };
|
|
96
|
+
if (Date.now() >= deadline) {
|
|
97
|
+
await stop();
|
|
98
|
+
throw withOutput(`Dev server didn't answer at ${url} within ${Math.round(timeoutMs / 1000)}s: ${command}`);
|
|
99
|
+
}
|
|
100
|
+
await Promise.race([exited, new Promise((r) => setTimeout(r, POLL_MS))]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function killTree(child, signal) {
|
|
104
|
+
if (child.pid === undefined)
|
|
105
|
+
return;
|
|
106
|
+
try {
|
|
107
|
+
if (process.platform === 'win32') {
|
|
108
|
+
spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore' });
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
process.kill(-child.pid, signal);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Already gone.
|
|
116
|
+
}
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngbracket/a11y-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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",
|