From 8c048cdf06cc65a0e4de48795bc892964e89ea3e Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 26 Aug 2023 08:22:16 +1200 Subject: [PATCH] refactor: remove unneeded index check in favor of just always splitting (#210) --- pkg/lockfile/parse-pnpm-lock.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/lockfile/parse-pnpm-lock.go b/pkg/lockfile/parse-pnpm-lock.go index 0d4adad1..3f78f7f5 100644 --- a/pkg/lockfile/parse-pnpm-lock.go +++ b/pkg/lockfile/parse-pnpm-lock.go @@ -96,11 +96,9 @@ func extractPnpmPackageNameAndVersion(dependencyPath string) (string, string) { return "", "" } - underscoreIndex := strings.Index(version, "_") - - if underscoreIndex != -1 { - version = strings.Split(version, "_")[0] - } + // peer dependencies in v5 lockfiles are attached to the end of the version + // with an "_", so we always want the first element if an "_" is present + version = strings.Split(version, "_")[0] return name, version }