import semver from 'semver'; import type { Metadata } from '../types'; /* * Check if the MFE supports re-rendering itself when data changes * * `bundledWith.@servicetitan/web-components` is checked first, as that guarantees support * `dependencies.@servicetitan/web-components` is checked second, in the case of the MFE's startup * hasn't been updated to add web-components to bundledWith yet, and the MFE's web-component * dependency is set in it's own package's package.json instead of the monorepo's root package.json * `bundledWith.@servicetitan/startup` is checked third, with the hope that the startup version * matches web-components */ export function getMFESupportsRerendering( bundledWith: Metadata['bundledWith'], dependencies: Metadata['dependencies'] ) { return !!( isSupportedVersion(bundledWith?.['@servicetitan/web-components']) ?? isSupportedVersion(dependencies?.['@servicetitan/web-components']) ?? isSupportedVersion(bundledWith?.['@servicetitan/startup']) ); } function isSupportedVersion(version?: string) { const minVersion = version && semver.minVersion(version); if (minVersion) { return semver.gte(minVersion, '22.12.0'); } }