helpers.js 1.5 KB

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