Skip to content

Commit

Permalink
fix: support alpha/beta semver ranges and 0.0.0 package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Sep 4, 2023
1 parent 49ec48a commit 7e5f8d1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 22 additions & 2 deletions src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,25 @@ export const randstr = (len: number) => {
return crypto.randomBytes(len).toString('hex')
}

export const isVersionInRange = (version: string, semverRange: string) =>
semver.satisfies(version, semverRange, { includePrerelease: true })
/**
* Any `0.0.0` version is assumed to be compatible with any version range. If
* the `semverRange` starts with a letter, it is assumed to be a tag name, and
* the version must end with it (plus an optional `.[0-9]+` suffix in case of
* alpha/beta versions). The only exception is when the range is `latest` or
* `next`, in which case all versions are assumed to be compatible.
*/
export function isVersionInRange(version: string, semverRange: string) {
if (/^0\.0\.0(-.+)?$/.test(version)) {
return true
}
if (/^[a-z]/i.test(semverRange)) {
if (semverRange === 'latest' || semverRange === 'next') {
return true
}
const tagRegex = new RegExp('-' + semverRange + '(\\.[0-9]+)?$')
return tagRegex.test(version)
}
return semver.satisfies(version, semverRange, {
includePrerelease: true,
})
}
1 change: 0 additions & 1 deletion src/core/linkPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function linkPackages(
if (dep) {
const valid =
!version ||
/^(latest|next)$/.test(version) ||
isVersionInRange(dep.version, version) ||
/^https?:\/\//.test(version)

Expand Down

0 comments on commit 7e5f8d1

Please sign in to comment.