Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vpm): Empty depeneencies block of locked section in vpm-manifest.json is removed #478

Merged
merged 2 commits into from Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,8 @@ The format is based on [Keep a Changelog].
### Removed

### Fixed
- Empty `depeneencies` block of `locked` section in `vpm-manifest.json` is removed `#478`
- This follows the changed behavior of the official VPM command.

### Security

Expand Down
10 changes: 7 additions & 3 deletions vrc-get-vpm/src/unity_project.rs
Expand Up @@ -18,6 +18,7 @@ use crate::version::{UnityVersion, Version, VersionRange};
use futures::future::try_join;
use futures::prelude::*;
use indexmap::IndexMap;
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -184,7 +185,7 @@ impl<IO: ProjectIo> UnityProject<IO> {
.unlocked_packages
.iter()
.filter_map(|(_, json)| json.as_ref())
.map(|x| LockedDependencyInfo::new(x.name(), x.version(), x.vpm_dependencies()));
.map(|x| LockedDependencyInfo::new(x.name(), x.version(), Some(x.vpm_dependencies())));

dependencies_locked.chain(dependencies_unlocked)
}
Expand Down Expand Up @@ -237,12 +238,15 @@ impl<'a> LockedDependencyInfo<'a> {
fn new(
name: &'a str,
version: &'a Version,
dependencies: &'a IndexMap<Box<str>, VersionRange>,
dependencies: Option<&'a IndexMap<Box<str>, VersionRange>>,
) -> Self {
lazy_static! {
static ref EMPTY_DEPENDENCIES: IndexMap<Box<str>, VersionRange> = IndexMap::new();
}
Self {
name,
version,
dependencies,
dependencies: dependencies.unwrap_or(&*EMPTY_DEPENDENCIES),
}
}

Expand Down
2 changes: 1 addition & 1 deletion vrc-get-vpm/src/unity_project/resolve.rs
Expand Up @@ -177,7 +177,7 @@ impl<IO: ProjectIo> UnityProject<IO> {
for x in changes.get_all_installing() {
virtual_locked_dependencies.insert(
x.name(),
LockedDependencyInfo::new(x.name(), x.version(), x.vpm_dependencies()),
LockedDependencyInfo::new(x.name(), x.version(), Some(x.vpm_dependencies())),
);
}

Expand Down
12 changes: 7 additions & 5 deletions vrc-get-vpm/src/unity_project/vpm_manifest.rs
Expand Up @@ -25,8 +25,8 @@ struct VpmDependency {
#[derive(Serialize, Deserialize, Debug, Clone)]
struct VpmLockedDependency {
pub version: Version,
#[serde(default, skip_serializing_if = "indexmap::IndexMap::is_empty")]
pub dependencies: IndexMap<Box<str>, VersionRange>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub dependencies: Option<IndexMap<Box<str>, VersionRange>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -59,15 +59,17 @@ impl VpmManifest {

pub(super) fn all_locked(&self) -> impl Iterator<Item = LockedDependencyInfo> {
self.controller.locked.iter().map(|(name, dep)| {
LockedDependencyInfo::new(name.as_ref(), &dep.version, &dep.dependencies)
LockedDependencyInfo::new(name.as_ref(), &dep.version, dep.dependencies.as_ref())
})
}

pub(super) fn get_locked(&self, package: &str) -> Option<LockedDependencyInfo> {
self.controller
.locked
.get_key_value(package)
.map(|(package, x)| LockedDependencyInfo::new(package, &x.version, &x.dependencies))
.map(|(package, x)| {
LockedDependencyInfo::new(package, &x.version, x.dependencies.as_ref())
})
}

pub(super) fn add_dependency(&mut self, name: &str, version: DependencyRange) {
Expand All @@ -87,7 +89,7 @@ impl VpmManifest {
name.into(),
VpmLockedDependency {
version,
dependencies,
dependencies: Some(dependencies),
},
);
}
Expand Down