File tree Expand file tree Collapse file tree
react-devtools-shared/src
react-devtools-shell/src/e2e-regression Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils'
1515import {
1616 format ,
1717 formatWithStyles ,
18+ semvercmp ,
19+ gt ,
20+ gte ,
1821} from 'react-devtools-shared/src/backend/utils' ;
1922import {
2023 REACT_SUSPENSE_LIST_TYPE as SuspenseList ,
@@ -252,4 +255,52 @@ describe('utils', () => {
252255 ] ) ;
253256 } ) ;
254257 } ) ;
258+
259+ describe ( 'semvercmp' , ( ) => {
260+ it ( 'should sort semver comparisons ascending' , ( ) => {
261+ const unsortedVersions = [
262+ '1.2.3' ,
263+ '4.11.6' ,
264+ '4.2.0' ,
265+ '11.0.0-alpha.1' ,
266+ '1.5.19' ,
267+ '11.0.0-alpha.0' ,
268+ '1.5.5' ,
269+ '4.1.3' ,
270+ '2.3.1' ,
271+ '11.0.0' ,
272+ '10.5.5' ,
273+ '11.3.0' ,
274+ ] ;
275+
276+ const sortedVersions = unsortedVersions . slice ( ) . sort ( semvercmp ) ;
277+ expect ( sortedVersions ) . toEqual ( [
278+ '1.2.3' ,
279+ '1.5.5' ,
280+ '1.5.19' ,
281+ '2.3.1' ,
282+ '4.1.3' ,
283+ '4.2.0' ,
284+ '4.11.6' ,
285+ '10.5.5' ,
286+ // Specifically check non-numerical pre-release versions
287+ '11.0.0-alpha.0' ,
288+ '11.0.0-alpha.1' ,
289+ '11.0.0' ,
290+ '11.3.0' ,
291+ ] ) ;
292+ } ) ;
293+
294+ it ( 'gte should compare versions correctly' , ( ) => {
295+ expect ( gte ( '1.2.3' , '1.2.1' ) ) . toBe ( true ) ;
296+ expect ( gte ( '1.2.1' , '1.2.1' ) ) . toBe ( true ) ;
297+ expect ( gte ( '1.2.1' , '1.2.2' ) ) . toBe ( false ) ;
298+ } ) ;
299+
300+ it ( 'gt should compare versions correctly' , ( ) => {
301+ expect ( gt ( '1.2.3' , '1.2.1' ) ) . toBe ( true ) ;
302+ expect ( gt ( '1.2.1' , '1.2.1' ) ) . toBe ( false ) ;
303+ expect ( gt ( '1.2.1' , '1.2.2' ) ) . toBe ( false ) ;
304+ } ) ;
305+ } ) ;
255306} ) ;
Original file line number Diff line number Diff line change 77 * @flow
88 */
99
10- import { gt , gte } from 'semver' ;
1110import {
1211 ComponentFilterDisplayName ,
1312 ComponentFilterElementType ,
@@ -39,6 +38,7 @@ import {
3938 utfEncodeString ,
4039} from 'react-devtools-shared/src/utils' ;
4140import { sessionStorageGetItem } from 'react-devtools-shared/src/storage' ;
41+ import { gt , gte } from 'react-devtools-shared/src/backend/utils' ;
4242import {
4343 cleanForBridge ,
4444 copyToClipboard ,
Original file line number Diff line number Diff line change @@ -275,3 +275,28 @@ export function isSynchronousXHRSupported(): boolean {
275275 window . document . featurePolicy . allowsFeature ( 'sync-xhr' )
276276 ) ;
277277}
278+
279+ // https://www.npmjs.com/package/semver-compare
280+ export function semvercmp ( a : string = '' , b : string = '' ) : number {
281+ const pa = a . split ( '.' ) ;
282+ const pb = b . split ( '.' ) ;
283+ // Handle more than 3 places, like '11.0.0-alpha.1'
284+ const maxLength = Math . max ( pa . length , pb . length ) ;
285+ for ( let i = 0 ; i < maxLength ; i ++ ) {
286+ const na = + pa [ i ] ;
287+ const nb = + pb [ i ] ;
288+ if ( na > nb ) return 1 ;
289+ if ( nb > na ) return - 1 ;
290+ if ( ! isNaN ( na ) && isNaN ( nb ) ) return 1 ;
291+ if ( isNaN ( na ) && ! isNaN ( nb ) ) return - 1 ;
292+ }
293+ return 0 ;
294+ }
295+
296+ export function gt ( a : string = '' , b : string = '' ) : boolean {
297+ return semvercmp ( a , b ) === 1 ;
298+ }
299+
300+ export function gte ( a : string = '' , b : string = '' ) : boolean {
301+ return semvercmp ( a , b ) > - 1 ;
302+ }
Original file line number Diff line number Diff line change 44
55import * as React from 'react' ;
66import * as ReactDOM from 'react-dom' ;
7- import { gte } from 'semver' ;
87import ListApp from '../e2e-apps/ListApp' ;
98import ListAppLegacy from '../e2e-apps/ListAppLegacy' ;
9+ import { gte } from 'react-devtools-shared/src/backend/utils' ;
10+
1011const version = process . env . E2E_APP_REACT_VERSION ;
1112
1213function mountApp ( App : ( ) = > React$Node ) {
You can’t perform that action at this time.
0 commit comments