Skip to content

Commit 9c53879

Browse files
committed
refactor(shared): improve version 'getReactVersion'
1 parent 1575df8 commit 9c53879

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

packages/shared/docs/functions/getReactVersion.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66

77
# Function: getReactVersion()
88

9-
> **getReactVersion**(`fallback`): `string`
9+
> **getReactVersion**(`at`, `fallback`): `string`
1010
1111
## Parameters
1212

13+
### at
14+
15+
`string` = `...`
16+
1317
### fallback
1418

1519
`string` = `"19.0.0"`

packages/shared/src/get-react-version.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
/* eslint-disable import-x/no-extraneous-dependencies */
44
import module from "node:module";
55

6-
const require = module.createRequire(import.meta.url);
7-
8-
export function getReactVersion(fallback = "19.0.0"): string {
6+
export function getReactVersion(at = import.meta.url, fallback = "19.0.0"): string {
7+
const require = module.createRequire(at);
98
try {
109
return require("react").version ?? fallback;
1110
} catch {

packages/shared/src/settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const normalizeSettings = memoize((settings: ESLintReactSettings): ESLint
8282
return acc.set(name, as);
8383
}, new Map<string, string>()),
8484
version: match(settings.version)
85-
.with(P.union(P.nullish, "", "detect"), () => getReactVersion("19.0.0"))
85+
.with(P.union(P.nullish, "", "detect"), () => getReactVersion())
8686
.otherwise(F.identity),
8787
};
8888
}, { isEqual: shallowEqual });

0 commit comments

Comments
 (0)