design-spine 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +136 -2
- package/bin/resolve-bun.d.ts +23 -0
- package/bin/resolve-bun.js +66 -0
- package/bin/spine.js +27 -0
- package/package.json +67 -3
- package/src/assets.d.ts +13 -0
- package/src/cli.ts +638 -0
- package/src/lib/blank.ts +34 -0
- package/src/lib/capture.ts +585 -0
- package/src/lib/comparison-worker.ts +25 -0
- package/src/lib/comparison.ts +190 -0
- package/src/lib/critique-run.ts +185 -0
- package/src/lib/critique.ts +119 -0
- package/src/lib/diff.ts +73 -0
- package/src/lib/docker.ts +196 -0
- package/src/lib/doctor.ts +22 -0
- package/src/lib/gate.ts +61 -0
- package/src/lib/history.ts +28 -0
- package/src/lib/lint.ts +129 -0
- package/src/lib/manifest.ts +211 -0
- package/src/lib/names.ts +41 -0
- package/src/lib/report.ts +53 -0
- package/src/lib/review.ts +26 -0
- package/src/lib/routes.ts +178 -0
- package/src/lib/runs.ts +163 -0
- package/src/lib/server.ts +226 -0
- package/src/lib/summary.ts +70 -0
- package/src/lib/types.ts +151 -0
- package/src/ui/index.html +42 -0
- package/src/ui/review.css +1313 -0
- package/src/ui/review.js +1575 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Elizabeth Stein
|
|
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
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Design Spine
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Look at every screen before you ship it.
|
|
4
|
+
|
|
5
|
+
Design Spine screenshots every route of your Next.js app in every state, width and theme, flags what broke, and gives you one contact sheet to approve or reject each screen. Approved screens become baselines, and `spine diff` fails CI when a screen drifts from what a person approved.
|
|
6
|
+
|
|
7
|
+
Everything runs on your machine. No account, no upload, no per-snapshot bill.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Why
|
|
12
|
+
|
|
13
|
+
Most UI gets built and checked in one state: the happy path, at desktop width, in light mode. AI coding agents make this worse, because they build screen by screen and never open the 390px dark-mode empty state. Design Spine makes the full matrix visible and makes "someone looked at it" a recorded fact instead of a hope.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
Requires a running copy of your app. The CLI runs on [Bun](https://bun.sh), which the npm install bundles, so you do not install it yourself. A Bun 1.3+ already on your PATH is used first.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -D design-spine
|
|
21
|
+
npx playwright install chromium
|
|
22
|
+
|
|
23
|
+
npx spine plan # reads app/ and drafts design-spine.json
|
|
24
|
+
npx spine capture # screenshots route x state x 390/1280 x light/dark
|
|
25
|
+
npx spine review # opens the contact sheet at http://localhost:4747
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
In the contact sheet, press `j`/`k` to move, `a` to approve, `r` to reject and `Enter` to inspect a screenshot at full size against its baseline.
|
|
29
|
+
|
|
30
|
+
## What it checks on every screenshot
|
|
31
|
+
|
|
32
|
+
- HTTP errors, redirects and failed captures
|
|
33
|
+
- Console errors and uncaught page errors
|
|
34
|
+
- Horizontal overflow (the classic mobile bug)
|
|
35
|
+
- Near-blank regions, such as cards that rendered empty
|
|
36
|
+
- Broken images and clipped text
|
|
37
|
+
- Fixed overlays covering content, such as cookie banners and chat widgets
|
|
38
|
+
- Optional: axe accessibility scan, repeat-capture stability, and a Claude vision critique
|
|
39
|
+
|
|
40
|
+
Automatic checks never count as approval. Only a person approves.
|
|
41
|
+
|
|
42
|
+
## Reach the states nobody opens
|
|
43
|
+
|
|
44
|
+
Empty, loading and error states need data. Describe them in `design-spine.json` with mocked responses and interaction steps instead of seeding a database:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"path": "/dashboard",
|
|
49
|
+
"states": [
|
|
50
|
+
{ "name": "ideal", "storageState": "auth/populated.json" },
|
|
51
|
+
{
|
|
52
|
+
"name": "error",
|
|
53
|
+
"responses": [{ "url": "**/api/dashboard", "status": 503, "body": "Unavailable" }],
|
|
54
|
+
"ready": { "selector": "[role=alert]" }
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`spine doctor` lists every state you have not made capturable yet, so missing coverage stays visible instead of silently passing.
|
|
61
|
+
|
|
62
|
+
## Gate CI on approved screens
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
spine approve # approved tiles become baselines
|
|
66
|
+
spine diff # exit 1 when a screen differs from its approved baseline
|
|
67
|
+
spine diff --strict # also require full coverage and a person's approval on this run
|
|
68
|
+
spine report --out review.html # portable offline record of what was approved and why
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
In CI, add the action after the step that starts your app, and commit `design-spine.json` and `.design-spine/baselines/`:
|
|
72
|
+
|
|
73
|
+
```yaml
|
|
74
|
+
- run: npm run build && (npm start &) && npx wait-on http://localhost:3000
|
|
75
|
+
- uses: forbiddenlink/design-spine@v0.2.0
|
|
76
|
+
with:
|
|
77
|
+
base-url: http://localhost:3000
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The job fails when any screen changes from its approved baseline. The action writes a pass/fail summary with a table of changed tiles to the job summary, and uploads two artifacts: `design-spine-run` (the captures) and `design-spine-report` (a single offline HTML file with the screenshots). Reviewers open the report instead of unzipping the run.
|
|
81
|
+
|
|
82
|
+
To also post that summary on the pull request, set `comment: "true"` and grant the job write access to pull requests. The action keeps one comment, marked `<!-- design-spine -->`, and edits it on each push:
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
permissions:
|
|
86
|
+
contents: read
|
|
87
|
+
pull-requests: write
|
|
88
|
+
steps:
|
|
89
|
+
- uses: forbiddenlink/design-spine@v0.2.0
|
|
90
|
+
with:
|
|
91
|
+
comment: "true"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Comments are skipped outside `pull_request` events. On pull requests from forks the token is read-only, so the comment step fails without failing the job. The job summary still appears.
|
|
95
|
+
|
|
96
|
+
To accept a change, download the artifact into `.design-spine/runs/`, run `spine review --run <id>`, approve, then `spine approve --run <id>` and commit the new baselines. Fonts render differently on macOS and Linux. Capture with `spine capture --docker` and approve those baselines; the action also captures in that image by default, so the two match pixel for pixel. The first run builds a local image, and amd64 emulation on Apple silicon is slower. See [Matching CI baselines](docs/USAGE.md#matching-ci-baselines).
|
|
97
|
+
|
|
98
|
+
Upgrading from v0.1.0: that version captured with the runner's own Chromium and fonts. Baselines approved from those runs differ from docker captures, so either approve new baselines from a `--docker` capture, or keep the old behavior with `docker: "false"`.
|
|
99
|
+
|
|
100
|
+
## Commands
|
|
101
|
+
|
|
102
|
+
| Command | What it does |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `plan` | Drafts `design-spine.json` from `app/` or `src/app/` |
|
|
105
|
+
| `doctor` | Validates the manifest and lists unfinished coverage, without a browser |
|
|
106
|
+
| `capture` | Screenshots every route x state x viewport x theme and runs the checks |
|
|
107
|
+
| `review` | Local contact sheet for approve, reject and notes |
|
|
108
|
+
| `critique` | Optional Claude vision pass through the `claude` CLI |
|
|
109
|
+
| `approve` | Promotes approved tiles to baselines |
|
|
110
|
+
| `diff` | Compares a run with baselines; `--strict` requires complete approved evidence |
|
|
111
|
+
| `report` | Self-contained HTML record of a review |
|
|
112
|
+
| `lint` | Ratchet on arbitrary Tailwind values such as `w-[37px]` |
|
|
113
|
+
| `status` | Writes `.design-spine/status.json` for dashboards |
|
|
114
|
+
|
|
115
|
+
Full reference: [docs/USAGE.md](docs/USAGE.md).
|
|
116
|
+
|
|
117
|
+
## How it compares
|
|
118
|
+
|
|
119
|
+
| | Design Spine | Chromatic, Percy, Argos | Playwright `toHaveScreenshot` |
|
|
120
|
+
|---|---|---|---|
|
|
121
|
+
| Screenshots stay on your machine | Yes | No, uploaded to a hosted service | Yes |
|
|
122
|
+
| Plans the route x state matrix from your app | Yes | No, captures the stories or tests you write | No |
|
|
123
|
+
| Human approval per screenshot | Yes, local review UI | Yes, in the vendor's web app | No, `--update-snapshots` accepts all at once |
|
|
124
|
+
| Needs an account | No | Yes | No |
|
|
125
|
+
| Pricing | Free, MIT | Free tier, then billed per screenshot | Free |
|
|
126
|
+
|
|
127
|
+
Checked 2026-10-18 against each vendor's docs and pricing pages. Argos is open source; Chromatic works with Storybook, Vitest, Playwright and Cypress.
|
|
128
|
+
|
|
129
|
+
## Limits
|
|
130
|
+
|
|
131
|
+
- Next.js App Router only for `plan`. Other apps can write the manifest by hand.
|
|
132
|
+
- Chromium only. Tested on macOS, and the test suite runs on Linux in CI. Windows is not verified.
|
|
133
|
+
- The CLI runs on Bun. The npm package bundles Bun 1.3.13 for macOS, Linux and Windows on x64 and arm64; other platforms need Bun 1.3+ installed. `--docker` also needs Docker and downloads a 2.6 GB image once.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const MIN_MAJOR: number
|
|
2
|
+
export const MIN_MINOR: number
|
|
3
|
+
export function satisfiesMinimum(versionText: string): boolean
|
|
4
|
+
export function platformPackage(target: {
|
|
5
|
+
platform: string
|
|
6
|
+
arch: string
|
|
7
|
+
musl?: boolean
|
|
8
|
+
}): string | undefined
|
|
9
|
+
export function bundledBunPath(options?: {
|
|
10
|
+
platform?: string
|
|
11
|
+
arch?: string
|
|
12
|
+
musl?: boolean
|
|
13
|
+
resolve?: (id: string) => string
|
|
14
|
+
exists?: (path: string) => boolean
|
|
15
|
+
}): string | undefined
|
|
16
|
+
export function resolveBun(options?: {
|
|
17
|
+
run?: (
|
|
18
|
+
command: string,
|
|
19
|
+
args: string[],
|
|
20
|
+
options: { encoding: 'utf8' },
|
|
21
|
+
) => { error?: Error; status: number | null; stdout?: string | null }
|
|
22
|
+
bundled?: () => string | undefined
|
|
23
|
+
}): string | undefined
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Finds a Bun >= 1.3: one on PATH first, else the binary from the bundled @oven/bun-<platform> package.
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
export const MIN_MAJOR = 1
|
|
8
|
+
export const MIN_MINOR = 3
|
|
9
|
+
|
|
10
|
+
export function satisfiesMinimum(versionText) {
|
|
11
|
+
const [major = 0, minor = 0] = String(versionText).trim().split('.').map(Number)
|
|
12
|
+
return major > MIN_MAJOR || (major === MIN_MAJOR && minor >= MIN_MINOR)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Maps node's platform/arch to the @oven/bun-* package that holds the real binary.
|
|
16
|
+
export function platformPackage({ platform, arch, musl = false }) {
|
|
17
|
+
const cpu = { x64: 'x64', arm64: 'aarch64' }[arch]
|
|
18
|
+
const os = { darwin: 'darwin', linux: 'linux', win32: 'windows' }[platform]
|
|
19
|
+
if (!cpu || !os) return undefined
|
|
20
|
+
return `@oven/bun-${os}-${cpu}${os === 'linux' && musl ? '-musl' : ''}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isMusl() {
|
|
24
|
+
if (process.platform !== 'linux') return false
|
|
25
|
+
try {
|
|
26
|
+
return !process.report.getReport().header.glibcVersionRuntime
|
|
27
|
+
} catch {
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Oven's `bun` package ships a stub bin until its postinstall runs, which pnpm 12 and
|
|
33
|
+
// --ignore-scripts skip, and pnpm 12 fails the whole install over that script. So we depend on
|
|
34
|
+
// the script-free platform packages directly; they carry the real binary.
|
|
35
|
+
export function bundledBunPath({
|
|
36
|
+
platform = process.platform,
|
|
37
|
+
arch = process.arch,
|
|
38
|
+
musl = isMusl(),
|
|
39
|
+
resolve = createRequire(import.meta.url).resolve,
|
|
40
|
+
exists = existsSync,
|
|
41
|
+
} = {}) {
|
|
42
|
+
const name = platformPackage({ platform, arch, musl })
|
|
43
|
+
if (!name) return undefined
|
|
44
|
+
try {
|
|
45
|
+
const pkgDir = dirname(resolve(`${name}/package.json`))
|
|
46
|
+
const file = join(pkgDir, 'bin', platform === 'win32' ? 'bun.exe' : 'bun')
|
|
47
|
+
return exists(file) ? file : undefined
|
|
48
|
+
} catch {
|
|
49
|
+
return undefined
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function bunVersion(command, run) {
|
|
54
|
+
const result = run(command, ['--version'], { encoding: 'utf8' })
|
|
55
|
+
if (result.error || result.status !== 0) return undefined
|
|
56
|
+
return result.stdout ?? ''
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Returns the command to run Bun with, or undefined when no usable Bun exists.
|
|
60
|
+
export function resolveBun({ run = spawnSync, bundled = bundledBunPath } = {}) {
|
|
61
|
+
const onPath = bunVersion('bun', run)
|
|
62
|
+
if (onPath !== undefined && satisfiesMinimum(onPath)) return 'bun'
|
|
63
|
+
const file = bundled()
|
|
64
|
+
if (file && satisfiesMinimum(bunVersion(file, run) ?? '')) return file
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
package/bin/spine.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Thin launcher: Design Spine needs Bun (HTML imports, Bun.serve), so hand off to it.
|
|
3
|
+
import { spawn } from 'node:child_process'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { resolveBun } from './resolve-bun.js'
|
|
6
|
+
|
|
7
|
+
const MESSAGE = 'Design Spine runs on Bun 1.3+. Install: curl -fsSL https://bun.sh/install | bash'
|
|
8
|
+
const cli = fileURLToPath(new URL('../src/cli.ts', import.meta.url))
|
|
9
|
+
const bun = resolveBun()
|
|
10
|
+
if (!bun) {
|
|
11
|
+
console.error(MESSAGE)
|
|
12
|
+
process.exit(1)
|
|
13
|
+
}
|
|
14
|
+
const child = spawn(bun, [cli, ...process.argv.slice(2)], { stdio: 'inherit' })
|
|
15
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) process.on(signal, () => child.kill(signal))
|
|
16
|
+
child.on('error', () => {
|
|
17
|
+
console.error(MESSAGE)
|
|
18
|
+
process.exit(1)
|
|
19
|
+
})
|
|
20
|
+
child.on('exit', (code, signal) => {
|
|
21
|
+
if (signal) {
|
|
22
|
+
process.removeAllListeners(signal)
|
|
23
|
+
process.kill(process.pid, signal)
|
|
24
|
+
} else {
|
|
25
|
+
process.exit(code ?? 1)
|
|
26
|
+
}
|
|
27
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "design-spine",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Screenshot every route and state of your Next.js app, then approve each screen by eye. Local, no account.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Elizabeth Stein",
|
|
7
|
+
"homepage": "https://github.com/forbiddenlink/design-spine#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/forbiddenlink/design-spine.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/forbiddenlink/design-spine/issues",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"visual-regression",
|
|
15
|
+
"screenshot",
|
|
16
|
+
"nextjs",
|
|
17
|
+
"playwright",
|
|
18
|
+
"design-review",
|
|
19
|
+
"ui-testing",
|
|
20
|
+
"cli",
|
|
21
|
+
"claude-code"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"bin/",
|
|
25
|
+
"src/",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=22.12",
|
|
31
|
+
"bun": ">=1.3.13"
|
|
32
|
+
},
|
|
33
|
+
"type": "module",
|
|
34
|
+
"bin": {
|
|
35
|
+
"spine": "bin/spine.js"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@axe-core/playwright": "^4.13.0",
|
|
39
|
+
"commander": "^15.0.0",
|
|
40
|
+
"pixelmatch": "^7.2.0",
|
|
41
|
+
"playwright": "^1.63.0",
|
|
42
|
+
"pngjs": "^7.0.0"
|
|
43
|
+
},
|
|
44
|
+
"optionalDependencies": {
|
|
45
|
+
"@oven/bun-darwin-aarch64": "1.3.13",
|
|
46
|
+
"@oven/bun-darwin-x64": "1.3.13",
|
|
47
|
+
"@oven/bun-linux-aarch64": "1.3.13",
|
|
48
|
+
"@oven/bun-linux-aarch64-musl": "1.3.13",
|
|
49
|
+
"@oven/bun-linux-x64": "1.3.13",
|
|
50
|
+
"@oven/bun-linux-x64-musl": "1.3.13",
|
|
51
|
+
"@oven/bun-windows-aarch64": "1.3.13",
|
|
52
|
+
"@oven/bun-windows-x64": "1.3.13"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@biomejs/biome": "^2.5.15",
|
|
56
|
+
"@types/bun": "^1.4.2",
|
|
57
|
+
"@types/pngjs": "^6.0.5",
|
|
58
|
+
"typescript": "^7.0.2",
|
|
59
|
+
"vitest": "^5.0.3"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "bun build --compile src/cli.ts src/lib/comparison-worker.ts --external 'chromium-bidi/*' --external electron --define 'import.meta.spineWorker=\"./lib/comparison-worker.js\"' --outfile dist/spine",
|
|
63
|
+
"spine": "bun src/cli.ts",
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:visual": "bun scripts/visual-tests.ts",
|
|
66
|
+
"test:visual:update": "bun scripts/visual-tests.ts --update",
|
|
67
|
+
"lint": "biome check .",
|
|
68
|
+
"format": "biome format --write ."
|
|
69
|
+
}
|
|
6
70
|
}
|