Skip to content

Commit fe61d6e

Browse files
authored
[FIX] resourceListCreator: Include dependencies of subModules (#588)
JIRA: CPOUI5FOUNDATION-310
1 parent 0531fda commit fe61d6e

File tree

10 files changed

+574
-34
lines changed

10 files changed

+574
-34
lines changed

lib/lbt/resources/ResourceCollector.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ class ResourceCollector {
109109
}
110110

111111
async enrichWithDependencyInfo(resourceInfo) {
112-
return this._pool.getModuleInfo(resourceInfo.name).then((moduleInfo) => {
112+
return this._pool.getModuleInfo(resourceInfo.name).then(async (moduleInfo) => {
113113
if ( moduleInfo.name ) {
114114
resourceInfo.module = moduleInfo.name;
115115
}
116116
if ( moduleInfo.dynamicDependencies ) {
117117
resourceInfo.dynRequired = true;
118118
}
119+
119120
if ( moduleInfo.dependencies.length > 0 ) {
120121
resourceInfo.required = resourceInfo.required || new Set();
121122
resourceInfo.condRequired = resourceInfo.condRequired || new Set();
@@ -127,11 +128,51 @@ class ResourceCollector {
127128
}
128129
});
129130
}
131+
130132
if ( moduleInfo.subModules.length > 0 ) {
131133
resourceInfo.included = resourceInfo.included || new Set();
132134
moduleInfo.subModules.forEach((mod) => {
133135
resourceInfo.included.add(mod);
134136
});
137+
await Promise.all(moduleInfo.subModules.map(async (subModule) => {
138+
// Try to inherit dependency info
139+
let subModuleInfo;
140+
try {
141+
subModuleInfo = await this._pool.getModuleInfo(subModule);
142+
} catch (err) {
143+
log.verbose(` missing submodule ${subModule} included by ${moduleInfo.name}`);
144+
}
145+
if (subModuleInfo) {
146+
// Inherit subModule dependencies
147+
if ( subModuleInfo.dependencies.length > 0 ) {
148+
resourceInfo.required = resourceInfo.required || new Set();
149+
resourceInfo.condRequired = resourceInfo.condRequired || new Set();
150+
subModuleInfo.dependencies.forEach((dep) => {
151+
if (resourceInfo.included.has(dep)) {
152+
// Don't add dependency if module is already listed as "included"
153+
return;
154+
}
155+
if ( subModuleInfo.isConditionalDependency(dep) ) {
156+
// Avoid having module listed in both required and condRequired
157+
if (!resourceInfo.required.has(dep)) {
158+
resourceInfo.condRequired.add(dep);
159+
}
160+
} else if ( !subModuleInfo.isImplicitDependency(dep) ) {
161+
// Move module from condRequired to required
162+
if (resourceInfo.condRequired.has(dep)) {
163+
resourceInfo.condRequired.delete(dep);
164+
}
165+
resourceInfo.required.add(dep);
166+
}
167+
});
168+
}
169+
170+
// Inherit dynamicDependencies flag
171+
if ( moduleInfo.dynamicDependencies ) {
172+
resourceInfo.dynRequired = true;
173+
}
174+
}
175+
}));
135176
}
136177

137178
if (moduleInfo.requiresTopLevelScope) {

lib/lbt/resources/ResourcePool.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ class ResourcePool {
182182
async getModuleInfo(name) {
183183
let info = this._dependencyInfos.get(name);
184184
if ( info == null ) {
185-
// console.log("analyzing ", name);
186-
const resource = await this.findResource(name);
187-
info = await determineDependencyInfo( resource, this._rawModuleInfos.get(name), this );
188-
// console.log("finished analyzing ", name);
185+
info = Promise.resolve().then(async () => {
186+
const resource = await this.findResource(name);
187+
return determineDependencyInfo( resource, this._rawModuleInfos.get(name), this );
188+
});
189189
this._dependencyInfos.set(name, info);
190190
}
191191
return info;

test/expected/build/application.j/dest-resources-json/resources.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
"module": "application/j/Component-preload.js",
77
"size": 3682,
88
"merged": true,
9+
"required": [
10+
"sap/m/library.js",
11+
"sap/ui/core/UIComponent.js",
12+
"sap/ui/core/library.js",
13+
"sap/ui/fl/library.js",
14+
"sap/ui/layout/library.js"
15+
],
916
"included": [
1017
"application/j/Component.js",
1118
"application/j/changes/coding/MyExtension.js",
@@ -80,7 +87,7 @@
8087
},
8188
{
8289
"name": "resources.json",
83-
"size": 1870
90+
"size": 2040
8491
}
8592
]
8693
}

test/expected/build/library.h/dest-resources-json/resources/library/h/components/resources.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"module": "library/h/components/Component-preload.js",
77
"size": 361,
88
"merged": true,
9+
"required": [
10+
"sap/ui/core/UIComponent.js"
11+
],
912
"included": [
1013
"library/h/components/Component.js",
1114
"library/h/components/TodoComponent.js"
@@ -27,13 +30,16 @@
2730
},
2831
{
2932
"name": "resources.json",
30-
"size": 1904
33+
"size": 2128
3134
},
3235
{
3336
"name": "subcomponent1/Component-preload.js",
3437
"module": "library/h/components/subcomponent1/Component-preload.js",
3538
"size": 279,
3639
"merged": true,
40+
"required": [
41+
"sap/ui/core/UIComponent.js"
42+
],
3743
"included": [
3844
"library/h/components/subcomponent1/Component.js"
3945
]
@@ -51,6 +57,9 @@
5157
"module": "library/h/components/subcomponent2/Component-preload.js",
5258
"size": 279,
5359
"merged": true,
60+
"required": [
61+
"sap/ui/core/UIComponent.js"
62+
],
5463
"included": [
5564
"library/h/components/subcomponent2/Component.js"
5665
]
@@ -68,6 +77,9 @@
6877
"module": "library/h/components/subcomponent3/Component-preload.js",
6978
"size": 279,
7079
"merged": true,
80+
"required": [
81+
"sap/ui/core/UIComponent.js"
82+
],
7183
"included": [
7284
"library/h/components/subcomponent3/Component.js"
7385
]

test/expected/build/library.h/dest-resources-json/resources/library/h/components/subcomponent1/resources.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"module": "library/h/components/subcomponent1/Component-preload.js",
77
"size": 279,
88
"merged": true,
9+
"required": [
10+
"sap/ui/core/UIComponent.js"
11+
],
912
"included": [
1013
"library/h/components/subcomponent1/Component.js"
1114
]
@@ -20,7 +23,7 @@
2023
},
2124
{
2225
"name": "resources.json",
23-
"size": 494
26+
"size": 550
2427
}
2528
]
2629
}

test/expected/build/library.h/dest-resources-json/resources/library/h/components/subcomponent2/resources.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"module": "library/h/components/subcomponent2/Component-preload.js",
77
"size": 279,
88
"merged": true,
9+
"required": [
10+
"sap/ui/core/UIComponent.js"
11+
],
912
"included": [
1013
"library/h/components/subcomponent2/Component.js"
1114
]
@@ -20,7 +23,7 @@
2023
},
2124
{
2225
"name": "resources.json",
23-
"size": 494
26+
"size": 550
2427
}
2528
]
2629
}

