Skip to main content

Crate composer_install

Crate composer_install 

Source
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:

  1. verify the lock’s content-hash (warn, never block, on drift);
  2. preflight the lockfile (reject unsupported dists and sources; warn about Composer plugins and unrun scripts);
  3. diff against vendor/composer/installed.json to skip up-to-date packages and sweep stale ones;
  4. download + verify + extract each changed dist in parallel into vendor/<vendor>/<package>/;
  5. check out git-source packages (with a SourceFetcher) and materialize type: path packages (symlink-or-copy);
  6. apply cweagans-style patches (composer_patches);
  7. run the declarative install plugins — the Magento deploy and Laravel discovery (composer_installers);
  8. dump the autoloader (composer_autoload);
  9. link vendor/bin proxies.

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. ReqwestFetcher is the batteries-included default (Composer User-Agent, sha1 verify, atomic placement, bounded retry).
  • Progress — per-package download/extract callbacks. NoProgress is the silent default.
  • cache_root (on InstallEnv) — where dist archives are cached.
  • SourceFetcher — optional; installs packages locked to a git source. GitSourceFetcher shells out to the system git.

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 source installs — the seam for packages the lock pins to a VCS checkout instead of a dist archive.

Structs§

InstallEnv
The runtime seams an install needs, injected so the crate stays free of any HTTP-client / progress-bar / paths policy. Build it with InstallEnv::new plus the with_* methods, and pass it by reference to install_from_lock.
InstallOptions
Caller-supplied install options. Mirrors the subset of Composer’s install flags this installer honors.
InstallSummary
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::default and set the fields that differ.

Enums§

AuthCredentials
One repository host’s credential. Debug never shows the secret.
LinkMode
How a dist’s files are materialized into vendor/.

Traits§

ScriptHooks
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-cmd vs pre-update-cmd, …) and runs it.

Functions§

install_from_lock
Apply composer.lock to project_root. See module docs for the flow.
install_from_lock_with_patches
Like install_from_lock, but also applies a resolved PatchPlan (cweagans-style patches, applied natively). patches is None for the patches-disabled path, which keeps install-set diffing dist-ref-only.