support updating from 1- and 2-digit version ranges

This commit is contained in:
silverwind 2022-11-10 22:44:24 +01:00
parent c3af221bd5
commit 724dace6ea
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
3 changed files with 23 additions and 7 deletions

@ -10,7 +10,7 @@
"@babel/preset-env": "7.0.0",
"updates": "https://github.com/silverwind/updates/tarball/6941e05",
"ipaddr.js": "https://github.com/silverwind/ipaddr.js/tarball/ipv6_cidrs_take2",
"react": "18.0.0"
"react": "18.0"
},
"devDependencies": {
"updates": "file:."

@ -189,7 +189,7 @@ test("latest", makeTest("-j", {
info: "https://github.com/silverwind/updates",
},
"react": {
old: "18.0.0",
old: "18.0",
new: "18.2.0",
info: "https://github.com/facebook/react/tree/HEAD/packages/react",
},
@ -253,7 +253,7 @@ test("greatest", makeTest("-j -g", {
info: "https://github.com/silverwind/updates",
},
"react": {
old: "18.0.0",
old: "18.0",
new: "18.2.0",
info: "https://github.com/facebook/react/tree/HEAD/packages/react",
}
@ -322,7 +322,7 @@ test("prerelease", makeTest("-j -g -p", {
info: "https://github.com/silverwind/updates",
},
"react": {
old: "18.0.0",
old: "18.0",
new: "18.3.0-next-d1e35c703-20221110",
info: "https://github.com/facebook/react/tree/HEAD/packages/react",
}
@ -391,7 +391,7 @@ test("release", makeTest("-j -R", {
info: "https://github.com/silverwind/updates",
},
"react": {
old: "18.0.0",
old: "18.0",
new: "18.2.0",
info: "https://github.com/facebook/react/tree/HEAD/packages/react",
}

@ -26,6 +26,7 @@ const sep = "\0";
const stripRe = /^.*?:\/\/(.*?@)?(github\.com[:/])/i;
const partsRe = /^([^/]+)\/([^/#]+)?.*?\/([0-9a-f]+|v?[0-9]+\.[0-9]+\.[0-9]+)$/i;
const hashRe = /^[0-9a-f]{7,}$/i;
const versionRe = /[0-9]+(\.[0-9]+)?(\.[0-9]+)?/g;
const esc = str => str.replace(/[|\\{}()[\]^$+*?.-]/g, "\\$&");
const gitInfo = memoize(fromUrl);
const registryAuthToken = memoize(rat);
@ -232,6 +233,10 @@ function finish(obj, deps = {}) {
value.new = value.newPrint;
delete value.newPrint;
}
if ("oldOriginal" in value) {
value.old = value.oldOriginal;
delete value.oldOriginal;
}
}
if (args.json) {
@ -508,6 +513,12 @@ function resolutionsBasePackage(name) {
return packages[packages.length - 1];
}
function normalizeRange(range) {
const versionMatches = range.match(versionRe);
if (versionMatches.length !== 1) return range;
return range.replace(versionRe, semver.coerce(versionMatches[0]));
}
function parseMixedArg(arg) {
if (arg === undefined) {
return false;
@ -643,9 +654,14 @@ async function main() {
for (const depType of dependencyTypes) {
for (const [name, value] of Object.entries(pkg[depType] || {})) {
if (semver.validRange(value) && canInclude(name)) {
deps[`${depType}${sep}${name}`] = {old: value};
deps[`${depType}${sep}${name}`] = {
old: normalizeRange(value),
oldOriginal: value,
};
} else if (canInclude(name)) {
maybeUrlDeps[`${depType}${sep}${name}`] = {old: value};
maybeUrlDeps[`${depType}${sep}${name}`] = {
old: value,
};
}
}
}