Skip to content

Commit 4dc651f

Browse files
committed
Replace DevTools semver usages with compare-versions for size
1 parent f0cf832 commit 4dc651f

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

packages/react-devtools-shared/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"@reach/menu-button": "^0.16.1",
1919
"@reach/tooltip": "^0.16.0",
2020
"clipboard-js": "^0.3.6",
21+
"compare-versions": "^5.0.3",
2122
"json5": "^2.1.3",
2223
"local-storage-fallback": "^4.1.1",
2324
"lodash.throttle": "^4.1.1",
2425
"memoize-one": "^3.1.1",
25-
"react-virtualized-auto-sizer": "^1.0.6",
26-
"semver": "^6.3.0"
26+
"react-virtualized-auto-sizer": "^1.0.6"
2727
}
2828
}

packages/react-devtools-shared/src/__tests__/utils-test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils'
1515
import {
1616
format,
1717
formatWithStyles,
18+
gt,
19+
gte,
1820
} from 'react-devtools-shared/src/backend/utils';
1921
import {
2022
REACT_SUSPENSE_LIST_TYPE as SuspenseList,
@@ -252,4 +254,18 @@ describe('utils', () => {
252254
]);
253255
});
254256
});
257+
258+
describe('semver comparisons', () => {
259+
it('gte should compare versions correctly', () => {
260+
expect(gte('1.2.3', '1.2.1')).toBe(true);
261+
expect(gte('1.2.1', '1.2.1')).toBe(true);
262+
expect(gte('1.2.1', '1.2.2')).toBe(false);
263+
});
264+
265+
it('gt should compare versions correctly', () => {
266+
expect(gt('1.2.3', '1.2.1')).toBe(true);
267+
expect(gt('1.2.1', '1.2.1')).toBe(false);
268+
expect(gt('1.2.1', '1.2.2')).toBe(false);
269+
});
270+
});
255271
});

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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import {copy} from 'clipboard-js';
12+
import {compareVersions} from 'compare-versions';
1213
import {dehydrate} from '../hydration';
1314
import isArray from 'shared/isArray';
1415

@@ -275,3 +276,11 @@ export function isSynchronousXHRSupported(): boolean {
275276
window.document.featurePolicy.allowsFeature('sync-xhr')
276277
);
277278
}
279+
280+
export function gt(a: string = '', b: string = ''): boolean {
281+
return compareVersions(a, b) === 1;
282+
}
283+
284+
export function gte(a: string = '', b: string = ''): boolean {
285+
return compareVersions(a, b) > -1;
286+
}

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) {

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5458,6 +5458,11 @@ commondir@^1.0.1:
54585458
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
54595459
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
54605460

5461+
compare-versions@^5.0.3:
5462+
version "5.0.3"
5463+
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.3.tgz#a9b34fea217472650ef4a2651d905f42c28ebfd7"
5464+
integrity sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==
5465+
54615466
component-emitter@^1.2.1:
54625467
version "1.3.0"
54635468
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"

0 commit comments

Comments
 (0)