chore: check version lazily in babel-eslint-parser (#11647)

This commit is contained in:
Kai Cataldo 2020-05-31 00:50:46 -04:00 committed by GitHub
parent b1923fd140
commit 30d7236397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import semver from "semver"; import semver from "semver";
import { import {
version as CURRENT_BABEL_VERSION, version as babelCoreVersion,
parseSync as babelParse, parseSync as babelParse,
} from "@babel/core"; } from "@babel/core";
import packageJson from "../package.json"; import packageJson from "../package.json";
@ -12,17 +12,19 @@ import convert from "./convert";
import analyzeScope from "./analyze-scope"; import analyzeScope from "./analyze-scope";
import visitorKeys from "./visitor-keys"; import visitorKeys from "./visitor-keys";
const SUPPORTED_BABEL_VERSION_RANGE = let isRunningSupportedVersion;
packageJson.peerDependencies["@babel/core"];
const IS_RUNNING_SUPPORTED_VERSION = semver.satisfies(
CURRENT_BABEL_VERSION,
SUPPORTED_BABEL_VERSION_RANGE,
);
function baseParse(code, options) { function baseParse(code, options) {
if (!IS_RUNNING_SUPPORTED_VERSION) { if (typeof isRunningSupportedVersion !== "boolean") {
isRunningSupportedVersion = semver.satisfies(
babelCoreVersion,
packageJson.peerDependencies["@babel/core"],
);
}
if (!isRunningSupportedVersion) {
throw new Error( throw new Error(
`babel-eslint@${packageJson.version} does not support @babel/core@${CURRENT_BABEL_VERSION}. Please downgrade to babel-eslint@^10 or upgrade to @babel/core@${SUPPORTED_BABEL_VERSION_RANGE}`, `@babel/eslint-parser@${packageJson.version} does not support @babel/core@${babelCoreVersion}. Please upgrade to @babel/core@${packageJson.peerDependencies["@babel/core"]}`,
); );
} }