@ui5/task-adaptation 1.5.2 → 1.5.4

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.
Files changed (35) hide show
  1. package/.hyperspace/pull_request_bot.json +19 -0
  2. package/CHANGELOG.md +9 -1
  3. package/dist/baseAppManager.js +3 -3
  4. package/dist/buildStrategy.d.ts +0 -3
  5. package/dist/buildStrategy.js +0 -7
  6. package/dist/bundle.d.ts +4 -3
  7. package/dist/bundle.js +3650 -3595
  8. package/dist/cache/cacheHolder.d.ts +1 -1
  9. package/dist/cache/cacheHolder.js +8 -6
  10. package/dist/model/authenticationError.d.ts +3 -0
  11. package/dist/model/authenticationError.js +8 -0
  12. package/dist/util/cfUtil.d.ts +8 -1
  13. package/dist/util/cfUtil.js +16 -8
  14. package/dist/util/filesUtil.d.ts +3 -2
  15. package/dist/util/filesUtil.js +20 -4
  16. package/dist/util/renamingHandlers/jsonRenamingHandler.d.ts +12 -0
  17. package/dist/util/renamingHandlers/jsonRenamingHandler.js +34 -0
  18. package/dist/util/renamingHandlers/manifestRenamingHandler.d.ts +4 -5
  19. package/dist/util/renamingHandlers/manifestRenamingHandler.js +7 -18
  20. package/dist/util/resourceUtil.d.ts +11 -3
  21. package/dist/util/resourceUtil.js +83 -18
  22. package/eslint.config.js +4 -3
  23. package/package.json +19 -20
  24. package/rollup/amdToEsm.ts +22 -0
  25. package/rollup/bundle.d.ts +25 -0
  26. package/rollup/bundleDefinition.js +19 -0
  27. package/rollup/bundler.ts +35 -0
  28. package/rollup/overrides/sap/base/config.js +59 -0
  29. package/rollup/overrides/sap/ui/fl/apply/_internal/flexObjects/AppDescriptorChange.js +68 -0
  30. package/rollup/overrides/sap/ui/performance/Measurement.js +4 -0
  31. package/rollup/project/package.json +4 -0
  32. package/rollup/project/ui5.yaml +13 -0
  33. package/rollup/project/webapp/manifest.json +5 -0
  34. package/rollup/rollup.ts +133 -0
  35. package/rollup/ui5Resolve.ts +145 -0
