-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replaced
semver
dependency with custom implementation (#1594)
- Loading branch information
Showing
6 changed files
with
100 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 4 additions & 13 deletions
17
packages/versions/src/lib/checkFuelCoreVersionCompatibility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import semver from 'semver'; | ||
|
||
import { getBuiltinVersions } from './getBuiltinVersions'; | ||
import { majorEq, minorEq, patchEq } from './semver'; | ||
|
||
export function checkFuelCoreVersionCompatibility(networkVersion: string) { | ||
const { FUEL_CORE: supportedVersion } = getBuiltinVersions(); | ||
|
||
const networkMajor = semver.major(networkVersion); | ||
const networkMinor = semver.minor(networkVersion); | ||
const networkPatch = semver.patch(networkVersion); | ||
|
||
const supportedMajor = semver.major(supportedVersion); | ||
const supportedMinor = semver.minor(supportedVersion); | ||
const supportedPatch = semver.patch(supportedVersion); | ||
|
||
return { | ||
supportedVersion, | ||
isMajorSupported: networkMajor === supportedMajor, | ||
isMinorSupported: networkMinor === supportedMinor, | ||
isPatchSupported: networkPatch === supportedPatch, | ||
isMajorSupported: majorEq(networkVersion, supportedVersion), | ||
isMinorSupported: minorEq(networkVersion, supportedVersion), | ||
isPatchSupported: patchEq(networkVersion, supportedVersion), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { eq, gt, majorEq, minorEq, patchEq } from './semver'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
describe('semver', () => { | ||
test('majorEq', () => { | ||
expect(majorEq('1.2.3', '1.2.3')).toBe(true); | ||
expect(majorEq('1.2.3', '1.2.4')).toBe(true); | ||
expect(majorEq('1.2.3', '1.3.3')).toBe(true); | ||
expect(majorEq('1.2.3', '2.2.3')).toBe(false); | ||
}); | ||
test('minorEq', () => { | ||
expect(minorEq('1.2.3', '1.2.3')).toBe(true); | ||
expect(minorEq('1.2.3', '1.2.4')).toBe(true); | ||
expect(minorEq('1.2.3', '2.2.3')).toBe(true); | ||
expect(minorEq('1.2.3', '1.3.3')).toBe(false); | ||
}); | ||
test('patchEq', () => { | ||
expect(patchEq('1.2.3', '1.2.3')).toBe(true); | ||
expect(patchEq('1.2.3', '1.3.3')).toBe(true); | ||
expect(patchEq('1.2.3', '2.2.3')).toBe(true); | ||
expect(patchEq('1.2.3', '1.2.4')).toBe(false); | ||
}); | ||
test('gt', () => { | ||
expect(gt('1.2.3', '0.2.3')).toBe(true); | ||
expect(gt('1.2.3', '1.1.3')).toBe(true); | ||
expect(gt('1.2.3', '1.2.2')).toBe(true); | ||
expect(gt('1.2.3', '1.2.3')).toBe(false); | ||
expect(gt('1.2.3', '2.2.3')).toBe(false); | ||
expect(gt('1.2.3', '1.3.3')).toBe(false); | ||
expect(gt('1.2.3', '1.2.4')).toBe(false); | ||
}); | ||
test('eq', () => { | ||
expect(eq('1.2.3', '1.2.3')).toBe(true); | ||
expect(eq('1.2.3', '0.2.3')).toBe(false); | ||
expect(eq('1.2.3', '2.2.3')).toBe(false); | ||
expect(eq('1.2.3', '1.1.3')).toBe(false); | ||
expect(eq('1.2.3', '1.3.3')).toBe(false); | ||
expect(eq('1.2.3', '1.2.2')).toBe(false); | ||
expect(eq('1.2.3', '1.2.4')).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function parseVersion(version: string): { major: number; minor: number; patch: number } { | ||
const [major, minor, patch] = version.split('.').map((v) => parseInt(v, 10)); | ||
return { major, minor, patch }; | ||
} | ||
|
||
function versionDiffs( | ||
version1: string, | ||
version2: string | ||
): { major: number; minor: number; patch: number; fullVersionDiff: number } { | ||
const semver1 = parseVersion(version1); | ||
const semver2 = parseVersion(version2); | ||
const major = semver1.major - semver2.major; | ||
const minor = semver1.minor - semver2.minor; | ||
const patch = semver1.patch - semver2.patch; | ||
return { | ||
major, | ||
minor, | ||
patch, | ||
fullVersionDiff: major || minor || patch, | ||
}; | ||
} | ||
|
||
export function gt(version1: string, version2: string): boolean { | ||
const { fullVersionDiff } = versionDiffs(version1, version2); | ||
return fullVersionDiff > 0; | ||
} | ||
|
||
export function eq(version1: string, version2: string): boolean { | ||
const { fullVersionDiff } = versionDiffs(version1, version2); | ||
return fullVersionDiff === 0; | ||
} | ||
|
||
export function majorEq(version1: string, version2: string): boolean { | ||
const { major } = versionDiffs(version1, version2); | ||
return major === 0; | ||
} | ||
|
||
export function minorEq(version1: string, version2: string): boolean { | ||
const { minor } = versionDiffs(version1, version2); | ||
return minor === 0; | ||
} | ||
|
||
export function patchEq(version1: string, version2: string): boolean { | ||
const { patch } = versionDiffs(version1, version2); | ||
return patch === 0; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.