Skip to content

Commit 1eac448

Browse files
authored
refactor: replace semver with verkit (#18145)
1 parent 36057c7 commit 1eac448

28 files changed

Lines changed: 77 additions & 123 deletions

File tree

‎.yarnrc.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ catalog:
66
babel-plugin-polyfill-corejs3: ^1.0.0
77
core-js: ^3.48.0
88
core-js-compat: ^3.48.0
9-
semver: ^7.7.3
9+
verkit: ^0.3.2
1010

1111
catalogs:
1212
dev:

‎eslint.config.ts‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import pluginUnicorn from "eslint-plugin-unicorn";
1111
import pluginBabelDevelopment from "@babel/eslint-plugin-development";
1212
import pluginBabelDevelopmentInternal from "@babel/eslint-plugin-development-internal";
1313
import typescriptEslint from "typescript-eslint";
14-
import { commonJS } from "$repo-utils";
15-
16-
const { require } = commonJS(import.meta.url);
1714

1815
const cjsGlobals = ["__dirname", "__filename", "require", "module", "exports"];
1916

@@ -351,22 +348,6 @@ export default defineConfig([
351348
files: [...sourceFiles("js,ts,mjs"), ...testFiles, "test/**/*.js"],
352349
rules: {
353350
"no-restricted-globals": ["error", ...cjsGlobals],
354-
"no-restricted-imports": [
355-
"error",
356-
{
357-
paths: [
358-
{
359-
name: "semver",
360-
message:
361-
"semver's named exports are not recognized by the Node.js ESM-CJS interop.",
362-
importNames: Object.keys(require("semver")).filter(
363-
// We use it as a type import.
364-
name => name !== "SemVer"
365-
),
366-
},
367-
],
368-
},
369-
],
370351
},
371352
},
372353
{

‎eslint/babel-eslint-parser/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"dependencies": {
3636
"eslint-scope": "^9.1.0",
3737
"eslint-visitor-keys": "^5.0.0",
38-
"semver": "catalog:"
38+
"verkit": "catalog:"
3939
},
4040
"devDependencies": {
4141
"@babel/core": "workspace:^",

‎eslint/babel-eslint-parser/src/parse.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import semver from "semver";
1+
import { satisfies } from "verkit";
22
import type { Options } from "./types";
33
import { version } from "@babel/core";
44
import { WorkerClient, type Client } from "./client.ts";
@@ -24,7 +24,7 @@ export default function parse(code: string, options: Options) {
2424
const minSupportedCoreVersion = REQUIRED_VERSION("^7.2.0 || ^8.0.0");
2525

2626
if (typeof isRunningMinSupportedCoreVersion !== "boolean") {
27-
isRunningMinSupportedCoreVersion = semver.satisfies(
27+
isRunningMinSupportedCoreVersion = satisfies(
2828
version,
2929
minSupportedCoreVersion,
3030
);

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
"rollup": "^4.18.0",
8383
"rollup-plugin-dts": "patch:rollup-plugin-dts@npm%3A6.1.0#~/.yarn/patches/rollup-plugin-dts-npm-6.1.0-6d41e665a7.patch",
8484
"rollup-plugin-polyfill-node": "^0.13.0",
85-
"semver": "catalog:",
8685
"shelljs": "^0.10.0",
8786
"terser": "catalog:dev",
8887
"test262-stream": "^1.4.0",

‎packages/babel-cli/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@babel/core": "workspace:^",
39-
"@babel/helper-transform-fixture-test-runner": "workspace:^",
40-
"semver": "catalog:"
39+
"@babel/helper-transform-fixture-test-runner": "workspace:^"
4140
},
4241
"bin": {
4342
"babel": "./bin/babel.js"

‎packages/babel-core/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"import-meta-resolve": "^4.2.0",
5454
"json5": "^2.2.3",
5555
"obug": "^2.1.1",
56-
"semver": "catalog:"
56+
"verkit": "catalog:"
5757
},
5858
"devDependencies": {
5959
"@babel/helper-transform-fixture-test-runner": "workspace:^",
@@ -67,7 +67,6 @@
6767
"@jridgewell/trace-mapping": "catalog:",
6868
"@types/convert-source-map": "^2.0.0",
6969
"@types/resolve": "^1.3.2",
70-
"@types/semver": "^5.4.0",
7170
"ts-node": "^11.0.0-beta.1",
7271
"tsx": "^4.20.3"
7372
},

‎packages/babel-core/src/config/helpers/config-api.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import semver from "semver";
1+
import { satisfies } from "verkit";
22
import type { Targets } from "@babel/helper-compilation-targets";
33

44
import { version as coreVersion } from "../../index.ts";
@@ -132,9 +132,9 @@ function assertVersion(range: string | number): void {
132132
}
133133

134134
// We want "*" to also allow any pre-release, but we do not pass
135-
// the includePrerelease option to semver.satisfies because we
135+
// the includePrerelease option to satisfies because we
136136
// do not want ^7.0.0 to match 8.0.0-alpha.1.
137-
if (range === "*" || semver.satisfies(coreVersion, range)) return;
137+
if (range === "*" || satisfies(coreVersion, range)) return;
138138

139139
const message =
140140
`Requires Babel "${range}", but was loaded with "${coreVersion}". ` +

‎packages/babel-core/src/transformation/file/file.ts‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { HubInterface, Scope } from "@babel/traverse";
44
import { codeFrameColumns } from "@babel/code-frame";
55
import { cloneNode, interpreterDirective, traverseFast } from "@babel/types";
66
import type * as t from "@babel/types";
7-
import semver from "semver";
7+
import { isValid, rangesIntersect } from "verkit";
88

99
import type { NormalizedFile } from "../normalize-file.ts";
1010

@@ -102,28 +102,17 @@ export default class File {
102102

103103
if (typeof versionRange !== "string") return true;
104104

105-
// semver.intersects() has some surprising behavior with comparing ranges
106-
// with pre-release versions. We add '^' to ensure that we are always
107-
// comparing ranges with ranges, which sidesteps this logic.
108-
// For example:
109-
//
110-
// semver.intersects(`<7.0.1`, "7.0.0-beta.0") // false - surprising
111-
// semver.intersects(`<7.0.1`, "^7.0.0-beta.0") // true - expected
112-
//
113-
// This is because the first falls back to
114-
//
115-
// semver.satisfies("7.0.0-beta.0", `<7.0.1`) // false - surprising
116-
//
117-
// and this fails because a prerelease version can only satisfy a range
118-
// if it is a prerelease within the same major/minor/patch range.
105+
// Treat a concrete version as its compatible range. This ensures that a
106+
// helper introduced after a prerelease is not considered available for
107+
// that prerelease, while preserving the existing behavior for ranges.
119108
//
120109
// Note: If this is found to have issues, please also revisit the logic in
121110
// transform-runtime's definitions.js file.
122-
if (semver.valid(versionRange)) versionRange = `^${versionRange}`;
111+
if (isValid(versionRange)) versionRange = `^${versionRange}`;
123112

124113
return (
125-
!semver.intersects(`<${minVersion}`, versionRange) &&
126-
!semver.intersects(`>=9.0.0`, versionRange)
114+
!rangesIntersect(`<${minVersion}`, versionRange) &&
115+
!rangesIntersect(`>=9.0.0`, versionRange)
127116
);
128117
}
129118

‎packages/babel-core/test/config-ts-integration-tsx.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { loadPartialConfigSync } from "../lib/index.js";
22
import path from "node:path";
3-
import semver from "semver";
3+
import { isLess } from "verkit";
44
import { commonJS } from "$repo-utils";
55

66
const { __dirname, require } = commonJS(import.meta.url);
77

88
// We skip older versions of node testing for two reasons.
99
// 1. tsx and ts don't support the old version of node.
1010
// 2. In the old version of node, jest has been registered in `require.extensions`, which will cause babel to disable the transforming as expected.
11-
const shouldSkip = semver.lt(process.version, "18.0.0");
11+
const shouldSkip = isLess(process.version, "18.0.0");
1212

1313
(shouldSkip ? describe : describe.skip)(
1414
"@babel/core config with ts [dummy]",

0 commit comments

Comments
 (0)