Skip to content

Commit

Permalink
refactor: replace alias with rename_all
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Aug 8, 2023
1 parent 5538664 commit 8e908b7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 14 deletions.
6 changes: 2 additions & 4 deletions crates/lockfile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ pub struct LockfilePeerDependencyMeta {
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LockfileSettings {
#[serde(alias = "autoInstallPeers")]
auto_install_peers: bool,
#[serde(alias = "excludeLinksFromLockfile")]
exclude_links_from_lockfile: bool,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Lockfile {
#[serde(alias = "lockFileVersion")]
pub lock_file_version: String,
pub settings: Option<LockfileSettings>,
#[serde(alias = "neverBuiltDependencies")]
pub never_built_dependencies: Option<Vec<String>>,
pub overrides: Option<HashMap<String, String>>,
pub dependencies: Option<HashMap<String, LockfileDependency>>,
Expand Down
6 changes: 1 addition & 5 deletions crates/lockfile/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct LockfilePackageResolution {

// Reference: https://github.com/pnpm/pnpm/blob/main/lockfile/lockfile-file/src/sortLockfileKeys.ts#L5
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LockfilePackage {
resolution: LockfilePackageResolution,
id: Option<String>,
Expand All @@ -23,22 +24,17 @@ pub struct LockfilePackage {
os: Option<Vec<String>>,
// TODO: Add `libc`
deprecated: Option<bool>,
#[serde(alias = "hasBin")]
has_bin: Option<bool>,
// TODO: Add `prepare`
#[serde(alias = "requiresBuild")]
requires_build: Option<bool>,

// TODO: Add `bundleDependencies`
#[serde(alias = "peerDependencies")]
peer_dependencies: Option<HashMap<String, String>>,
#[serde(alias = "peerDependenciesMeta")]
peer_dependencies_meta: Option<HashMap<String, LockfilePeerDependencyMeta>>,

dependencies: Option<HashMap<String, String>>,
optional_dependencies: Option<HashMap<String, String>>,

#[serde(alias = "transitivePeerDependencies")]
transitive_peer_dependencies: Option<Vec<String>>,
dev: bool,
optional: Option<bool>,
Expand Down
2 changes: 1 addition & 1 deletion crates/registry/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{package_version::PackageVersion, RegistryError};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Package {
pub name: String,
#[serde(alias = "dist-tags")]
#[serde(rename = "dist-tags")]
dist_tags: HashMap<String, String>,
pub versions: HashMap<String, PackageVersion>,

Expand Down
3 changes: 1 addition & 2 deletions crates/registry/src/package_distribution.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PackageDistribution {
pub integrity: String,
pub shasum: String,
pub tarball: String,
#[serde(alias = "fileCount")]
pub file_count: Option<usize>,
#[serde(alias = "unpackedSize")]
pub unpacked_size: Option<usize>,
}

Expand Down
3 changes: 1 addition & 2 deletions crates/registry/src/package_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use crate::package_distribution::PackageDistribution;
use crate::RegistryError;

#[derive(Serialize, Deserialize, Debug, Clone, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PackageVersion {
pub name: String,
pub version: node_semver::Version,
pub dist: PackageDistribution,
pub dependencies: Option<HashMap<String, String>>,
#[serde(alias = "devDependencies")]
pub dev_dependencies: Option<HashMap<String, String>>,
#[serde(alias = "peerDependencies")]
pub peer_dependencies: Option<HashMap<String, String>>,
}

Expand Down

0 comments on commit 8e908b7

Please sign in to comment.