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(pnpm): support pnpm lockfile v9 #7994

Merged
merged 1 commit into from
Apr 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions crates/turborepo-lockfiles/fixtures/pnpm-v9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
lockfileVersion: "9.0"

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

importers:
.:
devDependencies:
turbo:
specifier: canary
version: 1.13.3-canary.1

apps/apps-a:
dependencies:
pkg-a:
specifier: workspace:*
version: link:../../packages/pkg-a
tooling-config:
specifier: workspace:*
version: link:../../packages/tooling-config

apps/apps-b:
dependencies:
tooling-config:
specifier: workspace:*
version: link:../../packages/tooling-config

packages/pkg-a:
dependencies:
tooling-config:
specifier: workspace:*
version: link:../tooling-config

packages/pkg-b:
dependencies:
tooling-config:
specifier: workspace:*
version: link:../tooling-config

packages/tooling-config: {}

packages:
turbo-darwin-64@1.13.3-canary.1:
resolution:
{
integrity: sha512-1xfKCf/d7mD7oGT1qBnD5pYsZfI43Wftlo/N0GTpBLDjKhfJifBvng9ns5grhs79wNiIdDxYYGt6pHOUzc+6YQ==,
}
cpu: [x64]
os: [darwin]

turbo-darwin-arm64@1.13.3-canary.1:
resolution:
{
integrity: sha512-uNK9QnlDJBLuaR7l4/68AoKByQ+q+rT9OyvizzUV2KZ8r2u/Sv+f3GiV48qxtG1duYlWLlLnDGuEnUPKEq0WZg==,
}
cpu: [arm64]
os: [darwin]

turbo-linux-64@1.13.3-canary.1:
resolution:
{
integrity: sha512-D/RRtqHch0I5q/Pod7mgLPGrvjcDpvBe95yp5hNy59+ZSyKHlkDrm/pQaA/+6mdjHEQB8eIL/18nrKx/B5qduA==,
}
Comment on lines +62 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

umm.. what is this?? json inside yaml?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They did in fact add JSON to YAML: https://www.yaml.info/learn/flowstyle.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look-how-theyve-massacred-my-boy.jpg

cpu: [x64]
os: [linux]

turbo-linux-arm64@1.13.3-canary.1:
resolution:
{
integrity: sha512-FXwgkadDZr6mPLN7lmlc0ESRZFfXDONEKTQbDV9h4n/7I0HOehMM0CrWZsptoekKEKFEqQDxZo5QXFDZON0cww==,
}
cpu: [arm64]
os: [linux]

turbo-windows-64@1.13.3-canary.1:
resolution:
{
integrity: sha512-ce6TENLbCeFAWVrJtLMOjv7FkPCpfSNvczFpaolbOB9omPW3uO4hXMbpqk14hgsU8OsmMt61rLzI38L0miJuEw==,
}
cpu: [x64]
os: [win32]

turbo-windows-arm64@1.13.3-canary.1:
resolution:
{
integrity: sha512-7sm8tZRqcmWo/D3Mb513/diVZuFC6rwz/ZaW8IGsEcLrUdqq6qSRlW6e7ZsfOMR7cO6geeGhuFsJg8ILOETTgw==,
}
cpu: [arm64]
os: [win32]

turbo@1.13.3-canary.1:
resolution:
{
integrity: sha512-bxOFjIhBxwWiExjUyTV2KOP6P28M5TOHUaM6YKRR2oPtKoQpIGUmYP+DCxG+icjaLXviUJRHU4YxzEOaL9Bf6A==,
}
hasBin: true

snapshots:
turbo-darwin-64@1.13.3-canary.1:
optional: true

turbo-darwin-arm64@1.13.3-canary.1:
optional: true

turbo-linux-64@1.13.3-canary.1:
optional: true

turbo-linux-arm64@1.13.3-canary.1:
optional: true

turbo-windows-64@1.13.3-canary.1:
optional: true

turbo-windows-arm64@1.13.3-canary.1:
optional: true

