Skip to content

Commit

Permalink
Replace DevTools semver usages with compare-versions for size
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Feb 8, 2023
1 parent f0cf832 commit 4dc651f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"@reach/menu-button": "^0.16.1",
"@reach/tooltip": "^0.16.0",
"clipboard-js": "^0.3.6",
"compare-versions": "^5.0.3",
"json5": "^2.1.3",
"local-storage-fallback": "^4.1.1",
"lodash.throttle": "^4.1.1",
"memoize-one": "^3.1.1",
"react-virtualized-auto-sizer": "^1.0.6",
"semver": "^6.3.0"
"react-virtualized-auto-sizer": "^1.0.6"
}
}
16 changes: 16 additions & 0 deletions packages/react-devtools-shared/src/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {stackToComponentSources} from 'react-devtools-shared/src/devtools/utils'
import {
format,
formatWithStyles,
gt,
gte,
} from 'react-devtools-shared/src/backend/utils';
import {
REACT_SUSPENSE_LIST_TYPE as SuspenseList,
Expand Down Expand Up @@ -252,4 +254,18 @@ describe('utils', () => {
]);
});
});

describe('semver comparisons', () => {
it('gte should compare versions correctly', () => {
expect(gte('1.2.3', '1.2.1')).toBe(true);
expect(gte('1.2.1', '1.2.1')).toBe(true);
expect(gte('1.2.1', '1.2.2')).toBe(false);
});

it('gt should compare versions correctly', () => {
expect(gt('1.2.3', '1.2.1')).toBe(true);
expect(gt('1.2.1', '1.2.1')).toBe(false);
expect(gt('1.2.1', '1.2.2')).toBe(false);
});
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @flow
*/

import {gt, gte} from 'semver';
import {
ComponentFilterDisplayName,
ComponentFilterElementType,
Expand Down Expand Up @@ -39,6 +38,7 @@ import {
utfEncodeString,
} from 'react-devtools-shared/src/utils';
import {sessionStorageGetItem} from 'react-devtools-shared/src/storage';
import {gt, gte} from 'react-devtools-shared/src/backend/utils';
import {
cleanForBridge,
copyToClipboard,
Expand Down
9 changes: 9 additions & 0 deletions packages/react-devtools-shared/src/backend/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import {copy} from 'clipboard-js';
import {compareVersions} from 'compare-versions';
import {dehydrate} from '../hydration';
import isArray from 'shared/isArray';

Expand Down Expand Up @@ -275,3 +276,11 @@ export function isSynchronousXHRSupported(): boolean {
window.document.featurePolicy.allowsFeature('sync-xhr')
);
}

export function gt(a: string = '', b: string = ''): boolean {
return compareVersions(a, b) === 1;
}

export function gte(a: string = '', b: string = ''): boolean {
return compareVersions(a, b) > -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {gte} from 'semver';
import ListApp from '../e2e-apps/ListApp';
import ListAppLegacy from '../e2e-apps/ListAppLegacy';
import {gte} from 'react-devtools-shared/src/backend/utils';

const version = process.env.E2E_APP_REACT_VERSION;

function mountApp(App: () => React$Node) {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5458,6 +5458,11 @@ commondir@^1.0.1:
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=

compare-versions@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.3.tgz#a9b34fea217472650ef4a2651d905f42c28ebfd7"
integrity sha512-4UZlZP8Z99MGEY+Ovg/uJxJuvoXuN4M6B3hKaiackiHrgzQFEe3diJi1mf1PNHbFujM7FvLrK2bpgIaImbtZ1A==

component-emitter@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
Expand Down

0 comments on commit 4dc651f

Please sign in to comment.