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

feat(lockfiles): add support pnpm lockfile version 6.1 #5195

Merged
merged 3 commits into from
Jun 5, 2023
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
22 changes: 22 additions & 0 deletions crates/turborepo-lockfiles/fixtures/pnpm-v6.1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
lockfileVersion: "6.1"

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

importers:
.: {}

packages/a:
dependencies:
c:
specifier: workspace:*
version: link:../c

packages/b:
dependencies:
c:
specifier: workspace:*
version: link:../c

packages/c: {}
16 changes: 14 additions & 2 deletions crates/turborepo-lockfiles/src/pnpm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Map<K, V> = std::collections::BTreeMap<K, V>;
pub struct PnpmLockfile {
lockfile_version: LockfileVersion,
#[serde(skip_serializing_if = "Option::is_none")]
settings: Option<LockfileSettings>,
#[serde(skip_serializing_if = "Option::is_none")]
never_built_dependencies: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
only_built_dependencies: Option<Vec<String>>,
Expand Down Expand Up @@ -125,6 +127,13 @@ pub struct PackageResolution {
commit: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
struct LockfileSettings {
auto_install_peer_deps: Option<bool>,
exclude_links_from_lockfile: Option<bool>,
}

impl PnpmLockfile {
pub fn from_bytes(bytes: &[u8]) -> Result<Self, crate::Error> {
let this = serde_yaml::from_slice(bytes)?;
Expand Down Expand Up @@ -293,6 +302,7 @@ impl PnpmLockfile {
package_extensions_checksum: self.package_extensions_checksum.clone(),
patched_dependencies: patches,
time: None,
settings: self.settings.clone(),
})
}

Expand Down Expand Up @@ -430,7 +440,8 @@ pub fn pnpm_global_change(
Ok(prev_data.lockfile_version != curr_data.lockfile_version
|| prev_data.package_extensions_checksum != curr_data.package_extensions_checksum
|| prev_data.overrides != curr_data.overrides
|| prev_data.patched_dependencies != curr_data.patched_dependencies)
|| prev_data.patched_dependencies != curr_data.patched_dependencies
|| prev_data.settings != curr_data.settings)
}

#[cfg(test)]
Expand All @@ -441,6 +452,7 @@ mod tests {
const PNPM6: &[u8] = include_bytes!("../../fixtures/pnpm6-workspace.yaml").as_slice();
const PNPM7: &[u8] = include_bytes!("../../fixtures/pnpm7-workspace.yaml").as_slice();
const PNPM8: &[u8] = include_bytes!("../../fixtures/pnpm8.yaml").as_slice();
const PNPM8_6: &[u8] = include_bytes!("../../fixtures/pnpm-v6.1.yaml").as_slice();
const PNPM_ABSOLUTE: &[u8] = include_bytes!("../../fixtures/pnpm-absolute.yaml").as_slice();
const PNPM_ABSOLUTE_V6: &[u8] =
include_bytes!("../../fixtures/pnpm-absolute-v6.yaml").as_slice();
Expand All @@ -456,7 +468,7 @@ mod tests {

#[test]
fn test_roundtrip() {
for fixture in &[PNPM6, PNPM7, PNPM8] {
for fixture in &[PNPM6, PNPM7, PNPM8, PNPM8_6] {
let lockfile = PnpmLockfile::from_bytes(fixture).unwrap();
let serialized_lockfile = serde_yaml::to_string(&lockfile).unwrap();
let lockfile_from_serialized =
Expand Down