Skip to content

Commit

Permalink
fix: support yarn locks with quoted properties (#250)
Browse files Browse the repository at this point in the history
Resolves #249

This files are actually valid, and generated by npm v7+
  • Loading branch information
G-Rath authored and hayleycd committed Mar 9, 2023
1 parent 06e0b0a commit 398c0f9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
18 changes: 18 additions & 0 deletions pkg/lockfile/fixtures/yarn/with-quotes.v1.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


concat-map@0.0.1:
"version" "0.0.1"
"resolved" "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
"integrity" sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=

concat-stream@^1.5.0:
"version" "1.6.2"
"resolved" "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz"
"integrity" sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==
"dependencies":
"buffer-from" "^1.0.0"
"inherits" "^2.0.3"
"readable-stream" "^2.2.2"
"typedarray" "^0.0.6"
23 changes: 23 additions & 0 deletions pkg/lockfile/fixtures/yarn/with-quotes.v2.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 5
cacheKey: 8

"compare-func@npm:^2.0.0":
"version": 2.0.0
"resolution": "compare-func@npm:2.0.0"
"dependencies":
"array-ify": ^1.0.0
"dot-prop": ^5.1.0
"checksum": fb71d70632baa1e93283cf9d80f30ac97f003aabee026e0b4426c9716678079ef5fea7519b84d012cbed938c476493866a38a79760564a9e21ae9433e40e6f0d
"languageName": node
"linkType": hard

"concat-map@npm:0.0.1":
"version": 0.0.1
"resolution": "concat-map@npm:0.0.1"
"checksum": 902a9f5d8967a3e2faf138d5cb784b9979bad2e6db5357c5b21c568df4ebe62bcb15108af1b2253744844eb964fc023fbd9afbbbb6ddd0bcc204c6fb5b7bf3af
"languageName": node
"linkType": hard
25 changes: 25 additions & 0 deletions pkg/lockfile/parse-yarn-lock-v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ func TestParseYarnLock_v1_TwoPackages(t *testing.T) {
})
}

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

packages, err := lockfile.ParseYarnLock("fixtures/yarn/with-quotes.v1.lock")

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

expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "concat-stream",
Version: "1.6.2",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
{
Name: "concat-map",
Version: "0.0.1",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
})
}

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

Expand Down
25 changes: 25 additions & 0 deletions pkg/lockfile/parse-yarn-lock-v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@ func TestParseYarnLock_v2_TwoPackages(t *testing.T) {
})
}

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

packages, err := lockfile.ParseYarnLock("fixtures/yarn/with-quotes.v2.lock")

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

expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "compare-func",
Version: "2.0.0",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
{
Name: "concat-map",
Version: "0.0.1",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
})
}

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

Expand Down
4 changes: 2 additions & 2 deletions pkg/lockfile/parse-yarn-lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func extractYarnPackageName(str string) string {
}

func determineYarnPackageVersion(group []string) string {
re := regexp.MustCompile(`^ {2}version:? "?([\w-.]+)"?$`)
re := regexp.MustCompile(`^ {2}"?version"?:? "?([\w-.]+)"?$`)

for _, s := range group {
matched := re.FindStringSubmatch(s)
Expand All @@ -78,7 +78,7 @@ func determineYarnPackageVersion(group []string) string {
}

func determineYarnPackageResolution(group []string) string {
re := regexp.MustCompile(`^ {2}(?:resolution:|resolved) "([^ '"]+)"$`)
re := regexp.MustCompile(`^ {2}"?(?:resolution:|resolved)"? "([^ '"]+)"$`)

for _, s := range group {
matched := re.FindStringSubmatch(s)
Expand Down

0 comments on commit 398c0f9

Please sign in to comment.