mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 11:05:41 +00:00
Simplify checkPluginVersion (#9740)
This commit is contained in:
@ -3,28 +3,16 @@ import {
|
|||||||
type InvenTreePluginContext
|
type InvenTreePluginContext
|
||||||
} from '../types/Plugins';
|
} from '../types/Plugins';
|
||||||
|
|
||||||
function extractVersion(version: string) {
|
|
||||||
// Extract the version number from the string
|
|
||||||
const [major, minor, patch] = version
|
|
||||||
.split('.')
|
|
||||||
.map((v) => Number.parseInt(v, 10));
|
|
||||||
|
|
||||||
return { major, minor, patch };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check th e
|
* Check that the plugin version matches the expected version.
|
||||||
|
* This is a helper function which only generates a warning if there is a mismatch.
|
||||||
*/
|
*/
|
||||||
export function checkPluginVersion(context: InvenTreePluginContext) {
|
export function checkPluginVersion(context: InvenTreePluginContext) {
|
||||||
const pluginVersion = extractVersion(INVENTREE_PLUGIN_VERSION);
|
const systemVersion: string = context?.version?.inventree || '';
|
||||||
const systemVersion = extractVersion(context.version.inventree);
|
|
||||||
|
|
||||||
const mismatch = `Plugin version mismatch! Expected version ${INVENTREE_PLUGIN_VERSION}, got ${context.version}`;
|
if (INVENTREE_PLUGIN_VERSION != systemVersion) {
|
||||||
|
console.info(
|
||||||
// A major version mismatch indicates a potentially breaking change
|
`Plugin version mismatch! Expected version ${INVENTREE_PLUGIN_VERSION}, got ${systemVersion}`
|
||||||
if (pluginVersion.major !== systemVersion.major) {
|
);
|
||||||
console.warn(mismatch);
|
|
||||||
} else if (INVENTREE_PLUGIN_VERSION != context.version.inventree) {
|
|
||||||
console.info(mismatch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@inventreedb/ui",
|
"name": "@inventreedb/ui",
|
||||||
"description": "UI components for the InvenTree project",
|
"description": "UI components for the InvenTree project",
|
||||||
"version": "0.0.8",
|
"version": "0.1.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
Reference in New Issue
Block a user