Skip to content

feat: add webperf-snippets CLI (MVP)#73

Merged
nucliweb merged 19 commits into
mainfrom
feat/cli-mvp
May 5, 2026
Merged

feat: add webperf-snippets CLI (MVP)#73
nucliweb merged 19 commits into
mainfrom
feat/cli-mvp

Conversation

@nucliweb
Copy link
Copy Markdown
Owner

@nucliweb nucliweb commented Apr 29, 2026

Summary

  • Adds a headless CLI (webperf-snippets) that runs curated WebPerf Snippets via Playwright, enabling Core Web Vitals diagnosis and structural audits in CI without manual DevTools copy-paste.
  • Root package renamed to webperf-snippets-docs (private, no external impact); cli/ added as npm workspace with name: webperf-snippets.
  • Zero non-peer deps — only requires Node ≥ 20.12 and Playwright as a peer dependency.

Available snippets

Alias Snippet Category
LCP Largest Contentful Paint Core Web Vitals
CLS Cumulative Layout Shift Core Web Vitals
LCP-Subparts LCP Subparts breakdown Core Web Vitals
fonts Fonts Preloaded, Loaded, and Used Above The Fold Loading
render-blocking Find render-blocking resources Loading
resource-hints Resource Hints Validation Loading
preload-scripts Validate Preload / Async / Defer Scripts Loading
priority-hints Priority Hints Audit Loading
critical-css Critical CSS Detection Loading
ttfb TTFB Sub-Parts Loading
script-parties First and Third-Party Script Info Loading
script-loading Script Loading Loading
lazy-atf Above-the-fold lazy-loaded images Loading
lazy-conflict Images with lazy + fetchpriority conflict Loading
eager-below-fold Non-lazy images outside viewport Loading

Workflows

Two built-in workflows selectable via --workflow:

  • core-web-vitals (default) — runs LCP + CLS, auto-enqueues LCP-Subparts if LCP exceeds 2.5 s.
  • audit — deterministic structural checks (no timing noise) covering all Tier 1 Loading and Media snippets; designed for CI pass/fail gating.

Usage

# Default workflow: LCP + CLS, auto-enqueues LCP-Subparts if LCP > 2.5 s
npx webperf-snippets https://example.com

# Structural audit — deterministic, CI-friendly
npx webperf-snippets https://example.com --workflow audit

# JSON output for CI pipes
npx webperf-snippets https://example.com --json

# Single snippet by alias
npx webperf-snippets https://example.com --snippet LCP-Subparts
npx webperf-snippets https://example.com --snippet render-blocking

# Viewport preset (mobile default)
npx webperf-snippets https://example.com --viewport desktop

# Show all items, even passing checks
npx webperf-snippets https://example.com --verbose

# Budget gating — exits 1 on violation
npx webperf-snippets https://example.com --budget-lcp 2500 --budget-cls 0.1

Files added / changed

File Purpose
cli/package.json Package config, bin, peer dep
cli/src/bin.js CLI entry, util.parseArgs, exit codes 0/1/2
cli/src/runner.js Playwright launch, snippet evaluator
cli/src/load-snippet.js Resolves snippets by alias or Category/Name path
cli/src/workflows/cwv.js Core Web Vitals workflow
cli/src/workflows/audit.js Structural audit workflow (Tier 1 + Tier 2 snippets)
cli/src/decision-tree.js Declarative follow-up rules
cli/src/reporters/human.js Colour table via util.styleText
cli/src/reporters/json.js Raw JSON output
cli/tests/unit/ Vitest unit tests (reporters, decision-tree, viewport presets)
cli/tests/e2e/ Vitest E2E tests against local HTML fixtures (CWV + audit workflows)
cli/tests/fixtures/ Minimal HTML pages for deterministic E2E runs
cli/README.md Usage, options, CI example, known limitations
pages/CLI.mdx CLI documentation page on the site
.github/workflows/ci.yml Unit + E2E tests added to CI
.github/workflows/publish-cli.yml Automated npm publish on release tag

