Fix prerelease checks in .availableHelper and transform-runtime definitions. (#8659)

This commit is contained in:
Logan Smyth
2018-09-10 18:25:21 -07:00
committed by GitHub
parent 9ad8b2bb2c
commit 13798feefb
31 changed files with 238 additions and 87 deletions

View File

@@ -166,6 +166,25 @@ export default class File {
return false;
}
// semver.intersects() has some surprising behavior with comparing ranges
// with preprelease versions. We add '^' to ensure that we are always
// comparing ranges with ranges, which sidesteps this logic.
// For example:
//
// semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
// semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
//
// This is because the first falls back to
//
// semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
//
// and this fails because a prerelease version can only satisfy a range
// if it is a prerelease within the same major/minor/patch range.
//
// Note: If this is found to have issues, please also revist the logic in
// transform-runtime's definitions.js file.
if (semver.valid(versionRange)) versionRange = `^${versionRange}`;
return (
typeof versionRange !== "string" ||
(!semver.intersects(`<${minVersion}`, versionRange) &&