Skip to content

Commit

Permalink
fix: introduce constant package to handle UI5 default version (#721)
Browse files Browse the repository at this point in the history
* fix: introduce constant package to handle UI5 default version in central package

* fix: http lik for reference

* fix: reuse constant

* fix: typo

* fix: use constant for object initialization
  • Loading branch information
marufrasully authored Aug 12, 2024
1 parent d09ce00 commit b2a8d01
Show file tree
Hide file tree
Showing 86 changed files with 727 additions and 312 deletions.
16 changes: 16 additions & 0 deletions .changeset/tender-rivers-matter.md
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions packages/constant/README.md
Original file line number Diff line number Diff line change
@@ -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).
15 changes: 15 additions & 0 deletions packages/constant/jest.config.js
Original file line number Diff line number Diff line change
@@ -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$/,
},
},
},
};
27 changes: 27 additions & 0 deletions packages/constant/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions packages/constant/src/api.ts
Original file line number Diff line number Diff line change
@@ -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";
14 changes: 14 additions & 0 deletions packages/constant/src/constant.ts
Original file line number Diff line number Diff line change
@@ -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/",
};
9 changes: 9 additions & 0 deletions packages/constant/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "lib",
"baseUrl": "."
},
"include": ["src/**/*", "api.d.ts"]
}
1 change: 1 addition & 0 deletions packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/context/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export {
getUI5Yaml,
findYamlPath,
} from "./ui5-yaml";
export { getCDNBaseUrl } from "./utils";
export { cache } from "./cache";
export {
reactOnCdsFileChange,
Expand Down
8 changes: 1 addition & 7 deletions packages/context/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions packages/context/src/ui5-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
3 changes: 2 additions & 1 deletion packages/context/src/ui5-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions packages/context/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export {
getLibraryAPIJsonUrl,
getVersionInfoUrl,
getVersionJsonUrl,
getCDNBaseUrl,
} from "./ui5";

export {
findAppRoot,
getLocalAnnotationsForService,
Expand Down
57 changes: 0 additions & 57 deletions packages/context/src/utils/ui5.ts

This file was deleted.

5 changes: 3 additions & 2 deletions packages/context/test/unit/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -39,7 +40,7 @@ describe("context", () => {
const getYamlDetailsStub = jest
.spyOn(ui5Yaml, "getYamlDetails")
.mockResolvedValue({
framework: "OpenUI5",
framework: OPEN_FRAMEWORK,
version: undefined,
});
const getSemanticModelStub = jest
Expand Down Expand Up @@ -80,7 +81,7 @@ describe("context", () => {
const getYamlDetailsStub = jest
.spyOn(ui5Yaml, "getYamlDetails")
.mockResolvedValue({
framework: "OpenUI5",
framework: OPEN_FRAMEWORK,
version: undefined,
});
const getSemanticModelStub = jest
Expand Down
Loading

0 comments on commit b2a8d01

Please sign in to comment.