Skip to content

Commit

Permalink
Fix backward compat for semver checks in class&regexp feat plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 2, 2023
1 parent 93d7808 commit d31172f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/babel-helper-create-class-features-plugin/src/index.ts
Expand Up @@ -96,9 +96,20 @@ export function createClassFeaturePlugin({
pre(file) {
enableFeature(file, feature, loose);

let existingVersion = file.get(versionKey);
if (!process.env.BABEL_8_BREAKING) {
if (typeof existingVersion === "number") {
// Up to version 7.21.4, we used to encode the version as a number
// using the following encoding algorithm:
// version.split(".").reduce((v, x) => v * 1e5 + +x, 0)
const patch = existingVersion % 1e5;
const minor = ((existingVersion - patch) / 1e5) % 1e5;
existingVersion = `7.${minor}.${patch}`;
}
}
if (
!file.get(versionKey) ||
semver.lt(file.get(versionKey), PACKAGE_JSON.version)
!existingVersion ||
semver.lt(existingVersion, PACKAGE_JSON.version)
) {
file.set(versionKey, PACKAGE_JSON.version);
}
Expand Down
15 changes: 13 additions & 2 deletions packages/babel-helper-create-regexp-features-plugin/src/index.ts
Expand Up @@ -82,9 +82,20 @@ export function createRegExpFeaturePlugin({
}
}

let existingVersion = file.get(versionKey);
if (!process.env.BABEL_8_BREAKING) {
if (typeof existingVersion === "number") {
// Up to version 7.21.4, we used to encode the version as a number
// using the following encoding algorithm:
// version.split(".").reduce((v, x) => v * 1e5 + +x, 0)
const patch = existingVersion % 1e5;
const minor = ((existingVersion - patch) / 1e5) % 1e5;
existingVersion = `7.${minor}.${patch}`;
}
}
if (
!file.has(versionKey) ||
semver.lt(file.get(versionKey), PACKAGE_JSON.version)
!existingVersion ||
semver.lt(existingVersion, PACKAGE_JSON.version)
) {
file.set(versionKey, PACKAGE_JSON.version);
}
Expand Down

0 comments on commit d31172f

Please sign in to comment.