@@ -60,12 +60,12 @@ const processManifest = async (manifestResource) => {
60
60
const manifestDependencies = manifestObject [ "sap.ui5" ] [ "dependencies" ] ;
61
61
if ( manifestDependencies ) {
62
62
const libs = { } ;
63
- Object . keys ( manifestDependencies . libs ) . forEach ( ( libKey ) => {
63
+ for ( const [ libKey , libValue ] of Object . entries ( manifestDependencies . libs ) ) {
64
64
libs [ libKey ] = { } ;
65
- if ( manifestDependencies . libs [ libKey ] . lazy ) {
65
+ if ( libValue . lazy ) {
66
66
libs [ libKey ] . lazy = true ;
67
67
}
68
- } ) ;
68
+ }
69
69
manifestInfo . libs = libs ;
70
70
}
71
71
}
@@ -140,8 +140,8 @@ const getManifestPath = (filePath, subPath) => {
140
140
141
141
/**
142
142
* Represents dependency information for a library.
143
- * Dependencies can be resolved recursively using <code>#resolve </code>
144
- * and are stored then in <code>libsResolved</code>
143
+ * Dependencies can be retrieved using <code>#getResolvedLibraries </code>
144
+ * and with that are resolved recursively
145
145
*/
146
146
class DependencyInfo {
147
147
/**
@@ -152,14 +152,6 @@ class DependencyInfo {
152
152
constructor ( libs , name ) {
153
153
this . libs = libs ;
154
154
this . name = name ;
155
-
156
- /**
157
- * contains as key the library name and as value an object with an optional lazy property
158
- *
159
- * @type {ManifestLibraries }
160
- */
161
- this . libsResolved = Object . create ( null ) ;
162
- this . wasResolved = false ;
163
155
}
164
156
165
157
/**
@@ -171,13 +163,13 @@ class DependencyInfo {
171
163
* @returns {{lazy: boolean} } the added library
172
164
*/
173
165
addResolvedLibDependency ( libName , lazy ) {
174
- let alreadyResolved = this . libsResolved [ libName ] ;
166
+ let alreadyResolved = this . _libsResolved [ libName ] ;
175
167
if ( ! alreadyResolved ) {
176
168
alreadyResolved = Object . create ( null ) ;
177
169
if ( lazy ) {
178
170
alreadyResolved . lazy = true ;
179
171
}
180
- this . libsResolved [ libName ] = alreadyResolved ;
172
+ this . _libsResolved [ libName ] = alreadyResolved ;
181
173
} else {
182
174
// siblings if sibling is eager only if one other sibling eager
183
175
alreadyResolved . lazy = alreadyResolved . lazy && lazy ;
@@ -186,38 +178,38 @@ class DependencyInfo {
186
178
}
187
179
188
180
/**
189
- * Resolves dependencies recursively and stores them in libsResolved
190
- * with
181
+ * Resolves dependencies recursively and retrieves them with
191
182
* - resolved siblings a lazy and a eager dependency becomes eager
192
183
* - resolved children become lazy if their parent is lazy
193
184
*
194
185
* @param {Map<string,DependencyInfo> } dependencyInfoMap
186
+ * @returns {ManifestLibraries } resolved libraries
195
187
*/
196
- resolve ( dependencyInfoMap ) {
197
- if ( ! this . wasResolved ) {
188
+ getResolvedLibraries ( dependencyInfoMap ) {
189
+ if ( ! this . _libsResolved ) {
198
190
// early set if there is a potential cycle
199
- this . wasResolved = true ;
200
- Object . keys ( this . libs ) . forEach ( ( libName ) => {
201
- const lazy = this . libs [ libName ] . lazy ;
191
+ this . _libsResolved = Object . create ( null ) ;
192
+ for ( const [ libName , libValue ] of Object . entries ( this . libs ) ) {
193
+ const lazy = libValue . lazy ;
202
194
const dependencyInfoObjectAdded = this . addResolvedLibDependency ( libName , lazy ) ;
203
195
const dependencyInfo = dependencyInfoMap . get ( libName ) ;
204
196
if ( dependencyInfo ) {
205
- dependencyInfo . resolve ( dependencyInfoMap ) ;
197
+ const childLibsResolved = dependencyInfo . getResolvedLibraries ( dependencyInfoMap ) ;
206
198
207
199
// children if parent is lazy children become lazy
208
- Object . keys ( dependencyInfo . libsResolved ) . forEach ( ( resolvedLibName ) => {
209
- const resolvedLib = dependencyInfo . libsResolved [ resolvedLibName ] ;
200
+ for ( const [ resolvedLibName , resolvedLib ] of Object . entries ( childLibsResolved ) ) {
210
201
this . addResolvedLibDependency ( resolvedLibName ,
211
202
resolvedLib . lazy || dependencyInfoObjectAdded . lazy ) ;
212
- } ) ;
203
+ }
213
204
} else {
214
205
log . info ( `Cannot find dependency '${ libName } ' ` +
215
206
`defined in the manifest.json or .library file of project '${ this . name } '. ` +
216
207
"This might prevent some UI5 runtime performance optimizations from taking effect. " +
217
208
"Please double check your project's dependency configuration." ) ;
218
209
}
219
- } ) ;
210
+ }
220
211
}
212
+ return this . _libsResolved ;
221
213
}
222
214
}
223
215
@@ -226,7 +218,7 @@ class DependencyInfo {
226
218
* Sorts the keys of a given object
227
219
*
228
220
* @param {object } obj the object
229
- * @returns {{} } the object with sorted keys
221
+ * @returns {object } the object with sorted keys
230
222
*/
231
223
const sortObjectKeys = ( obj ) => {
232
224
const sortedObject = { } ;
@@ -242,78 +234,33 @@ const sortObjectKeys = (obj) => {
242
234
* Builds the manifestHints object from the dependencyInfo
243
235
*
244
236
* @param {DependencyInfo } dependencyInfo
237
+ * @param {Map<string, DependencyInfo> } dependencyInfoMap
245
238
* @returns {{dependencies: {libs: ManifestLibraries}} } manifestHints
246
239
*/
247
- const getManifestHints = ( dependencyInfo ) => {
248
- if ( dependencyInfo && Object . keys ( dependencyInfo . libsResolved ) . length ) {
249
- return {
250
- dependencies : {
251
- libs : sortObjectKeys ( dependencyInfo . libsResolved )
252
- }
253
- } ;
240
+ const getManifestHints = ( dependencyInfo , dependencyInfoMap ) => {
241
+ if ( dependencyInfo ) {
242
+ const libsResolved = dependencyInfo . getResolvedLibraries ( dependencyInfoMap ) ;
243
+ if ( libsResolved && Object . keys ( libsResolved ) . length ) {
244
+ return {
245
+ dependencies : {
246
+ libs : sortObjectKeys ( libsResolved )
247
+ }
248
+ } ;
249
+ }
254
250
}
255
251
} ;
256
252
257
253
/**
258
254
* Common type for Library and Component
259
255
* embeds and bundled components makes only sense for library
256
+ *
257
+ * @typedef {object } ArtifactInfo
258
+ * @property {string } componentName The library name, e.g. "lib.x"
259
+ * @property {Set<string> } bundledComponents The embedded components which have a embeddedBy reference to the library
260
+ * @property {DependencyInfo } dependencyInfo The dependency info object
261
+ * @property {ArtifactInfo[] } embeds The embedded artifact infos
260
262
*/
261
- class ArtifactInfo {
262
- /**
263
- * @param {string } componentName e.g. lib.x
264
- */
265
- constructor ( componentName ) {
266
- this . componentName = componentName ;
267
- this . artifactInfos = [ ] ;
268
- this . parentBundledComponents = new Set ( ) ;
269
- }
270
-
271
- /**
272
- *
273
- * @param {DependencyInfo } dependencyInfo
274
- */
275
- setDependencyInfo ( dependencyInfo ) {
276
- this . dependencyInfo = dependencyInfo ;
277
- }
278
263
279
- /**
280
- * The embedded components which have a embeddedBy reference to the library
281
- *
282
- * @param {Set<string> } bundledComponents e.g. ["lib.x.sub"]
283
- */
284
- setBundledComponents ( bundledComponents ) {
285
- this . bundledComponents = bundledComponents ;
286
- }
287
-
288
- /**
289
- * Set the embedded components of the library
290
- *
291
- * @param {ArtifactInfo[] } artifactInfos embedded components
292
- */
293
- setEmbeds ( artifactInfos ) {
294
- this . artifactInfos = artifactInfos ;
295
- this . artifactInfos . forEach ( ( artifactInfo ) => {
296
- artifactInfo . _setParent ( this ) ;
297
- } ) ;
298
- }
299
-
300
- /**
301
- * @returns {ArtifactInfo[] } get embedded components of this library
302
- */
303
- getEmbeds ( ) {
304
- return this . artifactInfos ;
305
- }
306
-
307
- /**
308
- * @param {ArtifactInfo } parent set the parent library
309
- * @private
310
- */
311
- _setParent ( parent ) {
312
- this . parent = parent ;
313
- this . parentBundledComponents = this . parent . bundledComponents ;
314
- this . parentComponentName = this . parent . componentName ;
315
- }
316
- }
317
264
318
265
/**
319
266
* Processes the manifest and creates a ManifestInfo and an ArtifactInfo.
@@ -325,8 +272,9 @@ class ArtifactInfo {
325
272
async function processManifestAndGetArtifactInfo ( libraryManifest , name ) {
326
273
const manifestInfo = await processManifest ( libraryManifest ) ;
327
274
name = name || manifestInfo . id ;
328
- const libraryArtifactInfo = new ArtifactInfo ( name ) ;
329
- libraryArtifactInfo . setDependencyInfo ( new DependencyInfo ( manifestInfo . libs , name ) ) ;
275
+ const libraryArtifactInfo = Object . create ( null ) ;
276
+ libraryArtifactInfo . componentName = name ;
277
+ libraryArtifactInfo . dependencyInfo = new DependencyInfo ( manifestInfo . libs , name ) ;
330
278
return { manifestInfo, libraryArtifactInfo} ;
331
279
}
332
280
@@ -347,7 +295,7 @@ const processLibraryInfo = async (libraryInfo) => {
347
295
await processManifestAndGetArtifactInfo ( libraryInfo . libraryManifest , libraryInfo . name ) ;
348
296
349
297
const bundledComponents = new Set ( ) ;
350
- libraryArtifactInfo . setBundledComponents ( bundledComponents ) ;
298
+ libraryArtifactInfo . bundledComponents = bundledComponents ;
351
299
352
300
const embeds = manifestInfo . embeds ; // e.g. ["sub"]
353
301
// filter only embedded manifests
@@ -378,7 +326,7 @@ const processLibraryInfo = async (libraryInfo) => {
378
326
} ) ;
379
327
380
328
const embeddedArtifactInfos = await Promise . all ( embeddedManifestPromises ) ;
381
- libraryArtifactInfo . setEmbeds ( embeddedArtifactInfos ) ;
329
+ libraryArtifactInfo . embeds = embeddedArtifactInfos ;
382
330
383
331
return libraryArtifactInfo ;
384
332
} ;
@@ -434,29 +382,18 @@ module.exports = async function({options}) {
434
382
435
383
436
384
// process library infos
437
- const librariesPromises = options . libraryInfos . map ( ( libraryInfo ) => {
385
+ const libraryInfosProcessPromises = options . libraryInfos . map ( ( libraryInfo ) => {
438
386
return processLibraryInfo ( libraryInfo ) ;
439
387
} ) ;
440
388
441
- let artifactInfos = await Promise . all ( librariesPromises ) ;
389
+ let artifactInfos = await Promise . all ( libraryInfosProcessPromises ) ;
442
390
artifactInfos = artifactInfos . filter ( Boolean ) ;
443
391
444
392
// fill dependencyInfoMap
445
393
artifactInfos . forEach ( ( artifactInfo ) => {
446
394
dependencyInfoMap . set ( artifactInfo . componentName , artifactInfo . dependencyInfo ) ;
447
395
} ) ;
448
396
449
- // resolve library dependencies (transitive)
450
- dependencyInfoMap . forEach ( ( dependencyInfo ) => {
451
- dependencyInfo . resolve ( dependencyInfoMap ) ;
452
- } ) ;
453
-
454
- // resolve dependencies of embedded components
455
- artifactInfos . forEach ( ( artifactInfo ) => {
456
- artifactInfo . getEmbeds ( ) . forEach ( ( embeddedArtifactInfo ) => {
457
- embeddedArtifactInfo . dependencyInfo . resolve ( dependencyInfoMap ) ;
458
- } ) ;
459
- } ) ;
460
397
461
398
const libraries = options . libraryInfos . map ( ( libraryInfo ) => {
462
399
const library = {
@@ -467,7 +404,7 @@ module.exports = async function({options}) {
467
404
} ;
468
405
469
406
const dependencyInfo = dependencyInfoMap . get ( libraryInfo . name ) ;
470
- const manifestHints = getManifestHints ( dependencyInfo ) ;
407
+ const manifestHints = getManifestHints ( dependencyInfo , dependencyInfoMap ) ;
471
408
if ( manifestHints ) {
472
409
library . manifestHints = manifestHints ;
473
410
}
@@ -482,17 +419,16 @@ module.exports = async function({options}) {
482
419
// components
483
420
let components ;
484
421
artifactInfos . forEach ( ( artifactInfo ) => {
485
- artifactInfo . getEmbeds ( ) . forEach ( ( embeddedArtifactInfo ) => {
422
+ artifactInfo . embeds . forEach ( ( embeddedArtifactInfo ) => {
486
423
const componentObject = {
487
- library : embeddedArtifactInfo . parentComponentName
424
+ library : artifactInfo . componentName
488
425
} ;
489
426
const componentName = embeddedArtifactInfo . componentName ;
490
- const dependencyInfo = embeddedArtifactInfo . dependencyInfo ;
491
- const manifestHints = getManifestHints ( dependencyInfo ) ;
427
+ const manifestHints = getManifestHints ( embeddedArtifactInfo . dependencyInfo , dependencyInfoMap ) ;
492
428
if ( manifestHints ) {
493
429
componentObject . manifestHints = manifestHints ;
494
430
}
495
- const bundledComponents = embeddedArtifactInfo . parentBundledComponents ;
431
+ const bundledComponents = artifactInfo . bundledComponents ;
496
432
if ( bundledComponents . has ( componentName ) ) {
497
433
componentObject . hasOwnPreload = true ;
498
434
}
0 commit comments