Packagist Registry Adapter
Relevant source files
The following files were used as context for generating this wiki page:
The Packagist Registry Adapter is a specialized ecosystem implementation within the regxa library designed to interface with Packagist, the primary package repository for PHP's Composer dependency manager. It normalizes data from the Packagist JSON API into the project's standard core types, enabling universal package querying.
The adapter follows a plugin-based architecture, registering itself under the composer ecosystem key. It handles the mapping of PHP-specific metadata, such as vendor/package naming conventions, "require" and "require-dev" dependency sections, and complex versioning logic including development suffixes.
Sources: src/registries/packagist.ts:1-20, README.md:10-15, src/registries/AGENTS.md:5-15
Core Architecture and Data Flow
The adapter implements the Registry interface, providing a consistent set of methods for fetching package details, versions, dependencies, and maintainers. It utilizes a central Client for HTTP requests to ensure consistent retry and error handling logic.
Data Normalization Flow
The following diagram illustrates how the adapter transforms raw Packagist API responses into the normalized Package structure used across the regxa ecosystem.
The adapter specifically targets the /packages/{vendor}/{package}.json endpoint to retrieve comprehensive package data.
Sources: src/registries/packagist.ts:64-103, src/registries/AGENTS.md:23-28
Component Specifications
Class: PackagistRegistry
The PackagistRegistry class contains the logic for interacting with the Composer ecosystem. It is initialized via a factory and self-registers to the global registry map.
| Method | Description |
|---|---|
ecosystem() | Returns the constant string "composer". |
fetchPackage() | Retrieves general metadata and identifies the latest stable version. |
fetchVersions() | Lists all available versions with their respective integrity hashes and timestamps. |
fetchDependencies() | Maps require to runtime and require-dev to development scopes. |
fetchMaintainers() | Aggregates author information across all package versions. |
Sources: src/registries/packagist.ts:51-180, src/core/types.ts
Internal Logic and Helpers
The adapter includes private utilities to handle the specificities of the PHP ecosystem:
- Name Parsing: Enforces the
vendor/packageformat required by Composer. - Version Resolution: Implements a sorting algorithm that prioritizes stable versions over those with
dev-prefixes or-devsuffixes. - Dependency Filtering: Automatically skips virtual packages like
phpor native extensions (e.g.,ext-json) to focus on actual library dependencies.
Sources: src/registries/packagist.ts:228-285, test/unit/registries.test.ts:745-770
API Mapping and Interaction
The adapter communicates with two primary base URLs: the main registry for metadata and the repository for downloads.
URL Construction
The urls() method provides a URLBuilder that generates various links related to the package.
| Type | Pattern |
|---|---|
| Registry | https://packagist.org/packages/{vendor}/{package} |
| Download | https://repo.packagist.org/p/{vendor}/{package}/{version}.json |
| PURL | pkg:composer/{vendor}/{package}@{version} |
Sources: src/registries/packagist.ts:183-214, test/unit/registries.test.ts:805-820
Data Structures
Packagist Internal Interfaces
The adapter defines internal interfaces to type the upstream API responses before they are mapped to core types.
interface PackagistVersion {
name: string;
version: string;
license?: string | string[];
require?: Record<string, string>;
"require-dev"?: Record<string, string>;
source?: { url?: string };
dist?: { shasum?: string };
time?: string;
}
Sources: src/registries/packagist.ts:24-50
Summary
The Packagist Registry Adapter provides the necessary bridge between PHP's Composer ecosystem and the regxa library. By implementing custom logic for stable version resolution and dependency filtering, it ensures that PHP packages are treated with the same consistency as packages from npm, PyPI, or Cargo, while respecting the unique conventions of the Packagist API.
Sources: src/registries/packagist.ts:288-293, README.md:55-60