Skip to content

Auto-install Playwright when not in consumer project#49

Merged
DeDuckProject merged 2 commits intomainfrom
claude/fix-playwright-install-S7SeK
Mar 15, 2026
Merged

Auto-install Playwright when not in consumer project#49
DeDuckProject merged 2 commits intomainfrom
claude/fix-playwright-install-S7SeK

Conversation

@DeDuckProject
Copy link
Owner

Summary

Refactored Playwright resolution to automatically install @playwright/test and Chromium browser binaries when they're not available in the consumer project. This enables git-glimpse to work in projects without existing Playwright setup.

Key Changes

  • New module ensure-playwright.ts: Extracted Playwright resolution logic into a dedicated module that:

    • First attempts to resolve @playwright/test from the consumer's project (respecting their pinned version)
    • Falls back to auto-installing in ~/.cache/git-glimpse/playwright if not found
    • Automatically ensures Chromium browser binaries are installed via the Playwright CLI
    • Handles cache directory resolution with fallback to temp directory
  • Updated playwright-runner.ts: Replaced direct createRequire call with ensurePlaywright() to leverage the new auto-install logic

  • Updated fallback.ts: Replaced direct createRequire call with ensurePlaywright() for consistency

  • Improved error handling in resolve-base-url.ts: Enhanced resolveBaseUrl() function to return structured error objects instead of null, providing clearer error messages when preview URL configuration is invalid

  • Updated action entry point: Integrated the new resolveBaseUrl() function with proper error reporting

Implementation Details

  • The resolution order prioritizes the consumer's own node_modules to respect their dependency versions
  • Stable cache directory uses ~/.cache/git-glimpse/playwright with fallback to system temp directory
  • Chromium installation checks the ms-playwright cache to avoid redundant installations
  • All file system and child process operations use Node.js built-in modules

https://claude.ai/code/session_01XDxRzi588C73zsj1xPwmEb

claude added 2 commits March 14, 2026 23:47
Most projects integrating git-glimpse won't have @playwright/test as a
dependency (e.g. game/backend projects). The action previously relied on
the consumer's node_modules, failing with ERESOLVE for those projects.

Adds ensurePlaywright() in packages/core/src/recorder/ensure-playwright.ts:
- First tries to resolve @playwright/test from the consumer's project (preserving
  existing behaviour for projects that already have it pinned)
- Falls back to auto-installing @playwright/test into ~/.cache/git-glimpse/playwright
- Also ensures Chromium browser binaries are installed via playwright CLI

Both playwright-runner.ts and fallback.ts now use ensurePlaywright() instead
of a bare createRequire(process.cwd()) call.

https://claude.ai/code/session_01XDxRzi588C73zsj1xPwmEb
Tests cover: consumer resolution (fast path), auto-install when missing,
skip-install when cached, and Chromium browser installation.

Also adds a note to CLAUDE.md that features/fixes should include unit tests.

https://claude.ai/code/session_01XDxRzi588C73zsj1xPwmEb
@DeDuckProject DeDuckProject merged commit 81361f3 into main Mar 15, 2026
3 checks passed
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.

2 participants