Skip to content

Commit d1fd90e

Browse files
committed
Replace DevTools semver usages with a simpler inlined method
1 parent f0cf832 commit d1fd90e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @flow
88
*/
99

10-
import {gt, gte} from 'semver';
1110
import {
1211
ComponentFilterDisplayName,
1312
ComponentFilterElementType,
@@ -39,6 +38,7 @@ import {
3938
utfEncodeString,
4039
} from 'react-devtools-shared/src/utils';
4140
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
41+
import {gt, gte} from 'react-devtools-shared/src/backend/utils';
4242
import {
4343
cleanForBridge,
4444
copyToClipboard,

packages/react-devtools-shared/src/backend/utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,26 @@ 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+
for (let i = 0; i < 3; i++) {
284+
const na = +pa[i];
285+
const nb = +pb[i];
286+
if (na > nb) return 1;
287+
if (nb > na) return -1;
288+
if (!isNaN(na) && isNaN(nb)) return 1;
289+
if (isNaN(na) && !isNaN(nb)) return -1;
290+
}
291+
return 0;
292+
}
293+
294+
export function gt(a: string = '', b: string = ''): boolean {
295+
return semvercmp(a, b) === 1;
296+
}
297+
298+
export function gte(a: string = '', b: string = ''): boolean {
299+
return semvercmp(a, b) > -1;
300+
}

packages/react-devtools-shell/src/e2e-regression/app-legacy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import * as React from 'react';
66
import * as ReactDOM from 'react-dom';
7-
import {gte} from 'semver';
87
import ListApp from '../e2e-apps/ListApp';
98
import ListAppLegacy from '../e2e-apps/ListAppLegacy';
9+
import {gte} from 'react-devtools-shared/src/backend/utils';
10+
1011
const version = process.env.E2E_APP_REACT_VERSION;
1112

1213
function mountApp(App: () => React$Node) {

0 commit comments

Comments
 (0)