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 Nov 19, 2021
1 parent 5c2c92b commit 242ac99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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
}
4 changes: 2 additions & 2 deletions src/getPackageResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readFileSync, existsSync } from "fs-extra"
import { parse as parseYarnLockFile } from "@yarnpkg/lockfile"
import findWorkspaceRoot from "find-yarn-workspace-root"
import { getPackageVersion } from "./getPackageVersion"
import { coerceSemVer } from "./coerceSemVer"

export function getPackageResolution({
packageDetails,
Expand Down Expand Up @@ -39,7 +40,7 @@ export function getPackageResolution({
const entries = Object.entries(appLockFile.object).filter(
([k, v]) =>
k.startsWith(packageDetails.name + "@") &&
v.version === installedVersion,
coerceSemVer(v.version) === coerceSemVer(installedVersion),
)

const resolutions = entries.map(([_, v]) => {
Expand Down Expand Up @@ -100,7 +101,6 @@ if (require.main === module) {
if (!packageDetails) {
console.error(`Can't find package ${process.argv[2]}`)
process.exit(1)
throw new Error()
}
console.log(
getPackageResolution({
Expand Down

0 comments on commit 242ac99

Please sign in to comment.