diff --git a/cli/internal/lockfile/lockfile_test.go b/cli/internal/lockfile/lockfile_test.go new file mode 100644 index 0000000000000..7c666cc4f3000 --- /dev/null +++ b/cli/internal/lockfile/lockfile_test.go @@ -0,0 +1,25 @@ +package lockfile + +import ( + "sort" + "testing" + + "gotest.tools/v3/assert" +) + +func Test_ByKeySortIsStable(t *testing.T) { + packagesA := []Package{ + {"/foo/1.2.3", "1.2.3", true}, + {"/baz/1.0.9", "/baz/1.0.9", true}, + {"/bar/1.2.3", "1.2.3", true}, + {"/foo/1.2.3", "/foo/1.2.3", true}, + {"/baz/1.0.9", "1.0.9", true}, + } + packagesB := make([]Package, len(packagesA)) + copy(packagesB, packagesA) + + sort.Sort(ByKey(packagesA)) + sort.Sort(ByKey(packagesB)) + + assert.DeepEqual(t, packagesA, packagesB) +} diff --git a/cli/internal/lockfile/pnpm_lockfile.go b/cli/internal/lockfile/pnpm_lockfile.go index be259201168be..a51b36e768a9a 100644 --- a/cli/internal/lockfile/pnpm_lockfile.go +++ b/cli/internal/lockfile/pnpm_lockfile.go @@ -230,7 +230,9 @@ func (p *PnpmLockfile) ResolvePackage(workspacePath turbopath.AnchoredUnixPath, if entry.Version != "" { version = entry.Version } else { - version = resolvedVersion + // If there isn't a version field in the entry then the version is + // encoded in the key and we can omit the name from the version. + version = p.extractVersion(resolvedVersion) } return Package{Key: resolvedVersion, Version: version, Found: true}, nil } diff --git a/cli/internal/lockfile/pnpm_lockfile_test.go b/cli/internal/lockfile/pnpm_lockfile_test.go index b93541d153de8..b4c8475711b3a 100644 --- a/cli/internal/lockfile/pnpm_lockfile_test.go +++ b/cli/internal/lockfile/pnpm_lockfile_test.go @@ -307,7 +307,7 @@ func Test_PnpmOverride(t *testing.T) { assert.NilError(t, err, "failure to find package") assert.Assert(t, pkg.Found) assert.DeepEqual(t, pkg.Key, "/hardhat-deploy-ethers/0.3.0-beta.13_yab2ug5tvye2kp6e24l5x3z7uy") - assert.DeepEqual(t, pkg.Version, "/hardhat-deploy-ethers/0.3.0-beta.13_yab2ug5tvye2kp6e24l5x3z7uy") + assert.DeepEqual(t, pkg.Version, "0.3.0-beta.13_yab2ug5tvye2kp6e24l5x3z7uy") } func Test_DepPathParsing(t *testing.T) { @@ -377,7 +377,7 @@ func Test_DepPathParsing(t *testing.T) { } } -func Test_MixedVersioning(t *testing.T) { +func Test_PnpmAliasesOverlap(t *testing.T) { contents, err := getFixture(t, "pnpm-absolute.yaml") assert.NilError(t, err) @@ -398,7 +398,6 @@ func Test_MixedVersioning(t *testing.T) { assert.DeepEqual(t, deps, []Package{ {"/@scope/child/1.0.0", "1.0.0", true}, {"/@scope/parent/1.0.0", "1.0.0", true}, - {"/Special/1.2.3", "/Special/1.2.3", true}, {"/Special/1.2.3", "1.2.3", true}, {"/another/1.0.0", "1.0.0", true}, {"/foo/1.0.0", "1.0.0", true},