afterbefore 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 Kai Revicius
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,122 @@
1
+ # afterbefore
2
+
3
+ Automatic before/after screenshot capture for pull requests. **The git diff is the config.**
4
+
5
+ Change code, run one command, get a visual comparison. No config files, no manual URL lists, no SaaS — `afterbefore` reads your diff, walks the import graph, and captures both versions automatically.
6
+
7
+ ```bash
8
+ npx afterbefore
9
+ ```
10
+
11
+ ## The Problem
12
+
13
+ Visual PR reviews are painful:
14
+
15
+ 1. Switch to main, start the app, take screenshots
16
+ 2. Switch back to your branch, start the app, take more screenshots
17
+ 3. Crop, label, and paste into the PR description
18
+
19
+ This takes 5-10 minutes. Most developers skip it. Reviewers approve visual changes blind.
20
+
21
+ ## How It Works
22
+
23
+ ```
24
+ git diff → classify changed files → build import graph → BFS to find affected pages
25
+ → git worktree for base version → start 2 dev servers → Playwright capture
26
+ → pixelmatch diff → side-by-side comparison → HTML report + PR comment
27
+ ```
28
+
29
+ 1. **Diff** — reads `git diff --name-status` to find changed files
30
+ 2. **Classify** — categorizes as page, component, style, layout, utility, config, test
31
+ 3. **Import graph** — parses all imports with `es-module-lexer`, resolves `@/` tsconfig aliases
32
+ 4. **Impact analysis** — BFS traverses the reverse import graph (depth 3) to find affected pages
33
+ 5. **Worktree** — creates a git worktree for the base branch, installs deps
34
+ 6. **Dev servers** — starts two Next.js dev servers (before + after) on random ports
35
+ 7. **Capture** — Playwright takes full-page screenshots at 1280x720 for each affected route
36
+ 8. **Compare** — pixelmatch detects pixel-level differences, sharp generates side-by-side images
37
+ 9. **Report** — HTML card grid, drag-to-compare sliders, markdown summary, optional PR comment
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ # npm
43
+ npm install --save-dev afterbefore
44
+
45
+ # From GitHub (builds automatically on install)
46
+ npm install --save-dev github:kairevicius/afterbefore
47
+
48
+ # Or run directly without installing
49
+ npx afterbefore
50
+ ```
51
+
52
+ Playwright's Chromium browser is required for screenshots:
53
+
54
+ ```bash
55
+ npx playwright install chromium
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ ```bash
61
+ # Compare current branch against main
62
+ npx afterbefore
63
+
64
+ # Compare against a different base
65
+ npx afterbefore --base develop
66
+
67
+ # Capture and post results to the open PR
68
+ npx afterbefore --post
69
+ ```
70
+
71
+ ### Options
72
+
73
+ | Flag | Description | Default |
74
+ |------|-------------|---------|
75
+ | `--base <ref>` | Base branch or ref to compare against | `main` |
76
+ | `--output <dir>` | Output directory | `.afterbefore` |
77
+ | `--post` | Post results as a PR comment via `gh` CLI | `false` |
78
+
79
+ ## Output
80
+
81
+ ```
82
+ .afterbefore/
83
+ summary.md Markdown table (for PR comments)
84
+ index.html HTML report with card grid
85
+ _root/
86
+ before.png Screenshot of / on base branch
87
+ after.png Screenshot of / on current branch
88
+ diff.png Pixel diff overlay
89
+ side-by-side.png Labeled comparison image
90
+ slider.html Interactive drag-to-compare
91
+ about/
92
+ before.png
93
+ after.png
94
+ diff.png
95
+ side-by-side.png
96
+ slider.html
97
+ ```
98
+
99
+ Open `index.html` in a browser to see all comparisons at a glance. Each changed route gets a card with before/after/diff images and a link to the interactive slider.
100
+
101
+ ## Requirements
102
+
103
+ - Node.js 18+
104
+ - Git
105
+ - Next.js project using the app router
106
+ - Playwright Chromium (`npx playwright install chromium`)
107
+
108
+ ## How It's Different
109
+
110
+ Every visual regression tool either captures everything on every run (Chromatic, Lost Pixel) or requires manual URL configuration (Percy, BackstopJS). `afterbefore` is the only tool that figures out what to capture from the code diff.
111
+
112
+ | | Visual regression tools | afterbefore |
113
+ |---|---|---|
114
+ | Config | URL lists, story lists | Zero — reads git diff |
115
+ | Scope | Everything, every run | Only affected pages |
116
+ | Philosophy | "Did anything break?" | "Here's what changed" |
117
+ | Hosting | Cloud SaaS | Local, nothing leaves your machine |
118
+ | Cost | Per-snapshot pricing | Free, open source |
119
+
120
+ ## License
121
+
122
+ MIT