Skip to content

Commit 510e071

Browse files
authored
perf(client-container-runtime): reduce semver bundle regression (#24486)
using ESM and tree-shakable `semver-ts`. PR to main: #24483
1 parent 35b2e3e commit 510e071

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

packages/runtime/container-runtime/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"@tylerbu/sorted-btree-es6": "^1.8.0",
185185
"double-ended-queue": "^2.1.0-0",
186186
"lz4js": "^0.2.0",
187-
"semver": "^7.7.1",
187+
"semver-ts": "^1.0.3",
188188
"uuid": "^9.0.0"
189189
},
190190
"devDependencies": {
@@ -205,7 +205,6 @@
205205
"@types/lz4js": "^0.2.0",
206206
"@types/mocha": "^10.0.10",
207207
"@types/node": "^18.19.0",
208-
"@types/semver": "^7.7.0",
209208
"@types/sinon": "^17.0.3",
210209
"@types/uuid": "^9.0.2",
211210
"c8": "^8.0.1",

packages/runtime/container-runtime/src/compatUtils.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
*/
55

66
import { FlushMode } from "@fluidframework/runtime-definitions/internal";
7-
// The semver package documents and encourages these imports for users that only need some of the semver functionality.
8-
// eslint-disable-next-line import/no-internal-modules
9-
import semverGte from "semver/functions/gte.js";
10-
// eslint-disable-next-line import/no-internal-modules
11-
import semverLte from "semver/functions/lte.js";
12-
// eslint-disable-next-line import/no-internal-modules
13-
import semverValid from "semver/functions/valid.js";
7+
import { compare, gte, lte, valid } from "semver-ts";
148

159
import {
1610
disabledCompressionConfig,
@@ -181,12 +175,12 @@ export function getConfigsForCompatMode<T extends Record<SemanticVersion, unknow
181175
for (const key of Object.keys(configMap)) {
182176
const config = configMap[key as keyof T];
183177
// Sort the versions in ascending order so we can short circuit the loop.
184-
const versions = Object.keys(config).sort((a, b) => (semverGte(b, a) ? -1 : 1));
178+
const versions = Object.keys(config).sort(compare);
185179
// For each config, we iterate over the keys and check if compatibilityVersion is greater than or equal to the version.
186180
// If so, we set it as the default value for the option. At the end of the loop we should have the most recent default
187181
// value that is compatible with the version specified as the compatibilityVersion.
188182
for (const version of versions) {
189-
if (semverGte(compatibilityVersion, version)) {
183+
if (gte(compatibilityVersion, version)) {
190184
defaultConfigs[key] = config[version as MinimumMinorSemanticVersion];
191185
} else {
192186
// If the compatibility mode is less than the version, we break out of the loop since we don't need to check
@@ -205,7 +199,7 @@ export function getConfigsForCompatMode<T extends Record<SemanticVersion, unknow
205199
export function isValidCompatVersion(compatibilityVersion: SemanticVersion): boolean {
206200
return (
207201
compatibilityVersion !== undefined &&
208-
semverValid(compatibilityVersion) !== null &&
209-
semverLte(compatibilityVersion, pkgVersion)
202+
valid(compatibilityVersion) !== null &&
203+
lte(compatibilityVersion, pkgVersion)
210204
);
211205
}

pnpm-lock.yaml

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)