11import packageJson from "../package.json" with { type : "json" } ;
22
3+ function getSupportedReactRange ( ) {
4+ const supportedReactRange = packageJson . testRenderer ?. supportedReactRange ;
5+
6+ if ( typeof supportedReactRange !== "string" || supportedReactRange . trim ( ) === "" ) {
7+ throw new Error ( "package.json must define testRenderer.supportedReactRange" ) ;
8+ }
9+
10+ return supportedReactRange ;
11+ }
12+
313function parseSemver ( version ) {
414 const match = / ^ ( \d + ) \. ( \d + ) \. ( \d + ) (?: [ - + ] .* ) ? $ / . exec ( version ) ;
515
@@ -71,13 +81,11 @@ function parseExclusiveUpperBounds(range) {
7181 return upperBounds ;
7282}
7383
74- function getReactSupportWindow ( range ) {
84+ function getSupportedReactCeiling ( range ) {
7585 const upperBounds = parseExclusiveUpperBounds ( range ) ;
7686
7787 if ( upperBounds . length === 0 ) {
78- throw new Error (
79- `Could not derive a supported React ceiling from peerDependencies.react: ${ range } ` ,
80- ) ;
88+ throw new Error ( `Could not derive a supported React ceiling from range: ${ range } ` ) ;
8189 }
8290
8391 return upperBounds . reduce ( ( lowest , candidate ) =>
@@ -89,16 +97,16 @@ function formatSemver(version) {
8997 return `${ version . major } .${ version . minor } .${ version . patch } ` ;
9098}
9199
92- function getSupportedLineLabel ( upperBound ) {
100+ function getSupportedLinesLabel ( upperBound ) {
93101 if ( upperBound . patch === 0 && upperBound . minor > 0 ) {
94- return `${ upperBound . major } .${ upperBound . minor - 1 } .x` ;
102+ return `React ${ upperBound . major } .0.x through ${ upperBound . major } .${ upperBound . minor - 1 } .x` ;
95103 }
96104
97105 if ( upperBound . minor === 0 && upperBound . patch === 0 ) {
98- return `${ upperBound . major - 1 } .x` ;
106+ return `React ${ upperBound . major - 1 } .x` ;
99107 }
100108
101- return `<${ formatSemver ( upperBound ) } ` ;
109+ return `React versions <${ formatSemver ( upperBound ) } ` ;
102110}
103111
104112async function getLatestReactVersion ( ) {
@@ -130,20 +138,24 @@ async function main() {
130138 const latestVersion = await getLatestReactVersion ( ) ;
131139 const parsedLatest = parseSemver ( latestVersion ) ;
132140 const peerRange = packageJson . peerDependencies ?. react ?? "<missing>" ;
133- const upperBound = getReactSupportWindow ( peerRange ) ;
134- const supportedLineLabel = getSupportedLineLabel ( upperBound ) ;
141+ const supportedReactRange = getSupportedReactRange ( ) ;
142+ const supportedReactCeiling = getSupportedReactCeiling ( supportedReactRange ) ;
143+ const supportedLinesLabel = getSupportedLinesLabel ( supportedReactCeiling ) ;
135144
136- if ( compareSemver ( parsedLatest , upperBound ) < 0 ) {
137- console . log ( `React ${ latestVersion } is still within the supported line (${ supportedLineLabel } ).` ) ;
145+ if ( compareSemver ( parsedLatest , supportedReactCeiling ) < 0 ) {
146+ console . log (
147+ `React ${ latestVersion } is still within the supported window (${ supportedLinesLabel } ).` ,
148+ ) ;
138149 return ;
139150 }
140151
141152 const failureLines = [
142- `React ${ latestVersion } has been released on npm, but this repository only supports up to React ${ supportedLineLabel } .` ,
153+ `React ${ latestVersion } has been released on npm, but this repository currently supports only ${ supportedLinesLabel } .` ,
143154 `A plain npm install of test-renderer is no longer safely constrained for the newest React release.` ,
144155 `Current peerDependencies.react: ${ peerRange } ` ,
145- `Current derived React ceiling: <${ formatSemver ( upperBound ) } ` ,
146- `Update the compatibility policy, add support for the new React line, and tighten the published peer dependency range before relying on latest again.` ,
156+ `Configured supportedReactRange: ${ supportedReactRange } ` ,
157+ `Current derived React ceiling: <${ formatSemver ( supportedReactCeiling ) } ` ,
158+ `Update testRenderer.supportedReactRange or tighten peerDependencies.react before relying on latest again.` ,
147159 ] ;
148160
149161 throw new Error ( failureLines . join ( "\n" ) ) ;
0 commit comments