Skip to content

Commit

Permalink
fix(pnpm): support pnpm lockfile v9 (#7994)
Browse files Browse the repository at this point in the history
### Description

Closes #7993

Only thing that required updating is that as of `9.0.0-rc.0` the
lockfile version was updated to `9.0` instead of `7.0` that was used
from `9.0.0-alpha.0`-`9.0.0-beta.3`. I believe this was the only change
made since I added support for lockfile v7 in #7853.

### Testing Instructions

Added roundtrip test along with unit test for package resolution.

Manual test with repro provided in #7993
```
[0 olszewski@chriss-mbp] /tmp/pnpm-prune-repro $ turbo_dev --skip-infer prune app-a 
Generating pruned monorepo for app-a in /private/tmp/pnpm-prune-repro/out
 - Added app-a
 - Added pkg-a
 - Added tooling-config
[0 olszewski@chriss-mbp] /tmp/pnpm-prune-repro $ cd out 
[0 olszewski@chriss-mbp] /tmp/pnpm-prune-repro/out $ pnpm i --frozen-lockfile
Scope: all 4 workspace projects
Lockfile is up to date, resolution step is skipped
Packages: +2
++
Progress: resolved 2, reused 2, downloaded 0, added 2, done

devDependencies:
+ turbo 1.13.3-canary.1

Done in 245ms
```


Closes TURBO-2826
  • Loading branch information
chris-olszewski committed Apr 17, 2024
1 parent adbfe4c commit 6a34946
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 6 deletions.
125 changes: 125 additions & 0 deletions crates/turborepo-lockfiles/fixtures/pnpm-v9.yaml
@@ -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==,
}
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
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
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
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

0 comments on commit 6a34946

Please sign in to comment.