Skip to content

Commit

Permalink
fix: pnpm prune misses git dependency (vercel#3517)
Browse files Browse the repository at this point in the history
Fixes vercel#2870

The resolved version of a `github:` dependency is the lockfile key of
the package so now when resolving a package we check and see if we can
find a package by using just the version instead of `/name@version`.

This is built on top of vercel#3483 so review that first.
  • Loading branch information
chris-olszewski authored Feb 1, 2023
1 parent 93a0e54 commit b4c22a5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cli/internal/lockfile/pnpm_lockfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,16 @@ func (p *PnpmLockfile) ResolvePackage(workspacePath turbopath.AnchoredUnixPath,
return Package{Key: key, Version: version, Found: true}, nil
}

if entry, ok := p.Packages[resolvedVersion]; ok {
var version string
if entry.Version != "" {
version = entry.Version
} else {
version = resolvedVersion
}
return Package{Key: resolvedVersion, Version: version, Found: true}, nil
}

return Package{}, nil
}

Expand Down
17 changes: 17 additions & 0 deletions cli/internal/lockfile/pnpm_lockfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func Test_SpecifierResolution(t *testing.T) {
{workspacePath: "apps/web", pkg: "typescript", specifier: "^4.5.3", version: "4.8.3", found: true},
{workspacePath: "apps/web", pkg: "lodash", specifier: "bad-tag", version: "", found: false},
{workspacePath: "apps/web", pkg: "lodash", specifier: "^4.17.21", version: "4.17.21_ehchni3mpmovsvjxesffg2i5a4", found: true},
{workspacePath: "apps/docs", pkg: "dashboard-icons", specifier: "github:peerigon/dashboard-icons", version: "github.com/peerigon/dashboard-icons/ce27ef933144e09cef3911025f3649040a8571b6", found: true},
{workspacePath: "", pkg: "turbo", specifier: "latest", version: "1.4.6", found: true},
{workspacePath: "apps/bad_workspace", pkg: "turbo", specifier: "latest", version: "1.4.6", err: "no workspace 'apps/bad_workspace' found in lockfile"},
}
Expand Down Expand Up @@ -160,6 +161,22 @@ func Test_SubgraphInjectedPackages(t *testing.T) {

}

func Test_GitPackages(t *testing.T) {
contents, err := getFixture(t, "pnpm7-workspace.yaml")
if err != nil {
t.Error(err)
}
lockfile, err := DecodePnpmLockfile(contents)
assert.NilError(t, err, "decode lockfile")

pkg, err := lockfile.ResolvePackage(turbopath.AnchoredUnixPath("apps/docs"), "dashboard-icons", "github:peerigon/dashboard-icons")
assert.NilError(t, err, "failure to find package")
assert.Assert(t, pkg.Found)
assert.DeepEqual(t, pkg.Key, "github.com/peerigon/dashboard-icons/ce27ef933144e09cef3911025f3649040a8571b6")
assert.DeepEqual(t, pkg.Version, "1.0.0")
// make sure subgraph produces git dep
}

func Test_DecodePnpmUnquotedURL(t *testing.T) {
resolutionWithQuestionMark := `{integrity: sha512-deadbeef, tarball: path/to/tarball?foo=bar}`
var resolution map[string]interface{}
Expand Down
11 changes: 11 additions & 0 deletions cli/internal/lockfile/testdata/pnpm7-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ importers:
"@babel/core": ^7.0.0
"@types/node": ^17.0.12
"@types/react": 18.0.17
dashboard-icons: github:peerigon/dashboard-icons
eslint: 7.32.0
eslint-config-custom: workspace:*
next: 12.2.5
Expand All @@ -35,6 +36,7 @@ importers:
ui: workspace:*
underscore: ^1.13.4
dependencies:
dashboard-icons: github.com/peerigon/dashboard-icons/ce27ef933144e09cef3911025f3649040a8571b6
next: 12.2.5_ir3quccc6i62x6qn6jjhyjjiey
react: 18.2.0
react-dom: [email protected]
Expand Down Expand Up @@ -3432,3 +3434,12 @@ packages:
name: ui
version: 0.0.0
dev: false

github.com/peerigon/dashboard-icons/ce27ef933144e09cef3911025f3649040a8571b6:
resolution:
{
tarball: https://codeload.github.com/peerigon/dashboard-icons/tar.gz/ce27ef933144e09cef3911025f3649040a8571b,
}
name: dashboard-icons
version: 1.0.0
dev: false

0 comments on commit b4c22a5

Please sign in to comment.