Skip to content

Commit 5512aec

Browse files
chore(bun): split out actual lockfile data from processed info
1 parent c1c961c commit 5512aec

File tree

1 file changed

+13
-6
lines changed
  • crates/turborepo-lockfiles/src/bun

1 file changed

+13
-6
lines changed

crates/turborepo-lockfiles/src/bun/mod.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ pub enum Error {
2727
NotImplemented,
2828
}
2929

30+
#[derive(Debug)]
31+
pub struct BunLockfile {
32+
data: BunLockfileData,
33+
}
34+
3035
#[derive(Debug, Deserialize)]
3136
#[serde(rename_all = "camelCase")]
32-
pub struct BunLockfile {
37+
pub struct BunLockfileData {
3338
#[allow(unused)]
3439
lockfile_version: i32,
3540
workspaces: Map<String, WorkspaceEntry>,
@@ -92,6 +97,7 @@ impl Lockfile for BunLockfile {
9297
version: &str,
9398
) -> Result<Option<crate::Package>, crate::Error> {
9499
let workspace_entry = self
100+
.data
95101
.workspaces
96102
.get(workspace_path)
97103
.ok_or_else(|| crate::Error::MissingWorkspace(workspace_path.into()))?;
@@ -100,7 +106,7 @@ impl Lockfile for BunLockfile {
100106
if let Some((_key, entry)) = self.package_entry(&workspace_key) {
101107
let mut version = entry.version().to_string();
102108
// Check for any patches
103-
if let Some(patch) = self.patched_dependencies.get(&entry.ident) {
109+
if let Some(patch) = self.data.patched_dependencies.get(&entry.ident) {
104110
version.push('+');
105111
version.push_str(patch);
106112
}
@@ -131,6 +137,7 @@ impl Lockfile for BunLockfile {
131137
key: &str,
132138
) -> Result<Option<std::collections::HashMap<String, String>>, crate::Error> {
133139
let entry = self
140+
.data
134141
.packages
135142
.get(key)
136143
.ok_or_else(|| crate::Error::MissingPackage(key.into()))?;
@@ -173,7 +180,7 @@ impl Lockfile for BunLockfile {
173180
}
174181

175182
fn human_name(&self, package: &crate::Package) -> Option<String> {
176-
let entry = self.packages.get(&package.key)?;
183+
let entry = self.data.packages.get(&package.key)?;
177184
Some(entry.ident.clone())
178185
}
179186
}
@@ -188,7 +195,7 @@ impl BunLockfile {
188195
// present in the lockfile
189196
fn package_entry(&self, key: &str) -> Option<(&str, &PackageEntry)> {
190197
let (key, entry) =
191-
PossibleKeyIter::new(key).find_map(|k| self.packages.get_key_value(k))?;
198+
PossibleKeyIter::new(key).find_map(|k| self.data.packages.get_key_value(k))?;
192199
Some((key, entry))
193200
}
194201
}
@@ -217,8 +224,8 @@ impl FromStr for BunLockfile {
217224
)
218225
.map_err(Error::from)?;
219226
let strict_json = format.print().map_err(Error::from)?;
220-
let this = serde_json::from_str(strict_json.as_code())?;
221-
Ok(this)
227+
let data = serde_json::from_str(strict_json.as_code())?;
228+
Ok(Self { data })
222229
}
223230
}
224231
impl PackageEntry {

0 commit comments

Comments
 (0)