Skip to content

Commit

Permalink
coercing semantic package version while searching lockfile entries in…
Browse files Browse the repository at this point in the history
… yarn.lock
  • Loading branch information
MHekert committed Oct 18, 2022
1 parent fe6138b commit cbd9722
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 cbd9722

Please sign in to comment.