Skip to content

Commit

Permalink
feat: add NpmResolutionPackage.scripts (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Apr 25, 2024
1 parent 3989613 commit f129664
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ pub struct NpmResolutionPackage {
pub dependencies: HashMap<String, NpmPackageId>,
pub optional_dependencies: HashSet<String>,
pub bin: Option<NpmPackageVersionBinEntry>,
pub scripts: HashMap<String, String>,
}

impl std::fmt::Debug for NpmResolutionPackage {
Expand Down Expand Up @@ -282,6 +283,7 @@ impl NpmResolutionPackage {
dependencies: self.dependencies.clone(),
optional_dependencies: self.optional_dependencies.clone(),
bin: self.bin.clone(),
scripts: self.scripts.clone(),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ pub struct NpmPackageVersionInfo {
pub os: Vec<String>,
#[serde(default)]
pub cpu: Vec<String>,
#[serde(default)]
pub scripts: HashMap<String, String>,
}

impl NpmPackageVersionInfo {
Expand Down
1 change: 1 addition & 0 deletions src/resolution/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ impl Graph {
.cloned()
.collect(),
bin: version_info.bin.clone(),
scripts: version_info.scripts.clone(),
},
);
}
Expand Down
9 changes: 9 additions & 0 deletions src/resolution/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub struct SerializedNpmResolutionSnapshotPackage {
pub dependencies: HashMap<String, NpmPackageId>,
pub optional_dependencies: HashSet<String>,
pub bin: Option<NpmPackageVersionBinEntry>,
pub scripts: HashMap<String, String>,
}

#[derive(Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -239,6 +240,7 @@ impl NpmResolutionSnapshot {
dependencies: package.dependencies,
optional_dependencies: package.optional_dependencies,
bin: package.bin,
scripts: package.scripts,
},
);
}
Expand Down Expand Up @@ -298,6 +300,7 @@ impl NpmResolutionSnapshot {
system: Default::default(),
optional_dependencies: Default::default(),
bin: None,
scripts: Default::default(),
};
for (key, dep_id) in &pkg.dependencies {
let dep = self.packages.get(dep_id).unwrap();
Expand Down Expand Up @@ -978,6 +981,7 @@ pub async fn snapshot_from_lockfile<'a>(
.into_keys()
.collect(),
bin: version_info.bin.clone(),
scripts: version_info.scripts.clone(),
});
}
Err(err) => {
Expand Down Expand Up @@ -1079,6 +1083,7 @@ mod tests {
dist: Default::default(),
optional_dependencies: HashSet::from(["c".to_string()]),
bin: None,
scripts: Default::default(),
},
SerializedNpmResolutionSnapshotPackage {
id: NpmPackageId::from_serialized("b@1.0.0").unwrap(),
Expand All @@ -1087,6 +1092,7 @@ mod tests {
dist: Default::default(),
optional_dependencies: Default::default(),
bin: None,
scripts: Default::default(),
},
SerializedNpmResolutionSnapshotPackage {
id: NpmPackageId::from_serialized("c@1.0.0").unwrap(),
Expand All @@ -1098,6 +1104,7 @@ mod tests {
dist: Default::default(),
optional_dependencies: Default::default(),
bin: None,
scripts: Default::default(),
},
SerializedNpmResolutionSnapshotPackage {
id: NpmPackageId::from_serialized("d@1.0.0").unwrap(),
Expand All @@ -1106,6 +1113,7 @@ mod tests {
dist: Default::default(),
optional_dependencies: Default::default(),
bin: None,
scripts: Default::default(),
},
],
}
Expand Down Expand Up @@ -1217,6 +1225,7 @@ mod tests {
dist: Default::default(),
optional_dependencies: Default::default(),
bin: None,
scripts: Default::default(),
}
}

Expand Down

0 comments on commit f129664

Please sign in to comment.