Skip to content

Commit 7ee5914

Browse files
d3xter666Lonwyr
andauthored
feat(builder): Enhance generateFlexChangeBundle task to add new 'flexBundle' property to the manifest.json (#1165)
JIRA: CPOUI5FOUNDATION-1125 Co-authored-by: Christian Voshage <[email protected]>
1 parent a78a829 commit 7ee5914

File tree

31 files changed

+640
-221
lines changed

31 files changed

+640
-221
lines changed

packages/builder/lib/tasks/bundlers/generateFlexChangesBundle.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import semver from "semver";
1414
* at runtime.
1515
* If a change bundle is created, "sap.ui.fl" is added as a dependency to the manifest.json if not already present -
1616
* if the dependency is already listed but lazy-loaded, lazy loading is disabled.
17-
* If minUI5Version >= 1.73 flexibility-bundle.json will be create.
17+
* If minUI5Version >= 1.73 flexibility-bundle.json is created.
1818
* If there are control variants and minUI5Version < 1.73 build will break and throw an error.
1919
*
2020
* @public
@@ -38,29 +38,34 @@ export default async function({workspace, taskUtil, options = {}}) {
3838
pathPrefix = `/resources/${namespace}`;
3939
}
4040

41-
function updateJson(data) {
42-
// ensure the existence of the libs section in the dependencies
41+
function updateJson(data, bBundleCreated) {
4342
data["sap.ui5"] = data["sap.ui5"] || {};
44-
data["sap.ui5"].dependencies = data["sap.ui5"].dependencies || {};
45-
const mLibs = data["sap.ui5"].dependencies.libs = data["sap.ui5"].dependencies.libs || {};
46-
47-
if (mLibs["sap.ui.fl"]) {
48-
log.verbose("sap.ui.fl found in manifest.json");
49-
if (mLibs["sap.ui.fl"].lazy) {
50-
log.verbose("sap.ui.fl 'lazy' attribute found in manifest.json, setting it to false...");
51-
mLibs["sap.ui.fl"].lazy = false;
43+
// explicit set the flag to inform the runtime if a bundle is present before the preload can be interpreted
44+
data["sap.ui5"].flexBundle = bBundleCreated;
45+
46+
if (bBundleCreated) {
47+
// ensure the existence of the libs section in the dependencies
48+
data["sap.ui5"].dependencies = data["sap.ui5"].dependencies || {};
49+
const mLibs = data["sap.ui5"].dependencies.libs = data["sap.ui5"].dependencies.libs || {};
50+
51+
if (mLibs["sap.ui.fl"]) {
52+
log.verbose("sap.ui.fl found in manifest.json");
53+
if (mLibs["sap.ui.fl"].lazy) {
54+
log.verbose("sap.ui.fl 'lazy' attribute found in manifest.json, setting it to false...");
55+
mLibs["sap.ui.fl"].lazy = false;
56+
}
57+
} else {
58+
log.verbose("sap.ui.fl not found in manifest.json, inserting it...");
59+
mLibs["sap.ui.fl"] = {};
5260
}
53-
} else {
54-
log.verbose("sap.ui.fl not found in manifest.json, inserting it...");
55-
mLibs["sap.ui.fl"] = {};
5661
}
5762
}
5863

59-
async function updateFLdependency() {
64+
async function updateManifestWithFlDependencyAndFlexBundleFlag(bBundleCreated) {
6065
const manifestResource = await workspace.byPath(`${pathPrefix}/manifest.json`);
6166
const manifestContent = JSON.parse(await manifestResource.getString());
6267

63-
updateJson(manifestContent);
68+
updateJson(manifestContent, bBundleCreated);
6469
manifestResource.setString(JSON.stringify(manifestContent, null, "\t"));
6570

6671
await workspace.write(manifestResource);
@@ -83,6 +88,9 @@ export default async function({workspace, taskUtil, options = {}}) {
8388
log.verbose("Collecting flexibility changes");
8489
const allResources = await workspace.byGlob(
8590
`${pathPrefix}/changes/*.{change,variant,ctrl_variant,ctrl_variant_change,ctrl_variant_management_change}`);
91+
92+
let bBundleCreated = false;
93+
8694
if (allResources.length > 0) {
8795
const versionArray = await readManifestMinUI5Version();
8896
const versions = versionArray.map((version) => semver.coerce(version));
@@ -109,9 +117,7 @@ export default async function({workspace, taskUtil, options = {}}) {
109117
return workspace.write(resource);
110118
}));
111119
// Add the sap.ui.fl dependency if a bundle has been created
112-
if (processedResources.length > 0) {
113-
await updateFLdependency();
114-
}
120+
bBundleCreated = processedResources.length > 0;
115121

116122
// Do not write bundled source files to build result
117123
if (taskUtil) {
@@ -120,4 +126,7 @@ export default async function({workspace, taskUtil, options = {}}) {
120126
});
121127
}
122128
}
129+
130+
// Always append the flexBundle flag to the manifest.json, even if no bundle was created
131+
await updateManifestWithFlDependencyAndFlexBundleFlag(bBundleCreated);
123132
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "id1",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.2.2"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"sap.ui5": {
16+
"flexBundle": false
17+
}
1318
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "id1",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.2.2"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"sap.ui5": {
16+
"flexBundle": false
17+
}
1318
}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "id1",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.2.2"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"sap.ui5": {
16+
"flexBundle": false
17+
}
1318
}

packages/builder/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "id1",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.2.2"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"sap.ui5": {
16+
"flexBundle": false
17+
}
1318
}

packages/builder/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "id1",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.2.2"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "id1",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.2.2"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"sap.ui5": {
16+
"flexBundle": false
17+
}
1318
}

packages/builder/test/expected/build/application.g/cachebuster/Component-preload.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{
2-
"_version": "1.1.0",
3-
"sap.app": {
4-
"_version": "1.1.0",
5-
"id": "application.g",
6-
"type": "application",
7-
"applicationVersion": {
8-
"version": "1.0.0"
9-
},
10-
"embeds": ["embedded"],
11-
"title": "{{title}}"
12-
},
13-
"customCopyrightString": "Some fancy copyright"
14-
}
2+
"_version": "1.1.0",
3+
"sap.app": {
4+
"_version": "1.1.0",
5+
"id": "application.g",
6+
"type": "application",
7+
"applicationVersion": {
8+
"version": "1.0.0"
9+
},
10+
"embeds": [
11+
"embedded"
12+
],
13+
"title": "{{title}}"
14+
},
15+
"customCopyrightString": "Some fancy copyright",
16+
"sap.ui5": {
17+
"flexBundle": false
18+
}
19+
}

0 commit comments

Comments
 (0)