renderer.ts 791 B

1234567891011121314151617181920212223242526272829
  1. // Get renderer version from its config field, return 1 by default
  2. import { config } from '@grafana/runtime';
  3. export const getRendererMajorVersion = (): number | null => {
  4. const version = config.rendererVersion;
  5. if (version === '') {
  6. return null;
  7. }
  8. const semverRegex =
  9. /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
  10. const res = semverRegex.exec(version);
  11. let majorVersionStr = '';
  12. if (res && res.length > 1) {
  13. majorVersionStr = res[1];
  14. }
  15. if (majorVersionStr === '') {
  16. return 1;
  17. }
  18. let majorVersion = parseInt(majorVersionStr, 10);
  19. if (isNaN(majorVersion)) {
  20. majorVersion = 1;
  21. }
  22. return majorVersion;
  23. };