Skip to content

Commit

Permalink
Merge pull request #361 from MHekert/fix/yarn-lock-coercing-semantic-…
Browse files Browse the repository at this point in the history
…package-version

coercing semantic package version while searching lockfile entries in yarn.lock
  • Loading branch information
ds300 committed Apr 25, 2023
2 parents 0dd9c7e + cbd9722 commit 67f929b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/coerceSemVer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import semver from "semver"

export function coerceSemVer(version: string): string | null {
return semver.coerce(version)?.version || null
}
3 changes: 2 additions & 1 deletion src/getPackageResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
import yaml from "yaml"
import findWorkspaceRoot from "find-yarn-workspace-root"
import { getPackageVersion } from "./getPackageVersion"
import { coerceSemVer } from "./coerceSemVer"

export function getPackageResolution({
packageDetails,
Expand Down Expand Up @@ -54,7 +55,7 @@ export function getPackageResolution({
([k, v]) =>
k.startsWith(packageDetails.name + "@") &&
// @ts-ignore
v.version === installedVersion,
coerceSemVer(v.version) === coerceSemVer(installedVersion),
)

const resolutions = entries.map(([_, v]) => {
Expand Down

0 comments on commit 67f929b

Please sign in to comment.