@ngbracket/a11y-devtools 0.18.1 → 0.18.2

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,19 @@
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.18.2
7
+
8
+ ### Fixed
9
+
10
+ - `--serve` stops as soon as the Angular build fails. `ng serve` keeps
11
+ watching after a failed build and never answers, so report mode used to wait
12
+ the full `--serve-timeout` (180 s by default) and then say the server didn't
13
+ answer. It now waits until Angular has printed the build errors, stops the
14
+ server, and exits with code 2 and "The Angular build failed", followed by
15
+ the last lines of output. Both the application builder and the older
16
+ webpack builder are covered. `--serve-timeout` still applies to servers
17
+ that never print a failure.
18
+
6
19
  ## 0.18.1
7
20
 
8
21
  ### Fixed
@@ -28,7 +28,8 @@ Options:
28
28
  answers, scan, then stop it — e.g. --serve "npx ng serve".
29
29
  If --base already answers, that server is used as-is
30
30
  --serve-timeout <s>
31
- Seconds to wait for --serve to answer (default 180)
31
+ Seconds to wait for --serve to answer (default 180).
32
+ A failed Angular build stops it straight away
32
33
  --route <path> Route to scan; repeat for multiple routes
33
34
  --from <file> Don't scan: read a previous run's JSON report (from --out)
34
35
  and write it in the --format(s) asked for — e.g. add an
@@ -26,8 +26,9 @@ export declare function isServing(url: string): Promise<boolean>;
26
26
  /**
27
27
  * Start a dev server and resolve once `url` answers — for report mode in CI,
28
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.
29
+ * command exits first, the Angular build fails, or `timeoutMs` passes; the
30
+ * error includes the last lines of its output. Always `stop()` the result when
31
+ * the scan is done. Until then, SIGINT/SIGTERM stop the server before the
32
+ * process ends.
32
33
  */
33
34
  export declare function startDevServer(options: DevServerOptions): Promise<DevServer>;
@@ -2,6 +2,16 @@ import { spawn } from 'node:child_process';
2
2
  /** Lines of dev-server output kept for the error message when it fails to start. */
3
3
  const OUTPUT_TAIL = 30;
4
4
  const POLL_MS = 500;
5
+ /**
6
+ * What `ng serve` prints when a build fails: the application builder (esbuild),
7
+ * then the older browser builder (webpack). Either way the server keeps watching
8
+ * and never answers, so waiting for the timeout only wastes CI time.
9
+ */
10
+ const BUILD_FAILED = /Application bundle generation failed|Failed to compile/;
11
+ /** `ng serve` prints this once it has listed the build errors. */
12
+ const WATCHING = /Watch mode enabled/;
13
+ /** After a failed build, how long to keep collecting its error lines (ms). */
14
+ const BUILD_ERRORS_MS = 2000;
5
15
  /** True when something at `url` answers with a non-5xx response. */
6
16
  export async function isServing(url) {
7
17
  try {
@@ -16,9 +26,10 @@ export async function isServing(url) {
16
26
  /**
17
27
  * Start a dev server and resolve once `url` answers — for report mode in CI,
18
28
  * 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.
29
+ * command exits first, the Angular build fails, or `timeoutMs` passes; the
30
+ * error includes the last lines of its output. Always `stop()` the result when
31
+ * the scan is done. Until then, SIGINT/SIGTERM stop the server before the
32
+ * process ends.
22
33
  */
23
34
  export async function startDevServer(options) {
24
35
  const { command, url, timeoutMs = 180_000, reuseExisting = true } = options;
@@ -35,18 +46,43 @@ export async function startDevServer(options) {
35
46
  stdio: ['ignore', 'pipe', 'pipe'],
36
47
  });
37
48
  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
- }
49
+ // Set when the build fails; `buildErrorsDone` once its error lines are in.
50
+ let buildFailedAt;
51
+ let buildErrorsDone = false;
52
+ const addLine = (line) => {
53
+ if (!line.trim())
54
+ return;
55
+ options.onOutput?.(line);
56
+ tail.push(line);
57
+ if (tail.length > OUTPUT_TAIL)
58
+ tail.shift();
59
+ const plain = stripAnsi(line);
60
+ if (buildFailedAt === undefined && BUILD_FAILED.test(plain))
61
+ buildFailedAt = Date.now();
62
+ else if (buildFailedAt !== undefined && WATCHING.test(plain))
63
+ buildErrorsDone = true;
64
+ };
65
+ // A chunk can end mid-line, so each stream keeps its unfinished last line
66
+ // until the rest arrives (or the stream ends).
67
+ const lineReader = () => {
68
+ let partial = '';
69
+ return {
70
+ data: (chunk) => {
71
+ const lines = (partial + chunk.toString()).split(/\r?\n/);
72
+ partial = lines.pop() ?? '';
73
+ lines.forEach(addLine);
74
+ },
75
+ end: () => {
76
+ addLine(partial);
77
+ partial = '';
78
+ },
79
+ };
47
80
  };
48
- child.stdout?.on('data', collect);
49
- child.stderr?.on('data', collect);
81
+ for (const stream of [child.stdout, child.stderr]) {
82
+ const reader = lineReader();
83
+ stream?.on('data', reader.data);
84
+ stream?.on('end', reader.end);
85
+ }
50
86
  let exitCode;
51
87
  const exited = new Promise((done) => {
52
88
  child.once('exit', (code, signal) => {
@@ -91,7 +127,12 @@ export async function startDevServer(options) {
91
127
  await stop();
92
128
  throw withOutput(`Dev server command exited (code ${exitCode}) before ${url} answered: ${command}`);
93
129
  }
94
- if (await isServing(url))
130
+ if (buildFailedAt !== undefined &&
131
+ (buildErrorsDone || Date.now() - buildFailedAt >= BUILD_ERRORS_MS)) {
132
+ await stop();
133
+ throw withOutput(`The Angular build failed, so the dev server never started: ${command}`);
134
+ }
135
+ if (buildFailedAt === undefined && (await isServing(url)))
95
136
  return { reused: false, stop };
96
137
  if (Date.now() >= deadline) {
97
138
  await stop();
@@ -100,6 +141,9 @@ export async function startDevServer(options) {
100
141
  await Promise.race([exited, new Promise((r) => setTimeout(r, POLL_MS))]);
101
142
  }
102
143
  }
144
+ function stripAnsi(text) {
145
+ return text.replace(/\x1b\[[0-9;]*m/g, '');
146
+ }
103
147
  function killTree(child, signal) {
104
148
  if (child.pid === undefined)
105
149
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngbracket/a11y-devtools",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "Finds accessibility problems in Angular apps and names the component behind each one. A dev overlay, or headless reports for CI.",
5
5
  "license": "MIT",
6
6
  "author": "Duncan Faulkner",