test/expected/build/library.h/dest-resources-json/resources/library/h/components/subcomponent3/resources.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"module": "library/h/components/subcomponent3/Component-preload.js",
77
"size": 279,
88
"merged": true,
9+
"required": [
10+
"sap/ui/core/UIComponent.js"
11+
],
912
"included": [
1013
"library/h/components/subcomponent3/Component.js"
1114
]
@@ -20,7 +23,7 @@
2023
},
2124
{
2225
"name": "resources.json",
23-
"size": 494
26+
"size": 550
2427
}
2528
]
2629
}

test/expected/build/library.h/dest-resources-json/resources/library/h/resources.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"module": "library/h/components/Component-preload.js",
1111
"size": 361,
1212
"merged": true,
13+
"required": [
14+
"sap/ui/core/UIComponent.js"
15+
],
1316
"included": [
1417
"library/h/components/Component.js",
1518
"library/h/components/TodoComponent.js"
@@ -34,6 +37,9 @@
3437
"module": "library/h/components/subcomponent1/Component-preload.js",
3538
"size": 279,
3639
"merged": true,
40+
"required": [
41+
"sap/ui/core/UIComponent.js"
42+
],
3743
"included": [
3844
"library/h/components/subcomponent1/Component.js"
3945
]
@@ -51,6 +57,9 @@
5157
"module": "library/h/components/subcomponent2/Component-preload.js",
5258
"size": 279,
5359
"merged": true,
60+
"required": [
61+
"sap/ui/core/UIComponent.js"
62+
],
5463
"included": [
5564
"library/h/components/subcomponent2/Component.js"
5665
]
@@ -68,6 +77,9 @@
6877
"module": "library/h/components/subcomponent3/Component-preload.js",
6978
"size": 279,
7079
"merged": true,
80+
"required": [
81+
"sap/ui/core/UIComponent.js"
82+
],
7183
"included": [
7284
"library/h/components/subcomponent3/Component.js"
7385
]
@@ -143,7 +155,7 @@
143155
},
144156
{
145157
"name": "resources.json",
146-
"size": 3500
158+
"size": 3724
147159
},
148160
{
149161
"name": "some.js",

test/lib/lbt/resources/ResourcePool.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ test("getModuleInfo", async (t) => {
104104
const inputJsResource = {name: "a.js", buffer: async () => code};
105105
resourcePool.addResource(inputJsResource);
106106
const jsResource = await resourcePool.getModuleInfo("a.js");
107-
t.is(resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
107+
t.is(await resourcePool._dependencyInfos.get(inputJsResource.name), jsResource,
108108
"info has been added to _dependencyInfos map");
109109

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

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

188188

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

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

222222
const xmlViewResource = await resourcePool.getModuleInfo("a.view.xml");
223-
t.is(resourcePool._dependencyInfos.get(inputXmlViewResource.name), xmlViewResource,
223+
t.is(await resourcePool._dependencyInfos.get(inputXmlViewResource.name), xmlViewResource,
224224
"info has been added to _dependencyInfos map");
225225
t.deepEqual(xmlViewResource.size, 315);
226226
t.falsy(xmlViewResource.format);

0 commit comments

Comments
 (0)