Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/runtime/container-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
"@tylerbu/sorted-btree-es6": "^1.8.0",
"double-ended-queue": "^2.1.0-0",
"lz4js": "^0.2.0",
"semver": "^7.7.1",
"semver-ts": "^1.0.3",
"uuid": "^9.0.0"
},
"devDependencies": {
Expand All @@ -205,7 +205,6 @@
"@types/lz4js": "^0.2.0",
"@types/mocha": "^10.0.10",
"@types/node": "^18.19.0",
"@types/semver": "^7.7.0",
"@types/sinon": "^17.0.3",
"@types/uuid": "^9.0.2",
"c8": "^8.0.1",
Expand Down
16 changes: 5 additions & 11 deletions packages/runtime/container-runtime/src/compatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
*/

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

import {
disabledCompressionConfig,
Expand Down Expand Up @@ -181,12 +175,12 @@ export function getConfigsForCompatMode<T extends Record<SemanticVersion, unknow
for (const key of Object.keys(configMap)) {
const config = configMap[key as keyof T];
// Sort the versions in ascending order so we can short circuit the loop.
const versions = Object.keys(config).sort((a, b) => (semverGte(b, a) ? -1 : 1));
const versions = Object.keys(config).sort(compare);
// For each config, we iterate over the keys and check if compatibilityVersion is greater than or equal to the version.
// 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
// value that is compatible with the version specified as the compatibilityVersion.
for (const version of versions) {
if (semverGte(compatibilityVersion, version)) {
if (gte(compatibilityVersion, version)) {
defaultConfigs[key] = config[version as MinimumMinorSemanticVersion];
} else {
// If the compatibility mode is less than the version, we break out of the loop since we don't need to check
Expand All @@ -205,7 +199,7 @@ export function getConfigsForCompatMode<T extends Record<SemanticVersion, unknow
export function isValidCompatVersion(compatibilityVersion: SemanticVersion): boolean {
return (
compatibilityVersion !== undefined &&
semverValid(compatibilityVersion) !== null &&
semverLte(compatibilityVersion, pkgVersion)
valid(compatibilityVersion) !== null &&
lte(compatibilityVersion, pkgVersion)
);
}
15 changes: 9 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading