-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -20,6 +24,42 @@ module.exports = function({workspace, options}) { | |
pathPrefix = `/resources/${options.namespace}`; | ||
} | ||
|
||
function updateJson(data) { | ||
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) => { | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return workspace.write(resource); | ||
})); | ||
}); | ||
|
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 |
---|---|---|
@@ -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":{}}}}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.