Skip to content

Add support for spatie/crawler v9#7

Open
markvaneijk wants to merge 1 commit into
mainfrom
support-crawler-9
Open

Add support for spatie/crawler v9#7
markvaneijk wants to merge 1 commit into
mainfrom
support-crawler-9

Conversation

@markvaneijk

Copy link
Copy Markdown
Contributor

Why

spatie/crawler v9 requires PHP 8.4 and reworked the public API. Staying pinned to ^8.0 blocks consumers from combining laravel-static with anything that needs crawler v9 — most notably spatie/laravel-sitemap >= 8.0.1, a very common companion package (that's how this surfaced: markvaneijk.com couldn't install both).

What

composer.json now allows spatie/crawler: ^8.0 || ^9.0:

  • PHP 8.1–8.3 keeps resolving crawler v8 — behaviour unchanged
  • PHP 8.4+ resolves v9

Since v9 renamed the fluent API (Crawler::create($url), crawlProfile(), concurrency(), defaultScheme(), followNofollow(), start()) and changed the observer contract, the crawl in static:build is delegated to a version-specific runner picked at runtime via method_exists(Crawler::class, 'addObserver'):

  • CrawlerV8Runner — the existing v8 code, extracted verbatim
  • CrawlerV9Runner — v9 API; the default logging observer is replaced with v9's closure hooks (onCrawled/onFailed/onFinished), and a custom crawl_observer from config is passed through via addObserver() (it must extend the installed major's CrawlObserver — documented in the README)

PHPStan can only analyse against the single installed crawler major, so the three version-specific files are excluded from analysis.

Supporting fixes (needed to get CI meaningful again)

  • phpunit.xml.dist was still on the PHPUnit 9 schema — under PHPUnit 12 the suite silently ran zero tests and exited 0. Migrated the schema and dropped the stale coverage-report config that caused the silent abort.
  • Test matrix was PHP 8.1 / Laravel 9, which current constraints can't even install. Now PHP 8.2–8.4 × Laravel 11–13 × prefer-lowest/stable, which also exercises both crawler majors (8.4 + prefer-stable → v9, everything else → v8).
  • Dev dependencies widened (testbench 9–11, pest 3–4, larastan 2–3); phpstan CI pinned to PHP 8.4; two pre-existing findings surfaced by larastan 3 baselined (env() calls in config, deprecated forceRootUrl()).

Verified

  • pest: 7 passed (18 assertions) against crawler 9.3.2 (Laravel 13, PHP 8.4)
  • pest: 7 passed (18 assertions) against crawler 8.5.0 (same environment, pinned)
  • Runner detection returns V8/V9 correctly per installed version; StaticCrawlObserver still loads fine under v8
  • phpstan: no errors
  • pint: touched files clean

🤖 Generated with Claude Code

Crawler v9 was a full API rework (Crawler::create() takes the URL,
fluent setters renamed, observer signatures changed), so the crawl is
now delegated to a version-specific runner selected at runtime:

- CrawlerV8Runner keeps the existing v8 behaviour unchanged
- CrawlerV9Runner uses the v9 API; the default logging observer is
  replaced by v9's closure hooks, custom observers from config are
  passed through (they must target the installed major's signatures)
- Version detection via method_exists(Crawler::class, 'addObserver'),
  introduced in v9

Composer now allows "^8.0 || ^9.0": PHP 8.1-8.3 keeps resolving v8
(v9 requires PHP 8.4), PHP 8.4+ picks v9 — and consumers can combine
this package with spatie/laravel-sitemap >= 8.0.1 again.

Supporting changes:
- phpstan: exclude version-specific files (only one crawler major is
  installed at analysis time), pin CI to PHP 8.4, baseline two
  pre-existing findings surfaced by larastan 3
- phpunit.xml.dist migrated off the PHPUnit 9 schema; the stale
  coverage report config made PHPUnit 12 run zero tests silently
- test matrix refreshed to PHP 8.2-8.4 x Laravel 11-13 (was PHP 8.1 /
  Laravel 9, which current constraints can no longer install); dev
  dependencies widened accordingly
- README: document the dual-version support and the custom observer
  caveat

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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