utils.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.js");
  14. const versionRegExp = /^(?:\d+|\d(?:\d?[^\d\n\r\u2028\u2029]\d+|\d{2,}(?:[^\d\n\r\u2028\u2029]\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. version = version.toString();
  25. let pos = 0;
  26. let num = 0;
  27. while ((pos = version.indexOf(".", pos + 1)) > 0) {
  28. num++;
  29. }
  30. return version + ".0".repeat(2 - num);
  31. }
  32. function isUnreleasedVersion(version, env) {
  33. const unreleasedLabel = _targets.unreleasedLabels[env];
  34. return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
  35. }
  36. function getLowestUnreleased(a, b, env) {
  37. const unreleasedLabel = _targets.unreleasedLabels[env];
  38. if (a === unreleasedLabel) {
  39. return b;
  40. }
  41. if (b === unreleasedLabel) {
  42. return a;
  43. }
  44. return semverMin(a, b);
  45. }
  46. function getHighestUnreleased(a, b, env) {
  47. return getLowestUnreleased(a, b, env) === a ? b : a;
  48. }
  49. function getLowestImplementedVersion(plugin, environment) {
  50. const result = plugin[environment];
  51. if (!result && environment === "android") {
  52. return plugin.chrome;
  53. }
  54. return result;
  55. }
  56. //# sourceMappingURL=utils.js.map