Skip to content

Commit

Permalink
[FIX] resourceListCreator: Include dependencies of subModules (#588)
Browse files Browse the repository at this point in the history
JIRA: CPOUI5FOUNDATION-310
  • Loading branch information
matz3 committed Mar 4, 2021
1 parent 0531fda commit fe61d6e
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 34 deletions.
43 changes: 42 additions & 1 deletion lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ class ResourceCollector {
}

async enrichWithDependencyInfo(resourceInfo) {
return this._pool.getModuleInfo(resourceInfo.name).then((moduleInfo) => {
return this._pool.getModuleInfo(resourceInfo.name).then(async (moduleInfo) => {
if ( moduleInfo.name ) {
resourceInfo.module = moduleInfo.name;
}
if ( moduleInfo.dynamicDependencies ) {
resourceInfo.dynRequired = true;
}

if ( moduleInfo.dependencies.length > 0 ) {
resourceInfo.required = resourceInfo.required || new Set();
resourceInfo.condRequired = resourceInfo.condRequired || new Set();
Expand All @@ -127,11 +128,51 @@ class ResourceCollector {
}
});
}

if ( moduleInfo.subModules.length > 0 ) {
resourceInfo.included = resourceInfo.included || new Set();
moduleInfo.subModules.forEach((mod) => {
resourceInfo.included.add(mod);
});
await Promise.all(moduleInfo.subModules.map(async (subModule) => {
// Try to inherit dependency info
let subModuleInfo;
try {
subModuleInfo = await this._pool.getModuleInfo(subModule);
} catch (err) {
log.verbose(` missing submodule ${subModule} included by ${moduleInfo.name}`);
}
if (subModuleInfo) {
// Inherit subModule dependencies
if ( subModuleInfo.dependencies.length > 0 ) {
resourceInfo.required = resourceInfo.required || new Set();
resourceInfo.condRequired = resourceInfo.condRequired || new Set();
subModuleInfo.dependencies.forEach((dep) => {
if (resourceInfo.included.has(dep)) {
// Don't add dependency if module is already listed as "included"
return;
}
if ( subModuleInfo.isConditionalDependency(dep) ) {
// Avoid having module listed in both required and condRequired
if (!resourceInfo.required.has(dep)) {
resourceInfo.condRequired.add(dep);
}
} else if ( !subModuleInfo.isImplicitDependency(dep) ) {
// Move module from condRequired to required
if (resourceInfo.condRequired.has(dep)) {
resourceInfo.condRequired.delete(dep);
}
resourceInfo.required.add(dep);
}
});
}

// Inherit dynamicDependencies flag
if ( moduleInfo.dynamicDependencies ) {
resourceInfo.dynRequired = true;
}
}
}));
}

if (moduleInfo.requiresTopLevelScope) {
Expand Down
8 changes: 4 additions & 4 deletions lib/lbt/resources/ResourcePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ class ResourcePool {
async getModuleInfo(name) {
let info = this._dependencyInfos.get(name);
if ( info == null ) {
// console.log("analyzing ", name);
const resource = await this.findResource(name);
info = await determineDependencyInfo( resource, this._rawModuleInfos.get(name), this );
// console.log("finished analyzing ", name);
info = Promise.resolve().then(async () => {
const resource = await this.findResource(name);
return determineDependencyInfo( resource, this._rawModuleInfos.get(name), this );
});
this._dependencyInfos.set(name, info);
}
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
"module": "application/j/Component-preload.js",
"size": 3682,
"merged": true,
"required": [
"sap/m/library.js",
"sap/ui/core/UIComponent.js",
"sap/ui/core/library.js",
"sap/ui/fl/library.js",
"sap/ui/layout/library.js"
],
"included": [
"application/j/Component.js",
"application/j/changes/coding/MyExtension.js",
Expand Down Expand Up @@ -80,7 +87,7 @@
},
{
"name": "resources.json",
"size": 1870
"size": 2040
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "library/h/components/Component-preload.js",
"size": 361,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/Component.js",
"library/h/components/TodoComponent.js"
Expand All @@ -27,13 +30,16 @@
},
{
"name": "resources.json",
"size": 1904
"size": 2128
},
{
"name": "subcomponent1/Component-preload.js",
"module": "library/h/components/subcomponent1/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent1/Component.js"
]
Expand All @@ -51,6 +57,9 @@
"module": "library/h/components/subcomponent2/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent2/Component.js"
]
Expand All @@ -68,6 +77,9 @@
"module": "library/h/components/subcomponent3/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent3/Component.js"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "library/h/components/subcomponent1/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent1/Component.js"
]
Expand All @@ -20,7 +23,7 @@
},
{
"name": "resources.json",
"size": 494
"size": 550
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "library/h/components/subcomponent2/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent2/Component.js"
]
Expand All @@ -20,7 +23,7 @@
},
{
"name": "resources.json",
"size": 494
"size": 550
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"module": "library/h/components/subcomponent3/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent3/Component.js"
]
Expand All @@ -20,7 +23,7 @@
},
{
"name": "resources.json",
"size": 494
"size": 550
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"module": "library/h/components/Component-preload.js",
"size": 361,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/Component.js",
"library/h/components/TodoComponent.js"
Expand All @@ -34,6 +37,9 @@
"module": "library/h/components/subcomponent1/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent1/Component.js"
]
Expand All @@ -51,6 +57,9 @@
"module": "library/h/components/subcomponent2/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent2/Component.js"
]
Expand All @@ -68,6 +77,9 @@
"module": "library/h/components/subcomponent3/Component-preload.js",
"size": 279,
"merged": true,
"required": [
"sap/ui/core/UIComponent.js"
],
"included": [
"library/h/components/subcomponent3/Component.js"
]
Expand Down Expand Up @@ -143,7 +155,7 @@
},
{
"name": "resources.json",
"size": 3500
"size": 3724
},
{
"name": "some.js",
Expand Down
10 changes: 5 additions & 5 deletions test/lib/lbt/resources/ResourcePool.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ test("getModuleInfo", async (t) => {
const inputJsResource = {name: "a.js", buffer: async () => code};
resourcePool.addResource(inputJsResource);
const jsResource = await resourcePool.getModuleInfo("a.js");
t.is(resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
t.is(await resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
"info has been added to _dependencyInfos map");

t.deepEqual(jsResource.name, inputJsResource.name, "name should be the same");
Expand Down Expand Up @@ -159,7 +159,7 @@ test("getModuleInfo: determineDependencyInfo for js templateAssembler code", asy
resourcePool.addResource(inputJsResource);

const jsResource = await resourcePool.getModuleInfo("a.js");
t.is(resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
t.is(await resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
"info has been added to _dependencyInfos map");
t.deepEqual(jsResource.size, 372);
t.deepEqual(jsResource.format, "ui5-define", "contains sap.ui.define therefore should be a ui5-define format");
Expand Down Expand Up @@ -187,7 +187,7 @@ test("getModuleInfo: determineDependencyInfo for xml control and fragment", asyn


const xmlControlResource = await resourcePool.getModuleInfo("a.control.xml");
t.is(resourcePool._dependencyInfos.get(inputXmlControlResource.name), xmlControlResource,
t.is(await resourcePool._dependencyInfos.get(inputXmlControlResource.name), xmlControlResource,
"info has been added to _dependencyInfos map");
t.deepEqual(xmlControlResource.size, 298);
t.falsy(xmlControlResource.format);
Expand All @@ -196,7 +196,7 @@ test("getModuleInfo: determineDependencyInfo for xml control and fragment", asyn
t.deepEqual(xmlControlResource.subModules, []);

const xmlFragmentResource = await resourcePool.getModuleInfo("a.fragment.xml");
t.is(resourcePool._dependencyInfos.get(inputXmlFragmentResource.name), xmlFragmentResource,
t.is(await resourcePool._dependencyInfos.get(inputXmlFragmentResource.name), xmlFragmentResource,
"info has been added to _dependencyInfos map");
t.deepEqual(xmlFragmentResource.size, 298);
t.falsy(xmlFragmentResource.format);
Expand All @@ -220,7 +220,7 @@ test("getModuleInfo: determineDependencyInfo for xml view", async (t) => {
resourcePool.addResource(inputXmlViewResource);

const xmlViewResource = await resourcePool.getModuleInfo("a.view.xml");
t.is(resourcePool._dependencyInfos.get(inputXmlViewResource.name), xmlViewResource,
t.is(await resourcePool._dependencyInfos.get(inputXmlViewResource.name), xmlViewResource,
"info has been added to _dependencyInfos map");
t.deepEqual(xmlViewResource.size, 315);
t.falsy(xmlViewResource.format);
Expand Down

0 comments on commit fe61d6e

Please sign in to comment.