MCPcopy Create free account
hub / github.com/SAP/ui5-project / resolveVersion

Method resolveVersion

lib/ui5Framework/AbstractResolver.js:208–247  ·  view source on GitHub ↗
(version, {ui5DataDir, cwd} = {})

Source from the content-addressed store, hash-verified

206 }
207
208 static async resolveVersion(version, {ui5DataDir, cwd} = {}) {
209 // Don't allow nullish values
210 // An empty string is a valid semver range that converts to "*", which should not be supported
211 if (!version) {
212 throw new Error(`Framework version specifier "${version}" is incorrect or not supported`);
213 }
214
215 const spec = await this._getVersionSpec(version, {ui5DataDir, cwd});
216
217 // For all invalid cases which are not explicitly handled in _getVersionSpec
218 if (!spec) {
219 throw new Error(`Framework version specifier "${version}" is incorrect or not supported`);
220 }
221
222 const versions = await this.fetchAllVersions({ui5DataDir, cwd});
223 const resolvedVersion = semver.maxSatisfying(versions, spec, {
224 // Allow ranges that end with -SNAPSHOT to match any -SNAPSHOT version
225 // like a normal version in order to support ranges like 1.x.x-SNAPSHOT.
226 includePrerelease: this._isSnapshotVersionOrRange(version)
227 });
228
229 if (!resolvedVersion) {
230 if (semver.valid(spec)) {
231 if (this.name === "Sapui5Resolver" && semver.lt(spec, "1.76.0")) {
232 throw new Error(`Could not resolve framework version ${version}. ` +
233 `Note that SAPUI5 framework libraries can only be consumed by the UI5 CLI ` +
234 `starting with SAPUI5 v1.76.0`);
235 } else if (this.name === "Openui5Resolver" && semver.lt(spec, "1.52.5")) {
236 throw new Error(`Could not resolve framework version ${version}. ` +
237 `Note that OpenUI5 framework libraries can only be consumed by the UI5 CLI ` +
238 `starting with OpenUI5 v1.52.5`);
239 }
240 }
241 throw new Error(
242 `Could not resolve framework version ${version}. ` +
243 `Make sure the version is valid and available in the configured registry.`);
244 }
245
246 return resolvedVersion;
247 }
248
249 static async _getVersionSpec(version, {ui5DataDir, cwd}) {
250 if (this._isSnapshotVersionOrRange(version)) {

Calls 4

_getVersionSpecMethod · 0.95
fetchAllVersionsMethod · 0.95
ltMethod · 0.80

Tested by

no test coverage detected