Skip to content

Commit

Permalink
feat: rust pnpm lockfile implementation (#4906)
Browse files Browse the repository at this point in the history
### Description

This PR is a fairly faithful Rust port of the Go implementation. There
are two intentional differences:
- A few fields in the lockfile are no longer serialized in a flow. This
is a short coming of `serde_yaml`
(dtolnay/serde-yaml#303). Luckily pnpm doesn't
care, but it does mean that the outputs between Go and Rust aren't byte
identical
- I didn't port
[convertLockfileV6DepPathToV5DepPath](https://github.com/pnpm/pnpm/blob/e2293bd6e6033cd26a7e58e151b2770cfd1699d8/lockfile/lockfile-file/src/experiments/inlineSpecifiersLockfileConverters.ts#L162)
to Rust and instead added functionality to the `DepPath` parser to
handle both v5 and v6 paths.

Reviewer notes:
- Start with `dep_path.rs`, this is primarily the parsing of "dependency
paths" which is pnpm's term for lockfile keys. They consist of a package
name, version, and sometimes a suffix which can contain the resolved
versions of peer dependencies and/or patches.
- `data.rs` contains all of the structure for the lockfile as well as
the logic for traversing the lockfile
- `se.rs`/`de.rs` contain some custom logic for handling the
`lockfileVersion` field
- All helper methods of `PnpmLockfile` in Go got ported to Rust using
snake case

### Testing Instructions

Ported all existing unit tests. Existing integration and e2e tests pass.
Manual testing that `turbo prune` output can be used with `pnpm install
--frozen-lockfile`.

---------

Co-authored-by: Chris Olszewski <Chris Olszewski>
  • Loading branch information
chris-olszewski committed May 26, 2023
1 parent af8505e commit d0170ba
Show file tree
Hide file tree
Showing 26 changed files with 6,672 additions and 885 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/internal/ffi/ffi.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ func toPackageManager(packageManager string) ffi_proto.PackageManager {
return ffi_proto.PackageManager_NPM
case "berry":
return ffi_proto.PackageManager_BERRY
case "pnpm":
return ffi_proto.PackageManager_PNPM
default:
panic(fmt.Sprintf("Invalid package manager string: %s", packageManager))
}
Expand Down
9 changes: 6 additions & 3 deletions cli/internal/ffi/proto/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/internal/lockfile/lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func AllTransitiveClosures(
if lf, ok := lockFile.(*BerryLockfile); ok {
return rustTransitiveDeps(lf.contents, "berry", workspaces, lf.resolutions)
}
if lf, ok := lockFile.(*PnpmLockfile); ok {
return rustTransitiveDeps(lf.contents, "pnpm", workspaces, nil)
}

g := new(errgroup.Group)
c := make(chan closureMsg, len(workspaces))
Expand Down
Loading

0 comments on commit d0170ba

Please sign in to comment.