fix(tooling): migrate project config and test tooling while hardening fuzzy version parsing
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartversion',
|
||||
version: '3.0.5',
|
||||
description: 'handle semver with ease'
|
||||
version: '3.0.6',
|
||||
description: 'A library to handle semantic versioning with ease.'
|
||||
}
|
||||
|
||||
17
ts/index.ts
17
ts/index.ts
@@ -2,10 +2,14 @@ import * as plugins from './smartversion.plugins.js';
|
||||
|
||||
export class SmartVersion {
|
||||
public static fromFuzzyString(fuzzyString: string): SmartVersion {
|
||||
return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
|
||||
const minVersion = plugins.semver.minVersion(fuzzyString);
|
||||
if (!minVersion) {
|
||||
throw new Error(`Cannot determine a minimum version from fuzzy string "${fuzzyString}".`);
|
||||
}
|
||||
return new SmartVersion(minVersion.version, fuzzyString);
|
||||
}
|
||||
|
||||
public originalVersionString: string;
|
||||
public originalVersionString: string | undefined;
|
||||
public semver: plugins.semver.SemVer;
|
||||
public get versionString(): string {
|
||||
return this.semver.version;
|
||||
@@ -53,13 +57,14 @@ export class SmartVersion {
|
||||
/**
|
||||
* tries to get the best match from a range of available versions
|
||||
*/
|
||||
public getBestMatch(availableVersions: string[]): string {
|
||||
let bestMatchingVersion: string;
|
||||
public getBestMatch(availableVersions: string[]): string | undefined {
|
||||
const range = this.originalVersionString ?? this.versionString;
|
||||
let bestMatchingVersion: string | undefined;
|
||||
for (const versionArg of availableVersions) {
|
||||
if (!plugins.semver.satisfies(versionArg, this.originalVersionString)) {
|
||||
if (!plugins.semver.satisfies(versionArg, range)) {
|
||||
continue;
|
||||
}
|
||||
if(!bestMatchingVersion) {
|
||||
if (!bestMatchingVersion) {
|
||||
bestMatchingVersion = versionArg;
|
||||
} else {
|
||||
if (plugins.semver.lt(bestMatchingVersion, versionArg)) {
|
||||
|
||||
Reference in New Issue
Block a user