diff --git a/index.ts b/index.ts index a5d819c..c9deae5 100755 --- a/index.ts +++ b/index.ts @@ -428,9 +428,9 @@ function isRangePrerelease(range: string) { function rangeToVersion(range: string) { try { - return coerce(range)?.version ?? null; + return coerce(range)?.version ?? ""; } 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 if (useGreatest || !("time" in data)) { - const coerced = coerce(parsed?.version)?.version; - if (!coerced) continue; - if (gte(coerced, tempVersion)) { + if (gte(rangeToVersion(parsed?.version), tempVersion)) { tempVersion = parsed.version; } } else { @@ -487,16 +485,12 @@ function findNewVersion(data: NpmData, {mode, range, useGreatest, useRel, usePre let originalLatestTag; if (mode === "pypi") { originalLatestTag = data.info.version; // may not be a 3-part semver - const coerced = coerce(data.info.version); - if (!coerced) throw new Error(`Unable to coerce ${data.info.version}`); - latestTag = coerced.version; // add .0 to 6.0 so semver eats it + latestTag = rangeToVersion(data.info.version); // add .0 to 6.0 so semver eats it } else { latestTag = data["dist-tags"].latest; } - const coerced = coerce(range); - if (!coerced) throw new Error(`Unable to coerce ${range}`); - const oldVersion = coerced.version; + const oldVersion = rangeToVersion(range); const oldIsPre = isRangePrerelease(range); const newIsPre = isVersionPrerelease(version); const latestIsPre = isVersionPrerelease(latestTag); @@ -633,10 +627,7 @@ async function checkUrlDep(key: string, dep: Dep, useGreatest: boolean) { function normalizeRange(range: string) { const versionMatches = range.match(versionRe); if (versionMatches?.length !== 1) return range; - const coerced = coerce(versionMatches[0]); - if (!coerced) return range; - // @ts-ignore - return range.replace(versionRe, coerced); + return range.replace(versionRe, rangeToVersion(versionMatches[0])); } function parseMixedArg(arg: any) { diff --git a/snapshots/index.test.ts.snap b/snapshots/index.test.ts.snap index 9f9ab3f..2d509bb 100644 --- a/snapshots/index.test.ts.snap +++ b/snapshots/index.test.ts.snap @@ -6,47 +6,47 @@ exports[`dual 1`] = ` "dependencies": { "@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", }, "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, "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", }, "jpeg-buffer-orientation": { "info": "https://github.com/fisker/jpeg-buffer-orientation", - "new": "4.1.1", + "new": "2.0.3", "old": "0.0.0", }, "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, "prismjs": { - "info": "https://github.com/PrismJS/prism", - "new": "1.29.0", + "info": "https://github.com/LeaVerou/prism", + "new": "1.17.1", "old": "1.0.0", }, "react": { "info": "https://github.com/facebook/react/tree/HEAD/packages/react", - "new": "18.3.1", + "new": "18.2.0", "old": "18.0", }, "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", }, "svgstore": { "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", + "new": "^3.0.0-2", "old": "^3.0.0", }, "updates": { @@ -58,14 +58,14 @@ exports[`dual 1`] = ` "peerDependencies": { "@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", }, }, "resolutions": { "versions/updates": { "info": "https://github.com/silverwind/updates", - "new": "^16.1.1", + "new": "^10.0.0", "old": "^1.0.0", }, }, @@ -100,7 +100,7 @@ exports[`dual 2 1`] = ` "dependencies": { "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, }, @@ -128,7 +128,7 @@ exports[`exclude 2 1`] = ` "dependencies": { "react": { "info": "https://github.com/facebook/react/tree/HEAD/packages/react", - "new": "18.3.1", + "new": "18.2.0", "old": "18.0", }, }, @@ -142,7 +142,7 @@ exports[`exclude 3 1`] = ` "dependencies": { "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, }, @@ -170,22 +170,22 @@ exports[`greatest 1`] = ` "dependencies": { "@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", }, "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, "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", }, "jpeg-buffer-orientation": { "info": "https://github.com/fisker/jpeg-buffer-orientation", - "new": "4.1.1", + "new": "2.0.3", "old": "0.0.0", }, "noty": { @@ -194,25 +194,20 @@ exports[`greatest 1`] = ` "old": "3.1.0", }, "prismjs": { - "info": "https://github.com/PrismJS/prism", - "new": "1.29.0", + "info": "https://github.com/LeaVerou/prism", + "new": "1.17.1", "old": "1.0.0", }, "react": { "info": "https://github.com/facebook/react/tree/HEAD/packages/react", - "new": "18.3.1", + "new": "18.2.0", "old": "18.0", }, "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", }, - "svgstore": { - "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", - "old": "^3.0.0", - }, "updates": { "info": "https://github.com/silverwind/updates", "new": "537ccb7", @@ -222,14 +217,14 @@ exports[`greatest 1`] = ` "peerDependencies": { "@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", }, }, "resolutions": { "versions/updates": { "info": "https://github.com/silverwind/updates", - "new": "^16.1.1", + "new": "^10.0.0", "old": "^1.0.0", }, }, @@ -243,7 +238,7 @@ exports[`include 1`] = ` "dependencies": { "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, }, @@ -257,7 +252,7 @@ exports[`include 2 1`] = ` "dependencies": { "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, }, @@ -271,7 +266,7 @@ exports[`include 3 1`] = ` "dependencies": { "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, }, @@ -285,47 +280,47 @@ exports[`latest 1`] = ` "dependencies": { "@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", }, "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, "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", }, "jpeg-buffer-orientation": { "info": "https://github.com/fisker/jpeg-buffer-orientation", - "new": "4.1.1", + "new": "2.0.3", "old": "0.0.0", }, "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, "prismjs": { - "info": "https://github.com/PrismJS/prism", - "new": "1.29.0", + "info": "https://github.com/LeaVerou/prism", + "new": "1.17.1", "old": "1.0.0", }, "react": { "info": "https://github.com/facebook/react/tree/HEAD/packages/react", - "new": "18.3.1", + "new": "18.2.0", "old": "18.0", }, "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", }, "svgstore": { "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", + "new": "^3.0.0-2", "old": "^3.0.0", }, "updates": { @@ -337,14 +332,14 @@ exports[`latest 1`] = ` "peerDependencies": { "@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", }, }, "resolutions": { "versions/updates": { "info": "https://github.com/silverwind/updates", - "new": "^16.1.1", + "new": "^10.0.0", "old": "^1.0.0", }, }, @@ -363,7 +358,7 @@ exports[`patch 1`] = ` }, "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", }, "noty": { @@ -373,7 +368,7 @@ exports[`patch 1`] = ` }, "svgstore": { "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", + "new": "^3.0.0-2", "old": "^3.0.0", }, "updates": { @@ -399,47 +394,47 @@ exports[`prerelease 1`] = ` "dependencies": { "@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", }, "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, "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", }, "jpeg-buffer-orientation": { "info": "https://github.com/fisker/jpeg-buffer-orientation", - "new": "4.1.1", + "new": "2.0.3", "old": "0.0.0", }, "noty": { "info": "https://github.com/needim/noty", - "new": "3.2.0-beta-deprecated", + "new": "3.2.0-beta", "old": "3.1.0", }, "prismjs": { - "info": "https://github.com/PrismJS/prism", - "new": "1.29.0", + "info": "https://github.com/LeaVerou/prism", + "new": "1.17.1", "old": "1.0.0", }, "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", }, "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", }, "svgstore": { "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", + "new": "^3.0.0-2", "old": "^3.0.0", }, "updates": { @@ -451,14 +446,14 @@ exports[`prerelease 1`] = ` "peerDependencies": { "@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", }, }, "resolutions": { "versions/updates": { "info": "https://github.com/silverwind/updates", - "new": "^16.1.1", + "new": "^10.0.0", "old": "^1.0.0", }, }, @@ -491,22 +486,22 @@ exports[`release 1`] = ` "dependencies": { "@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", }, "gulp-sourcemaps": { "info": "https://github.com/gulp-sourcemaps/gulp-sourcemaps", - "new": "3.0.0", + "new": "2.6.5", "old": "2.0.0", }, "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", }, "jpeg-buffer-orientation": { "info": "https://github.com/fisker/jpeg-buffer-orientation", - "new": "4.1.1", + "new": "2.0.3", "old": "0.0.0", }, "noty": { @@ -515,23 +510,23 @@ exports[`release 1`] = ` "old": "3.1.0", }, "prismjs": { - "info": "https://github.com/PrismJS/prism", - "new": "1.29.0", + "info": "https://github.com/LeaVerou/prism", + "new": "1.17.1", "old": "1.0.0", }, "react": { "info": "https://github.com/facebook/react/tree/HEAD/packages/react", - "new": "18.3.1", + "new": "18.2.0", "old": "18.0", }, "styled-components": { "info": "https://github.com/styled-components/styled-components", - "new": "6.1.11", + "new": "4.4.1", "old": "2.5.0-1", }, "svgstore": { "info": "https://github.com/svgstore/svgstore", - "new": "^3.0.1", + "new": "^2.0.3", "old": "^3.0.0", }, "updates": { @@ -543,14 +538,14 @@ exports[`release 1`] = ` "peerDependencies": { "@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", }, }, "resolutions": { "versions/updates": { "info": "https://github.com/silverwind/updates", - "new": "^16.1.1", + "new": "^10.0.0", "old": "^1.0.0", }, },