@@ -0,0 +1,35 @@
1
+ import * as rollup from "rollup";
2
+ import * as builtins from "builtin-modules";
3
+ import ui5 from "./ui5Resolve.js";
4
+ import { nodeResolve } from "@rollup/plugin-node-resolve";
5
+
6
+
7
+ export default abstract class Bundler {
8
+
9
+ static async run(resources: Map<string, any>, input: string, output: string, skipTransformation: string[] = []): Promise<void> {
10
+ if (!skipTransformation.includes(input)) {
11
+ skipTransformation.push(input);
12
+ }
13
+ const inputOptions = <rollup.RollupOptions>{
14
+ input,
15
+ plugins: [
16
+ ui5({
17
+ resources,
18
+ skipTransformation,
19
+ output
20
+ }),
21
+ nodeResolve({
22
+ preferBuiltins: true
23
+ })
24
+ ],
25
+ external: builtins
26
+ };
27
+ const bundle = await rollup.rollup(inputOptions);
28
+ const outputOptions = <rollup.RollupOptions>{
29
+ file: output,
30
+ format: "esm"
31
+ };
32
+ await bundle.write(outputOptions);
33
+ await bundle.close();
34
+ }
35
+ }
@@ -0,0 +1,59 @@
1
+ /*!
2
+ * ${copyright}
3
+ */
4
+ sap.ui.define([
5
+ ], (
6
+ ) => {
7
+ "use strict";
8
+
9
+ /**
10
+ * The base Configuration.
11
+ *
12
+ * @author SAP SE
13
+ * @version ${version}
14
+ * @private
15
+ * @ui5-restricted sap.ui.core, sap.fl, sap.ui.intergration, sap.ui.export
16
+ * @alias module:sap/base/config
17
+ * @borrows module:sap/base/config/_Configuration.get as get
18
+ * @borrows module:sap/base/config/_Configuration.Type as Type
19
+ * @namespace
20
+ */
21
+
22
+ const _Configuration = { _: {} };
23
+
24
+ const internalConfig = new Map();
25
+
26
+ /**
27
+ * Returns a writable base configuration instance
28
+ * @returns {module:sap/base/config} The writable base configuration
29
+ * @private
30
+ * @ui5-restricted sap.ui.core, sap.fl
31
+ */
32
+ _Configuration.getWritableInstance = () => {
33
+ return {
34
+ get(obj) {
35
+ internalConfig.get(obj.name);
36
+ },
37
+ set(name, obj) {
38
+ internalConfig.set(name, obj);
39
+ }
40
+ }
41
+ };
42
+
43
+ /**
44
+ * Attaches the <code>fnFunction</code> event handler to the {@link #event:invalidated invalidated} event
45
+ *
46
+ * @param {function} fnFunction The function to be called when the event occurs
47
+ * @private
48
+ */
49
+ function attachInvalidated() {
50
+ }
51
+ _Configuration._.attachInvalidated = attachInvalidated;
52
+
53
+ const origInvalidate = _Configuration._.invalidate;
54
+ _Configuration._.invalidate = () => {
55
+ origInvalidate();
56
+ };
57
+
58
+ return _Configuration;
59
+ });
@@ -0,0 +1,68 @@
1
+ /*!
2
+ * OpenUI5
3
+ * (c) Copyright 2009-2020 SAP SE or an SAP affiliate company.
4
+ * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5
+ */
6
+
7
+ sap.ui.define([
8
+ ], function (
9
+ ) {
10
+ "use strict";
11
+
12
+ /**
13
+ * Flexibility change class. Stores change content and related information.
14
+ *
15
+ * @param {object} oFile - File content and admin data
16
+ *
17
+ * @class sap.ui.fl.Change
18
+ * @private
19
+ * @ui5-restricted
20
+ * @experimental Since 1.25.0
21
+ */
22
+ var AppDescriptorChange = function (content) {
23
+ this.content = content;
24
+ };
25
+
26
+ /**
27
+ * Returns the change type.
28
+ *
29
+ * @returns {String} Change type of the file, for example <code>LabelChange</code>
30
+ * @public
31
+ */
32
+ AppDescriptorChange.prototype.getChangeType = function () {
33
+ return this.content?.flexObjectMetadata?.changeType || this.content?.changeType;
34
+ };
35
+
36
+ /**
37
+ * Gets the layer type for the change.
38
+ * @returns {string} Layer of the change file
39
+ *
40
+ * @public
41
+ */
42
+ AppDescriptorChange.prototype.getLayer = function () {
43
+ return this.content.layer;
44
+ };
45
+
46
+ /**
47
+ * Returns the content section of the change.
48
+ * @returns {string} Content of the change file. The content structure can be any JSON.
49
+ *
50
+ * @public
51
+ */
52
+ AppDescriptorChange.prototype.getContent = function () {
53
+ return this.content.content;
54
+ };
55
+
56
+ /**
57
+ * Returns all texts.
58
+ *
59
+ * @returns {object} All texts
60
+ *
61
+ * @function
62
+ */
63
+ AppDescriptorChange.prototype.getTexts = function () {
64
+ return this.content.texts;
65
+ };
66
+
67
+ return AppDescriptorChange;
68
+ }, true);
@@ -0,0 +1,4 @@
1
+ export default class PerfMeasurement {
2
+ static average() {}
3
+ static end() {}
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "rollup",
3
+ "version": "1.0.0"
4
+ }
@@ -0,0 +1,13 @@
1
+ ---
2
+ specVersion: "2.2"
3
+ type: application
4
+ metadata:
5
+ name: rollup
6
+ allowSapInternal: true
7
+ framework:
8
+ name: SAPUI5
9
+ version: 0.0.0
10
+ libraries:
11
+ - name: sap.ui.fl
12
+ - name: sap.suite.ui.generic.template
13
+ - name: sap.fe.core
@@ -0,0 +1,5 @@
1
+ {
2
+ "sap.app": {
3
+ "id": "rollup"
4
+ }
5
+ }
@@ -0,0 +1,133 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import * as semver from "semver";
4
+ import * as yaml from "js-yaml";
5
+ import Bundler from "./bundler.js";
6
+ import { dirname } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ import * as resourceFactory from "@ui5/fs/resourceFactory";
10
+ import { graphFromPackageDependencies } from "@ui5/project/graph";
11
+ import { getLogger } from "@ui5/logger";
12
+
13
+ const log = getLogger("rollup-plugin-ui5-resolve-task-adaptation");
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+
16
+ const projectPaths = [
17
+ path.resolve(__dirname, "project")
18
+ ];
19
+ const LATEST_VERSION_PLACEHOLDER = "0.0.0";
20
+
21
+ export default class Builder {
22
+
23
+ static async getProjectInfo(projectPaths: string[]) {
24
+ for (const cwd of projectPaths) {
25
+ try {
26
+ const options = <any>{
27
+ cwd
28
+ };
29
+ const version = this.validateProjectSettings(cwd);
30
+ if (version === LATEST_VERSION_PLACEHOLDER) {
31
+ options.versionOverride = "latest";
32
+ }
33
+ return await graphFromPackageDependencies(options);
34
+ } catch (error: any) {
35
+ log.info(`${error.message}`);
36
+ }
37
+ }
38
+ }
39
+
40
+ static validateProjectSettings(projectPath: string): string {
41
+ const FRAMEWORK_TYPES = ["OpenUI5", "SAPUI5"];
42
+ const content = fs.readFileSync(path.join(projectPath, "ui5.yaml"), { encoding: "utf-8" });
43
+ const yamlJson = <any>yaml.load(content);
44
+ const framework = yamlJson["framework"];
45
+ if (!FRAMEWORK_TYPES.includes(framework.name)) {
46
+ throw new Error(`UI5 framework name is incorrect, possible values: ${FRAMEWORK_TYPES.join(" or ")}`);
47
+ }
48
+ if (!semver.valid(framework.version)) {
49
+ throw new Error(`UI5 framework version should correspond semantic version standard, e.g: 1.85.2`);
50
+ }
51
+ return framework.version;
52
+ }
53
+
54
+ static getBundledUI5Version(destination: string) {
55
+ const bundleFilePath = path.join(process.cwd(), destination);
56
+ if (fs.existsSync(bundleFilePath)) {
57
+ const bundle = fs.readFileSync(bundleFilePath, { encoding: "utf-8" });
58
+ const version = bundle.substring(2, bundle.indexOf("\n"));
59
+ return semver.coerce(version);
60
+ }
61
+ }
62
+
63
+ static async getResources(namespaces: Map<string, string[]>, projectGraph: any): Promise<Map<string, any>> {
64
+ const fsBasePaths = new Set<string>();
65
+ const adapters = new Map<string, any>();
66
+ for (const project of [...projectGraph.getProjects("rollup")]) {
67
+ const fsBasePath = project.getSourcePath();
68
+ if (!fsBasePaths.has(fsBasePath)) {
69
+ adapters.set(project.getNamespace(), resourceFactory.createReader({
70
+ fsBasePath,
71
+ virBasePath: "/resources/"
72
+ }));
73
+ fsBasePaths.add(fsBasePath);
74
+ }
75
+ }
76
+
77
+ const resources = new Map<string, any>();
78
+ for (const [namespace, adapter] of adapters.entries()) {
79
+ const patterns = namespaces.get(namespace);
80
+ if (patterns) {
81
+ for (const pattern of patterns) {
82
+ const result = await adapter.byGlob(pattern) as any[];
83
+ result.forEach(resource => resources.set(resource.getPath(), resource));
84
+ }
85
+ }
86
+ }
87
+
88
+ return resources;
89
+ }
90
+
91
+ static copyTypeDefinition() {
92
+ fs.copyFileSync(path.join(__dirname, "bundle.d.ts"), path.join(process.cwd(), "dist", "bundle.d.ts"))
93
+ }
94
+
95
+ static async run(): Promise<void> {
96
+ const project = await this.getProjectInfo(projectPaths);
97
+ if (!project) {
98
+ throw new Error("ui5.yaml is not found or incorrect");
99
+ }
100
+ const namespaces = new Map([
101
+ ["sap/fe/core", [
102
+ "/resources/sap/fe/core/**"
103
+ ]],
104
+ ["sap/ui/fl", [
105
+ "/resources/sap/ui/fl/**"
106
+ ]],
107
+ ["sap/ui/core", [
108
+ "/resources/ui5loader-autoconfig.js",
109
+ "/resources/sap/base/**",
110
+ "/resources/sap/ui/{base,thirdparty,model,util}/**"
111
+ ]],
112
+ ["sap/suite/ui/generic/template", [
113
+ "/resources/sap/suite/ui/generic/template/**"
114
+ ]]
115
+ ]);
116
+ const resources = await this.getResources(namespaces, project);
117
+ await Bundler.run(
118
+ resources,
119
+ "bundleDefinition.js",
120
+ "./dist/bundle.js",
121
+ [
122
+ "sap/ui/performance/Measurement"
123
+ ]
124
+ );
125
+ this.copyTypeDefinition();
126
+ }
127
+ }
128
+
129
+ if (process.argv.length === 2) {
130
+ const start = Date.now();
131
+ await Builder.run();
132
+ log.info(`Bundled in ${Date.now() - start} ms`);
133
+ }
@@ -0,0 +1,145 @@
1
+ import * as crypto from "crypto";
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+
5
+ //@ts-ignore
6
+ import convertAMDtoES6 from "@buxlabs/amd-to-es6";
7
+ import convertAMDtoESM from "./amdToEsm.js";
8
+ import { dirname } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+ import { getLogger } from "@ui5/logger";
11
+
12
+ const log = getLogger("rollup-plugin-ui5-resolve-task-adaptation");
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+
15
+
16
+ interface TransformCase {
17
+ accept(code: string, id: string): string;
18
+ }
19
+
20
+ class UriTransformCase implements TransformCase {
21
+ accept(code: string, id: string) {
22
+ if (id !== "sap/ui/thirdparty/URI") {
23
+ return code;
24
+ }
25
+ const header = code.substring(0, code.indexOf("(function"));
26
+ const neededCode = code.substring(code.indexOf("root) {") + 8, code.lastIndexOf("}));"))
27
+ .replace(/root/g, "window");
28
+ return header + "define('sap/ui/thirdparty/URI', [], function () {" + neededCode + "});";
29
+ }
30
+ }
31
+
32
+
33
+ export default function (options: any) {
34
+
35
+ const skipTransformation = (id: string) => !options.skipTransformation?.includes(id);
36
+
37
+ return {
38
+
39
+ name: "ui5-resolve",
40
+
41
+ /*
42
+ * Right before writing result to dist
43
+ */
44
+ renderChunk: (code: string) => {
45
+ return `var window = {};\n${code}`;
46
+ },
47
+
48
+
49
+ resolveId: (source: string, importer: string) => {
50
+ log.verbose(`resolveId: ${source} from ${importer}`);
51
+ if (importer && source.startsWith(".")) {
52
+ source = path.posix.join(path.dirname(importer), source);
53
+ }
54
+ log.verbose(" --> resolve to: " + source);
55
+ return source;
56
+ },
57
+
58
+
59
+ load: async (id: string) => {
60
+ log.verbose(`load: ${id}`);
61
+
62
+ const localFile = path.join(__dirname, id);
63
+ if (fs.existsSync(localFile)) {
64
+ log.info(`Bundle definition "${id}"`);
65
+ return fs.readFileSync(localFile, {
66
+ encoding: "utf8"
67
+ });
68
+ }
69
+
70
+ const localOverride = path.resolve(__dirname, "overrides", id + ".js");
71
+ if (fs.existsSync(localOverride)) {
72
+ log.info(`Override with "${id}"`);
73
+ return fs.readFileSync(localOverride, { encoding: "utf8" });
74
+ }
75
+ const filepath = `/resources/${id}.js`;
76
+ if (options.resources.has(filepath)) {
77
+ return await options.resources.get(filepath).getString();
78
+ }
79
+ },
80
+
81
+
82
+ transform: (code: string, id: string): string | undefined => {
83
+ const skipped = !skipTransformation(id);
84
+ log.verbose(`transform: ${id} ${skipped ? "skipped" : ""}`);
85
+ if (skipped) {
86
+ return;
87
+ }
88
+
89
+ code = replaceRequireAsync(code);
90
+ code = transform(code, id);
91
+
92
+ code = code
93
+ .replace(/sap\.ui\.define/g, "define")
94
+ .replace(/\, \/\* bExport\= \*\/ true\)/g, ")")
95
+ .replace(/},.*(true|false)\);$/g, "});")
96
+ .replace(/},.*(true|false)\);(\n\/\/# sourceMappingURL=)*/g, "});\n//# sourceMappingURL=");
97
+ try {
98
+ return convertAMDtoES6(code);
99
+ } catch (_: any) {
100
+ return convertAMDtoESM(code);
101
+ }
102
+ }
103
+
104
+ };
105
+ };
106
+
107
+
108
+ function transform(code: string, id: string) {
109
+ const transformers = [
110
+ new UriTransformCase()
111
+ ];
112
+ for (const transformer of transformers) {
113
+ code = transformer.accept(code, id);
114
+ }
115
+ return code;
116
+ }
117
+
118
+
119
+ function replaceRequireAsync(code: string) {
120
+ const requireAsyncPattern = /requireAsync((.bind\(this, ")|(\("))+(?<url>[\/\w]*)"\)/mg;
121
+ let match, defineUrls = new Array<string>(), defineVars = new Array<string>(), matches = new Map();
122
+ // eslint-disable-next-line no-cond-assign
123
+ while (match = requireAsyncPattern.exec(code)) {
124
+ if (match.groups?.url) {
125
+ const varaibleName = match.groups.url.split("/").pop() + crypto.randomBytes(16).toString("hex");
126
+ defineUrls.push(`"${match.groups.url}"`);
127
+ defineVars.push(varaibleName);
128
+ const value = match[0].includes("requireAsync.bind")
129
+ ? `() => Promise.resolve(${varaibleName})`
130
+ : varaibleName;
131
+ matches.set(match[0], value);
132
+ }
133
+ }
134
+ if (defineUrls.length > 0 && defineVars.length > 0) {
135
+ matches.forEach((value, key) => code = code.replace(key, value));
136
+ code = replaceRequireAsyncWith(code, `"sap/ui/fl/requireAsync"`, defineUrls);
137
+ code = replaceRequireAsyncWith(code, "requireAsync", defineVars);
138
+ }
139
+ return code;
140
+ }
141
+
142
+
143
+ function replaceRequireAsyncWith(code: string, requireAsyncSearchKeyword: string, inserts: string[]) {
144
+ return code.replace(requireAsyncSearchKeyword, inserts.join(",\n\t"));
145
+ }