helpers.js 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.hasMinVersion = hasMinVersion;
  4. var _semver = _interopRequireDefault(require("semver"));
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. function hasMinVersion(minVersion, runtimeVersion) {
  7. // If the range is unavailable, we're running the script during Babel's
  8. // build process, and we want to assume that all versions are satisfied so
  9. // that the built output will include all definitions.
  10. if (!runtimeVersion || !minVersion) return true;
  11. runtimeVersion = String(runtimeVersion);
  12. // semver.intersects() has some surprising behavior with comparing ranges
  13. // with preprelease versions. We add '^' to ensure that we are always
  14. // comparing ranges with ranges, which sidesteps this logic.
  15. // For example:
  16. //
  17. // semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
  18. // semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
  19. //
  20. // This is because the first falls back to
  21. //
  22. // semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
  23. //
  24. // and this fails because a prerelease version can only satisfy a range
  25. // if it is a prerelease within the same major/minor/patch range.
  26. //
  27. // Note: If this is found to have issues, please also revist the logic in
  28. // babel-core's availableHelper() API.
  29. if (_semver.default.valid(runtimeVersion)) runtimeVersion = `^${runtimeVersion}`;
  30. return !_semver.default.intersects(`<${minVersion}`, runtimeVersion) && !_semver.default.intersects(`>=8.0.0`, runtimeVersion);
  31. }