File tree Expand file tree Collapse file tree 4 files changed +79
-2
lines changed
react-devtools-shared/src
react-devtools-shell/src/e2e-regression Expand file tree Collapse file tree 4 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,9 @@ import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils'
15
15
import {
16
16
format ,
17
17
formatWithStyles ,
18
+ semvercmp ,
19
+ gt ,
20
+ gte ,
18
21
} from 'react-devtools-shared/src/backend/utils' ;
19
22
import {
20
23
REACT_SUSPENSE_LIST_TYPE as SuspenseList ,
@@ -252,4 +255,52 @@ describe('utils', () => {
252
255
] ) ;
253
256
} ) ;
254
257
} ) ;
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
+ } ) ;
255
306
} ) ;
Original file line number Diff line number Diff line change 7
7
* @flow
8
8
*/
9
9
10
- import { gt , gte } from 'semver' ;
11
10
import {
12
11
ComponentFilterDisplayName ,
13
12
ComponentFilterElementType ,
@@ -39,6 +38,7 @@ import {
39
38
utfEncodeString ,
40
39
} from 'react-devtools-shared/src/utils' ;
41
40
import { sessionStorageGetItem } from 'react-devtools-shared/src/storage' ;
41
+ import { gt , gte } from 'react-devtools-shared/src/backend/utils' ;
42
42
import {
43
43
cleanForBridge ,
44
44
copyToClipboard ,
Original file line number Diff line number Diff line change @@ -275,3 +275,28 @@ export function isSynchronousXHRSupported(): boolean {
275
275
window . document . featurePolicy . allowsFeature ( 'sync-xhr' )
276
276
) ;
277
277
}
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 4
4
5
5
import * as React from 'react' ;
6
6
import * as ReactDOM from 'react-dom' ;
7
- import { gte } from 'semver' ;
8
7
import ListApp from '../e2e-apps/ListApp' ;
9
8
import ListAppLegacy from '../e2e-apps/ListAppLegacy' ;
9
+ import { gte } from 'react-devtools-shared/src/backend/utils' ;
10
+
10
11
const version = process . env . E2E_APP_REACT_VERSION ;
11
12
12
13
function mountApp ( App : ( ) = > React$Node ) {
You can’t perform that action at this time.
0 commit comments