Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SemVer handling & add 0.9.0 compat #104

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function handleCompatibility(header: unknown, payload: unknown): UcanPart

// parse either the "ucv" or "uav" as a version in the header
// we translate 'uav: 1.0.0' into 'ucv: 0.3.0'
let version: "0.8.1" | "0.3.0" = "0.8.1"
let version: "0.9.1" | "0.3.0" = "0.9.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blaine Not entirely sure what this does, does it set the default version to 0.9.1?

if (!util.hasProp(header, "ucv") || typeof header.ucv !== "string") {
if (!util.hasProp(header, "uav") || typeof header.uav !== "string") {
throw fail("header", "Invalid format: Missing version indicator")
Expand Down
19 changes: 14 additions & 5 deletions packages/core/src/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,27 @@ const matchesRegex = (regex: RegExp) => (str: string) => {
}

export function parse(version: string): SemVer | null {
const parts = version.split(".")

const sv = version.match(
/^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
)

if (sv === null) {
return null
}

const parts =
`${sv.groups?.major}.${sv.groups?.minor}.${sv.groups?.patch}`.split(".")

if (parts.length !== 3) {
return null
}

if (!parts.every(matchesRegex(NUM_REGEX))) {
return null
}
const [ major, minor, patch ] = parts.map(part => parseInt(part, 10))

const [major, minor, patch] = parts.map(part => parseInt(part, 10))

if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) {
return null
}
Expand Down
Loading