-
Notifications
You must be signed in to change notification settings - Fork 77
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
Support monorepos by coercing version strings #128
Comments
We added I'd like another opinion from maintainers more active in this repo than me; but from a quick read of d4c005f, it looks to me like Also CC @juliangruber for opinion as he wrote both of those patches! 😸 |
+1 to using |
An alternative would be a custom semver-cleaning function that grabs the first actually-valid semver substring out of a larger string: /**
* @param {string} version_string
* @returns {string|null}
*/
function find_semver_substring(version_string) {
if (!version_string || typeof version_string !== 'string') {
return false;
}
let version = semver.valid(version_string);
if (version) {
return version;
}
// Else grab the first substring that looks like a semver
// Adapted from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
version =
/(?<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-]+)*))?/.exec(
version_string,
)?.[0];
return version ?? null;
} That regex is from the official semver docs, with the leading If it doesn't make sense to capture build strings that part of the regex could be removed, or run the final result through Some examples, where each field is the string passed into {
"v10.0.3": {
"valid": "10.0.3",
"clean": "10.0.3",
"coerced": "10.0.3",
"custom": "10.0.3"
},
"0.0.11": {
"valid": "0.0.11",
"clean": "0.0.11",
"coerced": "0.0.11",
"custom": "0.0.11"
},
"0.0.11-rc": {
"valid": "0.0.11-rc",
"clean": "0.0.11-rc",
"coerced": "0.0.11",
"custom": "0.0.11-rc"
},
"[email protected]": {
"valid": null,
"clean": null,
"coerced": "2.3.4",
"custom": "2.3.4-rc.0.10"
},
"monorepo2.3": {
"valid": null,
"clean": null,
"coerced": "2.3.0",
"custom": null
},
"1.2.3-rc": {
"valid": "1.2.3-rc",
"clean": "1.2.3-rc",
"coerced": "1.2.3",
"custom": "1.2.3-rc"
},
"hello world 1": {
"valid": null,
"clean": null,
"coerced": "1.0.0",
"custom": null
}
} |
Looks like there's consensus on coerce, so @adam-coster feel free to make the PR you suggested 👍 |
The updater currenty relies on
semver.valid
to determine whether incoming version strings are valid. It does this for the parsed URL as well as the tags from GitHub releases.Monorepos have to uses more complex tag prefixes, since they can contain many projects that each have a different version. The typical format is
[email protected]
.If the updater were to clean putative version strings with
semver.coerce
, that would solve this problem.It looks like that would be an easy update -- if the feature is wanted I can make a PR!
The text was updated successfully, but these errors were encountered: