diff --git a/pkg/lockfile/fixtures/yarn/with-build-string.v1.lock b/pkg/lockfile/fixtures/yarn/with-build-string.v1.lock new file mode 100644 index 0000000000..b95d9494c6 --- /dev/null +++ b/pkg/lockfile/fixtures/yarn/with-build-string.v1.lock @@ -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== diff --git a/pkg/lockfile/fixtures/yarn/with-build-string.v2.lock b/pkg/lockfile/fixtures/yarn/with-build-string.v2.lock new file mode 100644 index 0000000000..de6dd4ef4b --- /dev/null +++ b/pkg/lockfile/fixtures/yarn/with-build-string.v2.lock @@ -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 diff --git a/pkg/lockfile/fixtures/yarn/versions-with-build-strings.v1.lock b/pkg/lockfile/fixtures/yarn/with-prerelease.v1.lock similarity index 100% rename from pkg/lockfile/fixtures/yarn/versions-with-build-strings.v1.lock rename to pkg/lockfile/fixtures/yarn/with-prerelease.v1.lock diff --git a/pkg/lockfile/fixtures/yarn/versions-with-build-strings.v2.lock b/pkg/lockfile/fixtures/yarn/with-prerelease.v2.lock similarity index 100% rename from pkg/lockfile/fixtures/yarn/versions-with-build-strings.v2.lock rename to pkg/lockfile/fixtures/yarn/with-prerelease.v2.lock diff --git a/pkg/lockfile/parse-yarn-lock-v1_test.go b/pkg/lockfile/parse-yarn-lock-v1_test.go index 80e26797d9..c2363e739c 100644 --- a/pkg/lockfile/parse-yarn-lock-v1_test.go +++ b/pkg/lockfile/parse-yarn-lock-v1_test.go @@ -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) @@ -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() diff --git a/pkg/lockfile/parse-yarn-lock-v2_test.go b/pkg/lockfile/parse-yarn-lock-v2_test.go index 23d66ba2a8..55959faecc 100644 --- a/pkg/lockfile/parse-yarn-lock-v2_test.go +++ b/pkg/lockfile/parse-yarn-lock-v2_test.go @@ -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) @@ -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() diff --git a/pkg/lockfile/parse-yarn-lock.go b/pkg/lockfile/parse-yarn-lock.go index 5c764c7b5b..43e6836403 100644 --- a/pkg/lockfile/parse-yarn-lock.go +++ b/pkg/lockfile/parse-yarn-lock.go @@ -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)