pesde/src/lockfile.rs
daimond113 f4050abec8
feat: add engines
Squashed commit of the following:

commit 5767042964
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Thu Jan 16 18:28:52 2025 +0100

    fix(engines): correct engine detection on unix

    The `current_exe` function doesn't return the
    symlinked path on Unix, so the engine detection
    was failing there. This commit fixes that by
    using the 0th argument of the program to get
    the path of the executable on Unix.

commit b51c9d9571
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Wed Jan 15 22:43:50 2025 +0100

    refactor: print deprecated warning on CLI side

    Prints the deprecated warning on the CLI side
    which means it'll have a more consistent look
    with the rest of the CLI output.

commit 5ace844035
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Wed Jan 15 22:21:36 2025 +0100

    feat: add alias validation

    Ensures aliases don't contain characters which could
    cause issues. They are now also forbidden from being
    the same as an engine name to avoid issues.

commit a33302aff9
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Wed Jan 15 21:23:40 2025 +0100

    refactor: apply clippy lints

commit 2d534a534d
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Wed Jan 15 21:22:14 2025 +0100

    feat(engines): print incompatibility warning for dependencies

    Adds a warning message when a dependency depends
    on an incompatible engine.

commit 4946a19f8b
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Wed Jan 15 18:33:38 2025 +0100

    feat(engines): create linkers at install time

    Additionally fixes engines being executed as scripts,
    and fixes downloading pesde from GitHub.

commit e3177eeb75
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Tue Jan 14 14:33:26 2025 +0100

    fix(engines): store & link engines correctly

    Fixes issues with how engines were stored
    which resulted in errors. Also makes outdated
    linkers get updated.

commit 037ead66bb
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Mon Jan 13 12:26:19 2025 +0100

    docs: remove prerequisites

commit ddb496ff7d
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Mon Jan 13 12:25:53 2025 +0100

    ci: remove tar builds

commit e9f0c25554
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Mon Jan 13 12:25:11 2025 +0100

    chore(docs): update astro and starlight

commit fc349e6f21
Author: daimond113 <72147841+daimond113@users.noreply.github.com>
Date:   Sun Jan 12 23:12:27 2025 +0100

    feat: add engines

    Adds the initial implementation of the engines feature.
    Not tested yet. Requires documentation and
    more work for non-pesde engines to be usable.
2025-01-16 19:11:16 +01:00

145 lines
4.5 KiB
Rust

#![allow(deprecated)]
use crate::{
graph::DependencyGraph,
manifest::{overrides::OverrideKey, target::TargetKind},
names::PackageName,
source::specifiers::DependencySpecifiers,
};
use relative_path::RelativePathBuf;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
/// A lockfile
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Lockfile {
/// The name of the package
pub name: PackageName,
/// The version of the package
pub version: Version,
/// The target of the package
pub target: TargetKind,
/// The overrides of the package
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
/// The workspace members
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub workspace: BTreeMap<PackageName, BTreeMap<TargetKind, RelativePathBuf>>,
/// The graph of dependencies
#[serde(default, skip_serializing_if = "DependencyGraph::is_empty")]
pub graph: DependencyGraph,
}
/// Old lockfile stuff. Will be removed in a future version.
#[deprecated(
note = "Intended to be used to migrate old lockfiles to the new format. Will be removed in a future version."
)]
pub mod old {
use crate::{
manifest::{
overrides::OverrideKey,
target::{Target, TargetKind},
Alias, DependencyType,
},
names::{PackageName, PackageNames},
source::{
ids::{PackageId, VersionId},
refs::PackageRefs,
specifiers::DependencySpecifiers,
},
};
use relative_path::RelativePathBuf;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
/// An old dependency graph node
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DependencyGraphNodeOld {
/// The alias, specifier, and original (as in the manifest) type for the dependency, if it is a direct dependency (i.e. used by the current project)
#[serde(default, skip_serializing_if = "Option::is_none")]
pub direct: Option<(Alias, DependencySpecifiers, DependencyType)>,
/// The dependencies of the package
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub dependencies: BTreeMap<PackageNames, (VersionId, Alias)>,
/// The resolved (transformed, for example Peer -> Standard) type of the dependency
pub resolved_ty: DependencyType,
/// Whether the resolved type should be Peer if this isn't depended on
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub is_peer: bool,
/// The package reference
pub pkg_ref: PackageRefs,
}
/// A downloaded dependency graph node, i.e. a `DependencyGraphNode` with a `Target`
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct DownloadedDependencyGraphNodeOld {
/// The target of the package
pub target: Target,
/// The node
#[serde(flatten)]
pub node: DependencyGraphNodeOld,
}
/// An old version of a lockfile
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LockfileOld {
/// The name of the package
pub name: PackageName,
/// The version of the package
pub version: Version,
/// The target of the package
pub target: TargetKind,
/// The overrides of the package
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub overrides: BTreeMap<OverrideKey, DependencySpecifiers>,
/// The workspace members
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub workspace: BTreeMap<PackageName, BTreeMap<TargetKind, RelativePathBuf>>,
/// The graph of dependencies
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub graph: BTreeMap<PackageNames, BTreeMap<VersionId, DownloadedDependencyGraphNodeOld>>,
}
impl LockfileOld {
/// Converts this lockfile to a new lockfile
pub fn to_new(self) -> super::Lockfile {
super::Lockfile {
name: self.name,
version: self.version,
target: self.target,
overrides: self.overrides,
workspace: self.workspace,
graph: self
.graph
.into_iter()
.flat_map(|(name, versions)| {
versions.into_iter().map(move |(version, node)| {
(
PackageId(name.clone(), version),
crate::graph::DependencyGraphNode {
direct: node.node.direct,
dependencies: node
.node
.dependencies
.into_iter()
.map(|(name, (version, alias))| {
(PackageId(name, version), alias)
})
.collect(),
resolved_ty: node.node.resolved_ty,
is_peer: node.node.is_peer,
pkg_ref: node.node.pkg_ref,
},
)
})
})
.collect(),
}
}
}
}