@out-of-order/cli 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bart Spaans
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @out-of-order/cli
2
+
3
+ > ⚠️ **Under heavy development.** Released, but the API is still changing and may break between versions.
4
+
5
+ Audit any URL's tab order from the command line. It drives real Chromium (via [Playwright](https://playwright.dev/)), runs the [`@out-of-order/core`](../core) analyzer against the live page, and prints the findings to stdout. Pipe them into an AI agent or gate a CI job on the exit code.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add -D @out-of-order/cli
11
+ # playwright browsers, if not already present:
12
+ pnpm exec playwright install chromium
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```bash
18
+ out-of-order <url> [options]
19
+ ```
20
+
21
+ ```bash
22
+ # text report to stdout, exits non-zero if the page has violations
23
+ out-of-order https://example.com
24
+
25
+ # machine-readable output, grouped per element
26
+ out-of-order https://example.com --format by-element
27
+
28
+ # wait for a selector before auditing a JS-heavy page
29
+ out-of-order https://example.com --wait "main [role=dialog]"
30
+
31
+ # open a headed browser with the live overlay, Ctrl-C to quit
32
+ out-of-order https://example.com --overlay
33
+ ```
34
+
35
+ ## Options
36
+
37
+ | Option | What it does |
38
+ | ------------------- | ------------------------------------------------------------------ |
39
+ | `--format <name>` | Output shape: `text` (default) or `by-element`. |
40
+ | `--overlay` | Open a headed browser with the visual overlay instead of printing. |
41
+ | `--wait <selector>` | Wait for a selector before auditing (JS-heavy pages). |
42
+ | `--help` | Show usage. |
43
+
44
+ ## Exit codes
45
+
46
+ | Code | Meaning |
47
+ | ---- | ------------------------------------------ |
48
+ | `0` | Audited, tab order is valid. |
49
+ | `1` | Audited, violations found. |
50
+ | `2` | Bad arguments, or the page failed to load. |
51
+
52
+ Because it exits `1` on any violation, dropping `out-of-order <url>` into a CI step fails the build on a broken tab order.
package/dist/cli.js ADDED
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { readFileSync } from "fs";
5
+ import { dirname, join } from "path";
6
+ import { fileURLToPath } from "url";
7
+ import { parseArgs } from "util";
8
+ import { chromium } from "playwright";
9
+ var FORMATS = ["by-element", "text"];
10
+ var USAGE = `out-of-order <url> [options]
11
+
12
+ --format <name> Output shape: ${FORMATS.join(" | ")} (default: text).
13
+ --overlay Open a headed browser with the visual overlay; Ctrl-C to quit.
14
+ --wait <selector> Wait for a selector before auditing (JS-heavy pages).
15
+ --help Show this message.`;
16
+ var { values, positionals } = parseArgs({
17
+ allowPositionals: true,
18
+ options: {
19
+ format: { type: "string", default: "text" },
20
+ overlay: { type: "boolean", default: false },
21
+ wait: { type: "string" },
22
+ help: { type: "boolean", default: false }
23
+ }
24
+ });
25
+ if (values.help) {
26
+ process.stdout.write(USAGE + "\n");
27
+ process.exit(0);
28
+ }
29
+ var url = positionals[0];
30
+ if (!url) {
31
+ process.stderr.write(USAGE + "\n");
32
+ process.exit(2);
33
+ }
34
+ var format = values.format;
35
+ if (!FORMATS.includes(format)) {
36
+ process.stderr.write(`Unknown --format "${format}".
37
+ ${USAGE}
38
+ `);
39
+ process.exit(2);
40
+ }
41
+ var here = dirname(fileURLToPath(import.meta.url));
42
+ async function open(page, targetUrl) {
43
+ const response = await page.goto(targetUrl, { waitUntil: "networkidle" });
44
+ if (response && !response.ok()) {
45
+ return response;
46
+ }
47
+ if (values.wait) {
48
+ await page.waitForSelector(values.wait);
49
+ }
50
+ return response;
51
+ }
52
+ if (values.overlay) {
53
+ const overlaySource = readFileSync(join(here, "inject-overlay.global.js"), "utf8");
54
+ const browser2 = await chromium.launch({ headless: false });
55
+ const context = await browser2.newContext({
56
+ viewport: null,
57
+ bypassCSP: true
58
+ });
59
+ const page = await context.newPage();
60
+ await page.addInitScript({ content: overlaySource });
61
+ const response = await open(page, url);
62
+ if (response && !response.ok()) {
63
+ process.stderr.write(`${url} returned HTTP ${response.status()}
64
+ `);
65
+ await browser2.close();
66
+ process.exit(2);
67
+ }
68
+ process.stderr.write("Overlay mounted. Ctrl-C to quit.\n");
69
+ await new Promise((resolve) => {
70
+ browser2.on("disconnected", () => resolve());
71
+ process.on("SIGINT", () => resolve());
72
+ });
73
+ await browser2.close().catch(() => {
74
+ });
75
+ process.exit(0);
76
+ }
77
+ var injectSource = readFileSync(join(here, "inject.global.js"), "utf8");
78
+ var browser = await chromium.launch();
79
+ try {
80
+ const page = await browser.newPage();
81
+ await page.addInitScript({ content: injectSource });
82
+ const response = await open(page, url);
83
+ if (response && !response.ok()) {
84
+ throw new Error(`${url} returned HTTP ${response.status()}`);
85
+ }
86
+ const out = await page.evaluate((fmt) => {
87
+ const ooo = window.__ooo;
88
+ const result = ooo.audit(document, { format: fmt });
89
+ const violations = result.violations;
90
+ const output = typeof violations === "string" ? violations : JSON.stringify(violations, null, 2);
91
+ return { output, valid: result.valid };
92
+ }, format);
93
+ process.stdout.write(out.output + "\n");
94
+ process.exitCode = out.valid ? 0 : 1;
95
+ } catch (err) {
96
+ process.stderr.write(`${err instanceof Error ? err.message : String(err)}
97
+ `);
98
+ process.exitCode = 2;
99
+ } finally {
100
+ await browser.close();
101
+ }