@sap-ux/ui5-application-writer 0.17.1 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,7 @@ export declare const enum UI5_DEFAULT {
27
27
  OPENUI5_CDN = "https://openui5.hana.ondemand.com",
28
28
  TYPES_VERSION_SINCE = "1.76.0",
29
29
  TYPES_VERSION_PREVIOUS = "1.71.18",
30
+ TYPES_VERSION_BEST = "1.102.7",
30
31
  MANIFEST_VERSION = "1.12.0",
31
32
  BASE_COMPONENT = "sap/ui/core/UIComponent"
32
33
  }
@@ -46,6 +47,14 @@ export declare const defaultUI5Libs: string[];
46
47
  * @returns {UI5} the updated copy of UI5 instance (does not change `ui5`)
47
48
  */
48
49
  export declare function mergeUi5(ui5: Partial<UI5>): UI5;
50
+ /**
51
+ * Get the best types version for the given minUI5Version.
52
+ * For the latest versions the LTS S/4 on-premise version (1.102.x) is used, for anything before we match the versions as far back as available.
53
+ *
54
+ * @param minUI5Version the mininum UI5 version that needs to be supported
55
+ * @returns semantic version representing the types version.
56
+ */
57
+ export declare function getTypesVersion(minUI5Version?: string): string;
49
58
  /**
50
59
  * Retrieve the tag version of the @sap/ux-specification based on the given version.
51
60
  *
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getSpecTagVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.mergeApp = exports.mergePackages = exports.packageDefaults = void 0;
6
+ exports.getSpecTagVersion = exports.getTypesVersion = exports.mergeUi5 = exports.defaultUI5Libs = exports.mergeApp = exports.mergePackages = exports.packageDefaults = void 0;
7
7
  const version_to_descriptor_mapping_json_1 = __importDefault(require("./version-to-descriptor-mapping.json")); // from https://github.com/SAP/ui5-manifest/blob/master/mapping.json
8
8
  const ui5Libs_1 = require("./ui5Libs");
9
9
  const semver_1 = __importDefault(require("semver"));
@@ -101,18 +101,37 @@ function mergeUi5(ui5) {
101
101
  framework,
102
102
  frameworkUrl: (_c = ui5.frameworkUrl) !== null && _c !== void 0 ? _c : defaultFrameworkUrl
103
103
  };
104
- // typesVersion must be a valid npm semantic version, we know they cannot be null as already validated
105
- const localSemVer = semver_1.default.valid(semver_1.default.coerce(merged.localVersion));
106
- const typesVersion = semver_1.default.gte(localSemVer, "1.76.0" /* TYPES_VERSION_SINCE */)
107
- ? localSemVer
108
- : "1.71.18" /* TYPES_VERSION_PREVIOUS */;
109
104
  merged.descriptorVersion = getManifestVersion(merged.minUI5Version, ui5.descriptorVersion);
110
- merged.typesVersion = (_d = ui5.typesVersion) !== null && _d !== void 0 ? _d : typesVersion;
105
+ merged.typesVersion = (_d = ui5.typesVersion) !== null && _d !== void 0 ? _d : getTypesVersion(merged.minUI5Version);
111
106
  merged.ui5Theme = (_e = ui5.ui5Theme) !== null && _e !== void 0 ? _e : 'sap_fiori_3';
112
107
  merged.ui5Libs = ui5Libs_1.getUI5Libs(ui5.ui5Libs);
113
108
  return Object.assign({}, ui5, merged);
114
109
  }
115
110
  exports.mergeUi5 = mergeUi5;
111
+ /**
112
+ * Get the best types version for the given minUI5Version.
113
+ * For the latest versions the LTS S/4 on-premise version (1.102.x) is used, for anything before we match the versions as far back as available.
114
+ *
115
+ * @param minUI5Version the mininum UI5 version that needs to be supported
116
+ * @returns semantic version representing the types version.
117
+ */
118
+ function getTypesVersion(minUI5Version) {
119
+ const version = semver_1.default.coerce(minUI5Version);
120
+ if (!version) {
121
+ return `~${"1.102.7" /* TYPES_VERSION_BEST */}`;
122
+ }
123
+ else {
124
+ if (semver_1.default.gte(version, "1.102.7" /* TYPES_VERSION_BEST */)) {
125
+ return `~${"1.102.7" /* TYPES_VERSION_BEST */}`;
126
+ }
127
+ else {
128
+ return semver_1.default.gte(version, "1.76.0" /* TYPES_VERSION_SINCE */)
129
+ ? `~${semver_1.default.major(version)}.${semver_1.default.minor(version)}.${semver_1.default.patch(version)}`
130
+ : "1.71.18" /* TYPES_VERSION_PREVIOUS */;
131
+ }
132
+ }
133
+ }
134
+ exports.getTypesVersion = getTypesVersion;
116
135
  /**
117
136
  * Gets the miminum UI5 version based on the specified version.
118
137
  *
@@ -8,12 +8,13 @@ const defaults_1 = require("./defaults");
8
8
  * @param ui5Libs - The ui5 libraries to be merged with the defaults
9
9
  * @returns UI5 libs with defaults
10
10
  */
11
- exports.getUI5Libs = (ui5Libs) => {
11
+ const getUI5Libs = (ui5Libs) => {
12
12
  const libs = Array.isArray(ui5Libs) ? ui5Libs : (ui5Libs === null || ui5Libs === void 0 ? void 0 : ui5Libs.split(',')) || [];
13
13
  return defaults_1.defaultUI5Libs.concat(libs).filter((value, index, self) => {
14
14
  return self.indexOf(value) === index;
15
15
  });
16
16
  };
17
+ exports.getUI5Libs = getUI5Libs;
17
18
  /**
18
19
  * UI5 task and middleware configurations required for TypeScript projects
19
20
  */
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ const ui5_config_1 = require("@sap-ux/ui5-config");
17
17
  const data_1 = require("./data");
18
18
  const ui5Libs_1 = require("./data/ui5Libs");
19
19
  const options_1 = require("./options");
20
+ const defaults_1 = require("./data/defaults");
20
21
  /**
21
22
  * Writes the template to the memfs editor instance.
22
23
  *
@@ -93,6 +94,7 @@ exports.isTypescriptEnabled = isTypescriptEnabled;
93
94
  * @returns the updated memfs editor instance
94
95
  */
95
96
  function enableTypescript(basePath, fs) {
97
+ var _a, _b;
96
98
  return __awaiter(this, void 0, void 0, function* () {
97
99
  if (!fs) {
98
100
  fs = mem_fs_editor_1.create(mem_fs_1.create());
@@ -108,7 +110,13 @@ function enableTypescript(basePath, fs) {
108
110
  const manifest = fs.readJSON(manifestPath);
109
111
  const ui5Config = yield ui5_config_1.UI5Config.newInstance(fs.read(ui5ConfigPath));
110
112
  const tmplPath = path_1.join(__dirname, '..', 'templates');
111
- options_1.enableTypescript({ basePath, fs, ui5Configs: [ui5Config], tmplPath, ui5App: { app: manifest['sap.app'] } }, true);
113
+ const ui5App = {
114
+ app: manifest['sap.app'],
115
+ ui5: {
116
+ typesVersion: defaults_1.getTypesVersion((_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.minUI5Version)
117
+ }
118
+ };
119
+ options_1.enableTypescript({ basePath, fs, ui5Configs: [ui5Config], tmplPath, ui5App }, true);
112
120
  fs.write(ui5ConfigPath, ui5Config.toString());
113
121
  return fs;
114
122
  });
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "bugs": {
10
10
  "url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aui5-application-writer"
11
11
  },
12
- "version": "0.17.1",
12
+ "version": "0.17.2",
13
13
  "license": "Apache-2.0",
14
14
  "main": "dist/index.js",
15
15
  "files": [
@@ -2,6 +2,6 @@
2
2
  "devDependencies": {
3
3
  "eslint": "7.32.0",
4
4
  "@sap/eslint-plugin-ui5-jsdocs": "2.0.5",
5
- "@sapui5/ts-types": "1.102.x"
5
+ "@sapui5/ts-types": "<%- ui5.typesVersion %>"
6
6
  }
7
7
  }
@@ -3,7 +3,7 @@
3
3
  "ts-typecheck": "tsc --noEmit"
4
4
  },
5
5
  "devDependencies": {
6
- "@sapui5/ts-types-esm": "1.102.x",
6
+ "@sapui5/ts-types-esm": "<%- ui5.typesVersion %>",
7
7
  "ui5-tooling-transpile": "^0.2.0",
8
8
  "typescript": "^4.6.3",
9
9
  "@typescript-eslint/eslint-plugin": "^5.17.0",