Skip to content

Commit 2a3d618

Browse files
authored
fix: fallback to 1.71.49 for old supported UI5 versions (#608)
* fix: customer issue fix * fix: work on pr comment * fix: version negotiation logic change * fix: readme styling
1 parent 9fd54de commit 2a3d618

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

.changeset/unlucky-trainers-hang.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@ui5-language-assistant/context": patch
3+
"vscode-ui5-language-assistant": patch
4+
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
5+
---
6+
7+
Issue 538 fix, for UI5 versions 1.38 and below the fallback 1.71.49 is used

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ It currently contains:
3535
[npm-bas-ext-url]: https://www.npmjs.com/package/@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext
3636
[npm-bas-ext-image]: https://img.shields.io/npm/v/@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext.svg
3737

38+
## Limitations
39+
40+
### UI5 version and framework.
41+
42+
This extension derives the UI5 version in the following sequence:
43+
44+
1. The `minUI5Version` from the manifest.json file (see note)
45+
2. Lookup in CDN for UI5 version and negotiate to the closest LTS version (see note).
46+
3. If it is not found or the version is 1.38 or older, then default back to 1.71 (latest patch level). The framework (SAPUI5/OpenUI5) is derived from the ui5.yaml file. This defaults to SAPUI5.
47+
48+
Note: If `minUI5Version` not found in the manifest.json or lookup in CDN fails, then fall back to default 1.71.49 version
49+
3850
## Support
3951

4052
Please open [issues](https://github.com/SAP/ui5-language-assistant/issues) on github.

packages/context/src/ui5-model.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,29 +361,40 @@ export async function negotiateVersionWithFetcher(
361361
let isFallback = false;
362362
let isIncorrectVersion = false;
363363
let versions = versionMap[framework];
364+
365+
let adjustedVersion: string = version || DEFAULT_UI5_VERSION;
366+
367+
if (version && !isVersionSupported(version)) {
368+
// version is out of support in LA, using default version
369+
getLogger().warn(
370+
`The version specified as minUI5Version in your manifest.json is not supported by Language Assistant, the fallback version ${DEFAULT_UI5_VERSION} is used instead`
371+
);
372+
adjustedVersion = "1.71";
373+
isIncorrectVersion = true;
374+
}
375+
364376
if (!version) {
365377
// no version defined, using default version
366378
getLogger().warn(
367379
"No version defined! Please check the minUI5Version in your manifest.json!"
368380
);
369-
version = DEFAULT_UI5_VERSION;
370381
isFallback = true;
371-
} else if (resolvedVersions[framework]?.[version]) {
382+
} else if (resolvedVersions[framework]?.[adjustedVersion]) {
372383
// version already resolved?
373-
const versionDefined = version;
374-
version = resolvedVersions[framework]?.[version];
375-
if (versionDefined !== version) {
384+
const versionDefined = adjustedVersion;
385+
adjustedVersion = resolvedVersions[framework]?.[adjustedVersion];
386+
if (versionDefined !== adjustedVersion) {
376387
isIncorrectVersion = true;
377388
}
378389
} else if (
379390
!(await getVersionInfo(
380391
versionInfoJsonFetcher,
381392
modelCachePath,
382393
framework,
383-
version
394+
adjustedVersion
384395
))
385396
) {
386-
const requestedVersion = version;
397+
const requestedVersion = adjustedVersion;
387398
// no version information found, try to negotiate the version
388399
if (!versions) {
389400
// retrieve the version mapping (only exists for SAPUI5 so far)
@@ -414,51 +425,65 @@ export async function negotiateVersionWithFetcher(
414425
versions = versionMap[framework];
415426
}
416427
// coerce the version (check for invalid version, which indicates development scenario)
417-
const parsedVersion = semver.coerce(version);
428+
const parsedVersion = semver.coerce(adjustedVersion);
418429
if (parsedVersion) {
419430
if (versions[`${parsedVersion.major}.${parsedVersion.minor}`]) {
420431
// lookup for a valid major.minor entry
421-
version =
432+
adjustedVersion =
422433
versions[`${parsedVersion.major}.${parsedVersion.minor}`].version;
423434
}
424435
if (
425436
!(await getVersionInfo(
426437
versionInfoJsonFetcher,
427438
modelCachePath,
428439
framework,
429-
version
440+
adjustedVersion
430441
))
431442
) {
432443
// find closest supported version
433-
version =
444+
adjustedVersion =
434445
semverMinSatisfying(
435446
Object.values(versions).map((entry) => {
436447
return entry.version;
437448
}) as string[],
438-
`^${version}`
449+
`^${adjustedVersion}`
439450
) || versions["latest"].version;
440451

441452
isIncorrectVersion = true;
442453
}
443454
} else {
444455
// development scenario => use latest version
445-
version = versions["latest"].version;
456+
adjustedVersion = versions["latest"].version;
446457
isIncorrectVersion = true;
447458
}
448459
// store the resolved version
449460
if (requestedVersion) {
450-
if (requestedVersion !== version) {
461+
if (requestedVersion !== adjustedVersion) {
451462
isIncorrectVersion = true;
452463
}
453464
if (!resolvedVersions[framework]) {
454465
resolvedVersions[framework] = Object.create(null);
455466
}
456-
resolvedVersions[framework][requestedVersion] = version;
467+
resolvedVersions[framework][requestedVersion] = adjustedVersion;
457468
}
458469
}
459470
return {
460-
version: version ?? DEFAULT_UI5_VERSION,
471+
version: adjustedVersion,
461472
isFallback,
462473
isIncorrectVersion,
463474
};
464475
}
476+
477+
// Versions 1.38 and older are not supported because of missing features in the API, while the LA relies on that API for validation.
478+
// See https://github.com/SAP/ui5-language-assistant/issues/538 for details
479+
function isVersionSupported(version: string | undefined): boolean {
480+
const versionDetails = semver.coerce(version);
481+
if (!versionDetails) {
482+
return false;
483+
}
484+
return !(
485+
versionDetails.major === 1 &&
486+
versionDetails.minor &&
487+
versionDetails.minor <= 38
488+
);
489+
}

packages/context/test/unit/ui5-model.test.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ describe("the UI5 language assistant ui5 model", () => {
520520
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
521521
});
522522

523-
it("resolve invalid versions (should be latest)", async () => {
523+
it("resolve invalid versions (should be fallback)", async () => {
524524
let objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
525525
async (): Promise<FetchResponse> => {
526526
return createResponse(true, 200, versionMap[FRAMEWORK]);
@@ -551,7 +551,7 @@ describe("the UI5 language assistant ui5 model", () => {
551551
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeFalse();
552552
});
553553

554-
it("resolve invalid versions OpenUI5 (should be latest)", async () => {
554+
it("resolve invalid versions OpenUI5 (should be fallback)", async () => {
555555
const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
556556
async (): Promise<FetchResponse> => {
557557
return createResponse(true, 200, versionMap[OPEN_FRAMEWORK]);
@@ -567,5 +567,39 @@ describe("the UI5 language assistant ui5 model", () => {
567567
expect(objNegotiatedVersionWithFetcher.isFallback).toBeTrue();
568568
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeFalse();
569569
});
570+
571+
it("resolve unsupported versions (should be latest)", async () => {
572+
const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
573+
async (): Promise<FetchResponse> => {
574+
return createResponse(true, 200, versionMap[OPEN_FRAMEWORK]);
575+
},
576+
async (): Promise<FetchResponse> => {
577+
return createResponse(false, 404);
578+
},
579+
cachePath,
580+
FRAMEWORK,
581+
"1.38"
582+
);
583+
expect(objNegotiatedVersionWithFetcher.version).toEqual("1.71.50");
584+
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
585+
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
586+
});
587+
588+
it("resolve wrong versions (should be latest)", async () => {
589+
const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher(
590+
async (): Promise<FetchResponse> => {
591+
return createResponse(true, 200, versionMap[OPEN_FRAMEWORK]);
592+
},
593+
async (): Promise<FetchResponse> => {
594+
return createResponse(false, 404);
595+
},
596+
cachePath,
597+
FRAMEWORK,
598+
"a.b"
599+
);
600+
expect(objNegotiatedVersionWithFetcher.version).toEqual("1.71.50");
601+
expect(objNegotiatedVersionWithFetcher.isFallback).toBeFalse();
602+
expect(objNegotiatedVersionWithFetcher.isIncorrectVersion).toBeTrue();
603+
});
570604
});
571605
});

0 commit comments

Comments
 (0)