fix snapshots and coerce

This commit is contained in:
silverwind 2024-05-27 23:44:41 +02:00
parent bea3b238aa
commit bb2968c6c4
Signed by untrusted user: silverwind
GPG Key ID: 2E62B41C93869443
2 changed files with 71 additions and 85 deletions

@ -428,9 +428,9 @@ function isRangePrerelease(range: string) {
function rangeToVersion(range: string) { function rangeToVersion(range: string) {
try { try {
return coerce(range)?.version ?? null; return coerce(range)?.version ?? "";
} catch { } catch {
return null; return "";
} }
} }
@ -455,9 +455,7 @@ function findVersion(data: NpmData, versions: string[], {range, semvers, usePre,
// some registries like github don't have data.time available, fall back to greatest on them // some registries like github don't have data.time available, fall back to greatest on them
if (useGreatest || !("time" in data)) { if (useGreatest || !("time" in data)) {
const coerced = coerce(parsed?.version)?.version; if (gte(rangeToVersion(parsed?.version), tempVersion)) {
if (!coerced) continue;
if (gte(coerced, tempVersion)) {
tempVersion = parsed.version; tempVersion = parsed.version;
} }
} else { } else {
@ -487,16 +485,12 @@ function findNewVersion(data: NpmData, {mode, range, useGreatest, useRel, usePre
let originalLatestTag; let originalLatestTag;
if (mode === "pypi") { if (mode === "pypi") {
originalLatestTag = data.info.version; // may not be a 3-part semver originalLatestTag = data.info.version; // may not be a 3-part semver
const coerced = coerce(data.info.version); latestTag = rangeToVersion(data.info.version); // add .0 to 6.0 so semver eats it
if (!coerced) throw new Error(`Unable to coerce ${data.info.version}`);
latestTag = coerced.version; // add .0 to 6.0 so semver eats it
} else { } else {
latestTag = data["dist-tags"].latest; latestTag = data["dist-tags"].latest;
} }
const coerced = coerce(range); const oldVersion = rangeToVersion(range);
if (!coerced) throw new Error(`Unable to coerce ${range}`);
const oldVersion = coerced.version;
const oldIsPre = isRangePrerelease(range); const oldIsPre = isRangePrerelease(range);
const newIsPre = isVersionPrerelease(version); const newIsPre = isVersionPrerelease(version);
const latestIsPre = isVersionPrerelease(latestTag); const latestIsPre = isVersionPrerelease(latestTag);
@ -633,10 +627,7 @@ async function checkUrlDep(key: string, dep: Dep, useGreatest: boolean) {
function normalizeRange(range: string) { function normalizeRange(range: string) {
const versionMatches = range.match(versionRe); const versionMatches = range.match(versionRe);
if (versionMatches?.length !== 1) return range; if (versionMatches?.length !== 1) return range;
const coerced = coerce(versionMatches[0]); return range.replace(versionRe, rangeToVersion(versionMatches[0]));
if (!coerced) return range;
// @ts-ignore
return range.replace(versionRe, coerced);
} }
function parseMixedArg(arg: any) { function parseMixedArg(arg: any) {

@ -6,47 +6,47 @@ exports[`dual 1`] = `
"dependencies": { "dependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "7.24.5", "new": "7.11.5",
"old": "7.0.0", "old": "7.0.0",
}, },
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "5.6.0", "new": "4.0.0-beta.11",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"jpeg-buffer-orientation": { "jpeg-buffer-orientation": {
"info": "https://github.com/fisker/jpeg-buffer-orientation", "info": "https://github.com/fisker/jpeg-buffer-orientation",
"new": "4.1.1", "new": "2.0.3",
"old": "0.0.0", "old": "0.0.0",
}, },
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
"prismjs": { "prismjs": {
"info": "https://github.com/PrismJS/prism", "info": "https://github.com/LeaVerou/prism",
"new": "1.29.0", "new": "1.17.1",
"old": "1.0.0", "old": "1.0.0",
}, },
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "18.3.1", "new": "18.2.0",
"old": "18.0", "old": "18.0",
}, },
"styled-components": { "styled-components": {
"info": "https://github.com/styled-components/styled-components", "info": "https://github.com/styled-components/styled-components",
"new": "6.1.11", "new": "5.0.0-rc.2",
"old": "2.5.0-1", "old": "2.5.0-1",
}, },
"svgstore": { "svgstore": {
"info": "https://github.com/svgstore/svgstore", "info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1", "new": "^3.0.0-2",
"old": "^3.0.0", "old": "^3.0.0",
}, },
"updates": { "updates": {
@ -58,14 +58,14 @@ exports[`dual 1`] = `
"peerDependencies": { "peerDependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "~7.24.5", "new": "~7.11.5",
"old": "~6.0.0", "old": "~6.0.0",
}, },
}, },
"resolutions": { "resolutions": {
"versions/updates": { "versions/updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "^16.1.1", "new": "^10.0.0",
"old": "^1.0.0", "old": "^1.0.0",
}, },
}, },
@ -100,7 +100,7 @@ exports[`dual 2 1`] = `
"dependencies": { "dependencies": {
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
}, },
@ -128,7 +128,7 @@ exports[`exclude 2 1`] = `
"dependencies": { "dependencies": {
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "18.3.1", "new": "18.2.0",
"old": "18.0", "old": "18.0",
}, },
}, },
@ -142,7 +142,7 @@ exports[`exclude 3 1`] = `
"dependencies": { "dependencies": {
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
}, },
@ -170,22 +170,22 @@ exports[`greatest 1`] = `
"dependencies": { "dependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "7.24.5", "new": "7.11.5",
"old": "7.0.0", "old": "7.0.0",
}, },
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "5.6.0", "new": "4.0.0-beta.11",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"jpeg-buffer-orientation": { "jpeg-buffer-orientation": {
"info": "https://github.com/fisker/jpeg-buffer-orientation", "info": "https://github.com/fisker/jpeg-buffer-orientation",
"new": "4.1.1", "new": "2.0.3",
"old": "0.0.0", "old": "0.0.0",
}, },
"noty": { "noty": {
@ -194,25 +194,20 @@ exports[`greatest 1`] = `
"old": "3.1.0", "old": "3.1.0",
}, },
"prismjs": { "prismjs": {
"info": "https://github.com/PrismJS/prism", "info": "https://github.com/LeaVerou/prism",
"new": "1.29.0", "new": "1.17.1",
"old": "1.0.0", "old": "1.0.0",
}, },
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "18.3.1", "new": "18.2.0",
"old": "18.0", "old": "18.0",
}, },
"styled-components": { "styled-components": {
"info": "https://github.com/styled-components/styled-components", "info": "https://github.com/styled-components/styled-components",
"new": "6.1.11", "new": "5.0.0-rc.2",
"old": "2.5.0-1", "old": "2.5.0-1",
}, },
"svgstore": {
"info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1",
"old": "^3.0.0",
},
"updates": { "updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "537ccb7", "new": "537ccb7",
@ -222,14 +217,14 @@ exports[`greatest 1`] = `
"peerDependencies": { "peerDependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "~7.24.5", "new": "~7.11.5",
"old": "~6.0.0", "old": "~6.0.0",
}, },
}, },
"resolutions": { "resolutions": {
"versions/updates": { "versions/updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "^16.1.1", "new": "^10.0.0",
"old": "^1.0.0", "old": "^1.0.0",
}, },
}, },
@ -243,7 +238,7 @@ exports[`include 1`] = `
"dependencies": { "dependencies": {
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
}, },
@ -257,7 +252,7 @@ exports[`include 2 1`] = `
"dependencies": { "dependencies": {
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
}, },
@ -271,7 +266,7 @@ exports[`include 3 1`] = `
"dependencies": { "dependencies": {
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
}, },
@ -285,47 +280,47 @@ exports[`latest 1`] = `
"dependencies": { "dependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "7.24.5", "new": "7.11.5",
"old": "7.0.0", "old": "7.0.0",
}, },
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "5.6.0", "new": "4.0.0-beta.11",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"jpeg-buffer-orientation": { "jpeg-buffer-orientation": {
"info": "https://github.com/fisker/jpeg-buffer-orientation", "info": "https://github.com/fisker/jpeg-buffer-orientation",
"new": "4.1.1", "new": "2.0.3",
"old": "0.0.0", "old": "0.0.0",
}, },
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
"prismjs": { "prismjs": {
"info": "https://github.com/PrismJS/prism", "info": "https://github.com/LeaVerou/prism",
"new": "1.29.0", "new": "1.17.1",
"old": "1.0.0", "old": "1.0.0",
}, },
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "18.3.1", "new": "18.2.0",
"old": "18.0", "old": "18.0",
}, },
"styled-components": { "styled-components": {
"info": "https://github.com/styled-components/styled-components", "info": "https://github.com/styled-components/styled-components",
"new": "6.1.11", "new": "5.0.0-rc.2",
"old": "2.5.0-1", "old": "2.5.0-1",
}, },
"svgstore": { "svgstore": {
"info": "https://github.com/svgstore/svgstore", "info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1", "new": "^3.0.0-2",
"old": "^3.0.0", "old": "^3.0.0",
}, },
"updates": { "updates": {
@ -337,14 +332,14 @@ exports[`latest 1`] = `
"peerDependencies": { "peerDependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "~7.24.5", "new": "~7.11.5",
"old": "~6.0.0", "old": "~6.0.0",
}, },
}, },
"resolutions": { "resolutions": {
"versions/updates": { "versions/updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "^16.1.1", "new": "^10.0.0",
"old": "^1.0.0", "old": "^1.0.0",
}, },
}, },
@ -363,7 +358,7 @@ exports[`patch 1`] = `
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "4.0.4", "new": "4.0.0-beta.11",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"noty": { "noty": {
@ -373,7 +368,7 @@ exports[`patch 1`] = `
}, },
"svgstore": { "svgstore": {
"info": "https://github.com/svgstore/svgstore", "info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1", "new": "^3.0.0-2",
"old": "^3.0.0", "old": "^3.0.0",
}, },
"updates": { "updates": {
@ -399,47 +394,47 @@ exports[`prerelease 1`] = `
"dependencies": { "dependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "8.0.0-alpha.8", "new": "7.11.5",
"old": "7.0.0", "old": "7.0.0",
}, },
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "5.6.0", "new": "4.0.0-beta.11",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"jpeg-buffer-orientation": { "jpeg-buffer-orientation": {
"info": "https://github.com/fisker/jpeg-buffer-orientation", "info": "https://github.com/fisker/jpeg-buffer-orientation",
"new": "4.1.1", "new": "2.0.3",
"old": "0.0.0", "old": "0.0.0",
}, },
"noty": { "noty": {
"info": "https://github.com/needim/noty", "info": "https://github.com/needim/noty",
"new": "3.2.0-beta-deprecated", "new": "3.2.0-beta",
"old": "3.1.0", "old": "3.1.0",
}, },
"prismjs": { "prismjs": {
"info": "https://github.com/PrismJS/prism", "info": "https://github.com/LeaVerou/prism",
"new": "1.29.0", "new": "1.17.1",
"old": "1.0.0", "old": "1.0.0",
}, },
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "19.0.0-rc-4c2e457c7c-20240522", "new": "18.3.0-next-d1e35c703-20221110",
"old": "18.0", "old": "18.0",
}, },
"styled-components": { "styled-components": {
"info": "https://github.com/styled-components/styled-components", "info": "https://github.com/styled-components/styled-components",
"new": "6.1.11", "new": "5.0.0-rc.2",
"old": "2.5.0-1", "old": "2.5.0-1",
}, },
"svgstore": { "svgstore": {
"info": "https://github.com/svgstore/svgstore", "info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1", "new": "^3.0.0-2",
"old": "^3.0.0", "old": "^3.0.0",
}, },
"updates": { "updates": {
@ -451,14 +446,14 @@ exports[`prerelease 1`] = `
"peerDependencies": { "peerDependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "~8.0.0-alpha.8", "new": "~7.11.5",
"old": "~6.0.0", "old": "~6.0.0",
}, },
}, },
"resolutions": { "resolutions": {
"versions/updates": { "versions/updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "^16.1.1", "new": "^10.0.0",
"old": "^1.0.0", "old": "^1.0.0",
}, },
}, },
@ -491,22 +486,22 @@ exports[`release 1`] = `
"dependencies": { "dependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "7.24.5", "new": "7.11.5",
"old": "7.0.0", "old": "7.0.0",
}, },
"gulp-sourcemaps": { "gulp-sourcemaps": {
"info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps",
"new": "3.0.0", "new": "2.6.5",
"old": "2.0.0", "old": "2.0.0",
}, },
"html-webpack-plugin": { "html-webpack-plugin": {
"info": "https://github.com/jantimon/html-webpack-plugin", "info": "https://github.com/jantimon/html-webpack-plugin",
"new": "5.6.0", "new": "3.2.0",
"old": "4.0.0-alpha.2", "old": "4.0.0-alpha.2",
}, },
"jpeg-buffer-orientation": { "jpeg-buffer-orientation": {
"info": "https://github.com/fisker/jpeg-buffer-orientation", "info": "https://github.com/fisker/jpeg-buffer-orientation",
"new": "4.1.1", "new": "2.0.3",
"old": "0.0.0", "old": "0.0.0",
}, },
"noty": { "noty": {
@ -515,23 +510,23 @@ exports[`release 1`] = `
"old": "3.1.0", "old": "3.1.0",
}, },
"prismjs": { "prismjs": {
"info": "https://github.com/PrismJS/prism", "info": "https://github.com/LeaVerou/prism",
"new": "1.29.0", "new": "1.17.1",
"old": "1.0.0", "old": "1.0.0",
}, },
"react": { "react": {
"info": "https://github.com/facebook/react/tree/HEAD/packages/react", "info": "https://github.com/facebook/react/tree/HEAD/packages/react",
"new": "18.3.1", "new": "18.2.0",
"old": "18.0", "old": "18.0",
}, },
"styled-components": { "styled-components": {
"info": "https://github.com/styled-components/styled-components", "info": "https://github.com/styled-components/styled-components",
"new": "6.1.11", "new": "4.4.1",
"old": "2.5.0-1", "old": "2.5.0-1",
}, },
"svgstore": { "svgstore": {
"info": "https://github.com/svgstore/svgstore", "info": "https://github.com/svgstore/svgstore",
"new": "^3.0.1", "new": "^2.0.3",
"old": "^3.0.0", "old": "^3.0.0",
}, },
"updates": { "updates": {
@ -543,14 +538,14 @@ exports[`release 1`] = `
"peerDependencies": { "peerDependencies": {
"@babel/preset-env": { "@babel/preset-env": {
"info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env", "info": "https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env",
"new": "~7.24.5", "new": "~7.11.5",
"old": "~6.0.0", "old": "~6.0.0",
}, },
}, },
"resolutions": { "resolutions": {
"versions/updates": { "versions/updates": {
"info": "https://github.com/silverwind/updates", "info": "https://github.com/silverwind/updates",
"new": "^16.1.1", "new": "^10.0.0",
"old": "^1.0.0", "old": "^1.0.0",
}, },
}, },