Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add 'sap.ui.fl' dependency to manifest.json #318

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 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,42 @@ module.exports = function({workspace, options}) {
pathPrefix = `/resources/${options.namespace}`;
}

function updateJson(data) {
const mLibs = data["sap.ui5"].dependencies.libs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't it happen that there's no dependencies/libs section yet in the manifest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least if createManifest > createSapUi5 > create > depdenencies is running / the creator is doing everything right, it should be fine.
In general the dependencies is flagged as mandatory while I only found a "have to be filled ... for ui5 apps" for the libs section.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

safety first... now within the mandatory part we always have the section not explicitly mentioned as mandatory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As most mandatory sections are not checked at runtime, I would expect the tooling to do the same. It should not expect that the given manifest is valid w.r.t. the schema.


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 +72,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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Processors return an array of resources, which should all be written to the workspace, although (currently) in this case it always returns one resource.

But updating the manifest should only happen once, right? So I would expect it to be done after the Promise.all.

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":{}}}}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is expected. When modifying the manifest IMO, it should still be formatted, preferably with the same indentation as before, but I think tabs should be fine.

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": {}
}
}
}
}