mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
[babel 8] Remove semver dependency from transform-runtime (#17511)
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
"babel-plugin-polyfill-corejs2": "condition:BABEL_8_BREAKING ? : ^0.4.14 (peer:@babel/core)",
|
||||
"babel-plugin-polyfill-corejs3": "condition:BABEL_8_BREAKING ? : ^0.13.0 (peer:@babel/core)",
|
||||
"babel-plugin-polyfill-regenerator": "condition:BABEL_8_BREAKING ? : ^0.6.5 (peer:@babel/core)",
|
||||
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.1"
|
||||
"semver": "condition:BABEL_8_BREAKING ? : ^6.3.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import semver from "semver";
|
||||
|
||||
export function hasMinVersion(
|
||||
minVersion: string,
|
||||
runtimeVersion: string | void,
|
||||
) {
|
||||
// If the range is unavailable, we're running the script during Babel's
|
||||
// build process, and we want to assume that all versions are satisfied so
|
||||
// that the built output will include all definitions.
|
||||
if (!runtimeVersion) return true;
|
||||
|
||||
// semver.intersects() has some surprising behavior with comparing ranges
|
||||
// with pre-release 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 revisit the logic in
|
||||
// babel-core's availableHelper() API.
|
||||
if (semver.valid(runtimeVersion)) runtimeVersion = `^${runtimeVersion}`;
|
||||
|
||||
return (
|
||||
!semver.intersects(`<${minVersion}`, runtimeVersion) &&
|
||||
!semver.intersects(`>=8.0.0`, runtimeVersion)
|
||||
);
|
||||
}
|
||||
@@ -2,11 +2,11 @@ import { declare } from "@babel/helper-plugin-utils";
|
||||
import { addDefault, isModule } from "@babel/helper-module-imports";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
import { hasMinVersion } from "./helpers.ts";
|
||||
import getRuntimePath, { resolveFSPath } from "./get-runtime-path/index.ts";
|
||||
|
||||
// TODO(Babel 8): Remove this
|
||||
import babel7 from "./babel-7/index.cjs" with { if: "!process.env.BABEL_8_BREAKING" };
|
||||
import semver from "semver" with { if: "!process.env.BABEL_8_BREAKING" };
|
||||
|
||||
export interface Options {
|
||||
absoluteRuntime?: boolean;
|
||||
@@ -46,9 +46,40 @@ export default declare((api, options: Options, dirname) => {
|
||||
// In recent @babel/runtime versions, we can use require("helper").default
|
||||
// instead of require("helper") so that it has the same interface as the
|
||||
// ESM helper, and bundlers can better exchange one format for the other.
|
||||
const DUAL_MODE_RUNTIME = "7.13.0";
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
var supportsCJSDefault = hasMinVersion(DUAL_MODE_RUNTIME, runtimeVersion);
|
||||
var supportsCJSDefault: boolean;
|
||||
if (!runtimeVersion) {
|
||||
// If the range is unavailable, we're running the script during Babel's
|
||||
// build process, and we want to assume that all versions are satisfied so
|
||||
// that the built output will include all definitions.
|
||||
supportsCJSDefault = true;
|
||||
} else {
|
||||
// semver.intersects() has some surprising behavior with comparing ranges
|
||||
// with pre-release 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 revisit the logic in
|
||||
// babel-core's availableHelper() API.
|
||||
const normalizedRuntimeVersion = semver.valid(runtimeVersion)
|
||||
? `^${runtimeVersion}`
|
||||
: runtimeVersion;
|
||||
|
||||
supportsCJSDefault =
|
||||
!semver.intersects(`<7.13.0`, normalizedRuntimeVersion) &&
|
||||
!semver.intersects(`>=8.0.0`, normalizedRuntimeVersion);
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.hasOwn(options, "useBuiltIns")) {
|
||||
|
||||
@@ -3563,7 +3563,7 @@ __metadata:
|
||||
babel-plugin-polyfill-corejs3: "npm:^0.13.0"
|
||||
babel-plugin-polyfill-regenerator: "condition:BABEL_8_BREAKING ? : ^0.6.5 (peer:@babel/core)"
|
||||
make-dir: "condition:BABEL_8_BREAKING ? : ^2.1.0"
|
||||
semver: "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.1"
|
||||
semver: "condition:BABEL_8_BREAKING ? : ^6.3.1"
|
||||
peerDependencies:
|
||||
"@babel/core": ^7.0.0-0
|
||||
languageName: unknown
|
||||
@@ -15969,6 +15969,15 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver@condition:BABEL_8_BREAKING ? : ^6.3.1":
|
||||
version: 0.0.0-condition-82bd19
|
||||
resolution: "semver@condition:BABEL_8_BREAKING?:^6.3.1#82bd19"
|
||||
dependencies:
|
||||
semver-BABEL_8_BREAKING-false: "npm:semver@^6.3.1"
|
||||
checksum: 10/821b359c1f8227348301eb813c0cf64fd6dc60fcaadcac61fba30b7cc42e34473c62716278d3e867ed1d6d8dad4ab765ddffb0288ef846d20da10a86824f7de3
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"semver@condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.1":
|
||||
version: 0.0.0-condition-34cbd2
|
||||
resolution: "semver@condition:BABEL_8_BREAKING?^7.3.4:^6.3.1#34cbd2"
|
||||
|
||||
Reference in New Issue
Block a user