turbo@1.13.3-canary.1:
optionalDependencies:
turbo-darwin-64: 1.13.3-canary.1
turbo-darwin-arm64: 1.13.3-canary.1
turbo-linux-64: 1.13.3-canary.1
turbo-linux-arm64: 1.13.3-canary.1
turbo-windows-64: 1.13.3-canary.1
turbo-windows-arm64: 1.13.3-canary.1
21 changes: 17 additions & 4 deletions crates/turborepo-lockfiles/src/pnpm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl PnpmLockfile {
SupportedLockfileVersion::V5 | SupportedLockfileVersion::V6 => {
self.packages.as_ref().map(|pkgs| pkgs.contains_key(key))
}
SupportedLockfileVersion::V7 => {
SupportedLockfileVersion::V7AndV9 => {
self.snapshots.as_ref().map(|snaps| snaps.contains_key(key))
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ impl PnpmLockfile {
return SupportedLockfileVersion::V5;
}
match self.lockfile_version.version.as_str() {
"7.0" => SupportedLockfileVersion::V7,
"7.0" | "9.0" => SupportedLockfileVersion::V7AndV9,
_ => SupportedLockfileVersion::V6,
}
}
Expand All @@ -230,7 +230,7 @@ impl PnpmLockfile {
match self.version() {
SupportedLockfileVersion::V5 => format!("/{name}/{version}"),
SupportedLockfileVersion::V6 => format!("/{name}@{version}"),
SupportedLockfileVersion::V7 => format!("{name}@{version}"),
SupportedLockfileVersion::V7AndV9 => format!("{name}@{version}"),
}
}

Expand Down Expand Up @@ -298,7 +298,7 @@ impl PnpmLockfile {
let patch_key = format!("{}@{}", dp.name, dp.version);
if let Some(patch) = patches.get(&patch_key).filter(|patch| {
// In V7 patch hash isn't included in packages key, so no need to check
matches!(self.version(), SupportedLockfileVersion::V7)
matches!(self.version(), SupportedLockfileVersion::V7AndV9)
|| dp.patch_hash() == Some(&patch.hash)
}) {
pruned_patches.insert(patch_key, patch.clone());
Expand Down Expand Up @@ -604,6 +604,7 @@ mod tests {
const PNPM_V7: &[u8] = include_bytes!("../../fixtures/pnpm-v7.yaml").as_slice();
const PNPM_V7_PEER: &[u8] = include_bytes!("../../fixtures/pnpm-v7-peer.yaml").as_slice();
const PNPM_V7_PATCH: &[u8] = include_bytes!("../../fixtures/pnpm-v7-patch.yaml").as_slice();
const PNPM_V9: &[u8] = include_bytes!("../../fixtures/pnpm-v9.yaml").as_slice();

use super::*;
use crate::{Lockfile, Package};
Expand All @@ -615,6 +616,7 @@ mod tests {
#[test_case(PNPM_V7)]
#[test_case(PNPM_V7_PEER)]
#[test_case(PNPM_V7_PATCH)]
#[test_case(PNPM_V9)]
fn test_roundtrip(fixture: &[u8]) {
let lockfile = PnpmLockfile::from_bytes(fixture).unwrap();
let serialized_lockfile = serde_yaml::to_string(&lockfile).unwrap();
Expand Down Expand Up @@ -856,6 +858,17 @@ mod tests {
}))
; "v7 peer 2"
)]
#[test_case(
PNPM_V9,
"",
"turbo",
"canary",
Ok(Some(crate::Package {
key: "turbo@1.13.3-canary.1".into(),
version: "1.13.3-canary.1".into(),
}))
; "v9"
)]
fn test_resolve_package(
lockfile: &[u8],
workspace_path: &str,
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lockfiles/src/pnpm/dep_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> DepPath<'a> {
input: &'a str,
) -> Result<Self, nom::error::Error<String>> {
let (_, dep_path) = match version {
SupportedLockfileVersion::V7 => parse_dep_path_v7(input),
SupportedLockfileVersion::V7AndV9 => parse_dep_path_v7(input),
SupportedLockfileVersion::V5 | SupportedLockfileVersion::V6 => parse_dep_path(input),
}
.map_err(|e| e.to_owned())
Expand Down
5 changes: 4 additions & 1 deletion crates/turborepo-lockfiles/src/pnpm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ enum VersionFormat {
enum SupportedLockfileVersion {
V5,
V6,
V7,
// As of pnpm@9.0.0-rc.0 the lockfile version will now match the pnpm version
// Lockfile version 7.0 and 9.0 are both the same version
// See https://github.com/pnpm/pnpm/pull/7861
V7AndV9,
}

pub fn pnpm_subgraph(
Expand Down
Loading