Skip to content

Commit

Permalink
[FIX] Add 'sap.ui.fl' dependency to manifest.json (#318)
Browse files Browse the repository at this point in the history
If changes are present during runtime, the 'sap.ui.fl' dependency should be added to the manifest.json so the changes contained in the changes bundled can be applied to the application

An already declared lazy dependency will be converted to an eager (non-lazy) dependency.
  • Loading branch information
dstork authored and codeworrior committed Aug 28, 2019
1 parent 6528053 commit a8edff4
Show file tree
Hide file tree
Showing 21 changed files with 277 additions and 16 deletions.
47 changes: 45 additions & 2 deletions lib/tasks/bundlers/generateFlexChangesBundle.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateFlexChangesBundle");
const flexChangesBundler = require("../../processors/bundlers/flexChangesBundler");
const resourceFactory = require("@ui5/fs").resourceFactory;

/**
* Task to create changesBundle.json file containing all changes stored in the /changes folder for easier consumption at runtime.
* Task to create changesBundle.json file containing all changes stored in the /changes folder for easier consumption
* at runtime.
* If a change bundle is created, "sap.ui.fl" is added as a dependency to the manifest.json if not already present -
* if the dependency is already listed but lazy-loaded, lazy loading is disabled.
*
* @public
* @alias module:@ui5/builder.tasks.generateFlexChangesBundle
Expand All @@ -20,6 +24,44 @@ module.exports = function({workspace, options}) {
pathPrefix = `/resources/${options.namespace}`;
}

function updateJson(data) {
// ensure the existence of the libs section in the dependencies
data["sap.ui5"].dependencies.libs = data["sap.ui5"].dependencies.libs || {};
const mLibs = data["sap.ui5"].dependencies.libs;

if ("sap.ui.fl" in mLibs) {
log.verbose("sap.ui.fl found in manifest.json");
if ("lazy" in mLibs["sap.ui.fl"]) {
log.verbose("sap.ui.fl 'lazy' attribute found in manifest.json, setting it to false...");
if (mLibs["sap.ui.fl"].lazy === true) {
mLibs["sap.ui.fl"].lazy = false;
}
}
} else {
log.verbose("sap.ui.fl not found in manifest.json, inserting it...");
mLibs["sap.ui.fl"] = {};
}

return data;
}

function updateFLdependency() {
return workspace.byPath(`${pathPrefix}/manifest.json`)
.then((manifestData) => {
return manifestData.getBuffer().then((buffer) => {
return JSON.parse(buffer.toString());
});
})
.then((manifestContent) => {
let updatedContent = updateJson(manifestContent);
updatedContent = JSON.stringify(updatedContent);
return workspace.write(resourceFactory.createResource({
path: `${pathPrefix}/manifest.json`,
string: updatedContent
}));
});
}

log.verbose("Collecting flexibility changes");
return workspace.byGlob(`${pathPrefix}/changes/*.change`)
.then((allResources) => {
Expand All @@ -32,8 +74,9 @@ module.exports = function({workspace, options}) {
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return Promise.all(processedResources.map(async (resource) => {
log.verbose("Writing flexibility changes bundle");
await updateFLdependency();
return workspace.write(resource);
}));
});
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions test/expected/build/application.i/dest/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.i",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
},
"embeds": ["embedded"],
"title": "{{title}}"
}
}
{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.i","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"},"sap.ui5":{"dependencies":{"libs":{"sap.ui.layout":{},"sap.ui.core":{},"sap.m":{},"sap.ui.fl":{}}}}}
11 changes: 11 additions & 0 deletions test/expected/build/application.j/dest/Component-preload.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/expected/build/application.j/dest/Component.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"fileName":"id_456_addField","fileType":"change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2023-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}},{"fileName":"id_123_addField","fileType":"change","changeType":"hideControl","component":"application.j.Component","content":{},"selector":{"id":"control1"},"layer":"VENDOR","texts":{},"namespace":"apps/application.j.Component/changes","creation":"2025-10-30T13:52:40.4754350Z","originalLanguage":"","conditions":{},"support":{"generator":"did it","user":"Max Mustermann"}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sap.ui.define([],function(){return{}});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xml>

</xml>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_123_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_456_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2023-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
1 change: 1 addition & 0 deletions test/expected/build/application.j/dest/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.j","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"},"sap.ui5":{"dependencies":{"libs":{"sap.ui.layout":{},"sap.ui.core":{},"sap.m":{},"sap.ui.fl":{"lazy":false}}}}}
9 changes: 9 additions & 0 deletions test/fixtures/application.i/webapp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@
},
"embeds": ["embedded"],
"title": "{{title}}"
},
"sap.ui5": {
"dependencies": {
"libs": {
"sap.ui.layout": {},
"sap.ui.core": {},
"sap.m": {}
}
}
}
}
10 changes: 10 additions & 0 deletions test/fixtures/application.j/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "application.j",
"version": "1.0.0",
"description": "Simple SAPUI5 based application",
"main": "index.html",
"dependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
25 changes: 25 additions & 0 deletions test/fixtures/application.j/ui5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
specVersion: "0.1"
type: application
metadata:
name: application.j
builder:
bundles:
- name: sap/ushell/bootstrap/cdm.js
defaultFileTypes:
- ".js"
sections:
- mode: raw
filters:
- ui5loader.js
- ui5loader-autoconfig.js
declareModules: false
resolve: true
- mode: preload
name: sap/ushell/bootstrap/common
filters:
- sap/ushell/bootstrap/cdm/cdm-def.js
resolve: true
- mode: require
filters:
- sap/ushell/bootstrap/cdm/cdm-def.js
8 changes: 8 additions & 0 deletions test/fixtures/application.j/webapp/Component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){
"use strict";
return UIComponent.extend('application.j.Component', {
metadata: {
manifest: "json"
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sap.ui.define([],function () {
return {};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xml>

</xml>
20 changes: 20 additions & 0 deletions test/fixtures/application.j/webapp/changes/id_123_addField.change
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_123_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2025-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
20 changes: 20 additions & 0 deletions test/fixtures/application.j/webapp/changes/id_456_addField.change
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"fileName": "id_456_addField",
"fileType": "change",
"changeType": "hideControl",
"component": "application.j.Component",
"content": {},
"selector": {
"id": "control1"
},
"layer": "VENDOR",
"texts": {},
"namespace": "apps/application.j.Component/changes",
"creation": "2023-10-30T13:52:40.4754350Z",
"originalLanguage": "",
"conditions": {},
"support": {
"generator": "did it",
"user": "Max Mustermann"
}
}
25 changes: 25 additions & 0 deletions test/fixtures/application.j/webapp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "application.j",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
},
"embeds": ["embedded"],
"title": "{{title}}"
},
"sap.ui5": {
"dependencies": {
"libs": {
"sap.ui.layout": {},
"sap.ui.core": {},
"sap.m": {},
"sap.ui.fl": {
"lazy": true
}
}
}
}
}
49 changes: 49 additions & 0 deletions test/lib/builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const applicationAPath = path.join(__dirname, "..", "..", "fixtures", "applicati
const applicationGPath = path.join(__dirname, "..", "..", "fixtures", "application.g");
const applicationHPath = path.join(__dirname, "..", "..", "fixtures", "application.h");
const applicationIPath = path.join(__dirname, "..", "..", "fixtures", "application.i");
const applicationJPath = path.join(__dirname, "..", "..", "fixtures", "application.j");
const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d");
const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e");
const libraryHPath = path.join(__dirname, "..", "..", "fixtures", "library.h");
Expand Down Expand Up @@ -259,6 +260,26 @@ test("Build application.i", (t) => {
});
});

test("Build application.j", (t) => {
const destPath = "./test/tmp/build/application.j/dest";
const expectedPath = path.join("test", "expected", "build", "application.j", "dest");

return builder.build({
tree: applicationJTree,
destPath,
excludedTasks: ["createDebugFiles", "generateStandaloneAppBundle", "generateVersionInfo"]
}).then(() => {
return findFiles(expectedPath);
}).then((expectedFiles) => {
// Check for all directories and files
assert.directoryDeepEqual(destPath, expectedPath);
// Check for all file contents
return checkFileContentsIgnoreLineFeeds(expectedFiles, expectedPath, destPath);
}).then(() => {
t.pass();
});
});

test("Build library.d with copyright from .library file", (t) => {
const destPath = "./test/tmp/build/library.d/dest";
const expectedPath = path.join("test", "expected", "build", "library.d", "dest");
Expand Down Expand Up @@ -787,6 +808,34 @@ const applicationITree = {
}
};

const applicationJTree = {
"id": "application.j",
"version": "1.0.0",
"path": applicationJPath,
"_level": 0,
"specVersion": "0.1",
"type": "application",
"metadata": {
"name": "application.j",
"namespace": "application/j"
},
"dependencies": [],
"resources": {
"configuration": {
"paths": {
"webapp": "webapp"
},
"propertiesFileSourceEncoding": "ISO-8859-1"
},
"pathMappings": {
"/": "webapp"
}
},
"builder": {
"bundles": []
}
};

const libraryDTree = {
"id": "library.d",
"version": "1.0.0",
Expand Down

0 comments on commit a8edff4

Please sign in to comment.