mirror of
https://github.com/jellyfin/jellyfin-sdk-typescript.git
synced 2024-11-22 21:49:48 +00:00
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:
parent
d7496cea01
commit
a27eba5d2b
8
package-lock.json
generated
8
package-lock.json
generated
@ -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",
|
||||
|
@ -43,9 +43,6 @@
|
||||
"typedoc": "0.24.4",
|
||||
"typescript": "5.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"compare-versions": "5.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"axios": "^1.3.4"
|
||||
}
|
||||
|
@ -28,8 +28,7 @@ export default {
|
||||
preserveModulesRoot: 'src'
|
||||
},
|
||||
external: [
|
||||
'axios',
|
||||
'compare-versions'
|
||||
'axios'
|
||||
],
|
||||
plugins: [ typescript() ]
|
||||
};
|
||||
|
@ -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);
|
||||
|
17
src/utils/version-comparison.ts
Normal file
17
src/utils/version-comparison.ts
Normal 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)
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user