BREAKING CHANGE(core): update
This commit is contained in:
parent
fdef084c6b
commit
fc41cb1403
23375
package-lock.json
generated
23375
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@ -5,6 +5,7 @@
|
|||||||
"description": "handle semver with ease",
|
"description": "handle semver with ease",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -12,16 +13,16 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.61",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.32",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.70",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^5.0.3",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^17.0.27",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/semver": "^7.3.4",
|
"@types/semver": "^7.3.9",
|
||||||
"semver": "^7.3.5"
|
"semver": "^7.3.5"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
|
22
test/test.ts
22
test/test.ts
@ -1,22 +1,22 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartversion from '../ts/index';
|
import * as smartversion from '../ts/index.js';
|
||||||
|
|
||||||
tap.test('should create a valid SmartVersion', async () => {
|
tap.test('should create a valid SmartVersion', async () => {
|
||||||
const localSmartVersion = new smartversion.SmartVersion('3.2.1');
|
const localSmartVersion = new smartversion.SmartVersion('3.2.1');
|
||||||
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion);
|
expect(localSmartVersion).toBeInstanceOf(smartversion.SmartVersion);
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false;
|
expect(localSmartVersion.greaterThanString('4.0.0')).toBeFalse();
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(localSmartVersion.greaterThanString('3.0.0')).to.be.true;
|
expect(localSmartVersion.greaterThanString('3.0.0')).toBeTrue();
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(localSmartVersion.lessThanString('v4.0.0')).to.be.true;
|
expect(localSmartVersion.lessThanString('v4.0.0')).toBeTrue();
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(localSmartVersion.lessThanString('v3.0.0')).to.be.false;
|
expect(localSmartVersion.lessThanString('v3.0.0')).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a valid SmartVersion', async () => {
|
tap.test('should create a valid SmartVersion', async () => {
|
||||||
const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4');
|
const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4');
|
||||||
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion);
|
expect(localSmartVersion).toBeInstanceOf(smartversion.SmartVersion);
|
||||||
console.log(localSmartVersion.versionString);
|
console.log(localSmartVersion.versionString);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -24,7 +24,13 @@ tap.test('should create a valid SmartVersion', async () => {
|
|||||||
const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4.x');
|
const localSmartVersion = smartversion.SmartVersion.fromFuzzyString('4.x');
|
||||||
const bestMatch = localSmartVersion.getBestMatch(['4.0.1', '4.7.5', '4.3.0']);
|
const bestMatch = localSmartVersion.getBestMatch(['4.0.1', '4.7.5', '4.3.0']);
|
||||||
console.log(bestMatch);
|
console.log(bestMatch);
|
||||||
expect(bestMatch).to.equal('4.7.5');
|
expect(bestMatch).toEqual('4.7.5');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a patch version', async () => {
|
||||||
|
const versInstance = smartversion.SmartVersion.fromFuzzyString('1.2.3');
|
||||||
|
const newVersion = versInstance.getNewPatchVersion();
|
||||||
|
console.log(newVersion.versionString);
|
||||||
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
37
ts/index.ts
37
ts/index.ts
@ -1,29 +1,19 @@
|
|||||||
import * as plugins from './smartversion.plugins';
|
import * as plugins from './smartversion.plugins.js';
|
||||||
|
|
||||||
export class SmartVersion {
|
export class SmartVersion {
|
||||||
public static fromFuzzyString(fuzzyString): SmartVersion {
|
public static fromFuzzyString(fuzzyString: string): SmartVersion {
|
||||||
return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
|
return new SmartVersion(plugins.semver.minVersion(fuzzyString).version, fuzzyString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public originalVersionString: string;
|
public originalVersionString: string;
|
||||||
public semver: plugins.semver.SemVer;
|
public semver: plugins.semver.SemVer;
|
||||||
public versionString: string;
|
public get versionString(): string {
|
||||||
public update = {
|
return this.semver.version;
|
||||||
patch: () => {
|
|
||||||
this.semver.patch = this.semver.patch + 1;
|
|
||||||
},
|
|
||||||
minor: () => {
|
|
||||||
this.semver.minor = this.semver.minor + 1;
|
|
||||||
},
|
|
||||||
major: () => {
|
|
||||||
this.semver.major = this.semver.major + 1;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(semVerStringArg: string, originalStringArg?: string) {
|
constructor(semVerStringArg: string, originalStringArg?: string) {
|
||||||
this.originalVersionString = originalStringArg;
|
this.originalVersionString = originalStringArg;
|
||||||
this.semver = new plugins.semver.SemVer(semVerStringArg);
|
this.semver = new plugins.semver.SemVer(semVerStringArg);
|
||||||
this.versionString = this.semver.version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get major() {
|
public get major() {
|
||||||
@ -45,7 +35,7 @@ export class SmartVersion {
|
|||||||
/**
|
/**
|
||||||
* compares the version of this against a string
|
* compares the version of this against a string
|
||||||
*/
|
*/
|
||||||
public greaterThanString(versionStringArg) {
|
public greaterThanString(versionStringArg: string) {
|
||||||
return plugins.semver.gt(this.versionString, versionStringArg);
|
return plugins.semver.gt(this.versionString, versionStringArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +46,7 @@ export class SmartVersion {
|
|||||||
/**
|
/**
|
||||||
* compares the version of this against a string
|
* compares the version of this against a string
|
||||||
*/
|
*/
|
||||||
public lessThanString(versionStringArg) {
|
public lessThanString(versionStringArg: string) {
|
||||||
return plugins.semver.lt(this.versionString, versionStringArg);
|
return plugins.semver.lt(this.versionString, versionStringArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,4 +69,19 @@ export class SmartVersion {
|
|||||||
}
|
}
|
||||||
return bestMatchingVersion;
|
return bestMatchingVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getNewPatchVersion() {
|
||||||
|
const newInstance = new SmartVersion(`${this.semver.major}.${this.semver.minor}.${this.semver.patch + 1}`);
|
||||||
|
return newInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNewMinorVersion() {
|
||||||
|
const newInstance = new SmartVersion(`${this.semver.major}.${this.semver.minor + 1}.${this.semver.patch}`);
|
||||||
|
return newInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNewMajorVersion() {
|
||||||
|
const newInstance = new SmartVersion(`${this.semver.major + 1}.${this.semver.minor}.${this.semver.patch}`);
|
||||||
|
return newInstance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
import * as semver from 'semver';
|
import semver from 'semver';
|
||||||
|
|
||||||
export { semver };
|
export { semver };
|
||||||
|
Loading…
Reference in New Issue
Block a user