Skip to main content

pray_core/
resolve_context.rs

1use crate::lockfile::Lockfile;
2use std::collections::BTreeSet;
3
4#[derive(Debug, Clone, Default, PartialEq, Eq)]
5pub struct ResolveOptions {
6    pub offline: bool,
7    pub unlocked_packages: BTreeSet<String>,
8    /// When true, git sources fetch remote HEAD instead of the revision pinned in Prayfile.lock.
9    pub refresh_source_revisions: bool,
10    /// When true, resolve against registry constraints instead of versions pinned in Prayfile.lock.
11    pub ignore_locked_versions: bool,
12    /// When true, refuse yanked versions even if the lockfile pins them (SPEC ยง60 strict).
13    pub fail_on_yanked: bool,
14    /// Selected render environment; does not change package resolution.
15    pub environment: Option<String>,
16}
17
18#[derive(Debug, Clone, Default, PartialEq, Eq)]
19pub struct PackageResolutionContext {
20    pub preferred_version: Option<String>,
21    pub offline: bool,
22    pub fail_on_yanked: bool,
23}
24
25impl PackageResolutionContext {
26    pub fn from_lockfile(
27        lockfile: Option<&Lockfile>,
28        package_name: &str,
29        options: &ResolveOptions,
30    ) -> Self {
31        let preferred_version =
32            if options.ignore_locked_versions || options.unlocked_packages.contains(package_name) {
33                None
34            } else {
35                lockfile.and_then(|lockfile| {
36                    lockfile
37                        .package
38                        .iter()
39                        .find(|package| package.name == package_name)
40                        .map(|package| package.version.clone())
41                })
42            };
43        Self {
44            preferred_version,
45            offline: options.offline,
46            fail_on_yanked: options.fail_on_yanked,
47        }
48    }
49}