Drop compare-versions dependency

The version check we needed is simple enough to implement ourselves,
shaving off some bytes from the bundle size consumers will have when using the SDK
This commit is contained in:
Fernando Fernández 2023-04-13 10:14:42 +00:00
parent d7496cea01
commit a27eba5d2b
5 changed files with 21 additions and 16 deletions

8
package-lock.json generated
View File

@ -8,9 +8,6 @@
"name": "@jellyfin/sdk",
"version": "0.8.2",
"license": "MPL-2.0",
"dependencies": {
"compare-versions": "5.0.3"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.6.0",
"@rollup/plugin-typescript": "11.1.0",
@ -2506,11 +2503,6 @@
"node": ">= 12"
}
},
"node_modules/compare-versions": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-5.0.3.tgz",
"integrity": "sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A=="
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",

View File

@ -43,9 +43,6 @@
"typedoc": "0.24.4",
"typescript": "5.0.4"
},
"dependencies": {
"compare-versions": "5.0.3"
},
"peerDependencies": {
"axios": "^1.3.4"
}

View File

@ -28,8 +28,7 @@ export default {
preserveModulesRoot: 'src'
},
external: [
'axios',
'compare-versions'
'axios'
],
plugins: [ typescript() ]
};

View File

@ -5,7 +5,6 @@
*/
import type { AxiosError, AxiosResponse } from 'axios';
import { compare } from 'compare-versions';
import type { PublicSystemInfo } from '../generated-client/models/public-system-info';
import type { Jellyfin } from '../jellyfin';
@ -14,6 +13,7 @@ import { RecommendedServerInfoScore } from '../models/recommended-server-info';
import type { RecommendedServerIssue } from '../models/recommended-server-issue';
import { ProductNameIssue, SlowResponseIssue, SystemInfoIssue, VersionMissingIssue, VersionOutdatedIssue, VersionUnsupportedIssue } from '../models/recommended-server-issue';
import { getSystemApi } from '../utils/api/system-api';
import { isVersionLess } from '../utils/version-comparison';
import { API_VERSION, MINIMUM_VERSION } from '../versions';
/** The result of a SystemInfo request. */
@ -56,11 +56,11 @@ function toRecommendedServerInfo(result: SystemInfoResult): RecommendedServerInf
// No version was returned
issues.push(new VersionMissingIssue());
scores.push(RecommendedServerInfoScore.BAD);
} else if (compare(version, MINIMUM_VERSION, '<')) {
} else if (isVersionLess(version, MINIMUM_VERSION)) {
// Version is less than the minimum supported
issues.push(new VersionUnsupportedIssue(version));
scores.push(RecommendedServerInfoScore.OK);
} else if (compare(version, API_VERSION, '<')) {
} else if (isVersionLess(version, API_VERSION)) {
// Version is less than the generated client, but above the minimum
issues.push(new VersionOutdatedIssue(version));
scores.push(RecommendedServerInfoScore.GOOD);

View File

@ -0,0 +1,17 @@
/**
* Check if given version is less than a baseline
*
* Versions must be in semver format: X.Y.Z (Major.Minor.Patch)
* @param check - The version to check
* @param baseline - The minimum version considered supported
*/
export function isVersionLess(check: string, baseline: string): boolean {
const [majorCheck, minorCheck, patchCheck] = check.split('.').map(Number);
const [majorBaseline, minorBaseline, patchBaseline] = baseline.split('.').map(Number);
return (
majorCheck < majorBaseline ||
(majorCheck === majorBaseline && minorCheck < minorBaseline) ||
(majorCheck === majorBaseline && minorCheck === minorBaseline && patchCheck < patchBaseline)
);
}