composer_install/lib.rs
1//! Install a resolved `composer.lock` into a project — the install-from-lock
2//! half of a Composer client, without running PHP.
3//!
4//! Given a `composer.json` + `composer.lock` and a project root, this crate
5//! reproduces what `composer install` does to the filesystem:
6//!
7//! 1. verify the lock's content-hash (warn, never block, on drift);
8//! 2. preflight the lockfile (reject unsupported dists and sources; warn about
9//! Composer plugins and unrun `scripts`);
10//! 3. diff against `vendor/composer/installed.json` to skip up-to-date
11//! packages and sweep stale ones;
12//! 4. download + verify + extract each changed dist in parallel into
13//! `vendor/<vendor>/<package>/`;
14//! 5. check out git-source packages (with a [`SourceFetcher`]) and
15//! materialize `type: path` packages (symlink-or-copy);
16//! 6. apply cweagans-style patches ([`composer_patches`]);
17//! 7. run the declarative install plugins — the Magento deploy and Laravel
18//! discovery ([`composer_installers`]);
19//! 8. dump the autoloader ([`composer_autoload`]);
20//! 9. link `vendor/bin` proxies.
21//!
22//! The **pubgrub solver is out of scope** — this consumes an already-resolved
23//! lock. It is a sibling of [`composer_manifest`] (the lock model),
24//! [`composer_installers`] (install-path routing + deploy + Laravel),
25//! [`composer_autoload`] (`dump-autoload`), and [`composer_patches`].
26//!
27//! # Seams
28//!
29//! App-specific concerns are injected so the crate carries no
30//! HTTP-client, progress-rendering, or paths policy of its own:
31//!
32//! - [`Fetcher`] — the single HTTP GET that populates the dist cache.
33//! [`ReqwestFetcher`] is the batteries-included default (Composer User-Agent,
34//! sha1 verify, atomic placement, bounded retry).
35//! - [`Progress`] — per-package download/extract callbacks. [`NoProgress`] is
36//! the silent default.
37//! - `cache_root` (on [`InstallEnv`]) — where dist archives are cached.
38//! - [`SourceFetcher`] — optional; installs packages locked to a git source.
39//! [`GitSourceFetcher`] shells out to the system `git`.
40//!
41//! Root-script execution is opted in via [`ScriptHooks`]; pass `None` for the
42//! deterministic scripts-off behavior.
43//!
44//! # Example
45//!
46//! ```no_run
47//! use std::path::Path;
48//! use composer_install::{InstallEnv, InstallOptions, NoProgress, ReqwestFetcher, install_from_lock};
49//!
50//! # fn main() -> eyre::Result<()> {
51//! let fetcher = ReqwestFetcher::new()?;
52//! let progress = NoProgress;
53//! let env = InstallEnv::new(&fetcher, &progress, Path::new("/tmp/composer-dist-cache"));
54//! let summary = install_from_lock(&env, Path::new("."), InstallOptions::default(), None)?;
55//! println!("installed {} package(s)", summary.packages_installed);
56//! # Ok(())
57//! # }
58//! ```
59
60pub mod archive;
61pub mod auth;
62pub mod downloader;
63pub mod error;
64pub mod fetch;
65pub mod progress;
66pub mod source;
67
68mod bin_proxy;
69mod orchestrate;
70mod path_link;
71mod stale;
72
73pub use archive::{
74 ArchiveKind, detect_tar_top_level, detect_zip_top_level, extract_dist, extract_tar, extract_zip,
75};
76pub use auth::{
77 AuthCredentials, parse_composer_auth_env, read_all_auth, read_all_auth_with,
78 read_auth_from_composer_json, read_auth_json, read_composer_auth_env, read_global_auth_json,
79};
80pub use downloader::{DistCandidate, DistOutcome, DistRequest, fetch_and_extract_dists};
81pub use error::{InstallError, VcsFailure};
82pub use fetch::{FetchSpec, Fetcher, ReqwestFetcher};
83pub use orchestrate::{
84 InstallEnv, InstallOptions, InstallSummary, LinkMode, ScriptHooks, Wording, install_from_lock,
85 install_from_lock_with_patches,
86};
87pub use progress::{NoProgress, Progress};
88pub use source::{GitSourceFetcher, SourceFetcher, SourceSpec};