Expand description
Install a resolved composer.lock into a project — the install-from-lock
half of a Composer client, without running PHP.
Given a composer.json + composer.lock and a project root, this crate
reproduces what composer install does to the filesystem:
- verify the lock’s content-hash (warn, never block, on drift);
- preflight the lockfile (reject unsupported dists and sources; warn about
Composer plugins and unrun
scripts); - diff against
vendor/composer/installed.jsonto skip up-to-date packages and sweep stale ones; - download + verify + extract each changed dist in parallel into
vendor/<vendor>/<package>/; - check out git-source packages (with a
SourceFetcher) and materializetype: pathpackages (symlink-or-copy); - apply cweagans-style patches (
composer_patches); - run the declarative install plugins — the Magento deploy and Laravel
discovery (
composer_installers); - dump the autoloader (
composer_autoload); - link
vendor/binproxies.
The pubgrub solver is out of scope — this consumes an already-resolved
lock. It is a sibling of composer_manifest (the lock model),
composer_installers (install-path routing + deploy + Laravel),
composer_autoload (dump-autoload), and composer_patches.
§Seams
App-specific concerns are injected so the crate carries no HTTP-client, progress-rendering, or paths policy of its own:
Fetcher— the single HTTP GET that populates the dist cache.ReqwestFetcheris the batteries-included default (Composer User-Agent, sha1 verify, atomic placement, bounded retry).Progress— per-package download/extract callbacks.NoProgressis the silent default.cache_root(onInstallEnv) — where dist archives are cached.SourceFetcher— optional; installs packages locked to a git source.GitSourceFetchershells out to the systemgit.
Root-script execution is opted in via ScriptHooks; pass None for the
deterministic scripts-off behavior.
§Example
use std::path::Path;
use composer_install::{InstallEnv, InstallOptions, NoProgress, ReqwestFetcher, install_from_lock};
let fetcher = ReqwestFetcher::new()?;
let progress = NoProgress;
let env = InstallEnv::new(&fetcher, &progress, Path::new("/tmp/composer-dist-cache"));
let summary = install_from_lock(&env, Path::new("."), InstallOptions::default(), None)?;
println!("installed {} package(s)", summary.packages_installed);Re-exports§
pub use archive::ArchiveKind;pub use archive::detect_tar_top_level;pub use archive::detect_zip_top_level;pub use archive::extract_dist;pub use archive::extract_tar;pub use archive::extract_zip;pub use auth::parse_composer_auth_env;pub use auth::read_all_auth;pub use auth::read_all_auth_with;pub use auth::read_auth_from_composer_json;pub use auth::read_auth_json;pub use auth::read_composer_auth_env;pub use auth::read_global_auth_json;pub use downloader::DistCandidate;pub use downloader::DistOutcome;pub use downloader::DistRequest;pub use downloader::fetch_and_extract_dists;pub use error::InstallError;pub use error::VcsFailure;pub use fetch::FetchSpec;pub use fetch::Fetcher;pub use fetch::ReqwestFetcher;pub use progress::NoProgress;pub use progress::Progress;pub use source::GitSourceFetcher;pub use source::SourceFetcher;pub use source::SourceSpec;
Modules§
- archive
- Dist archive extraction — the HTTP-free half of the downloader.
- auth
- Per-host repository credentials, read from the same sources Composer uses.
- downloader
- Parallel Composer dist downloader.
- error
- Typed install errors.
- fetch
- The download seam: fetch one dist URL to a verified cache file.
- progress
- Install progress reporting — a caller-supplied seam.
- source
- Git
sourceinstalls — the seam for packages the lock pins to a VCS checkout instead of a dist archive.
Structs§
- Install
Env - The runtime seams an install needs, injected so the crate stays free of any
HTTP-client / progress-bar / paths policy. Build it with
InstallEnv::newplus thewith_*methods, and pass it by reference toinstall_from_lock. - Install
Options - Caller-supplied install options. Mirrors the subset of Composer’s
installflags this installer honors. - Install
Summary - What happened. Returned to the caller for machine emission and a one-line text summary.
- Wording
- The words messages use for the calling tool, so a CLI built on this crate
can point its users at its own commands. Start from
Wording::defaultand set the fields that differ.
Enums§
- Auth
Credentials - One repository host’s credential.
Debugnever shows the secret. - Link
Mode - How a dist’s files are materialized into
vendor/.
Traits§
- Script
Hooks - Lifecycle hooks fired during an install when root-script execution is opted
in. The installer stays command- and PHP-agnostic: the caller supplies an
implementation that maps each hook to the right Composer event
(
pre-install-cmdvspre-update-cmd, …) and runs it.
Functions§
- install_
from_ lock - Apply
composer.locktoproject_root. See module docs for the flow. - install_
from_ lock_ with_ patches - Like
install_from_lock, but also applies a resolvedPatchPlan(cweagans-style patches, applied natively).patchesisNonefor the patches-disabled path, which keeps install-set diffing dist-ref-only.