afterbefore 0.1.1 → 0.1.3
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 +143 -21
- package/README.md +81 -95
- package/dist/cli.js +2 -2
- package/dist/index.js +1 -1
- package/package.json +2 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
PolyForm Shield License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/shield/1.0.0>
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2026 Paulius Kairevicius
|
|
6
|
+
|
|
7
|
+
Acceptance
|
|
8
|
+
|
|
9
|
+
In order to get any license under these terms, you must agree to them as
|
|
10
|
+
both strict obligations and conditions to all your licenses.
|
|
11
|
+
|
|
12
|
+
Copyright License
|
|
13
|
+
|
|
14
|
+
The licensor grants you a copyright license for the software to do
|
|
15
|
+
everything you might do with the software that would otherwise infringe
|
|
16
|
+
the licensor's copyright in it for any permitted purpose. However, you
|
|
17
|
+
may only distribute the software according to Distribution License and
|
|
18
|
+
make changes or new works based on the software according to Changes and
|
|
19
|
+
New Works License.
|
|
20
|
+
|
|
21
|
+
Distribution License
|
|
22
|
+
|
|
23
|
+
The licensor grants you an additional copyright license to distribute
|
|
24
|
+
copies of the software. Your license to distribute covers distributing
|
|
25
|
+
the software with changes and new works permitted by Changes and New
|
|
26
|
+
Works License.
|
|
27
|
+
|
|
28
|
+
Notices
|
|
29
|
+
|
|
30
|
+
You must ensure that anyone who gets a copy of any part of the software
|
|
31
|
+
from you also gets a copy of these terms or the URL for them above, as
|
|
32
|
+
well as copies of any plain-text lines beginning with "Required Notice:"
|
|
33
|
+
that the licensor provided with the software.
|
|
34
|
+
|
|
35
|
+
Changes and New Works License
|
|
36
|
+
|
|
37
|
+
The licensor grants you an additional copyright license to make changes
|
|
38
|
+
and new works based on the software for any permitted purpose.
|
|
39
|
+
|
|
40
|
+
Patent License
|
|
41
|
+
|
|
42
|
+
The licensor grants you a patent license for the software that covers
|
|
43
|
+
patent claims the licensor can license, or becomes able to license, that
|
|
44
|
+
you would infringe by using the software.
|
|
45
|
+
|
|
46
|
+
Noncompete
|
|
47
|
+
|
|
48
|
+
Any purpose is a permitted purpose, except for providing any product
|
|
49
|
+
that competes with the software or any product the licensor or any of
|
|
50
|
+
its affiliates provides using the software.
|
|
51
|
+
|
|
52
|
+
Competition
|
|
53
|
+
|
|
54
|
+
Goods and services compete even when they provide functionality through
|
|
55
|
+
different kinds of interfaces or for different technical platforms.
|
|
56
|
+
Applications can compete with services, libraries with plugins,
|
|
57
|
+
frameworks with development tools, and so on, even if they're written in
|
|
58
|
+
different programming languages or for different computer architectures.
|
|
59
|
+
Goods and services compete even when provided free of charge. If you
|
|
60
|
+
market a product as a practical substitute for the software or another
|
|
61
|
+
product, it definitely competes.
|
|
62
|
+
|
|
63
|
+
New Products
|
|
64
|
+
|
|
65
|
+
If you are using the software to provide a product that does not
|
|
66
|
+
compete, but the licensor or any of its affiliates brings your product
|
|
67
|
+
into competition by providing a new version of the software or another
|
|
68
|
+
product using the software, you may continue using versions of the
|
|
69
|
+
software available under these terms beforehand to provide your
|
|
70
|
+
competing product, but not any later versions.
|
|
71
|
+
|
|
72
|
+
Discontinued Products
|
|
73
|
+
|
|
74
|
+
You may begin using the software to compete with a product or service
|
|
75
|
+
that the licensor or any of its affiliates has stopped providing, unless
|
|
76
|
+
the licensor includes a plain-text line beginning with "Licensor Line of
|
|
77
|
+
Business:" with the software that mentions that line of business.
|
|
78
|
+
|
|
79
|
+
Sales of Business
|
|
80
|
+
|
|
81
|
+
If the licensor or any of its affiliates sells a line of business
|
|
82
|
+
developing the software or using the software to provide a product, the
|
|
83
|
+
buyer can also enforce Noncompete for that product.
|
|
84
|
+
|
|
85
|
+
Fair Use
|
|
86
|
+
|
|
87
|
+
You may have "fair use" rights for the software under the law. These
|
|
88
|
+
terms do not limit them.
|
|
89
|
+
|
|
90
|
+
No Other Rights
|
|
91
|
+
|
|
92
|
+
These terms do not allow you to sublicense or transfer any of your
|
|
93
|
+
licenses to anyone else, or prevent the licensor from granting licenses
|
|
94
|
+
to anyone else. These terms do not imply any other licenses.
|
|
95
|
+
|
|
96
|
+
Patent Defense
|
|
97
|
+
|
|
98
|
+
If you make any written claim that the software infringes or contributes
|
|
99
|
+
to infringement of any patent, your patent license for the software
|
|
100
|
+
granted under these terms ends immediately. If your company makes such a
|
|
101
|
+
claim, your patent license ends immediately for work on behalf of your
|
|
102
|
+
company.
|
|
103
|
+
|
|
104
|
+
Violations
|
|
105
|
+
|
|
106
|
+
The first time you are notified in writing that you have violated any of
|
|
107
|
+
these terms, or done anything with the software not covered by your
|
|
108
|
+
licenses, your licenses can nonetheless continue if you come into full
|
|
109
|
+
compliance with these terms, and take practical steps to correct past
|
|
110
|
+
violations, within 32 days of receiving notice. Otherwise, all your
|
|
111
|
+
licenses end immediately.
|
|
112
|
+
|
|
113
|
+
No Liability
|
|
114
|
+
|
|
115
|
+
As far as the law allows, the software comes as is, without any warranty
|
|
116
|
+
or condition, and the licensor will not be liable to you for any damages
|
|
117
|
+
arising out of these terms or the use or nature of the software, under
|
|
118
|
+
any kind of legal claim.
|
|
119
|
+
|
|
120
|
+
Definitions
|
|
121
|
+
|
|
122
|
+
The licensor is the individual or entity offering these terms, and the
|
|
123
|
+
software is the software the licensor makes available under these terms.
|
|
124
|
+
|
|
125
|
+
A product can be a good or service, or a combination of them.
|
|
126
|
+
|
|
127
|
+
You refers to the individual or entity agreeing to these terms.
|
|
128
|
+
|
|
129
|
+
Your company is any legal entity, sole proprietorship, or other kind of
|
|
130
|
+
organization that you work for, plus all its affiliates.
|
|
131
|
+
|
|
132
|
+
Affiliates means the other organizations than an organization has
|
|
133
|
+
control over, is under the control of, or is under common control with.
|
|
134
|
+
|
|
135
|
+
Control means ownership of substantially all the assets of an entity, or
|
|
136
|
+
the power to direct its management and policies by vote, contract, or
|
|
137
|
+
otherwise. Control can be direct or indirect.
|
|
138
|
+
|
|
139
|
+
Your licenses are all the licenses granted to you for the software under
|
|
140
|
+
these terms.
|
|
141
|
+
|
|
142
|
+
Use means anything you do with the software requiring one of your
|
|
143
|
+
licenses.
|
package/README.md
CHANGED
|
@@ -1,141 +1,127 @@
|
|
|
1
1
|
# afterbefore
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/afterbefore)
|
|
4
|
-
[](https://www.npmjs.com/package/afterbefore)
|
|
3
|
+
[](https://www.npmjs.com/package/afterbefore)
|
|
4
|
+
[](https://www.npmjs.com/package/afterbefore)
|
|
5
5
|
|
|
6
|
-
Automatic before/after screenshot capture for Next.js pull requests.
|
|
6
|
+
Automatic before/after screenshot capture for Next.js pull requests.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## The idea
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
npx afterbefore
|
|
12
|
-
```
|
|
10
|
+
Other visual regression tools make you list which URLs to capture. afterbefore reads your git diff instead, builds an import graph, and figures out which routes were affected by your changes. You change a button component, it finds every page that uses that button, and captures those. No URL lists, no config.
|
|
13
11
|
|
|
14
|
-
##
|
|
12
|
+
## Quick start
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
2. Builds an import graph and finds affected `app/**/page.*` routes
|
|
18
|
-
3. Handles layout/global style changes that are not direct imports
|
|
19
|
-
4. Creates a temporary git worktree for the base ref
|
|
20
|
-
5. Starts two Next.js dev servers (before + after)
|
|
21
|
-
6. Captures screenshots with Playwright
|
|
22
|
-
7. Computes pixel diffs with `pixelmatch`
|
|
23
|
-
8. Generates:
|
|
24
|
-
- `index.html` visual report
|
|
25
|
-
- per-route slider pages for changed routes
|
|
26
|
-
- `summary.md` for PR comments
|
|
27
|
-
9. Optionally posts/updates a GitHub PR comment (`--post`)
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
14
|
+
Run it from a feature branch in any Next.js app router project:
|
|
30
15
|
|
|
31
16
|
```bash
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
npx afterbefore
|
|
18
|
+
```
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
npm install --save-dev github:kairevicius/afterbefore
|
|
20
|
+
It spins up two dev servers (your branch and the base branch), captures screenshots of affected routes, diffs them pixel by pixel, and generates an HTML report with interactive before/after sliders.
|
|
37
21
|
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
Output lands in `.afterbefore/`:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
.afterbefore/
|
|
26
|
+
└── feature-branch_2026-02-26/
|
|
27
|
+
├── index.html # visual report
|
|
28
|
+
├── summary.md # markdown table
|
|
29
|
+
├── about-before.png
|
|
30
|
+
├── about-after.png
|
|
31
|
+
├── about-diff.png
|
|
32
|
+
├── about-compare.png
|
|
33
|
+
└── about-slider.html # interactive slider
|
|
40
34
|
```
|
|
41
35
|
|
|
42
|
-
|
|
36
|
+
Open the report automatically:
|
|
43
37
|
|
|
44
38
|
```bash
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
npx afterbefore --open
|
|
40
|
+
```
|
|
47
41
|
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
## How it works
|
|
43
|
+
|
|
44
|
+
1. Reads `git diff` to find changed files
|
|
45
|
+
2. Classifies each file (page, component, layout, style, utility, config)
|
|
46
|
+
3. Builds an import graph by parsing ES module imports across your codebase
|
|
47
|
+
4. Walks the graph backward from each changed file to find which `page.tsx` files are affected
|
|
48
|
+
5. Creates a git worktree for the base branch and runs `npm install`
|
|
49
|
+
6. Starts two Next.js dev servers in parallel (base branch + current branch)
|
|
50
|
+
7. Captures full-page screenshots of each affected route on both servers using Playwright
|
|
51
|
+
8. Compares screenshots with pixelmatch and generates diff images
|
|
52
|
+
9. Builds an HTML report with side-by-side comparisons and interactive sliders
|
|
53
|
+
|
|
54
|
+
Layouts work the same way. Edit `app/dashboard/layout.tsx` and it captures every page under `app/dashboard/`.
|
|
55
|
+
|
|
56
|
+
If only global files changed (like `globals.css` or `tailwind.config.ts`) and no specific routes were found, it captures all pages.
|
|
57
|
+
|
|
58
|
+
## Options
|
|
59
|
+
|
|
60
|
+
| Flag | Default | Description |
|
|
61
|
+
|------|---------|-------------|
|
|
62
|
+
| `--base <ref>` | `main` | Base branch to compare against |
|
|
63
|
+
| `--output <dir>` | `.afterbefore` | Output directory |
|
|
64
|
+
| `--post` | `false` | Post results as a GitHub PR comment |
|
|
65
|
+
| `--threshold <percent>` | `0.1` | Ignore diffs below this percentage |
|
|
66
|
+
| `--max-routes <count>` | `6` | Cap the number of routes captured (0 = unlimited) |
|
|
67
|
+
| `--open` | `false` | Open the HTML report in your browser |
|
|
68
|
+
| `--width <pixels>` | `1280` | Viewport width |
|
|
69
|
+
| `--height <pixels>` | `720` | Viewport height |
|
|
70
|
+
| `--device <name>` | — | Playwright device, e.g. `"iPhone 14"` |
|
|
71
|
+
| `--delay <ms>` | `0` | Extra wait time after page load |
|
|
72
|
+
| `--no-auto-tabs` | — | Disable auto-detection of ARIA tab states |
|
|
73
|
+
| `--max-tabs <count>` | `5` | Max tabs to capture per route |
|
|
74
|
+
| `--auto-sections` | `false` | Capture heading-labeled sections individually |
|
|
75
|
+
| `--max-sections <count>` | `10` | Max sections per page state |
|
|
76
|
+
|
|
77
|
+
## Post to PR
|
|
78
|
+
|
|
79
|
+
The `--post` flag uses the GitHub CLI (`gh`) to add a comment to your open pull request with a markdown summary of the results. On subsequent runs, it updates the same comment instead of creating a new one.
|
|
50
80
|
|
|
51
|
-
|
|
81
|
+
```bash
|
|
52
82
|
npx afterbefore --post
|
|
53
83
|
```
|
|
54
84
|
|
|
55
|
-
|
|
85
|
+
You need `gh` installed and authenticated.
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
|------|-------------|---------|
|
|
59
|
-
| `--base <ref>` | Base branch or ref to compare against | `main` |
|
|
60
|
-
| `--output <dir>` | Output directory root | `.afterbefore` |
|
|
61
|
-
| `--post` | Post/update results as a PR comment via `gh` CLI | `false` |
|
|
62
|
-
| `--threshold <percent>` | Diff threshold percentage below which route is marked unchanged | `0.1` |
|
|
63
|
-
| `--max-routes <count>` | Maximum routes to capture (`0` = unlimited) | `6` |
|
|
64
|
-
| `--open` | Auto-open `index.html` after run | `false` |
|
|
65
|
-
| `--width <pixels>` | Viewport width | `1280` |
|
|
66
|
-
| `--height <pixels>` | Viewport height | `720` |
|
|
67
|
-
| `--device <name>` | Playwright device preset (for example `iPhone 14`) | unset |
|
|
68
|
-
| `--delay <ms>` | Extra wait after page load/actions | `0` |
|
|
69
|
-
| `--no-auto-tabs` | Disable ARIA tab state auto-capture | auto-tabs enabled |
|
|
70
|
-
| `--max-tabs <count>` | Max auto-detected inactive tabs per route | `5` |
|
|
71
|
-
| `--auto-sections` | Auto-detect and capture heading-labeled sections | `false` |
|
|
72
|
-
| `--max-sections <count>` | Max auto-detected sections per page/tab state | `10` |
|
|
87
|
+
## Auto-detection
|
|
73
88
|
|
|
74
|
-
|
|
89
|
+
**Tabs.** If a page has ARIA tab controls (`role="tablist"` and `role="tab"`), afterbefore clicks through each tab and captures the state. This is on by default. Disable it with `--no-auto-tabs`.
|
|
75
90
|
|
|
76
|
-
|
|
91
|
+
**Sections.** With `--auto-sections`, pages with 3+ headings get captured section by section. Each heading-labeled section is matched by text between before and after, so you can see exactly which section changed.
|
|
77
92
|
|
|
78
|
-
|
|
79
|
-
- `afterbefore.config.js`
|
|
80
|
-
- `afterbefore.config.mjs`
|
|
93
|
+
## Configuration file
|
|
81
94
|
|
|
82
|
-
|
|
95
|
+
For pages that need interaction before capture (opening a modal, clicking a dropdown), create an `afterbefore.config.json`:
|
|
83
96
|
|
|
84
97
|
```json
|
|
85
98
|
{
|
|
86
99
|
"scenarios": {
|
|
87
|
-
"/
|
|
100
|
+
"/design-system": [
|
|
88
101
|
{
|
|
89
|
-
"name": "
|
|
102
|
+
"name": "components-tab",
|
|
90
103
|
"actions": [
|
|
91
|
-
{ "click": "
|
|
104
|
+
{ "click": ".tab-components" },
|
|
92
105
|
{ "wait": 300 }
|
|
93
106
|
]
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
"name": "plan-cards-only",
|
|
97
|
-
"selector": "[data-testid='plan-grid']",
|
|
98
|
-
"actions": []
|
|
99
107
|
}
|
|
100
108
|
]
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
111
|
```
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
Actions run in order before the screenshot is taken. Supported actions: `click` (CSS selector), `scroll` (CSS selector), `wait` (milliseconds).
|
|
106
114
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
Each run creates a dated session directory:
|
|
110
|
-
|
|
111
|
-
```text
|
|
112
|
-
.afterbefore/
|
|
113
|
-
<branch>_YYYY-MM-DD/
|
|
114
|
-
index.html
|
|
115
|
-
summary.md
|
|
116
|
-
_root-before.png
|
|
117
|
-
_root-after.png
|
|
118
|
-
_root-diff.png
|
|
119
|
-
_root-compare.png # only when changed
|
|
120
|
-
_root-slider.html # only when changed
|
|
121
|
-
about-before.png
|
|
122
|
-
about-after.png
|
|
123
|
-
about-diff.png
|
|
124
|
-
about-compare.png
|
|
125
|
-
about-slider.html
|
|
126
|
-
```
|
|
115
|
+
When scenarios are defined for a route, auto-tabs are disabled for that route.
|
|
127
116
|
|
|
128
|
-
|
|
117
|
+
## Requirements
|
|
129
118
|
|
|
130
|
-
|
|
119
|
+
- Next.js with the app router (`app/` directory)
|
|
120
|
+
- Git
|
|
121
|
+
- Node.js >= 18
|
|
131
122
|
|
|
132
|
-
|
|
133
|
-
- Git repository
|
|
134
|
-
- Next.js App Router project (`app/` pages)
|
|
135
|
-
- Dependencies installable in temporary worktree
|
|
136
|
-
- `gh` CLI authenticated if using `--post`
|
|
137
|
-
- Dynamic routes (for example `app/blog/[slug]/page.tsx`) are currently skipped
|
|
123
|
+
Playwright's Chromium browser is installed automatically on first run if it's missing.
|
|
138
124
|
|
|
139
125
|
## License
|
|
140
126
|
|
|
141
|
-
|
|
127
|
+
Licensed under [PolyForm Shield 1.0.0](https://polyformproject.org/licenses/shield/1.0.0)
|
package/dist/cli.js
CHANGED
|
@@ -1958,7 +1958,7 @@ async function runPipeline(options) {
|
|
|
1958
1958
|
const outputDir = resolve4(cwd, output, sessionName);
|
|
1959
1959
|
const startTime = Date.now();
|
|
1960
1960
|
try {
|
|
1961
|
-
const version = true ? "0.1.
|
|
1961
|
+
const version = true ? "0.1.3" : "dev";
|
|
1962
1962
|
console.log(`
|
|
1963
1963
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1964
1964
|
`);
|
|
@@ -2092,7 +2092,7 @@ afterbefore v${version} \xB7 Comparing against ${base}
|
|
|
2092
2092
|
var program = new Command();
|
|
2093
2093
|
program.name("afterbefore").description(
|
|
2094
2094
|
"Automatic before/after screenshot capture for PRs. Git diff is the config."
|
|
2095
|
-
).version("0.1.
|
|
2095
|
+
).version("0.1.3").option("--base <ref>", "Base branch or ref to compare against", "main").option("--output <dir>", "Output directory for screenshots", ".afterbefore").option("--post", "Post results as a PR comment via gh CLI", false).option(
|
|
2096
2096
|
"--threshold <percent>",
|
|
2097
2097
|
"Diff threshold percentage (changes below this are ignored)",
|
|
2098
2098
|
"0.1"
|
package/dist/index.js
CHANGED
|
@@ -1945,7 +1945,7 @@ async function runPipeline(options) {
|
|
|
1945
1945
|
const outputDir = resolve4(cwd, output, sessionName);
|
|
1946
1946
|
const startTime = Date.now();
|
|
1947
1947
|
try {
|
|
1948
|
-
const version = true ? "0.1.
|
|
1948
|
+
const version = true ? "0.1.3" : "dev";
|
|
1949
1949
|
console.log(`
|
|
1950
1950
|
afterbefore v${version} \xB7 Comparing against ${base}
|
|
1951
1951
|
`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "afterbefore",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Automatic before/after screenshot capture for PRs. Git diff is the config.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"dev": "tsup --watch",
|
|
23
23
|
"test": "vitest run",
|
|
24
24
|
"test:watch": "vitest",
|
|
25
|
-
|
|
26
25
|
"typecheck": "tsc --noEmit",
|
|
27
26
|
"lint": "tsc --noEmit",
|
|
28
27
|
"prepare": "tsup"
|
|
@@ -39,7 +38,7 @@
|
|
|
39
38
|
"visual-testing"
|
|
40
39
|
],
|
|
41
40
|
"author": "Kai Revicius",
|
|
42
|
-
"license": "
|
|
41
|
+
"license": "PolyForm-Shield-1.0.0",
|
|
43
42
|
"bugs": {
|
|
44
43
|
"url": "https://github.com/kairevicius/afterbefore/issues"
|
|
45
44
|
},
|