Test plan

  • node cli/src/bin.js --help prints usage
  • node cli/src/bin.js https://web.dev returns green LCP + CLS with element info
  • node cli/src/bin.js https://web.dev --workflow audit runs all structural checks
  • node cli/src/bin.js https://web.dev --json returns valid JSON with all fields
  • node cli/src/bin.js https://web.dev --snippet LCP-Subparts shows sub-part breakdown
  • node cli/src/bin.js https://web.dev --snippet render-blocking shows blocking resources
  • node cli/src/bin.js https://web.dev --snippet fonts shows loaded/used-above-fold font tables
  • node cli/src/bin.js https://web.dev --viewport desktop runs at desktop viewport
  • node cli/src/bin.js https://web.dev --budget-lcp 100 exits 1 with violation on stderr
  • node cli/src/bin.js https://web.dev --verbose shows all items including passing checks
  • Vitest unit + E2E suite passes (npm test in cli/)
  • CI pipeline runs tests on every push

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webperf-snippets Ready Ready Preview, Comment May 4, 2026 9:47pm
webperf-snippets-u6am Ready Ready Preview, Comment May 4, 2026 9:47pm

Adds a headless CLI that runs curated WebPerf Snippets via Playwright,
enabling Core Web Vitals diagnosis and CI budget gating without manual
DevTools copy-paste.

- npx webperf-snippets <url> runs LCP + CLS with human-readable output
- --json, --snippet, --budget-lcp/cls, --headed, --wait flags
- Decision tree: LCP > 2.5s auto-enqueues LCP-Sub-Parts
- Runner shims performance.getEntriesByType for LCP/layout-shift entries
  (Chrome does not expose these via the API without a buffered observer)
- Zero non-peer deps, requires Node >= 20.12, Playwright as peer dep
- Root package renamed to webperf-snippets-docs; workspace added at cli/
Replace the hardcoded desktop viewport with named presets (mobile, tablet,
desktop). Mobile (375×812) is now the default, matching real-world usage.
The --viewport flag lets callers select a preset from the CLI.
Add Vitest as dev dependency with three test layers:
- Unit tests for decision-tree, reporters (JSON and human), and viewport presets
- E2E tests using Playwright against a local HTTP server to verify LCP and
  CLS snippets return valid results on a real browser session
Publish to npm on cli-v* tags via publish-cli.yml. The workflow runs
the full test suite (unit + E2E) before publishing. Access is controlled
via GitHub tag protection rules on the cli-v* pattern.
Adds --snippet fonts as a short alias for the Fonts-Preloaded-Loaded-and-used-above-the-fold snippet.
Reporter now shows loaded fonts table (with font-display warnings for block/auto) and used-above-fold
table, matching the detail level of the browser console output.
Introduces --workflow audit with 11 CI-safe snippets (Tier 1 loading +
Tier 2 media) that return binary pass/fail results without timing noise.

- New auditWorkflow with render-blocking, resource-hints, preload-scripts,
  priority-hints, critical-css, ttfb, script-parties, script-loading,
  lazy-atf, lazy-conflict, eager-below-fold
- renderAuditResult reporter: shows issues with ✗/⚠/ℹ icons and items list
- Exit code 1 when any audit snippet reports error-severity issues (CI gate)
- 22 new snippet aliases (short + full names)
- Add issues field to Find-render-blocking-resources return value
- Fix LCP subparts renderer to not fire on TTFB-Sub-Parts (different schema)
- E2E tests: green and violations fixtures covering 🟢🟡🔴 states
nucliweb added 2 commits May 4, 2026 17:41
…I docs page

- Add --verbose flag to show items for passing checks (default: hidden when green)
- Fix critical-css items rendering empty bullet points by extending field name
  fallback chain to include item.filename and item.media
- Add pages/CLI.mdx with install, usage, options, exit codes, CI integration
- Add CLI section to homepage after AI Agent Skills
- Update _meta.json to include CLI in navigation
- Update webperf skill schema references across .claude/skills and skills/
- Update Loading MDX pages (Back-Forward-Cache, Cache-Strategy-Analysis,
  Client-Side-Redirect-Detection, First-And-Third-Party-Script-Info,
  Resource-Hints-Validation, Validate-Preload-Async-Defer-Scripts)
- Update First-And-Third-Party-Script-Info snippet
- Update cli/README.md and reporters unit tests
- Update README.md and public/llms-full.txt
nucliweb added 2 commits May 4, 2026 23:43
…rces

- Remove ### Overview section, intro paragraph goes directly under title
- Replace 9 bold-as-headers with ### headings in sentence case
- Fix 4 headings from title case to sentence case
- Refactor JS snippet: calculate lastBlockingEnd, totalSizeBytes, byType
  once before if/else to eliminate duplicate computation
@nucliweb nucliweb merged commit ee59095 into main May 5, 2026
4 checks passed
@nucliweb nucliweb deleted the feat/cli-mvp branch May 5, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant