utils.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.getHighestUnreleased = getHighestUnreleased;
  6. exports.getLowestImplementedVersion = getLowestImplementedVersion;
  7. exports.getLowestUnreleased = getLowestUnreleased;
  8. exports.isUnreleasedVersion = isUnreleasedVersion;
  9. exports.semverMin = semverMin;
  10. exports.semverify = semverify;
  11. var _semver = require("semver");
  12. var _helperValidatorOption = require("@babel/helper-validator-option");
  13. var _targets = require("./targets");
  14. const versionRegExp = /^(\d+|\d+.\d+)$/;
  15. const v = new _helperValidatorOption.OptionValidator("@babel/helper-compilation-targets");
  16. function semverMin(first, second) {
  17. return first && _semver.lt(first, second) ? first : second;
  18. }
  19. function semverify(version) {
  20. if (typeof version === "string" && _semver.valid(version)) {
  21. return version;
  22. }
  23. v.invariant(typeof version === "number" || typeof version === "string" && versionRegExp.test(version), `'${version}' is not a valid version`);
  24. const split = version.toString().split(".");
  25. while (split.length < 3) {
  26. split.push("0");
  27. }
  28. return split.join(".");
  29. }
  30. function isUnreleasedVersion(version, env) {
  31. const unreleasedLabel = _targets.unreleasedLabels[env];
  32. return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
  33. }
  34. function getLowestUnreleased(a, b, env) {
  35. const unreleasedLabel = _targets.unreleasedLabels[env];
  36. const hasUnreleased = [a, b].some(item => item === unreleasedLabel);
  37. if (hasUnreleased) {
  38. return a === hasUnreleased ? b : a || b;
  39. }
  40. return semverMin(a, b);
  41. }
  42. function getHighestUnreleased(a, b, env) {
  43. return getLowestUnreleased(a, b, env) === a ? b : a;
  44. }
  45. function getLowestImplementedVersion(plugin, environment) {
  46. const result = plugin[environment];
  47. if (!result && environment === "android") {
  48. return plugin.chrome;
  49. }
  50. return result;
  51. }