-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not update to pre-releases (#79)
- Loading branch information
Showing
13 changed files
with
169 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { parse as parseSemVer } from "./std/semver.ts"; | ||
import { Brand } from "./types.ts"; | ||
|
||
// Ref: https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | ||
const SEMVER_REGEXP = | ||
/v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/g; | ||
|
||
/** A string that represents a semver (e.g. `v1.0.0`.) */ | ||
export type SemVerString = Brand<string, "SemVerString">; | ||
|
||
export const SemVerString = { | ||
/** | ||
* Parse a semver string from the given import specifier. | ||
* | ||
* @param specifier The import specifier to parse. | ||
* | ||
* @returns The semver string parsed from the specifier, or `undefined` if no | ||
* semver string is found. | ||
* | ||
* @example | ||
* ```ts | ||
* parse("https://deno.land/std@0.205.0/version.ts"); | ||
* // -> "0.205.0" | ||
* ``` | ||
*/ | ||
parse(from: string): SemVerString | undefined { | ||
const match = from.match(SEMVER_REGEXP); | ||
if (!match) { | ||
return undefined; | ||
} | ||
if (match.length > 1) { | ||
console.warn( | ||
"Multiple semvers in a single specifier is not supported:", | ||
from, | ||
); | ||
return undefined; | ||
} | ||
return match[0] as SemVerString; | ||
}, | ||
|
||
/** | ||
* Check if the given semver string represents a pre-release. | ||
* @example | ||
* ```ts | ||
* isPreRelease("0.1.0" as SemVerString); // -> false | ||
* isPreRelease("0.1.0-alpha.1" as SemVerString); // -> true | ||
*/ | ||
isPreRelease(semver: SemVerString): boolean { | ||
const parsed = parseSemVer(semver); | ||
if (!parsed) { | ||
throw new TypeError(`Invalid semver: ${semver}`); | ||
} | ||
return parsed.prerelease.length > 0; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { assertEquals } from "./std/assert.ts"; | ||
import { SemVerString } from "./semver.ts"; | ||
|
||
Deno.test("SemVerString.parse()", () => { | ||
assertEquals( | ||
SemVerString.parse("https://deno.land/std@0.1.0"), | ||
"0.1.0", | ||
); | ||
assertEquals( | ||
SemVerString.parse("https://deno.land/std"), | ||
undefined, | ||
); | ||
assertEquals( | ||
SemVerString.parse("https://deno.land/std@1.0.0-rc.1"), | ||
"1.0.0-rc.1", | ||
); | ||
}); | ||
|
||
Deno.test("SemVerString.isPreRelease()", () => { | ||
assertEquals( | ||
SemVerString.isPreRelease("0.1.0" as SemVerString), | ||
false, | ||
); | ||
assertEquals( | ||
SemVerString.isPreRelease("0.1.0-alpha.1" as SemVerString), | ||
true, | ||
); | ||
assertEquals( | ||
SemVerString.isPreRelease("0.1.0-rc.1" as SemVerString), | ||
true, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { parse } from "https://deno.land/std@0.205.0/semver/parse.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters