diff --git a/fixtures/test.json b/fixtures/test.json index 95ed96d..ca23709 100644 --- a/fixtures/test.json +++ b/fixtures/test.json @@ -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:." diff --git a/test.js b/test.js index 4d298c5..c815e31 100644 --- a/test.js +++ b/test.js @@ -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", } diff --git a/updates.js b/updates.js index 27d6070..30abf6a 100755 --- a/updates.js +++ b/updates.js @@ -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, + }; } } }