utils.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. 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 =
  34. _targets.unreleasedLabels[env];
  35. return !!unreleasedLabel && unreleasedLabel === version.toString().toLowerCase();
  36. }
  37. function getLowestUnreleased(a, b, env) {
  38. const unreleasedLabel =
  39. _targets.unreleasedLabels[env];
  40. if (a === unreleasedLabel) {
  41. return b;
  42. }
  43. if (b === unreleasedLabel) {
  44. return a;
  45. }
  46. return semverMin(a, b);
  47. }
  48. function getHighestUnreleased(a, b, env) {
  49. return getLowestUnreleased(a, b, env) === a ? b : a;
  50. }
  51. function getLowestImplementedVersion(plugin, environment) {
  52. const result = plugin[environment];
  53. if (!result && environment === "android") {
  54. return plugin.chrome;
  55. }
  56. return result;
  57. }
  58. //# sourceMappingURL=utils.js.map