helpers.js 1.5 KB

1234567891011121314151617181920212223242526272829303132
  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. // semver.intersects() has some surprising behavior with comparing ranges
  12. // with preprelease versions. We add '^' to ensure that we are always
  13. // comparing ranges with ranges, which sidesteps this logic.
  14. // For example:
  15. //
  16. // semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
  17. // semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
  18. //
  19. // This is because the first falls back to
  20. //
  21. // semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
  22. //
  23. // and this fails because a prerelease version can only satisfy a range
  24. // if it is a prerelease within the same major/minor/patch range.
  25. //
  26. // Note: If this is found to have issues, please also revist the logic in
  27. // babel-core's availableHelper() API.
  28. if (_semver.default.valid(runtimeVersion)) runtimeVersion = `^${runtimeVersion}`;
  29. return !_semver.default.intersects(`<${minVersion}`, runtimeVersion) && !_semver.default.intersects(`>=8.0.0`, runtimeVersion);
  30. }