Skip to content

Commit

Permalink
fix: support peer dependencies in v6 versions of PNPM lockfiles (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Aug 25, 2023
1 parent a7d2626 commit 8a2a7bf
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
46 changes: 46 additions & 0 deletions pkg/lockfile/fixtures/pnpm/peer-dependencies-v6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
lockfileVersion: '6.0'

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

dependencies:
react-dom:
specifier: ^18.2.0
version: 18.2.0([email protected])

packages:

/[email protected]:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
dev: false

/[email protected]:
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
hasBin: true
dependencies:
js-tokens: 4.0.0
dev: false

/[email protected]([email protected]):
resolution: {integrity: sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==}
peerDependencies:
react: ^18.2.0
dependencies:
loose-envify: 1.4.0
react: 18.2.0
scheduler: 0.23.0
dev: false

/[email protected]:
resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==}
engines: {node: '>=0.10.0'}
dependencies:
loose-envify: 1.4.0
dev: false

/[email protected]:
resolution: {integrity: sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==}
dependencies:
loose-envify: 1.4.0
dev: false
2 changes: 1 addition & 1 deletion pkg/lockfile/parse-pnpm-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func extractPnpmPackageNameAndVersion(dependencyPath string) (string, string) {

func parseNameAtVersion(value string) (name string, version string) {
// look for pattern "name@version", where name is allowed to contain zero or more "@"
matches := regexp.MustCompile(`^(.+)@([\d.]+)$`).FindStringSubmatch(value)
matches := regexp.MustCompile(`^(.+)@([\d.]+)(?:\(|$)`).FindStringSubmatch(value)

if len(matches) != 3 {
return name, ""
Expand Down
43 changes: 43 additions & 0 deletions pkg/lockfile/parse-pnpm-lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,49 @@ func TestParsePnpmLock_PeerDependencies(t *testing.T) {
})
}

func TestParsePnpmLock_PeerDependenciesV6(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParsePnpmLock("fixtures/pnpm/peer-dependencies-v6.yaml")

if err != nil {
t.Errorf("Got unexpected error: %v", err)
}

expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "js-tokens",
Version: "4.0.0",
Ecosystem: lockfile.PnpmEcosystem,
CompareAs: lockfile.PnpmEcosystem,
},
{
Name: "loose-envify",
Version: "1.4.0",
Ecosystem: lockfile.PnpmEcosystem,
CompareAs: lockfile.PnpmEcosystem,
},
{
Name: "react-dom",
Version: "18.2.0",
Ecosystem: lockfile.PnpmEcosystem,
CompareAs: lockfile.PnpmEcosystem,
},
{
Name: "react",
Version: "18.2.0",
Ecosystem: lockfile.PnpmEcosystem,
CompareAs: lockfile.PnpmEcosystem,
},
{
Name: "scheduler",
Version: "0.23.0",
Ecosystem: lockfile.PnpmEcosystem,
CompareAs: lockfile.PnpmEcosystem,
},
})
}

func TestParsePnpmLock_PeerDependenciesAdvanced(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 8a2a7bf

Please sign in to comment.