composer-install
Install a resolved composer.lock into a project — the install-from-lock half of a
Composer client, without running PHP.
Part of composer-client.
What it does
Given a composer.json + composer.lock and a project root, it 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 (sha1) + 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.
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 (ComposerUser-Agent, sha1 verify, atomic placement, bounded retry). Bring your own to reuse a client, inject a proxy, or serve from a pre-seeded store.Progress— per-package download / extract / retry callbacks.NoProgressis the silent default; a CLI implements the trait to drive a progress bar.cache_root(onInstallEnv) — where dist archives are cached across runs.SourceFetcher— optional; installs packages the lock pins to a gitsourcewith no dist.GitSourceFetchershells out to the systemgitand caches bare mirrors. Without one, such packages fail preflight.- Machine credentials (
InstallEnv::with_machine_auth) — a tool's own credential store, merged above the globalauth.jsonand below every project source.
Failures a caller may want to map to its own exit codes (a missing composer.json or
composer.lock, an invalid manifest, an unsupported lock, a git failure) carry an
InstallError you can recover with report.downcast_ref::<InstallError>().
Root-script execution is opted in via the caller-supplied ScriptHooks trait; pass None
for deterministic scripts-off behavior.
Example
use Path;
use ;
let fetcher = new?;
let progress = NoProgress;
let env = new;
let summary = install_from_lock?;
println!;
# Ok::