Skip to content

Commit

Permalink
fix: support versions with build metadata in yarn.lock files (#576)
Browse files Browse the repository at this point in the history
Resolves #574
  • Loading branch information
G-Rath committed Oct 9, 2023
1 parent 4d86a90 commit 6c68bee
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pkg/lockfile/fixtures/yarn/with-build-string.v1.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"domino@https://github.com/angular/domino.git#f2435fe1f9f7c91ade0bd472c4723e5eacd7d19a":
version "2.1.6+git"
resolved "git+ssh://git@github.com/angular/domino.git"
integrity sha512-1D4hj4hN9Q3Coi+gXZjFlxrm+7Jkhe/WBWU6loAQ/BqDWDRYwqQB1YkKbCVvfaVJXAB8OM2sae7KMyqM69pfRQ==

tslib@^2.3.0:
version "2.6.2"
resolved "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz"
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
29 changes: 29 additions & 0 deletions pkg/lockfile/fixtures/yarn/with-build-string.v2.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 6
cacheKey: 8

"domino@https://github.com/angular/domino.git#f2435fe1f9f7c91ade0bd472c4723e5eacd7d19a":
version: 2.1.6+git
resolution: "domino@https://github.com/angular/domino.git#commit=f2435fe1f9f7c91ade0bd472c4723e5eacd7d19a"
checksum: 0d9cacf8fd9ee104b9608dd1bb309520db40026e9b31533f3de5994a779bddbf0865820b67bc735c7dcb8067497c35835eb14c1656c31e0679d250f1cfd41073
languageName: node
linkType: hard

"tslib@npm:^2.3.0":
version: 2.6.2
resolution: "tslib@npm:2.6.2"
checksum: 329ea56123005922f39642318e3d1f0f8265d1e7fcb92c633e0809521da75eeaca28d2cf96d7248229deb40e5c19adf408259f4b9640afd20d13aecc1430f3ad
languageName: node
linkType: hard

"zone.js@workspace:.":
version: 0.0.0-use.local
resolution: "zone.js@workspace:."
dependencies:
domino: "https://github.com/angular/domino.git#f2435fe1f9f7c91ade0bd472c4723e5eacd7d19a"
tslib: ^2.3.0
languageName: unknown
linkType: soft
29 changes: 27 additions & 2 deletions pkg/lockfile/parse-yarn-lock-v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ func TestParseYarnLock_v1_ScopedPackages(t *testing.T) {
})
}

func TestParseYarnLock_v1_VersionsWithBuildString(t *testing.T) {
func TestParseYarnLock_v1_WithPrerelease(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseYarnLock("fixtures/yarn/versions-with-build-strings.v1.lock")
packages, err := lockfile.ParseYarnLock("fixtures/yarn/with-prerelease.v1.lock")

if err != nil {
t.Errorf("Got unexpected error: %v", err)
Expand Down Expand Up @@ -226,6 +226,31 @@ func TestParseYarnLock_v1_VersionsWithBuildString(t *testing.T) {
})
}

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

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

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

expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "domino",
Version: "2.1.6+git",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
{
Name: "tslib",
Version: "2.6.2",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
})
}

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

Expand Down
36 changes: 34 additions & 2 deletions pkg/lockfile/parse-yarn-lock-v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func TestParseYarnLock_v2_ScopedPackages(t *testing.T) {
})
}

func TestParseYarnLock_v2_VersionsWithBuildString(t *testing.T) {
func TestParseYarnLock_v2_WithPrerelease(t *testing.T) {
t.Parallel()

packages, err := lockfile.ParseYarnLock("fixtures/yarn/versions-with-build-strings.v2.lock")
packages, err := lockfile.ParseYarnLock("fixtures/yarn/with-prerelease.v2.lock")

if err != nil {
t.Errorf("Got unexpected error: %v", err)
Expand Down Expand Up @@ -189,6 +189,38 @@ func TestParseYarnLock_v2_VersionsWithBuildString(t *testing.T) {
})
}

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

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

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

expectPackages(t, packages, []lockfile.PackageDetails{
{
Name: "domino",
Version: "2.1.6+git",
Commit: "f2435fe1f9f7c91ade0bd472c4723e5eacd7d19a",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
{
Name: "tslib",
Version: "2.6.2",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
{
Name: "zone.js",
Version: "0.0.0-use.local",
Ecosystem: lockfile.YarnEcosystem,
CompareAs: lockfile.YarnEcosystem,
},
})
}

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

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

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

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

0 comments on commit 6c68bee

Please sign in to comment.