omnisnap 0.0.0 → 0.1.0-rc.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/README.md +19 -2
- package/bin/omnisnap.js +19 -0
- package/index.d.ts +79 -0
- package/index.js +130 -0
- package/package.json +20 -4
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
# omnisnap
|
|
1
|
+
# omnisnap (npm)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Thin wrapper around the Omnisnap binary: writes a job, streams progress,
|
|
4
|
+
returns the summary. No runtime dependencies, no postinstall.
|
|
5
|
+
|
|
6
|
+
```js
|
|
7
|
+
import { run, browsers, merge, report } from 'omnisnap';
|
|
8
|
+
|
|
9
|
+
const summary = await run({
|
|
10
|
+
pages: ['http://localhost:3000/'],
|
|
11
|
+
engines: ['chrome', 'firefox'],
|
|
12
|
+
out: './omnisnap-out',
|
|
13
|
+
onProgress: (e) => console.log(e.type),
|
|
14
|
+
});
|
|
15
|
+
console.log(summary.results.map((r) => `${r.engine.engine}: ${r.stats.report} to report`));
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The binary comes from the platform package (`@omnisnap/<os>-<arch>`), then
|
|
19
|
+
`OMNISNAP_BINARY`, then `PATH`. Errors are `OmnisnapError` with `code` and
|
|
20
|
+
`stderr`; findings never throw.
|
package/bin/omnisnap.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The `omnisnap` bin shim: runs the platform binary with the same arguments,
|
|
3
|
+
// so npm users get the CLI and the API from one package.
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { resolveBinary } from '../index.js';
|
|
6
|
+
|
|
7
|
+
const binary = resolveBinary();
|
|
8
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: 'inherit' });
|
|
9
|
+
// A missing binary is an 'error' event, not an exit: without a handler node
|
|
10
|
+
// dies with an unhandled-error stack trace.
|
|
11
|
+
child.on('error', (err) => {
|
|
12
|
+
process.stderr.write(`omnisnap: cannot run ${binary}: ${err.message}\n` +
|
|
13
|
+
`install the platform package for ${process.platform}-${process.arch} (@omnisnap/${process.platform}-${process.arch}), or set OMNISNAP_BINARY\n`);
|
|
14
|
+
process.exit(127);
|
|
15
|
+
});
|
|
16
|
+
child.on('exit', (code, signal) => {
|
|
17
|
+
if (signal) process.kill(process.pid, signal);
|
|
18
|
+
else process.exit(code ?? 1);
|
|
19
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Generated from schema/*.schema.json by packages/types/generate.mjs; a drift
|
|
2
|
+
// check in CI regenerates and diffs. Do not edit by hand.
|
|
3
|
+
export type Tier = 'report' | 'info';
|
|
4
|
+
export type PageStatus = 'ok' | 'diverged' | 'failed' | 'unreachable';
|
|
5
|
+
|
|
6
|
+
export interface Box { baseline: [number, number, number, number] | null; engine: [number, number, number, number] | null; }
|
|
7
|
+
export interface Delta { dw: number; dh: number; dx: number; dy: number; dln: number; }
|
|
8
|
+
export interface Evidence {
|
|
9
|
+
mechanism: string | null;
|
|
10
|
+
consensus: 'baseline-odd' | 'engine-odd' | 'all-differ' | null;
|
|
11
|
+
perception: number | null;
|
|
12
|
+
ink: number | null;
|
|
13
|
+
intent: string[] | null;
|
|
14
|
+
calibration?: { explained: boolean; by: Array<{ model: string; expected?: number; tol?: number; dw?: number; dh?: number }> };
|
|
15
|
+
}
|
|
16
|
+
export interface Cause {
|
|
17
|
+
id: string;
|
|
18
|
+
tier: Tier;
|
|
19
|
+
title: string;
|
|
20
|
+
kinds: string[];
|
|
21
|
+
consequences: string[];
|
|
22
|
+
selector: string;
|
|
23
|
+
boxes: Box;
|
|
24
|
+
delta: Delta;
|
|
25
|
+
kb: string | null;
|
|
26
|
+
kbDetail?: { id: string; title: string; explanation: string; fix: string };
|
|
27
|
+
evidence: Evidence;
|
|
28
|
+
score: number | null;
|
|
29
|
+
count: number;
|
|
30
|
+
instances: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface Result {
|
|
33
|
+
host: { os: string; arch: string; id: string };
|
|
34
|
+
page: { slug: string; url: string };
|
|
35
|
+
baseline: { engine: string; version: string };
|
|
36
|
+
engine: { engine: string; family: string; version: string; profile: string };
|
|
37
|
+
status: PageStatus;
|
|
38
|
+
warnings: string[];
|
|
39
|
+
stats: { matchRate: number; report: number; info: number; ms: number };
|
|
40
|
+
shots?: { baseline: { src: string; w: number; h: number }; engine: { src: string; w: number; h: number } };
|
|
41
|
+
findings?: string;
|
|
42
|
+
causes: Cause[];
|
|
43
|
+
intent: Array<{ engine: 'baseline' | 'engine'; selector: string; relations: string[]; px: number; keptBy: string[] }>;
|
|
44
|
+
blocked: { baseline: string[]; engine: string[] };
|
|
45
|
+
dynamic: { baseline: string[]; engine: string[] };
|
|
46
|
+
audit?: { baseline: Array<{ check: string; selector: string; box: number[]; severity: string }>; engine: Array<{ check: string; selector: string; box: number[]; severity: string }> };
|
|
47
|
+
}
|
|
48
|
+
export interface Summary {
|
|
49
|
+
$schema: string;
|
|
50
|
+
tool: { name: 'omnisnap'; version: string };
|
|
51
|
+
generated: string;
|
|
52
|
+
job: Record<string, unknown>;
|
|
53
|
+
hosts: Array<{ machine: { os: string; arch: string; id: string }; engines: unknown[] }>;
|
|
54
|
+
skipped: Array<{ host?: string; engine: string; reason: string }>;
|
|
55
|
+
pages: Array<{ slug: string; url: string; report: number; info: number }>;
|
|
56
|
+
results: Result[];
|
|
57
|
+
}
|
|
58
|
+
export interface RunOptions {
|
|
59
|
+
pages: Array<string | { url: string; slug?: string }>;
|
|
60
|
+
engines?: string[];
|
|
61
|
+
baseline?: string;
|
|
62
|
+
runs?: number;
|
|
63
|
+
out?: string;
|
|
64
|
+
viewport?: { width: number; height: number; deviceScaleFactor?: number };
|
|
65
|
+
timeouts?: { navigationMs?: number; scriptMs?: number };
|
|
66
|
+
probes?: boolean;
|
|
67
|
+
fontParity?: boolean;
|
|
68
|
+
/** Do not treat a page under 50 elements as a bot wall (planted and test pages). */
|
|
69
|
+
allowSmallPages?: boolean;
|
|
70
|
+
cwd?: string;
|
|
71
|
+
onProgress?: (event: unknown) => void;
|
|
72
|
+
}
|
|
73
|
+
export class OmnisnapError extends Error { code: number | null; stderr: string; args: string[]; }
|
|
74
|
+
export function run(options: RunOptions): Promise<Summary>;
|
|
75
|
+
export function browsers(): Promise<Array<{ id: string; name: string; family: string; protocol: string; executable: string; version: string; source: string; notes?: string[] }>>;
|
|
76
|
+
export function merge(bundles: string[], out: string, options?: { onProgress?: (event: unknown) => void }): Promise<Summary>;
|
|
77
|
+
export function report(bundle: string): Promise<string>;
|
|
78
|
+
export function resolveBinary(): string;
|
|
79
|
+
export function runBinary(args: string[], options?: { onProgress?: (event: unknown) => void; cwd?: string; env?: Record<string, string> }): Promise<{ code: number; stdout: string; stderr: string; done: unknown }>;
|
package/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Thin wrapper around the Omnisnap binary (SPEC-wrappers.md): write a job.json,
|
|
2
|
+
// run the binary, stream its NDJSON progress, return the parsed summary. No
|
|
3
|
+
// capture or diff logic lives here. Zero runtime dependencies.
|
|
4
|
+
import { spawn } from 'node:child_process';
|
|
5
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
|
|
12
|
+
/** A failed binary run: the exit code and stderr travel with the error. */
|
|
13
|
+
export class OmnisnapError extends Error {
|
|
14
|
+
constructor(message, { code = null, stderr = '', args = [] } = {}) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'OmnisnapError';
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.stderr = stderr;
|
|
19
|
+
this.args = args;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Find the binary: OMNISNAP_BINARY, then the platform package, then PATH. */
|
|
24
|
+
export function resolveBinary() {
|
|
25
|
+
if (process.env.OMNISNAP_BINARY) return process.env.OMNISNAP_BINARY;
|
|
26
|
+
const key = `${process.platform}-${process.arch}`;
|
|
27
|
+
const names = { 'linux-x64': 'linux-x64', 'linux-arm64': 'linux-arm64', 'darwin-x64': 'darwin-x64', 'darwin-arm64': 'darwin-arm64', 'win32-x64': 'win32-x64' };
|
|
28
|
+
const pkg = names[key];
|
|
29
|
+
if (pkg) {
|
|
30
|
+
try {
|
|
31
|
+
const manifest = require.resolve(`@omnisnap/${pkg}/package.json`);
|
|
32
|
+
// The platform packages ship the binary under bin/ ("files": ["bin/"],
|
|
33
|
+
// where tools/release --stage puts it).
|
|
34
|
+
return join(dirname(manifest), 'bin', process.platform === 'win32' ? 'omnisnap.exe' : 'omnisnap');
|
|
35
|
+
} catch { /* not installed: fall through */ }
|
|
36
|
+
}
|
|
37
|
+
return process.platform === 'win32' ? 'omnisnap.exe' : 'omnisnap';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Run the binary, parse NDJSON lines as they arrive, collect stderr. */
|
|
41
|
+
export function runBinary(args, { onProgress, cwd, env } = {}) {
|
|
42
|
+
const binary = resolveBinary();
|
|
43
|
+
return new Promise((resolvePromise, reject) => {
|
|
44
|
+
const child = spawn(binary, args, { cwd, env: { ...process.env, ...env } });
|
|
45
|
+
let stderr = '';
|
|
46
|
+
let stdout = '';
|
|
47
|
+
let buffer = '';
|
|
48
|
+
let resultLine = null;
|
|
49
|
+
const handle = (line) => {
|
|
50
|
+
line = line.trim();
|
|
51
|
+
if (!line) return;
|
|
52
|
+
let event;
|
|
53
|
+
try { event = JSON.parse(line); } catch { return; } // not NDJSON: ignore
|
|
54
|
+
// Only typed events are progress; `browsers --json` writes an array.
|
|
55
|
+
if (event && !Array.isArray(event) && typeof event === 'object' && event.type) {
|
|
56
|
+
if (onProgress) onProgress(event);
|
|
57
|
+
if (event.type === 'done') resultLine = event;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
child.stdout.on('data', (chunk) => {
|
|
61
|
+
stdout += chunk;
|
|
62
|
+
buffer += chunk;
|
|
63
|
+
let i;
|
|
64
|
+
while ((i = buffer.indexOf('\n')) >= 0) {
|
|
65
|
+
handle(buffer.slice(0, i));
|
|
66
|
+
buffer = buffer.slice(i + 1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
70
|
+
child.on('error', (err) => reject(new OmnisnapError(`cannot run ${binary}: ${err.message}`, { args })));
|
|
71
|
+
child.on('close', (code) => {
|
|
72
|
+
handle(buffer); // a last line without a newline
|
|
73
|
+
if (code !== 0) {
|
|
74
|
+
reject(new OmnisnapError(`omnisnap ${args.join(' ')} exited ${code}: ${stderr.trim()}`, { code, stderr, args }));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
resolvePromise({ code, stdout, stderr, done: resultLine });
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Normalise the API's page list to the job schema. */
|
|
83
|
+
function jobOf({ pages, engines, baseline, runs, viewport, timeouts, probes, fontParity }) {
|
|
84
|
+
const out = { pages: [] };
|
|
85
|
+
for (const p of pages || []) out.pages.push(typeof p === 'string' ? { url: p } : { ...p });
|
|
86
|
+
if (engines && engines.length) out.engines = engines;
|
|
87
|
+
if (baseline) out.baseline = baseline;
|
|
88
|
+
if (runs) out.runs = runs;
|
|
89
|
+
if (viewport) out.viewport = viewport;
|
|
90
|
+
if (timeouts) out.timeouts = timeouts;
|
|
91
|
+
if (probes !== undefined) out.probes = probes;
|
|
92
|
+
if (fontParity !== undefined) out.fontParity = fontParity;
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Capture and compare a job; returns the parsed summary.json. */
|
|
97
|
+
export async function run(options = {}) {
|
|
98
|
+
if (!options.pages || !options.pages.length) throw new OmnisnapError('run() needs at least one page', {});
|
|
99
|
+
const out = resolve(options.out || './omnisnap-out');
|
|
100
|
+
mkdirSync(out, { recursive: true });
|
|
101
|
+
const jobPath = join(out, 'omnisnap-job.json');
|
|
102
|
+
writeFileSync(jobPath, JSON.stringify(jobOf(options), null, 1));
|
|
103
|
+
const args = ['run', jobPath, '--json', '--out', out];
|
|
104
|
+
// A planted or test page is small by design: below 50 elements the binary
|
|
105
|
+
// takes it for a bot wall unless told otherwise (`--allow-small-pages`).
|
|
106
|
+
if (options.allowSmallPages) args.push('--allow-small-pages');
|
|
107
|
+
await runBinary(args, { onProgress: options.onProgress, cwd: options.cwd });
|
|
108
|
+
return JSON.parse(readFileSync(join(out, 'summary.json'), 'utf8'));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The installed browsers, as `omnisnap browsers --json` (a JSON array). */
|
|
112
|
+
export async function browsers() {
|
|
113
|
+
const { stdout } = await runBinary(['browsers', '--json']);
|
|
114
|
+
return JSON.parse(stdout);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Merge bundles; returns the merged summary. */
|
|
118
|
+
export async function merge(bundles, out, { onProgress } = {}) {
|
|
119
|
+
if (!bundles || !bundles.length) throw new OmnisnapError('merge() needs bundle directories', {});
|
|
120
|
+
const dest = resolve(out);
|
|
121
|
+
await runBinary(['merge', ...bundles.map((b) => resolve(b)), '-o', dest], { onProgress });
|
|
122
|
+
return JSON.parse(readFileSync(join(dest, 'summary.json'), 'utf8'));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Re-render a bundle's report.html; returns its path. */
|
|
126
|
+
export async function report(bundle) {
|
|
127
|
+
const dir = resolve(bundle);
|
|
128
|
+
await runBinary(['report', dir]);
|
|
129
|
+
return join(dir, 'report.html');
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "omnisnap",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.1.0-rc.2",
|
|
4
|
+
"description": "Cross-engine layout differences from one command; see exactly which elements render differently in every browser you have installed",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": { "types": "./index.d.ts", "import": "./index.js" }
|
|
10
|
+
},
|
|
11
|
+
"bin": { "omnisnap": "bin/omnisnap.js" },
|
|
12
|
+
"files": ["index.js", "index.d.ts", "bin/", "README.md"],
|
|
13
|
+
"engines": { "node": ">=20" },
|
|
14
|
+
"optionalDependencies": {
|
|
15
|
+
"@omnisnap/linux-x64": "0.1.0-rc.2",
|
|
16
|
+
"@omnisnap/linux-arm64": "0.1.0-rc.2",
|
|
17
|
+
"@omnisnap/darwin-x64": "0.1.0-rc.2",
|
|
18
|
+
"@omnisnap/darwin-arm64": "0.1.0-rc.2",
|
|
19
|
+
"@omnisnap/win32-x64": "0.1.0-rc.2"
|
|
20
|
+
},
|
|
21
|
+
"scripts": { "test": "node --test \"test/*.test.mjs\"" },
|
|
22
|
+
"license": "AGPL-3.0-or-later"
|
|
7
23
|
}
|