diff --git a/.changeset/tender-rivers-matter.md b/.changeset/tender-rivers-matter.md new file mode 100644 index 000000000..4f34b9bea --- /dev/null +++ b/.changeset/tender-rivers-matter.md @@ -0,0 +1,16 @@ +--- +"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch +"vscode-ui5-language-assistant": patch +"@ui5-language-assistant/xml-views-completion": patch +"@ui5-language-assistant/xml-views-validation": patch +"@ui5-language-assistant/xml-views-tooltip": patch +"@ui5-language-assistant/language-server": patch +"@ui5-language-assistant/test-utils": patch +"@ui5-language-assistant/semantic-model": patch +"@ui5-language-assistant/semantic-model-types": patch +"@ui5-language-assistant/logic-utils": patch +"@ui5-language-assistant/constant": patch +"@ui5-language-assistant/context": patch +--- + +fix: introduce constant package to handle UI5 default version in central package diff --git a/packages/constant/README.md b/packages/constant/README.md new file mode 100644 index 000000000..68def8d34 --- /dev/null +++ b/packages/constant/README.md @@ -0,0 +1,32 @@ +[![npm (scoped)](https://img.shields.io/npm/v/@ui5-language-assistant/constant.svg)](https://www.npmjs.com/package/@ui5-language-assistant/constant) + +# @ui5-language-assistant/constant + +A package for constants that can be reused a cross other packages. This package is introduced to avoid cyclic dependency. + +## Installation + +With npm: + +- `npm install @ui5-language-assistant/constant` + +With Yarn: + +- `yarn add @ui5-language-assistant/constant` + +## Usage + +This package only exposes programmatic APIs, import the package and use the exported APIs +defined in [api.ts](./src/api.ts). + +## Support + +Please open [issues](https://github.com/SAP/ui5-language-assistant/issues) on github. + +## Contributing + +See [CONTRIBUTING.md](./CONTRIBUTING.md). + +## Licensing + +Copyright 2022 SAP SE. Please see our [LICENSE](../../LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/SAP/ui5-language-assistant). diff --git a/packages/constant/jest.config.js b/packages/constant/jest.config.js new file mode 100644 index 000000000..406cef575 --- /dev/null +++ b/packages/constant/jest.config.js @@ -0,0 +1,15 @@ +const { join } = require("path"); +const defaultConfig = require("../../jest.config"); + +module.exports = { + ...defaultConfig, + globals: { + "ts-jest": { + tsconfig: join(__dirname, "tsconfig-test.json"), + diagnostics: { + // warnOnly: true, + exclude: /\.(spec|test)\.ts$/, + }, + }, + }, +}; diff --git a/packages/constant/package.json b/packages/constant/package.json new file mode 100644 index 000000000..17f0f3520 --- /dev/null +++ b/packages/constant/package.json @@ -0,0 +1,27 @@ +{ + "name": "@ui5-language-assistant/constant", + "version": "0.0.0", + "private": true, + "description": "constant variables used across packages", + "keywords": [], + "files": [ + ".reuse", + "LICENSES", + "lib/src", + "src" + ], + "main": "lib/src/api.js", + "repository": "https://github.com/sap/ui5-language-assistant/", + "license": "Apache-2.0", + "dependencies": {}, + "devDependencies": {}, + "scripts": { + "ci": "npm-run-all clean compile lint", + "clean": "rimraf ./lib ./coverage ./nyc_output", + "compile": "yarn run clean && tsc -p .", + "compile:watch": "tsc -p . --watch", + "lint": "eslint . --ext .ts --max-warnings=0 --ignore-path=../../.gitignore", + "test": "echo nothing to test", + "format:fix": "prettier --write \"**/*.@(js|ts|json|md)\" --ignore-path=.gitignore" + } +} diff --git a/packages/constant/src/api.ts b/packages/constant/src/api.ts new file mode 100644 index 000000000..76e451a6f --- /dev/null +++ b/packages/constant/src/api.ts @@ -0,0 +1,8 @@ +export { + DEFAULT_OPEN_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, + DEFAULT_UI5_VERSION_BASE, + OPEN_FRAMEWORK, + UI5_FRAMEWORK_CDN_BASE_URL, +} from "./constant"; diff --git a/packages/constant/src/constant.ts b/packages/constant/src/constant.ts new file mode 100644 index 000000000..a5cd55d18 --- /dev/null +++ b/packages/constant/src/constant.ts @@ -0,0 +1,14 @@ +export const OPEN_FRAMEWORK = "OpenUI5"; +export const DEFAULT_UI5_FRAMEWORK = "SAPUI5"; + +//https://ui5.sap.com/version.json +export const DEFAULT_UI5_VERSION = "1.71.70"; +// https://sdk.openui5.org/version.json +export const DEFAULT_OPEN_UI5_VERSION = "1.71.67"; + +export const DEFAULT_UI5_VERSION_BASE = "1.71"; + +export const UI5_FRAMEWORK_CDN_BASE_URL = { + OpenUI5: "https://sdk.openui5.org/", + SAPUI5: "https://ui5.sap.com/", +}; diff --git a/packages/constant/tsconfig.json b/packages/constant/tsconfig.json new file mode 100644 index 000000000..3057a3012 --- /dev/null +++ b/packages/constant/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "lib", + "baseUrl": "." + }, + "include": ["src/**/*", "api.d.ts"] +} diff --git a/packages/context/package.json b/packages/context/package.json index 68988ee9d..ed6b431e3 100644 --- a/packages/context/package.json +++ b/packages/context/package.json @@ -22,6 +22,7 @@ "@ui5-language-assistant/logger": "0.0.1", "@ui5-language-assistant/logic-utils": "4.0.18", "@ui5-language-assistant/settings": "4.0.9", + "@ui5-language-assistant/constant": "0.0.0", "fs-extra": "10.1.0", "globby": "11.1.0", "js-yaml": "4.1.0", diff --git a/packages/context/src/api.ts b/packages/context/src/api.ts index f5f481f91..281fd1fff 100644 --- a/packages/context/src/api.ts +++ b/packages/context/src/api.ts @@ -21,7 +21,6 @@ export { getUI5Yaml, findYamlPath, } from "./ui5-yaml"; -export { getCDNBaseUrl } from "./utils"; export { cache } from "./cache"; export { reactOnCdsFileChange, diff --git a/packages/context/src/types.ts b/packages/context/src/types.ts index af603f6cb..6ebd8e1be 100644 --- a/packages/context/src/types.ts +++ b/packages/context/src/types.ts @@ -6,14 +6,8 @@ import { ConvertedMetadata } from "@sap-ux/vocabularies-types"; import type { Manifest } from "@sap-ux/project-access"; import { FetchResponse } from "@ui5-language-assistant/logic-utils"; -export const DEFAULT_UI5_FRAMEWORK = "SAPUI5"; -export const DEFAULT_UI5_VERSION = "1.71.69"; -export const DEFAULT_UI5_VERSION_BASE = "1.71"; export const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}"; -export const UI5_FRAMEWORK_CDN_BASE_URL = { - OpenUI5: "https://sdk.openui5.org/", - SAPUI5: "https://ui5.sap.com/", -}; + export const UI5_PROJECT_TYPE = "UI5"; export const CAP_PROJECT_TYPE = "CAP"; export enum DirName { diff --git a/packages/context/src/ui5-model.ts b/packages/context/src/ui5-model.ts index e55ad9a1f..cafe8ce67 100644 --- a/packages/context/src/ui5-model.ts +++ b/packages/context/src/ui5-model.ts @@ -7,28 +7,25 @@ import { UI5Framework, UI5SemanticModel, } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_VERSION_BASE, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generate, Json, TypeNameFix, } from "@ui5-language-assistant/semantic-model"; -import { - DEFAULT_UI5_VERSION_BASE, - Fetcher, - UI5_VERSION_S4_PLACEHOLDER, -} from "./types"; +import { Fetcher, UI5_VERSION_S4_PLACEHOLDER } from "./types"; import { fetch, getLocalUrl, tryFetch, -} from "@ui5-language-assistant/logic-utils"; -import { - getLibraryAPIJsonUrl, - getLogger, getVersionInfoUrl, getVersionJsonUrl, -} from "./utils"; -import { DEFAULT_UI5_VERSION } from "./types"; + getLibraryAPIJsonUrl, +} from "@ui5-language-assistant/logic-utils"; +import { getLogger } from "./utils"; import { cache } from "./cache"; export type VersionMapJsonType = Record< diff --git a/packages/context/src/ui5-yaml.ts b/packages/context/src/ui5-yaml.ts index c2134997d..22178d332 100644 --- a/packages/context/src/ui5-yaml.ts +++ b/packages/context/src/ui5-yaml.ts @@ -3,12 +3,13 @@ import { maxBy, map, filter } from "lodash"; import { readFile } from "fs-extra"; import { URI } from "vscode-uri"; import { loadAll } from "js-yaml"; -import { DEFAULT_UI5_FRAMEWORK, YamlDetails } from "./types"; +import { YamlDetails } from "./types"; import { FileName } from "@sap-ux/project-access"; import findUp from "find-up"; import { cache } from "./cache"; import { getLogger } from "./utils"; import { findAllFilesInWorkspace } from "./utils/fileUtils"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; export async function initializeUI5YamlData( workspaceFolderPath: string diff --git a/packages/context/src/utils/index.ts b/packages/context/src/utils/index.ts index eb040fb55..1c2b1584e 100644 --- a/packages/context/src/utils/index.ts +++ b/packages/context/src/utils/index.ts @@ -1,10 +1,3 @@ -export { - getLibraryAPIJsonUrl, - getVersionInfoUrl, - getVersionJsonUrl, - getCDNBaseUrl, -} from "./ui5"; - export { findAppRoot, getLocalAnnotationsForService, diff --git a/packages/context/src/utils/ui5.ts b/packages/context/src/utils/ui5.ts deleted file mode 100644 index c877db944..000000000 --- a/packages/context/src/utils/ui5.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { UI5Framework } from "@ui5-language-assistant/semantic-model-types"; -import { UI5_FRAMEWORK_CDN_BASE_URL } from "../types"; -import { getLogger } from "."; -import { tryFetch, getLocalUrl } from "@ui5-language-assistant/logic-utils"; - -/** - * Get CDN URL for UI5 framework. If a URL for `SAPUI5 Web Server` is maintained in settings, it appends UI5 version if available and tries to check if this URL is responding and return it, - * if it fails, it appends UI5 version if available to a public URL and return it - * - * @param framework UI5 framework e.g OpenUI5" | "SAPUI5" - * @param version min ui5 version specified in manifest.json file - */ -export async function getCDNBaseUrl( - framework: UI5Framework, - version: string | undefined -): Promise { - const localUrl = getLocalUrl(version); - if (localUrl) { - const response = await tryFetch(localUrl); - if (response) { - return localUrl; - } - - getLogger().info("Failed to load. Will try over internet.", { - localUrl, - }); - } - - let url = UI5_FRAMEWORK_CDN_BASE_URL[framework]; - if (version) { - url += `${version}/`; - } - return url; -} - -export function getVersionJsonUrl(framework: UI5Framework): string { - return `${UI5_FRAMEWORK_CDN_BASE_URL[framework]}version.json`; -} - -export async function getVersionInfoUrl( - framework: UI5Framework, - version: string -): Promise { - const cdnBaseUrl = await getCDNBaseUrl(framework, version); - return `${cdnBaseUrl}resources/sap-ui-version.json`; -} - -export async function getLibraryAPIJsonUrl( - framework: UI5Framework, - version: string, - libName: string -): Promise { - const cdnBaseUrl = await getCDNBaseUrl(framework, version); - const baseUrl = `${cdnBaseUrl}test-resources/`; - const suffix = "/designtime/api.json"; - return baseUrl + libName.replace(/\./g, "/") + suffix; -} diff --git a/packages/context/test/unit/api.test.ts b/packages/context/test/unit/api.test.ts index 6e737a35d..2f4df2afa 100644 --- a/packages/context/test/unit/api.test.ts +++ b/packages/context/test/unit/api.test.ts @@ -6,6 +6,7 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { getContext, isContext } from "../../src/api"; import type { Context } from "../../src/types"; import * as projectAccess from "@sap-ux/project-access"; +import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; describe("context", () => { afterEach(() => { @@ -39,7 +40,7 @@ describe("context", () => { const getYamlDetailsStub = jest .spyOn(ui5Yaml, "getYamlDetails") .mockResolvedValue({ - framework: "OpenUI5", + framework: OPEN_FRAMEWORK, version: undefined, }); const getSemanticModelStub = jest @@ -80,7 +81,7 @@ describe("context", () => { const getYamlDetailsStub = jest .spyOn(ui5Yaml, "getYamlDetails") .mockResolvedValue({ - framework: "OpenUI5", + framework: OPEN_FRAMEWORK, version: undefined, }); const getSemanticModelStub = jest diff --git a/packages/context/test/unit/ui5-model.test.ts b/packages/context/test/unit/ui5-model.test.ts index 9d50a5db9..543f435d4 100644 --- a/packages/context/test/unit/ui5-model.test.ts +++ b/packages/context/test/unit/ui5-model.test.ts @@ -25,6 +25,12 @@ import { sync as rimrafSync } from "rimraf"; import { forEach, isPlainObject } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_VERSION_BASE, + DEFAULT_UI5_VERSION, + OPEN_FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; import { expectExists } from "@ui5-language-assistant/test-utils"; import { getSemanticModel, @@ -35,54 +41,35 @@ import { VersionMapJsonType, } from "../../src/ui5-model"; import { FetchResponse } from "@ui5-language-assistant/language-server"; -import { fetch } from "@ui5-language-assistant/logic-utils"; import * as logicUtils from "@ui5-language-assistant/logic-utils"; -import { getVersionJsonUrl } from "../../src/utils"; import semverMinSatisfying from "semver/ranges/min-satisfying"; import { Response } from "node-fetch"; - +import { UI5Framework } from "@ui5-language-assistant/semantic-model-types"; +import { UI5_VERSION_S4_PLACEHOLDER } from "../../src/types"; const GET_MODEL_TIMEOUT = 30000; -const FRAMEWORK = "SAPUI5"; -const OPEN_FRAMEWORK = "OpenUI5"; -const FALLBACK_VERSION = "1.71.69"; -const FALLBACK_VERSION_BASE = "1.71"; -const UI5_VERSION_S4_PLACEHOLDER = "${sap.ui5.dist.version}"; const NO_CACHE_FOLDER = undefined; +const { getVersionsMap } = logicUtils; +const frameworks: UI5Framework[] = [OPEN_FRAMEWORK, DEFAULT_UI5_FRAMEWORK]; +const latestFallbackPatchVersion: Record = { + OpenUI5: undefined, + SAPUI5: undefined, +}; -type UI5FrameworkType = typeof FRAMEWORK | typeof OPEN_FRAMEWORK; -const frameworks = [FRAMEWORK, OPEN_FRAMEWORK] as UI5FrameworkType[]; - -async function getCurrentVersionMaps( - framework: UI5FrameworkType -): Promise { - const url = getVersionJsonUrl(framework); - const response = await fetch(url); - if (response.ok) { - return (await response.json()) as VersionMapJsonType; - } else { - return undefined; - } -} - -const latestFallbackPatchVersion: Record = - { - OpenUI5: undefined, - SAPUI5: undefined, - }; - -const currentVersionMaps: Record = { - OpenUI5: {}, - SAPUI5: {}, +const currentVersionMaps: Record = { + [OPEN_FRAMEWORK]: {}, + [DEFAULT_UI5_FRAMEWORK]: {}, }; const loadCurrentVersionMaps = Promise.all([ - getCurrentVersionMaps(FRAMEWORK).then((data) => { + getVersionsMap(DEFAULT_UI5_FRAMEWORK, logicUtils.fetch).then((data) => { currentVersionMaps.SAPUI5 = data || {}; - latestFallbackPatchVersion.SAPUI5 = data?.[FALLBACK_VERSION_BASE]?.version; + latestFallbackPatchVersion.SAPUI5 = + data?.[DEFAULT_UI5_VERSION_BASE]?.version; }), - getCurrentVersionMaps(OPEN_FRAMEWORK).then((data) => { + getVersionsMap(OPEN_FRAMEWORK, logicUtils.fetch).then((data) => { currentVersionMaps.OpenUI5 = data || {}; - latestFallbackPatchVersion.OpenUI5 = data?.[FALLBACK_VERSION_BASE]?.version; + latestFallbackPatchVersion.OpenUI5 = + data?.[DEFAULT_UI5_VERSION_BASE]?.version; }), ]); @@ -97,7 +84,7 @@ describe("the UI5 language assistant ui5 model", () => { ui5Model: UI5SemanticModel, expectedVersion?: string ): void { - expect(ui5Model.version).toEqual(expectedVersion || FALLBACK_VERSION); + expect(ui5Model.version).toEqual(expectedVersion || DEFAULT_UI5_VERSION); expect(Object.keys(ui5Model.classes).length).toBeGreaterThan(200); expect(Object.keys(ui5Model.namespaces).length).toBeGreaterThan(200); @@ -133,7 +120,7 @@ describe("the UI5 language assistant ui5 model", () => { async () => { const ui5Model = await getSemanticModel( NO_CACHE_FOLDER, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5, true ); @@ -154,7 +141,7 @@ describe("the UI5 language assistant ui5 model", () => { }; }, NO_CACHE_FOLDER, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, undefined, true ); @@ -179,7 +166,7 @@ describe("the UI5 language assistant ui5 model", () => { async () => { const ui5Model = await getSemanticModel( cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5, true ); @@ -199,7 +186,7 @@ describe("the UI5 language assistant ui5 model", () => { ); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5, true ); @@ -234,7 +221,11 @@ describe("the UI5 language assistant ui5 model", () => { async () => { // Create a folder with the file name so the file will not be written const cacheFilePath = getCacheFilePath( - getCacheFolder(cachePath, FRAMEWORK, FALLBACK_VERSION), + getCacheFolder( + cachePath, + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION + ), "sap.m" ); expectExists(cacheFilePath, "cacheFilePath"); @@ -242,7 +233,7 @@ describe("the UI5 language assistant ui5 model", () => { const ui5Model = await getSemanticModel( cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5 ); expect(ui5Model).not.toBeUndefined(); @@ -259,8 +250,8 @@ describe("the UI5 language assistant ui5 model", () => { // Create a file with non-json content so the file will not be deserialized const cacheFolder = getCacheFolder( cachePath, - FRAMEWORK, - FALLBACK_VERSION + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION ); await mkdirs(cacheFolder); const cacheFilePath = getCacheFilePath(cacheFolder, "sap.m"); @@ -269,7 +260,7 @@ describe("the UI5 language assistant ui5 model", () => { const ui5Model = await getSemanticModel( cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, undefined, true ); @@ -298,7 +289,7 @@ describe("the UI5 language assistant ui5 model", () => { async () => { const ui5Model = await getSemanticModel( cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5, true ); @@ -318,7 +309,7 @@ describe("the UI5 language assistant ui5 model", () => { }; }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, latestFallbackPatchVersion.SAPUI5, true ); @@ -371,7 +362,7 @@ describe("the UI5 language assistant ui5 model", () => { }); const getExpectedVersion = ( - framework: typeof FRAMEWORK | typeof OPEN_FRAMEWORK, + framework: UI5Framework, requestedVersion: string ) => { const versions = currentVersionMaps[framework]; @@ -584,7 +575,7 @@ describe("the UI5 language assistant ui5 model", () => { { // outdated version version: () => "1.104", - expected: () => getExpectedVersion(FRAMEWORK, "1.104"), + expected: () => getExpectedVersion("SAPUI5", "1.104"), }, { // supported version @@ -595,7 +586,7 @@ describe("the UI5 language assistant ui5 model", () => { }, { // fallback base - version: () => FALLBACK_VERSION_BASE, + version: () => DEFAULT_UI5_VERSION_BASE, expected: () => latestFallbackPatchVersion.SAPUI5 || "", }, { @@ -621,7 +612,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, testCase.version() ); expect(result.version).toEqual(testCase.expected()); @@ -631,7 +622,7 @@ describe("the UI5 language assistant ui5 model", () => { }); it("resolve major version (should be closest supported)", async () => { - const expectedVersion = getExpectedVersion(FRAMEWORK, "1"); + const expectedVersion = getExpectedVersion("SAPUI5", "1"); const objNegotiatedVersionWithFetcher = await negotiateVersionWithFetcher( async (): Promise> => { return createSuccessfulResponse(currentVersionMaps.SAPUI5); @@ -643,7 +634,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, "1" ); expect(objNegotiatedVersionWithFetcher.version).toEqual(expectedVersion); @@ -708,7 +699,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, "1.38" ); expect(objNegotiatedVersionWithFetcher.version).toEqual( @@ -730,7 +721,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, "a.b" ); expect(objNegotiatedVersionWithFetcher.version).toEqual( @@ -752,7 +743,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, UI5_VERSION_S4_PLACEHOLDER ); expect(objNegotiatedVersionWithFetcher.version).toEqual( @@ -786,7 +777,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, testVersion ); expect(objNegotiatedVersionWithFetcher.version).toEqual(testVersion); diff --git a/packages/context/test/unit/ui5-model_fs-mocked.test.ts b/packages/context/test/unit/ui5-model_fs-mocked.test.ts index daf6d3dd2..cafc1f5c1 100644 --- a/packages/context/test/unit/ui5-model_fs-mocked.test.ts +++ b/packages/context/test/unit/ui5-model_fs-mocked.test.ts @@ -7,17 +7,17 @@ jest.mock("fs-extra", () => { }); import { file as tempFile } from "tmp-promise"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; import { VersionMapJsonType, negotiateVersionWithFetcher, } from "../../src/ui5-model"; import { FetchResponse } from "@ui5-language-assistant/language-server"; -import { DEFAULT_UI5_VERSION } from "../../src/types"; +import { DEFAULT_UI5_VERSION } from "@ui5-language-assistant/constant"; describe("the UI5 language assistant ui5 model", () => { // The default timeout is 2000ms and getSemanticModel can take ~3000-5000ms - const FRAMEWORK = "SAPUI5"; describe("version negotiation", () => { let cachePath: string; @@ -52,7 +52,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, "1.104.0" ); expect(objNegotiatedVersionWithFetcher.isFallback).toBeTrue(); @@ -75,7 +75,7 @@ describe("the UI5 language assistant ui5 model", () => { return createFailedResponse(); }, cachePath, - FRAMEWORK, + DEFAULT_UI5_FRAMEWORK, "1.104.0" ); expect(objNegotiatedVersionWithFetcher2.version).toEqual( diff --git a/packages/context/test/unit/ui5-yaml.test.ts b/packages/context/test/unit/ui5-yaml.test.ts index 5f791dff5..82ae6ee21 100644 --- a/packages/context/test/unit/ui5-yaml.test.ts +++ b/packages/context/test/unit/ui5-yaml.test.ts @@ -7,6 +7,7 @@ import { } from "@ui5-language-assistant/test-framework"; import { toPosixPath } from "../../src/utils/fileUtils"; import { getVersionForXMLFile, getYamlDetails } from "../../src/ui5-yaml"; +import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; describe("UI5 yaml data handling", () => { let testFramework: TestFramework; @@ -55,7 +56,7 @@ describe("UI5 yaml data handling", () => { const dummyPath = entries[0] + "/dummyPath"; cache.setYamlDetails( dummyPath, - details || { framework: "OpenUI5", version: undefined } + details || { framework: OPEN_FRAMEWORK, version: undefined } ); let result = getVersionForXMLFile(dummyPath + "/a.xml"); expect(result).toBe("1.104.0"); diff --git a/packages/context/test/unit/utils/ui5.test.ts b/packages/context/test/unit/utils/ui5.test.ts deleted file mode 100644 index f5d366e01..000000000 --- a/packages/context/test/unit/utils/ui5.test.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as logicUtils from "@ui5-language-assistant/logic-utils"; -import { getCDNBaseUrl } from "../../../src/utils/ui5"; -import { Response } from "node-fetch"; - -describe("ui5", () => { - afterEach(() => { - jest.restoreAllMocks(); - }); - describe("getCDNBaseUrl", () => { - it("get CDN without local url [with version]", async () => { - const result = await getCDNBaseUrl("SAPUI5", "1.111.0"); - expect(result).toEqual("https://ui5.sap.com/1.111.0/"); - }); - it("get CDN without local url [without version]", async () => { - const result = await getCDNBaseUrl("SAPUI5", undefined); - expect(result).toEqual("https://ui5.sap.com/"); - }); - it("get CDN with local url", async () => { - const fakeGetLocalUrl = jest - .spyOn(logicUtils, "getLocalUrl") - .mockReturnValue("http://localhost:3000/1.111.0/"); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const fakeTryFetch = jest - .spyOn(logicUtils, "tryFetch") - .mockResolvedValue({ ok: true } as unknown as Response); - const result = await getCDNBaseUrl("SAPUI5", "1.111.0"); - expect(fakeGetLocalUrl).toHaveBeenCalled(); - expect(fakeTryFetch).toHaveBeenCalled(); - expect(result).toEqual("http://localhost:3000/1.111.0/"); - }); - it("get CDN with local url [fetch not responding => fall back to public]", async () => { - const fakeGetLocalUrl = jest - .spyOn(logicUtils, "getLocalUrl") - .mockReturnValue("http://localhost:3000/1.112.0/"); - const fakeTryFetch = jest - .spyOn(logicUtils, "tryFetch") - .mockResolvedValue(undefined); - const result = await getCDNBaseUrl("SAPUI5", "1.112.0"); - expect(fakeGetLocalUrl).toHaveBeenCalled(); - expect(fakeTryFetch).toHaveBeenCalled(); - expect(result).toEqual("https://ui5.sap.com/1.112.0/"); - }); - }); -}); diff --git a/packages/context/test/unit/watcher.test.ts b/packages/context/test/unit/watcher.test.ts index 0ed514cab..f598e027a 100644 --- a/packages/context/test/unit/watcher.test.ts +++ b/packages/context/test/unit/watcher.test.ts @@ -19,6 +19,10 @@ import * as utils from "../../src/utils"; import * as manifest from "../../src/manifest"; import { URI } from "vscode-uri"; import pathParse from "path-parse"; +import { + DEFAULT_UI5_FRAMEWORK, + OPEN_FRAMEWORK, +} from "@ui5-language-assistant/constant"; describe("watcher", () => { let testFramework: TestFramework; @@ -168,7 +172,7 @@ describe("watcher", () => { expect(setYamlDetailsSpy.mock.calls[0]).toEqual([ yamlPath, { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: undefined, }, ]); @@ -190,7 +194,7 @@ describe("watcher", () => { expect(setYamlDetailsSpy.mock.calls[1]).toEqual([ yamlPath, { - framework: "OpenUI5", + framework: OPEN_FRAMEWORK, version: undefined, }, ]); @@ -206,7 +210,7 @@ describe("watcher", () => { [directory]: { ["ui5.yaml"]: ` framework: - name: SAPUI5 + name: ${DEFAULT_UI5_FRAMEWORK} version: "1.100.0" `, }, @@ -216,7 +220,7 @@ describe("watcher", () => { expect(setYamlDetailsSpy.mock.calls[1]).toEqual([ yamlPath, { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: "1.100.0", }, ]); diff --git a/packages/language-server/package.json b/packages/language-server/package.json index 9d60576d6..044956329 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -25,6 +25,7 @@ "node": ">=10.0.0" }, "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/xml-views-definition": "0.0.4", "@ui5-language-assistant/binding": "1.0.30", "@sap/swa-for-sapbas-vsx": "1.1.9", diff --git a/packages/language-server/test/unit/completion-items-classes.test.ts b/packages/language-server/test/unit/completion-items-classes.test.ts index be0739ece..d01760691 100644 --- a/packages/language-server/test/unit/completion-items-classes.test.ts +++ b/packages/language-server/test/unit/completion-items-classes.test.ts @@ -5,11 +5,14 @@ import { CompletionItem, } from "vscode-languageserver"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; import { generateModel, expectExists, getFallbackPatchVersions, - DEFAULT_UI5_VERSION, } from "@ui5-language-assistant/test-utils"; import { generate } from "@ui5-language-assistant/semantic-model"; import { @@ -27,7 +30,7 @@ describe("the UI5 language assistant Code Completion Services - classes", () => let appContext: AppContext; beforeAll(async function () { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/completion-items-literals.test.ts b/packages/language-server/test/unit/completion-items-literals.test.ts index c52de2d9e..82beec059 100644 --- a/packages/language-server/test/unit/completion-items-literals.test.ts +++ b/packages/language-server/test/unit/completion-items-literals.test.ts @@ -3,6 +3,9 @@ import { CompletionItemKind, TextEdit } from "vscode-languageserver"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { DEFAULT_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -20,7 +23,7 @@ describe("the UI5 language assistant Code Completion Services", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/completion-items-utils.ts b/packages/language-server/test/unit/completion-items-utils.ts index 0de57e58f..c1a3202a7 100644 --- a/packages/language-server/test/unit/completion-items-utils.ts +++ b/packages/language-server/test/unit/completion-items-utils.ts @@ -15,6 +15,7 @@ import { expectExists } from "@ui5-language-assistant/test-utils"; import { getCompletionItems } from "../../src/completion-items"; import { Settings, getDefaultSettings } from "@ui5-language-assistant/settings"; import { Context } from "@ui5-language-assistant/context"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; /** Return the first part of a tag name suggestion insert text */ export function getTagName(textEdit: TextEdit | undefined): string | undefined { @@ -256,7 +257,7 @@ export const getDefaultContext = (ui5Model: UI5SemanticModel): Context => { }, services: {}, yamlDetails: { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: undefined, }, }; diff --git a/packages/language-server/test/unit/completion-items.test.ts b/packages/language-server/test/unit/completion-items.test.ts index dba63a345..5830e1af5 100644 --- a/packages/language-server/test/unit/completion-items.test.ts +++ b/packages/language-server/test/unit/completion-items.test.ts @@ -2,9 +2,12 @@ import { map, uniq, forEach, filter } from "lodash"; import { CompletionItemKind, TextEdit } from "vscode-languageserver"; import { UI5XMLViewCompletion } from "@ui5-language-assistant/xml-views-completion"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; -import { Settings } from "@ui5-language-assistant/settings"; import { DEFAULT_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; +import { Settings } from "@ui5-language-assistant/settings"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -33,7 +36,7 @@ describe("the UI5 language assistant Code Completion Services", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/documentation.test.ts b/packages/language-server/test/unit/documentation.test.ts index a3c81df0e..dfb0bee2c 100644 --- a/packages/language-server/test/unit/documentation.test.ts +++ b/packages/language-server/test/unit/documentation.test.ts @@ -1,18 +1,21 @@ import { - DEFAULT_UI5_VERSION, buildUI5Enum, generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { generate } from "@ui5-language-assistant/semantic-model"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { getNodeDocumentation } from "../../src/documentation"; describe("The @ui5-language-assistant/language-server function", () => { let ui5SemanticModel: UI5SemanticModel; beforeAll(async function () { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/hover.test.ts b/packages/language-server/test/unit/hover.test.ts index 6e9636cce..215a1557f 100644 --- a/packages/language-server/test/unit/hover.test.ts +++ b/packages/language-server/test/unit/hover.test.ts @@ -7,11 +7,14 @@ import { MarkupKind, } from "vscode-languageserver"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generateModel, expectExists, getFallbackPatchVersions, - DEFAULT_UI5_VERSION, } from "@ui5-language-assistant/test-utils"; import { generate } from "@ui5-language-assistant/semantic-model"; import { getHoverResponse } from "../../src/hover"; @@ -24,7 +27,7 @@ describe("the UI5 language assistant Hover Tooltip Service", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/quick-fix.test.ts b/packages/language-server/test/unit/quick-fix.test.ts index 2f745bee2..30ead90aa 100644 --- a/packages/language-server/test/unit/quick-fix.test.ts +++ b/packages/language-server/test/unit/quick-fix.test.ts @@ -1,11 +1,14 @@ import { - DEFAULT_UI5_VERSION, generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { Position, Range } from "vscode-languageserver-types"; import { generate } from "@ui5-language-assistant/semantic-model"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { QuickFixStableIdLSPInfo, diagnosticToCodeActionFix, @@ -23,7 +26,7 @@ describe("The @ui5-language-assistant/language-server diagnostics quick fix func let ui5SemanticModel: UI5SemanticModel; beforeAll(async function () { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/language-server/test/unit/snapshots/xml-view-diagnostics/snapshots-utils.ts b/packages/language-server/test/unit/snapshots/xml-view-diagnostics/snapshots-utils.ts index e18662649..40878a7d8 100644 --- a/packages/language-server/test/unit/snapshots/xml-view-diagnostics/snapshots-utils.ts +++ b/packages/language-server/test/unit/snapshots/xml-view-diagnostics/snapshots-utils.ts @@ -5,11 +5,14 @@ import { readJsonSync, readFileSync } from "fs-extra"; import { expect } from "chai"; import { sortBy, forEachRight, map, cloneDeep, forEach } from "lodash"; import { - DEFAULT_UI5_VERSION, generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; import { generate } from "@ui5-language-assistant/semantic-model"; import { getXMLViewDiagnostics } from "../../../../src/xml-view-diagnostics"; import { Context as AppContext } from "@ui5-language-assistant/context"; @@ -102,7 +105,7 @@ const ui5ModelPromise = new Promise((done, reject) => { getFallbackPatchVersions() .then((patch) => { generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: patch.SAPUI5 as typeof DEFAULT_UI5_VERSION, modelGenerator: generate, }) diff --git a/packages/language-server/test/unit/xml-view-diagnostics.test_.ts b/packages/language-server/test/unit/xml-view-diagnostics.test_.ts index 3c08a6b3f..079ff897a 100644 --- a/packages/language-server/test/unit/xml-view-diagnostics.test_.ts +++ b/packages/language-server/test/unit/xml-view-diagnostics.test_.ts @@ -6,6 +6,7 @@ import { Context as AppContext } from "@ui5-language-assistant/context"; import { getDefaultContext } from "./completion-items-utils"; import { getXMLViewDiagnostics } from "../../src/xml-view-diagnostics"; import { xmlSnippetToDocument } from "./testUtils"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; export function getDiagnostics( xmlSnippet: string, @@ -20,7 +21,7 @@ describe("the UI5 language assistant xml view diagnostics service", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: "1.108.26", modelGenerator: generate, }); diff --git a/packages/logic-utils/api.d.ts b/packages/logic-utils/api.d.ts index a1a375623..81173bf54 100644 --- a/packages/logic-utils/api.d.ts +++ b/packages/logic-utils/api.d.ts @@ -279,6 +279,11 @@ export { getLocalUrl, isXMLView, getUI5KindByXMLElement, + getCDNBaseUrl, + getLibraryAPIJsonUrl, + getVersionInfoUrl, + getVersionJsonUrl, + getVersionsMap, } from "./src/api"; -export { FetchResponse } from "./src/utils/types"; +export { FetchResponse } from "./src/api"; diff --git a/packages/logic-utils/package.json b/packages/logic-utils/package.json index 8d2edfd40..8af99ec77 100644 --- a/packages/logic-utils/package.json +++ b/packages/logic-utils/package.json @@ -16,8 +16,10 @@ "license": "Apache-2.0", "typings": "./api.d.ts", "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/semantic-model-types": "4.0.10", "@ui5-language-assistant/settings": "4.0.9", + "@ui5-language-assistant/logger": "0.0.1", "@xml-tools/ast": "5.0.0", "lodash": "4.17.21", "node-fetch": "2.6.9", diff --git a/packages/logic-utils/src/api.ts b/packages/logic-utils/src/api.ts index 15f17dc0b..f189352cd 100644 --- a/packages/logic-utils/src/api.ts +++ b/packages/logic-utils/src/api.ts @@ -41,3 +41,13 @@ export { export { fetch } from "./utils/fetch"; export { tryFetch, getLocalUrl } from "./utils/fetch-helper"; export { isXMLView } from "./utils/document"; + +export type { FetchResponse } from "./utils/types"; + +export { + getCDNBaseUrl, + getLibraryAPIJsonUrl, + getVersionInfoUrl, + getVersionJsonUrl, + getVersionsMap, +} from "./utils/ui5"; diff --git a/packages/logic-utils/src/utils/constant.ts b/packages/logic-utils/src/utils/constant.ts new file mode 100644 index 000000000..4120c0165 --- /dev/null +++ b/packages/logic-utils/src/utils/constant.ts @@ -0,0 +1 @@ +export const PACKAGE_NAME = "@ui5-language-assistant/logic-utils"; diff --git a/packages/logic-utils/src/utils/documentation.ts b/packages/logic-utils/src/utils/documentation.ts index 104e30da3..3d0e60fa2 100644 --- a/packages/logic-utils/src/utils/documentation.ts +++ b/packages/logic-utils/src/utils/documentation.ts @@ -3,6 +3,7 @@ import { UI5DeprecatedInfo, UI5SemanticModel, } from "@ui5-language-assistant/semantic-model-types"; +import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; export function getDeprecationPlainTextSnippet({ title, @@ -200,7 +201,7 @@ export function getLink(model: UI5SemanticModel, link: string): string { link = `api/${link}`; } let baseUrl; - if (model.framework === "OpenUI5") { + if (model.framework === OPEN_FRAMEWORK) { baseUrl = "https://sdk.openui5.org/"; } else { baseUrl = "https://ui5.sap.com/"; diff --git a/packages/logic-utils/src/utils/logger.ts b/packages/logic-utils/src/utils/logger.ts new file mode 100644 index 000000000..a856e3c17 --- /dev/null +++ b/packages/logic-utils/src/utils/logger.ts @@ -0,0 +1,6 @@ +import { getLogger as logger, ILogger } from "@ui5-language-assistant/logger"; +import { PACKAGE_NAME } from "./constant"; + +export const getLogger = (): ILogger => { + return logger(PACKAGE_NAME); +}; diff --git a/packages/logic-utils/src/utils/types.ts b/packages/logic-utils/src/utils/types.ts index 0e35c21fe..744298109 100644 --- a/packages/logic-utils/src/utils/types.ts +++ b/packages/logic-utils/src/utils/types.ts @@ -3,3 +3,10 @@ export type FetchResponse = { status: number; json: () => Promise; }; + +export type Fetcher = (url: string) => Promise>; + +export type VersionMapJsonType = Record< + string, + { version: string; support: string; lts: boolean } +>; diff --git a/packages/logic-utils/src/utils/ui5.ts b/packages/logic-utils/src/utils/ui5.ts new file mode 100644 index 000000000..914e8f4f3 --- /dev/null +++ b/packages/logic-utils/src/utils/ui5.ts @@ -0,0 +1,116 @@ +import { UI5Framework } from "@ui5-language-assistant/semantic-model-types"; +import { + UI5_FRAMEWORK_CDN_BASE_URL, + DEFAULT_OPEN_UI5_VERSION, + DEFAULT_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, +} from "@ui5-language-assistant/constant"; +import { Fetcher, VersionMapJsonType } from "./types"; +import { getLogger } from "./logger"; +import { tryFetch, getLocalUrl } from "./fetch-helper"; + +/** + * Get CDN URL for UI5 framework. If a URL for `SAPUI5 Web Server` is maintained in settings, it appends UI5 version if available and tries to check if this URL is responding and return it, + * if it fails, it appends UI5 version if available to a public URL and return it + * + * @param framework UI5 framework e.g OpenUI5" | "SAPUI5" + * @param version min ui5 version specified in manifest.json file + */ +export async function getCDNBaseUrl( + framework: UI5Framework, + version: string | undefined +): Promise { + const localUrl = getLocalUrl(version); + if (localUrl) { + const response = await tryFetch(localUrl); + if (response) { + return localUrl; + } + + getLogger().info("Failed to load. Will try over internet.", { + localUrl, + }); + } + + let url = UI5_FRAMEWORK_CDN_BASE_URL[framework]; + if (version) { + url += `${version}/`; + } + return url; +} + +export function getVersionJsonUrl(framework: UI5Framework): string { + return `${UI5_FRAMEWORK_CDN_BASE_URL[framework]}version.json`; +} + +export async function getVersionInfoUrl( + framework: UI5Framework, + version: string +): Promise { + const cdnBaseUrl = await getCDNBaseUrl(framework, version); + return `${cdnBaseUrl}resources/sap-ui-version.json`; +} + +export async function getLibraryAPIJsonUrl( + framework: UI5Framework, + version: string, + libName: string +): Promise { + const cdnBaseUrl = await getCDNBaseUrl(framework, version); + const baseUrl = `${cdnBaseUrl}test-resources/`; + const suffix = "/designtime/api.json"; + return baseUrl + libName.replace(/\./g, "/") + suffix; +} + +// if library is not found, resolve next minor highest patch +const versionMap: Record = + Object.create(null); // just an in-memory cache! + +/** + * Returns version map for the given framework + * + * @param framework The UI5 framework version + * @param versionJsonFetcher Fetcher function which loads version json + * @returns Object with versions json + * @note if it fails to read version mapping, it fallback to default version. + */ +export async function getVersionsMap( + framework: UI5Framework, + versionJsonFetcher: Fetcher +): Promise { + let versions = versionMap[framework]; + if (versions) { + return versions; + } + + // no version information found in the map, retrieve the version mapping using fetcher + const url = getVersionJsonUrl(framework); + const response = await versionJsonFetcher(url); + if (response.ok) { + versionMap[framework] = await response.json(); + } else { + const DEFAULT_FALL_BACK = + framework === DEFAULT_UI5_FRAMEWORK + ? DEFAULT_UI5_VERSION + : DEFAULT_OPEN_UI5_VERSION; + + getLogger().error( + "Could not read version mapping, fallback to default version", + { + url, + DEFAULT_FALL_BACK, + } + ); + // update version map with default version only + versionMap[framework] = { + latest: { + version: DEFAULT_FALL_BACK, + support: "Maintenance", + lts: true, + }, + }; + } + versions = versionMap[framework]; + + return versions; +} diff --git a/packages/logic-utils/test/unit/documentation.test.ts b/packages/logic-utils/test/unit/documentation.test.ts index dca05b1d4..28579e439 100644 --- a/packages/logic-utils/test/unit/documentation.test.ts +++ b/packages/logic-utils/test/unit/documentation.test.ts @@ -5,6 +5,7 @@ import { convertJSDocToPlainText, } from "../../src/utils/documentation"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; describe("The @ui5-language-assistant/logic-utils function", () => { let model: UI5SemanticModel; @@ -196,7 +197,7 @@ describe("The @ui5-language-assistant/logic-utils funct it("replaces link tags that point to UI5 classes with markdown links when model has a version (OpenUI5)", () => { const modelWithVersion = buildUI5Model({ - framework: "OpenUI5", + framework: OPEN_FRAMEWORK, version: "1.2.3", }); expect( @@ -210,7 +211,7 @@ describe("The @ui5-language-assistant/logic-utils funct }); it("replaces link tags that point to UI5 classes with markdown links when model doesn't have a version (OpenUI5)", () => { - const modelOpenUI5 = buildUI5Model({ framework: "OpenUI5" }); + const modelOpenUI5 = buildUI5Model({ framework: OPEN_FRAMEWORK }); expect( convertJSDocToMarkdown( "This text has a {@link sap.m.Button link to Button} and a nameless link to a type: {@link sap.m.Button}", @@ -223,7 +224,7 @@ describe("The @ui5-language-assistant/logic-utils funct it("replaces topic links with markdown links when model has a version", () => { const modelWithVersion = buildUI5Model({ - framework: "OpenUI5", + framework: OPEN_FRAMEWORK, version: "1.2.3", }); expect( @@ -237,7 +238,7 @@ describe("The @ui5-language-assistant/logic-utils funct }); it("replaces topic links with markdown links when model doesn't have a version", () => { - const modelOpenUI5 = buildUI5Model({ framework: "OpenUI5" }); + const modelOpenUI5 = buildUI5Model({ framework: OPEN_FRAMEWORK }); expect( convertJSDocToMarkdown( "This text link to the topic {@link topic:a4afb138acf64a61a038aa5b91a4f082 App}.", diff --git a/packages/logic-utils/test/unit/find-classes-matching.test.ts b/packages/logic-utils/test/unit/find-classes-matching.test.ts index eaa8e6033..0e0b88c53 100644 --- a/packages/logic-utils/test/unit/find-classes-matching.test.ts +++ b/packages/logic-utils/test/unit/find-classes-matching.test.ts @@ -2,7 +2,10 @@ import { map, forEach, cloneDeep } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -16,7 +19,7 @@ import { async function generateModelForLatestPatch(): Promise { const { SAPUI5: latestPatchVersion } = await getFallbackPatchVersions(); return await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: latestPatchVersion as typeof DEFAULT_UI5_VERSION, modelGenerator: generate, }); diff --git a/packages/logic-utils/test/unit/get-super-class.test.ts b/packages/logic-utils/test/unit/get-super-class.test.ts index 3de78fa99..753ec9276 100644 --- a/packages/logic-utils/test/unit/get-super-class.test.ts +++ b/packages/logic-utils/test/unit/get-super-class.test.ts @@ -1,8 +1,11 @@ import { cloneDeep } from "lodash"; import { UI5Class } from "@ui5-language-assistant/semantic-model-types"; -import { generate } from "@ui5-language-assistant/semantic-model"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generate } from "@ui5-language-assistant/semantic-model"; +import { buildUI5Class, generateModel, getFallbackPatchVersions, @@ -37,7 +40,7 @@ describe("The @ui5-language-assistant/logic-utils function", ( it("will avoid infinite loops in case of cyclic extends clauses", async () => { const ui5Model = cloneDeep( await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/logic-utils/test/unit/ui5.test.ts b/packages/logic-utils/test/unit/ui5.test.ts new file mode 100644 index 000000000..3337d9608 --- /dev/null +++ b/packages/logic-utils/test/unit/ui5.test.ts @@ -0,0 +1,131 @@ +import * as fetchHelper from "./../../src/utils/fetch-helper"; +import { + getCDNBaseUrl, + getLibraryAPIJsonUrl, + getVersionInfoUrl, + getVersionJsonUrl, + getVersionsMap, +} from "../../src/api"; +import { Response } from "node-fetch"; +import { + DEFAULT_OPEN_UI5_VERSION, + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, + OPEN_FRAMEWORK, +} from "@ui5-language-assistant/constant"; + +describe("ui5", () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + describe("getCDNBaseUrl", () => { + it("get CDN without local url [with version]", async () => { + const result = await getCDNBaseUrl(DEFAULT_UI5_FRAMEWORK, "1.111.0"); + expect(result).toEqual("https://ui5.sap.com/1.111.0/"); + }); + it("get CDN without local url [without version]", async () => { + const result = await getCDNBaseUrl(DEFAULT_UI5_FRAMEWORK, undefined); + expect(result).toEqual("https://ui5.sap.com/"); + }); + it("get CDN with local url", async () => { + const fakeGetLocalUrl = jest + .spyOn(fetchHelper, "getLocalUrl") + .mockReturnValue("http://localhost:3000/1.111.0/"); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const fakeTryFetch = jest + .spyOn(fetchHelper, "tryFetch") + .mockResolvedValue({ ok: true } as unknown as Response); + const result = await getCDNBaseUrl(DEFAULT_UI5_FRAMEWORK, "1.111.0"); + expect(fakeGetLocalUrl).toHaveBeenCalled(); + expect(fakeTryFetch).toHaveBeenCalled(); + expect(result).toEqual("http://localhost:3000/1.111.0/"); + }); + it("get CDN with local url [fetch not responding => fall back to public]", async () => { + const fakeGetLocalUrl = jest + .spyOn(fetchHelper, "getLocalUrl") + .mockReturnValue("http://localhost:3000/1.112.0/"); + const fakeTryFetch = jest + .spyOn(fetchHelper, "tryFetch") + .mockResolvedValue(undefined); + const result = await getCDNBaseUrl(DEFAULT_UI5_FRAMEWORK, "1.112.0"); + expect(fakeGetLocalUrl).toHaveBeenCalled(); + expect(fakeTryFetch).toHaveBeenCalled(); + expect(result).toEqual("https://ui5.sap.com/1.112.0/"); + }); + }); + describe("getVersionJsonUrl", () => { + it("get version uri for SAPUI5", () => { + const result = getVersionJsonUrl("SAPUI5"); + expect(result).toStrictEqual("https://ui5.sap.com/version.json"); + }); + it("get version uri for OpenUI5", () => { + const result = getVersionJsonUrl(OPEN_FRAMEWORK); + expect(result).toStrictEqual("https://sdk.openui5.org/version.json"); + }); + }); +}); + +describe("getVersionInfoUrl", () => { + it("get version info uri for SAPUI5", async () => { + const result = await getVersionInfoUrl( + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION + ); + expect(result).toStrictEqual( + "https://ui5.sap.com/1.71.70/resources/sap-ui-version.json" + ); + }); + it("get version info uri for OpenUI5", async () => { + const result = await getVersionInfoUrl( + OPEN_FRAMEWORK, + DEFAULT_OPEN_UI5_VERSION + ); + expect(result).toStrictEqual( + "https://sdk.openui5.org/1.71.67/resources/sap-ui-version.json" + ); + }); +}); + +it("getLibraryAPIJsonUrl", async () => { + const result = await getLibraryAPIJsonUrl( + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, + "sap.m" + ); + expect(result).toStrictEqual( + "https://ui5.sap.com/1.71.70/test-resources/sap/m/designtime/api.json" + ); +}); + +describe("getVersionsMap", () => { + it("get version map for SAPUI5 - http success", async () => { + const data = { + "1.71": { + version: "1.71.70", + support: "Maintenance", + lts: true, + }, + }; + const fetcherSpy = jest.fn().mockResolvedValue({ + ok: true, + json: () => data, + }); + const result = await getVersionsMap(DEFAULT_UI5_FRAMEWORK, fetcherSpy); + expect(result).toEqual(data); + }); + + it("get version map for OpenUI5 - fallback default", async () => { + const data = { + latest: { + version: "1.71.67", + support: "Maintenance", + lts: true, + }, + }; + const fetcherSpy = jest.fn().mockResolvedValue({ + ok: false, + }); + const result = await getVersionsMap(OPEN_FRAMEWORK, fetcherSpy); + expect(result).toEqual(data); + }); +}); diff --git a/packages/logic-utils/test/unit/xml-node-to-ui5-node.test.ts b/packages/logic-utils/test/unit/xml-node-to-ui5-node.test.ts index cf3271ea1..c67d2a5cf 100644 --- a/packages/logic-utils/test/unit/xml-node-to-ui5-node.test.ts +++ b/packages/logic-utils/test/unit/xml-node-to-ui5-node.test.ts @@ -2,12 +2,15 @@ import { find } from "lodash"; import { parse, DocumentCstNode } from "@xml-tools/parser"; import { buildAst, XMLElement, XMLAttribute } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generate } from "@ui5-language-assistant/semantic-model"; import { generateModel, expectExists, getFallbackPatchVersions, - DEFAULT_UI5_VERSION, } from "@ui5-language-assistant/test-utils"; import { getUI5ClassByXMLElement, @@ -22,7 +25,7 @@ import { async function generateModelForLatestPatch(): Promise { const { SAPUI5: latestPatchVersion } = await getFallbackPatchVersions(); return await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: latestPatchVersion as typeof DEFAULT_UI5_VERSION, modelGenerator: generate, }); diff --git a/packages/semantic-model-types/api.d.ts b/packages/semantic-model-types/api.d.ts index 0cd36497d..d5827d81a 100644 --- a/packages/semantic-model-types/api.d.ts +++ b/packages/semantic-model-types/api.d.ts @@ -1,5 +1,9 @@ -export type UI5Framework = "OpenUI5" | "SAPUI5"; +import { + DEFAULT_UI5_FRAMEWORK, + OPEN_FRAMEWORK, +} from "@ui5-language-assistant/constant"; +export type UI5Framework = typeof DEFAULT_UI5_FRAMEWORK | typeof OPEN_FRAMEWORK; export interface UI5SemanticModel { version?: string; framework?: UI5Framework; diff --git a/packages/semantic-model-types/package.json b/packages/semantic-model-types/package.json index 81d7c0fc4..98c262256 100644 --- a/packages/semantic-model-types/package.json +++ b/packages/semantic-model-types/package.json @@ -20,5 +20,8 @@ "lint": "eslint . --ext .ts --max-warnings=0 --ignore-path=../../.gitignore", "test": "echo nothing to test", "coverage": "echo nothing to test" + }, + "dependencies": { + "@ui5-language-assistant/constant": "0.0.0" } } diff --git a/packages/semantic-model/package.json b/packages/semantic-model/package.json index e40997e95..5c7517051 100644 --- a/packages/semantic-model/package.json +++ b/packages/semantic-model/package.json @@ -17,6 +17,7 @@ "license": "Apache-2.0", "typings": "./api.d.ts", "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/semantic-model-types": "4.0.10", "@ui5-language-assistant/logger": "0.0.1", "ajv": "6.12.3", diff --git a/packages/semantic-model/src/resolve.ts b/packages/semantic-model/src/resolve.ts index 48104a666..083cf12e6 100644 --- a/packages/semantic-model/src/resolve.ts +++ b/packages/semantic-model/src/resolve.ts @@ -21,6 +21,7 @@ import { import { TypeNameFix } from "../api"; import { SymbolBase, ClassSymbol, ObjCallableParameters } from "./api-json"; import { error, getParentFqn, findValueInMaps, findSymbol } from "./utils"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; // Exported for testing purpose export function setParent( @@ -35,7 +36,7 @@ export function setParent( // Always throwing an error because we add these symbols implicitly so an error here means we have a bug error( `Symbol ${parentFqn} not found (should be parent of ${fqn}) [${ - model.framework || "SAPUI5" + model.framework || DEFAULT_UI5_FRAMEWORK }:${model.version}]`, true ); @@ -108,7 +109,7 @@ export function resolveSemanticProperties( `${jsonSymbol.extends} is a ${ extendsType.kind } and not a class (class ${key} extends it) [${ - model.framework || "SAPUI5" + model.framework || DEFAULT_UI5_FRAMEWORK }:${model.version}]`, strict ); @@ -126,7 +127,7 @@ export function resolveSemanticProperties( `${interfacee} is a ${ interfaceType.kind } and not an interface (class ${key} implements it) [${ - model.framework || "SAPUI5" + model.framework || DEFAULT_UI5_FRAMEWORK }:${model.version}]`, strict ); @@ -148,7 +149,7 @@ export function resolveSemanticProperties( if (classs.defaultAggregation === undefined) { error( `Unknown default aggregation ${defaultAggregation} in class ${key} [${ - model.framework || "SAPUI5" + model.framework || DEFAULT_UI5_FRAMEWORK }:${model.version}]`, strict ); @@ -178,7 +179,7 @@ export function resolveSemanticProperties( classs.returnTypes = convertedTypes; } - if (classs.ctor?.parameters && jsonSymbol.constructor.parameters) { + if (classs.ctor?.parameters && jsonSymbol.constructor?.parameters) { classs.ctor.parameters.push( ...resolveConstructorParameters( model, @@ -439,7 +440,7 @@ export function resolveType({ }); } else { error( - `Unknown type: ${typeName} [${model.framework || "SAPUI5"}:${ + `Unknown type: ${typeName} [${model.framework || DEFAULT_UI5_FRAMEWORK}:${ model.version }]`, strict && !typedef diff --git a/packages/semantic-model/test/unit/api-negative.test.ts b/packages/semantic-model/test/unit/api-negative.test.ts index 64a02c305..8052411f3 100644 --- a/packages/semantic-model/test/unit/api-negative.test.ts +++ b/packages/semantic-model/test/unit/api-negative.test.ts @@ -1,12 +1,10 @@ import { keys } from "lodash"; -import { - DEFAULT_UI5_VERSION, - expectExists, -} from "@ui5-language-assistant/test-utils"; +import { expectExists } from "@ui5-language-assistant/test-utils"; import { UI5SemanticModel, UnresolvedType, } from "@ui5-language-assistant/semantic-model-types"; +import { DEFAULT_UI5_VERSION } from "@ui5-language-assistant/constant"; import { forEachSymbol } from "../../src/utils"; import { generate } from "../../src/api"; diff --git a/packages/semantic-model/test/unit/api.test.ts b/packages/semantic-model/test/unit/api.test.ts index a876abb9d..88c812e65 100644 --- a/packages/semantic-model/test/unit/api.test.ts +++ b/packages/semantic-model/test/unit/api.test.ts @@ -5,13 +5,16 @@ import { expectProperty, expectExists, downloadLibraries, - DEFAULT_UI5_VERSION, } from "@ui5-language-assistant/test-utils"; import { UI5Framework, UI5SemanticModel, UI5Typedef, } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { forEachSymbol } from "../../src/utils"; import { generate } from "../../src/api"; import { @@ -315,7 +318,7 @@ describe("The ui5-language-assistant semantic model package API", () => { ]; for (const version of versions) { // TODO: consider also openui5? - createModelConsistencyTests("SAPUI5", version); + createModelConsistencyTests(DEFAULT_UI5_FRAMEWORK, version); } describe("returned model is frozen", () => { @@ -324,7 +327,7 @@ describe("The ui5-language-assistant semantic model package API", () => { let model: UI5SemanticModel; beforeAll(async () => { model = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: DEFAULT_UI5_VERSION, modelGenerator: generate, }); @@ -393,7 +396,7 @@ describe("The ui5-language-assistant semantic model package API", () => { let model: UI5SemanticModel; beforeAll(async () => { model = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: DEFAULT_UI5_VERSION, modelGenerator: generate, }); diff --git a/packages/semantic-model/test/unit/unit.test.ts b/packages/semantic-model/test/unit/unit.test.ts index caa33d9a0..8df843631 100644 --- a/packages/semantic-model/test/unit/unit.test.ts +++ b/packages/semantic-model/test/unit/unit.test.ts @@ -3,7 +3,6 @@ import { buildUI5Model, buildUI5Class, expectExists, - DEFAULT_UI5_VERSION, } from "@ui5-language-assistant/test-utils"; import { UI5Class, @@ -11,6 +10,7 @@ import { UI5Type, UnresolvedType, } from "@ui5-language-assistant/semantic-model-types"; +import { DEFAULT_UI5_VERSION } from "@ui5-language-assistant/constant"; import { resolveType, setParent } from "../../src/resolve"; import { getSymbolMaps } from "../../src/utils"; import { generate } from "../../src/api"; diff --git a/packages/semantic-model/test/unit/utils.test.ts b/packages/semantic-model/test/unit/utils.test.ts index c3d67b681..15b178bf5 100644 --- a/packages/semantic-model/test/unit/utils.test.ts +++ b/packages/semantic-model/test/unit/utils.test.ts @@ -1,10 +1,13 @@ import { - DEFAULT_UI5_VERSION, expectExists, generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { findSymbol, generate } from "../../src/api"; import { getFQN } from "./utils/model-test-utils"; @@ -13,7 +16,7 @@ describe("The semantic model utils", () => { beforeAll(async () => { model = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/vscode-ui5-language-assistant/package.json b/packages/vscode-ui5-language-assistant/package.json index cc72fdcd9..5f409f47d 100644 --- a/packages/vscode-ui5-language-assistant/package.json +++ b/packages/vscode-ui5-language-assistant/package.json @@ -163,6 +163,7 @@ "devDependencies": { "@types/lodash": "4.14.168", "@types/vscode": "1.47.0", + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/settings": "4.0.9", "@ui5-language-assistant/logic-utils": "4.0.18", "@ui5-language-assistant/user-facing-text": "4.0.8", diff --git a/packages/vscode-ui5-language-assistant/src/extension.ts b/packages/vscode-ui5-language-assistant/src/extension.ts index 8442b00d9..00067c1cb 100644 --- a/packages/vscode-ui5-language-assistant/src/extension.ts +++ b/packages/vscode-ui5-language-assistant/src/extension.ts @@ -41,6 +41,7 @@ import { bindingLegend, bindingSemanticTokensProvider, } from "./binding-semantic-token-provider"; +import { OPEN_FRAMEWORK } from "@ui5-language-assistant/constant"; type UI5Model = { url: string; @@ -201,7 +202,7 @@ async function updateCurrentModel(model: UI5Model | undefined): Promise { } statusBarItem.tooltip = tooltipText; statusBarItem.text = `$(notebook-mimetype) ${version}${ - currentModel.framework === "OpenUI5" ? "'" : "" + currentModel.framework === OPEN_FRAMEWORK ? "'" : "" }`; statusBarItem.show(); } else { diff --git a/packages/xml-views-completion/package.json b/packages/xml-views-completion/package.json index b4d56ce8d..0fce6b12f 100644 --- a/packages/xml-views-completion/package.json +++ b/packages/xml-views-completion/package.json @@ -21,6 +21,7 @@ "license": "Apache-2.0", "typings": "./api.d.ts", "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/context": "4.0.26", "@ui5-language-assistant/logic-utils": "4.0.18", "@xml-tools/ast": "5.0.0", diff --git a/packages/xml-views-completion/test/unit/api.test.ts b/packages/xml-views-completion/test/unit/api.test.ts index 0ee973877..91ddcdb9d 100644 --- a/packages/xml-views-completion/test/unit/api.test.ts +++ b/packages/xml-views-completion/test/unit/api.test.ts @@ -6,7 +6,10 @@ import { UI5SemanticModel, } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -26,7 +29,7 @@ describe("The `getXMLViewCompletions()` api", () => { let appContext: AppContext; beforeAll(async function () { REAL_UI5_MODEL = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/attributeName/namespace.test.ts b/packages/xml-views-completion/test/unit/providers/attributeName/namespace.test.ts index 59b2061fa..4f23a81d1 100644 --- a/packages/xml-views-completion/test/unit/providers/attributeName/namespace.test.ts +++ b/packages/xml-views-completion/test/unit/providers/attributeName/namespace.test.ts @@ -9,10 +9,13 @@ import { UI5Prop, UI5SemanticModel, } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generate } from "@ui5-language-assistant/semantic-model"; import { ui5NodeToFQN } from "@ui5-language-assistant/logic-utils"; import { - DEFAULT_UI5_VERSION, expectSuggestions, expectXMLAttribute, generateModel, @@ -155,7 +158,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/attributeName/prop-event-assoc.test.ts b/packages/xml-views-completion/test/unit/providers/attributeName/prop-event-assoc.test.ts index 8bd930025..c84173945 100644 --- a/packages/xml-views-completion/test/unit/providers/attributeName/prop-event-assoc.test.ts +++ b/packages/xml-views-completion/test/unit/providers/attributeName/prop-event-assoc.test.ts @@ -1,9 +1,12 @@ import { difference, forEach, partial } from "lodash"; import { XMLAttribute } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; -import { generate } from "@ui5-language-assistant/semantic-model"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generate } from "@ui5-language-assistant/semantic-model"; +import { expectSuggestions, expectXMLAttribute, generateModel, @@ -63,7 +66,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/attributeValue/boolean-literal.test.ts b/packages/xml-views-completion/test/unit/providers/attributeValue/boolean-literal.test.ts index 311247d8b..0d1b3fb43 100644 --- a/packages/xml-views-completion/test/unit/providers/attributeValue/boolean-literal.test.ts +++ b/packages/xml-views-completion/test/unit/providers/attributeValue/boolean-literal.test.ts @@ -2,7 +2,10 @@ import { forEach, map } from "lodash"; import { XMLAttribute, XMLElement } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -20,7 +23,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/attributeValue/enum.test.ts b/packages/xml-views-completion/test/unit/providers/attributeValue/enum.test.ts index 80063f682..da8718807 100644 --- a/packages/xml-views-completion/test/unit/providers/attributeValue/enum.test.ts +++ b/packages/xml-views-completion/test/unit/providers/attributeValue/enum.test.ts @@ -1,7 +1,10 @@ import { forEach, map } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -17,7 +20,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async function () { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/attributeValue/namespace.test.ts b/packages/xml-views-completion/test/unit/providers/attributeValue/namespace.test.ts index de086f856..d29f80e09 100644 --- a/packages/xml-views-completion/test/unit/providers/attributeValue/namespace.test.ts +++ b/packages/xml-views-completion/test/unit/providers/attributeValue/namespace.test.ts @@ -1,10 +1,13 @@ import { partial } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { ui5NodeToFQN } from "@ui5-language-assistant/logic-utils"; import { UI5NamespacesInXMLAttributeValueCompletion } from "@ui5-language-assistant/xml-views-completion"; import { generate } from "@ui5-language-assistant/semantic-model"; import { - DEFAULT_UI5_VERSION, expectSuggestions, expectXMLAttribute, generateModel, @@ -32,7 +35,7 @@ describe("The ui5-editor-tools xml-views-completion", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/elementName/aggregation.test.ts b/packages/xml-views-completion/test/unit/providers/elementName/aggregation.test.ts index d25903acf..675918dd1 100644 --- a/packages/xml-views-completion/test/unit/providers/elementName/aggregation.test.ts +++ b/packages/xml-views-completion/test/unit/providers/elementName/aggregation.test.ts @@ -2,7 +2,10 @@ import { map, cloneDeep, forEach } from "lodash"; import { XMLElement } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { buildUI5Aggregation, generateModel, getFallbackPatchVersions, @@ -18,7 +21,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async () => { REAL_UI5_MODEL = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/providers/elementName/classes.test.ts b/packages/xml-views-completion/test/unit/providers/elementName/classes.test.ts index 3f5cbf6fc..ab05ca8bf 100644 --- a/packages/xml-views-completion/test/unit/providers/elementName/classes.test.ts +++ b/packages/xml-views-completion/test/unit/providers/elementName/classes.test.ts @@ -6,7 +6,10 @@ import { UI5SemanticModel, } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -28,7 +31,7 @@ describe("The ui5-language-assistant xml-views-completion", () => { let appContext: AppContext; beforeAll(async function () { ui5Model = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-completion/test/unit/utils.ts b/packages/xml-views-completion/test/unit/utils.ts index 1d2828238..b8a0822bc 100644 --- a/packages/xml-views-completion/test/unit/utils.ts +++ b/packages/xml-views-completion/test/unit/utils.ts @@ -12,6 +12,7 @@ import { getSuggestions, SuggestionProviders } from "@xml-tools/content-assist"; import { UI5XMLViewCompletion } from "../../api"; import { Context } from "@ui5-language-assistant/context"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; export function testSuggestionsScenario(opts: { xmlText: string; @@ -90,7 +91,7 @@ export const getDefaultContext = (ui5Model: UI5SemanticModel): Context => { }, services: {}, yamlDetails: { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: undefined, }, }; diff --git a/packages/xml-views-tooltip/package.json b/packages/xml-views-tooltip/package.json index b6e125874..5b6943dcc 100644 --- a/packages/xml-views-tooltip/package.json +++ b/packages/xml-views-tooltip/package.json @@ -22,6 +22,7 @@ "node": ">=10.0.0" }, "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/context": "4.0.26", "@ui5-language-assistant/logic-utils": "4.0.18", "@ui5-language-assistant/semantic-model": "4.0.17", diff --git a/packages/xml-views-tooltip/test/unit/tooltip.test.ts b/packages/xml-views-tooltip/test/unit/tooltip.test.ts index 281e47e98..1744054e7 100644 --- a/packages/xml-views-tooltip/test/unit/tooltip.test.ts +++ b/packages/xml-views-tooltip/test/unit/tooltip.test.ts @@ -6,11 +6,14 @@ import { UI5SemanticModel, BaseUI5Node, } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generate } from "@ui5-language-assistant/semantic-model"; import { generateModel, expectExists, - DEFAULT_UI5_VERSION, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { findUI5HoverNodeAtOffset } from "../../src/api"; @@ -22,7 +25,7 @@ describe("the UI5 language assistant Hover Tooltip Service", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-tooltip/test/unit/utils.ts b/packages/xml-views-tooltip/test/unit/utils.ts index ea6af434d..96cc96697 100644 --- a/packages/xml-views-tooltip/test/unit/utils.ts +++ b/packages/xml-views-tooltip/test/unit/utils.ts @@ -1,5 +1,6 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { Context } from "@ui5-language-assistant/context"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; export const getDefaultContext = (ui5Model: UI5SemanticModel): Context => { return { @@ -15,7 +16,7 @@ export const getDefaultContext = (ui5Model: UI5SemanticModel): Context => { }, services: {}, yamlDetails: { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: undefined, }, }; diff --git a/packages/xml-views-validation/package.json b/packages/xml-views-validation/package.json index 684a1e8b6..79d401309 100644 --- a/packages/xml-views-validation/package.json +++ b/packages/xml-views-validation/package.json @@ -21,6 +21,7 @@ "license": "Apache-2.0", "typings": "./api.d.ts", "dependencies": { + "@ui5-language-assistant/constant": "0.0.0", "@ui5-language-assistant/logic-utils": "4.0.18", "@ui5-language-assistant/semantic-model-types": "4.0.10", "@ui5-language-assistant/user-facing-text": "4.0.8", diff --git a/packages/xml-views-validation/test/unit/api.test.ts b/packages/xml-views-validation/test/unit/api.test.ts index 0593d9fa5..2fab00fbc 100644 --- a/packages/xml-views-validation/test/unit/api.test.ts +++ b/packages/xml-views-validation/test/unit/api.test.ts @@ -1,7 +1,10 @@ import { map, cloneDeep } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -20,7 +23,7 @@ describe("the ui5 xml views validations API", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/test-utils.ts b/packages/xml-views-validation/test/unit/test-utils.ts index 4bcaa95a7..128cd7d9b 100644 --- a/packages/xml-views-validation/test/unit/test-utils.ts +++ b/packages/xml-views-validation/test/unit/test-utils.ts @@ -7,6 +7,7 @@ import { UI5ValidatorsConfig } from "../../src/validate-xml-views"; import { UI5XMLViewIssue } from "../../api"; import { validateXMLView } from "../../src/api"; import { Context } from "@ui5-language-assistant/context"; +import { DEFAULT_UI5_FRAMEWORK } from "@ui5-language-assistant/constant"; const START_RANGE_MARKER = "🢂"; const END_RANGE_MARKER = "🢀"; @@ -139,7 +140,7 @@ export const getDefaultContext = (ui5Model: UI5SemanticModel): Context => { }, services: {}, yamlDetails: { - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: undefined, }, }; diff --git a/packages/xml-views-validation/test/unit/validators/attributes/invalid-boolean-value.test.ts b/packages/xml-views-validation/test/unit/validators/attributes/invalid-boolean-value.test.ts index 804102f18..db62eb935 100644 --- a/packages/xml-views-validation/test/unit/validators/attributes/invalid-boolean-value.test.ts +++ b/packages/xml-views-validation/test/unit/validators/attributes/invalid-boolean-value.test.ts @@ -1,6 +1,9 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -18,7 +21,7 @@ describe("the invalid boolean value validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/attributes/unknown-attribute-key.test.ts b/packages/xml-views-validation/test/unit/validators/attributes/unknown-attribute-key.test.ts index fd4a946c5..e31cd876b 100644 --- a/packages/xml-views-validation/test/unit/validators/attributes/unknown-attribute-key.test.ts +++ b/packages/xml-views-validation/test/unit/validators/attributes/unknown-attribute-key.test.ts @@ -2,10 +2,13 @@ import { find, partial } from "lodash"; import { DocumentCstNode, parse } from "@xml-tools/parser"; import { buildAst } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generateModel, expectExists, - DEFAULT_UI5_VERSION, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { generate } from "@ui5-language-assistant/semantic-model"; @@ -22,7 +25,7 @@ describe("the unknown attribute name validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/attributes/unknown-enum-value.test.ts b/packages/xml-views-validation/test/unit/validators/attributes/unknown-enum-value.test.ts index 39a6fc7ea..4c48aa551 100644 --- a/packages/xml-views-validation/test/unit/validators/attributes/unknown-enum-value.test.ts +++ b/packages/xml-views-validation/test/unit/validators/attributes/unknown-enum-value.test.ts @@ -1,6 +1,9 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -18,7 +21,7 @@ describe("the unknown enum value validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/attributes/unknown-xmlns-namespace.test.ts b/packages/xml-views-validation/test/unit/validators/attributes/unknown-xmlns-namespace.test.ts index 32f2f575e..bf9969ffd 100644 --- a/packages/xml-views-validation/test/unit/validators/attributes/unknown-xmlns-namespace.test.ts +++ b/packages/xml-views-validation/test/unit/validators/attributes/unknown-xmlns-namespace.test.ts @@ -1,6 +1,9 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -18,7 +21,7 @@ describe("the unknown namespace in xmlns attribute value validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/attributes/use-of-depracated-attribute.test.ts b/packages/xml-views-validation/test/unit/validators/attributes/use-of-depracated-attribute.test.ts index 4af49ec2e..4dbd318d9 100644 --- a/packages/xml-views-validation/test/unit/validators/attributes/use-of-depracated-attribute.test.ts +++ b/packages/xml-views-validation/test/unit/validators/attributes/use-of-depracated-attribute.test.ts @@ -2,10 +2,13 @@ import { partial, find } from "lodash"; import { parse, DocumentCstNode } from "@xml-tools/parser"; import { buildAst } from "@xml-tools/ast"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; +import { + DEFAULT_UI5_FRAMEWORK, + DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; import { generateModel, expectExists, - DEFAULT_UI5_VERSION, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; import { generate } from "@ui5-language-assistant/semantic-model"; @@ -26,7 +29,7 @@ describe("the use of deprecated attribute validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/document/non-unique-id.test.ts b/packages/xml-views-validation/test/unit/validators/document/non-unique-id.test.ts index 5062f8905..db2085771 100644 --- a/packages/xml-views-validation/test/unit/validators/document/non-unique-id.test.ts +++ b/packages/xml-views-validation/test/unit/validators/document/non-unique-id.test.ts @@ -1,6 +1,9 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -30,7 +33,7 @@ describe("the use of non unique id validation", () => { beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/element/cardinality-of-aggregation.test.ts b/packages/xml-views-validation/test/unit/validators/element/cardinality-of-aggregation.test.ts index aa579017d..356313ef7 100644 --- a/packages/xml-views-validation/test/unit/validators/element/cardinality-of-aggregation.test.ts +++ b/packages/xml-views-validation/test/unit/validators/element/cardinality-of-aggregation.test.ts @@ -1,7 +1,10 @@ import { partial } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -25,7 +28,7 @@ describe("the cardinality aggregation validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/element/non-stable-id.test.ts b/packages/xml-views-validation/test/unit/validators/element/non-stable-id.test.ts index 8612588b3..d91912d7a 100644 --- a/packages/xml-views-validation/test/unit/validators/element/non-stable-id.test.ts +++ b/packages/xml-views-validation/test/unit/validators/element/non-stable-id.test.ts @@ -1,7 +1,10 @@ import { partial } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -25,7 +28,7 @@ describe("the use of non stable id validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/element/type-of-aggregation.test.ts b/packages/xml-views-validation/test/unit/validators/element/type-of-aggregation.test.ts index 849d31793..9db494463 100644 --- a/packages/xml-views-validation/test/unit/validators/element/type-of-aggregation.test.ts +++ b/packages/xml-views-validation/test/unit/validators/element/type-of-aggregation.test.ts @@ -4,7 +4,10 @@ import { UI5Aggregation, } from "@ui5-language-assistant/semantic-model-types"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -28,7 +31,7 @@ describe("the type aggregation validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-aggregation.test.ts b/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-aggregation.test.ts index 463a1c581..db61bf3f1 100644 --- a/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-aggregation.test.ts +++ b/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-aggregation.test.ts @@ -1,8 +1,11 @@ import { partial, find } from "lodash"; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; -import { generate } from "@ui5-language-assistant/semantic-model"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generate } from "@ui5-language-assistant/semantic-model"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -23,7 +26,7 @@ describe("the use of deprecated aggregation validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-class.test.ts b/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-class.test.ts index 4d774a5b7..7d638834b 100644 --- a/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-class.test.ts +++ b/packages/xml-views-validation/test/unit/validators/element/use-of-deprecated-class.test.ts @@ -1,7 +1,10 @@ import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; -import { generate } from "@ui5-language-assistant/semantic-model"; import { + DEFAULT_UI5_FRAMEWORK, DEFAULT_UI5_VERSION, +} from "@ui5-language-assistant/constant"; +import { generate } from "@ui5-language-assistant/semantic-model"; +import { generateModel, getFallbackPatchVersions, } from "@ui5-language-assistant/test-utils"; @@ -18,7 +21,7 @@ describe("the use of deprecated class validation", () => { let appContext: AppContext; beforeAll(async () => { ui5SemanticModel = await generateModel({ - framework: "SAPUI5", + framework: DEFAULT_UI5_FRAMEWORK, version: ( await getFallbackPatchVersions() ).SAPUI5 as typeof DEFAULT_UI5_VERSION, diff --git a/test-packages/test-utils/api.d.ts b/test-packages/test-utils/api.d.ts index 68d16aa42..583bcc63c 100644 --- a/test-packages/test-utils/api.d.ts +++ b/test-packages/test-utils/api.d.ts @@ -20,6 +20,7 @@ import { import { XMLAttribute, XMLElement } from "@xml-tools/ast"; import { UI5XMLViewCompletion } from "@ui5-language-assistant/xml-views-completion"; import { FetchResponse } from "@ui5-language-assistant/language-server"; +import { DEFAULT_UI5_VERSION } from "@ui5-language-assistant/constant"; // easily build (partial) data structures for tests with mandatory "name" field export type PartialWithName = { name: string } & Partial; @@ -88,8 +89,6 @@ export function buildUI5Model>( opts: Partial ): UI5SemanticModel & Pick; -export const DEFAULT_UI5_VERSION = "1.71.69"; - // TODO: list should be updated continuously! export type TestModelVersion = | /* OOM */ typeof DEFAULT_UI5_VERSION diff --git a/test-packages/test-utils/package.json b/test-packages/test-utils/package.json index def767fdf..afe66916a 100644 --- a/test-packages/test-utils/package.json +++ b/test-packages/test-utils/package.json @@ -15,7 +15,9 @@ "dependencies": { "https-proxy-agent": "5.0.1", "node-fetch": "2.6.9", - "proxy-from-env": "1.1.0" + "proxy-from-env": "1.1.0", + "@ui5-language-assistant/constant": "0.0.0", + "@ui5-language-assistant/semantic-model-types": "4.0.10" }, "devDependencies": { "@types/node-fetch": "2.5.10" diff --git a/test-packages/test-utils/src/api.ts b/test-packages/test-utils/src/api.ts index 2471ffbb6..e83f9a3fd 100644 --- a/test-packages/test-utils/src/api.ts +++ b/test-packages/test-utils/src/api.ts @@ -30,5 +30,3 @@ export { expectProperty, } from "./utils/expect"; export { getFallbackPatchVersions } from "./utils/download-ui5-resources"; - -export const DEFAULT_UI5_VERSION = "1.71.69"; diff --git a/test-packages/test-utils/src/utils/download-ui5-resources.ts b/test-packages/test-utils/src/utils/download-ui5-resources.ts index 70d9d9686..4439bb471 100644 --- a/test-packages/test-utils/src/utils/download-ui5-resources.ts +++ b/test-packages/test-utils/src/utils/download-ui5-resources.ts @@ -1,11 +1,15 @@ import { zipObject, map, noop, get } from "lodash"; import { resolve } from "path"; import { writeFile, mkdirs, pathExists } from "fs-extra"; - -export const UI5_FRAMEWORK_CDN_BASE_URL = { - OpenUI5: "https://sdk.openui5.org/", - SAPUI5: "https://ui5.sap.com/", -}; +import { UI5Framework } from "@ui5-language-assistant/semantic-model-types"; +import { + UI5_FRAMEWORK_CDN_BASE_URL, + DEFAULT_OPEN_UI5_VERSION, + DEFAULT_UI5_VERSION, + DEFAULT_UI5_VERSION_BASE, + DEFAULT_UI5_FRAMEWORK, + OPEN_FRAMEWORK, +} from "@ui5-language-assistant/constant"; const importDynamic = (modulePath: string) => { try { @@ -124,19 +128,27 @@ type VersionMapJsonType = Record< { version: string; support: string; lts: boolean } >; -const FRAMEWORK = "SAPUI5"; -const OPEN_FRAMEWORK = "OpenUI5"; -const FALLBACK_VERSION_BASE = "1.71"; - async function getCurrentVersionMaps( - framework: typeof FRAMEWORK | typeof OPEN_FRAMEWORK -): Promise { + framework: UI5Framework +): Promise { const url = `${UI5_FRAMEWORK_CDN_BASE_URL[framework]}version.json`; const response = await fetch(url); if (response.ok) { return (await response.json()) as VersionMapJsonType; } else { - return undefined; + const DEFAULT_FALL_BACK = + framework === DEFAULT_UI5_FRAMEWORK + ? DEFAULT_UI5_VERSION + : DEFAULT_OPEN_UI5_VERSION; + const data = {}; + data[framework] = { + latest: { + version: DEFAULT_FALL_BACK, + support: "Maintenance", + lts: true, + }, + }; + return data; } } @@ -149,11 +161,11 @@ export async function getFallbackPatchVersions(): Promise<{ SAPUI5: undefined, }; - result.SAPUI5 = (await getCurrentVersionMaps(FRAMEWORK))?.[ - FALLBACK_VERSION_BASE + result.SAPUI5 = (await getCurrentVersionMaps(DEFAULT_UI5_FRAMEWORK))[ + DEFAULT_UI5_VERSION_BASE ]?.version; - result.OpenUI5 = (await getCurrentVersionMaps(OPEN_FRAMEWORK))?.[ - FALLBACK_VERSION_BASE + result.OpenUI5 = (await getCurrentVersionMaps(OPEN_FRAMEWORK))[ + DEFAULT_UI5_VERSION_BASE ]?.version; return result; } diff --git a/test-packages/test-utils/src/utils/semantic-model-provider.ts b/test-packages/test-utils/src/utils/semantic-model-provider.ts index d4fed1e5c..fa79cf9ed 100644 --- a/test-packages/test-utils/src/utils/semantic-model-provider.ts +++ b/test-packages/test-utils/src/utils/semantic-model-provider.ts @@ -14,7 +14,7 @@ const MODEL_CACHE: Record = Object.create(null); const fixes: Record = { - "1.71.69": { + "1.71.70": { array: "any[]", Array: "any[]", bloolean: undefined, @@ -258,7 +258,7 @@ type LibraryFix = (content: Json) => void; // Library version -> library name -> fix function const libraryFixes: Record> = { - "1.71.69": {}, + "1.71.70": {}, "1.84.41": {}, "1.96.27": { "sap.ui.mdc": [ diff --git a/tsconfig.json b/tsconfig.json index d50540f55..e70d22204 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,16 +1,13 @@ { "references": [ { - "path": "./test-packages/framework" - }, - { - "path": "./packages/logic-utils" + "path": "./packages/semantic-model-types" }, { - "path": "./packages/semantic-model" + "path": "./packages/constant" }, { - "path": "./packages/semantic-model-types" + "path": "./packages/binding-parser" }, { "path": "./packages/settings" @@ -19,31 +16,39 @@ "path": "./packages/user-facing-text" }, { - "path": "./packages/xml-views-completion" + "path": "./test-packages/framework" }, { - "path": "./packages/xml-views-quick-fix" + "path": "./test-packages/test-utils" }, { - "path": "./packages/xml-views-tooltip" + "path": "./packages/logger" }, + { - "path": "./packages/xml-views-validation" + "path": "./packages/semantic-model" }, + { - "path": "./packages/xml-views-definition" + "path": "./packages/logic-utils" }, { - "path": "./test-packages/test-utils" + "path": "./packages/context" }, { - "path": "./packages/context" + "path": "./packages/xml-views-validation" }, { - "path": "./packages/logger" + "path": "./packages/xml-views-completion" }, { - "path": "./packages/binding-parser" + "path": "./packages/xml-views-definition" + }, + { + "path": "./packages/xml-views-quick-fix" + }, + { + "path": "./packages/xml-views-tooltip" }, { "path": "./packages/binding"