Skip to content

Commit

Permalink
Replace DevTools semver usages with a simpler inlined method
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Feb 7, 2023
1 parent f0cf832 commit 2673489
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
24 changes: 23 additions & 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 @@ -142,6 +141,29 @@ type ReactPriorityLevelsType = {
NoPriority: number,
};

// https://www.npmjs.com/package/semver-compare
function semvercmp(a: string = '', b: string = '') {
const pa = a.split('.');
const pb = b.split('.');
for (var i = 0; i < 3; i++) {
const na = Number(pa[i]);
const nb = Number(pb[i]);
if (na > nb) return 1;
if (nb > na) return -1;
if (!isNaN(na) && isNaN(nb)) return 1;
if (isNaN(na) && !isNaN(nb)) return -1;
}
return 0;
}

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

function gte(a: string = '', b: string = '') {
return semvercmp(a, b) > -1;
}

function getFiberFlags(fiber: Fiber): number {
// The name of this field changed from "effectTag" to "flags"
return fiber.flags !== undefined ? fiber.flags : (fiber: any).effectTag;
Expand Down
20 changes: 19 additions & 1 deletion packages/react-devtools-shell/src/e2e-regression/app-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@

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';
const version = process.env.E2E_APP_REACT_VERSION;

// https://www.npmjs.com/package/semver-compare
function semvercmp(a: string = '', b: string = '') {
const pa = a.split('.');
const pb = b.split('.');
for (var i = 0; i < 3; i++) {
const na = Number(pa[i]);
const nb = Number(pb[i]);
if (na > nb) return 1;
if (nb > na) return -1;
if (!isNaN(na) && isNaN(nb)) return 1;
if (isNaN(na) && !isNaN(nb)) return -1;
}
return 0;
}

function gte(a: string = '', b: string = '') {
return semvercmp(a, b) > -1;
}

function mountApp(App: () => React$Node) {
const container = document.createElement('div');

Expand Down

0 comments on commit 2673489

Please sign in to comment.