@@ -19,7 +19,7 @@ function getTimestamp() {
19
19
/**
20
20
* Manifest libraries as defined in the manifest.json file
21
21
*
22
- * @typedef {object<string, object > } ManifestLibraries
22
+ * @typedef {object<string, {lazy: boolean} > } ManifestLibraries
23
23
*
24
24
* sample:
25
25
* <pre>
@@ -37,10 +37,10 @@ function getTimestamp() {
37
37
*
38
38
* @typedef {object } ManifestInfo
39
39
*
40
- * @property {string } id The library name
41
- * @property {string } embeddedBy the library this component is embedded in
42
- * @property {string[] } embeds the embedded component names
43
- * @property {ManifestLibraries } libs the dependencies
40
+ * @property {string } id The library name, e.g. "lib.x"
41
+ * @property {string } embeddedBy the library this component is embedded in, e.g. "lib.x"
42
+ * @property {string[] } embeds the embedded component names, e.g. ["lib.x.sub"]
43
+ * @property {ManifestLibraries } libs the dependencies, e.g. {"sap.chart":{"lazy": true}, "sap.f":{}}
44
44
*/
45
45
46
46
@@ -85,6 +85,7 @@ const processManifest = async (manifestResource) => {
85
85
} ;
86
86
87
87
/**
88
+ * Checks if a component (componentPath) is bundled with the library (embeddedBy)
88
89
*
89
90
* @param {string } embeddedBy e.g. "../"
90
91
* @param {string } componentPath e.g. "lib/x/sub"
@@ -126,7 +127,7 @@ const isBundledWithLibrary = (embeddedBy, componentPath, libraryPathPrefix) => {
126
127
} ;
127
128
128
129
/**
129
- * Retrieves the manifest path
130
+ * Retrieves the manifest path of a subcomponent
130
131
*
131
132
* @param {string } filePath path to the manifest, e.g. "lib/x/manifest.json"
132
133
* @param {string } subPath relative sub path, e.g. "sub"
@@ -137,31 +138,37 @@ const getManifestPath = (filePath, subPath) => {
137
138
return posixPath . resolve ( folderPathOfManifest + "/manifest.json" ) ;
138
139
} ;
139
140
140
-
141
+ /**
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>
145
+ */
141
146
class DependencyInfo {
142
147
/**
143
148
*
144
- * @param {object } libs
145
- * @param {string } name
149
+ * @param {ManifestLibraries } libs
150
+ * @param {string } name library name, e.g. "lib.x"
146
151
*/
147
152
constructor ( libs , name ) {
148
153
this . libs = libs ;
149
154
this . name = name ;
150
155
151
156
/**
152
- * contains as key the lirbary name and as value the lazy property
157
+ * contains as key the library name and as value an object with an optional lazy property
153
158
*
154
- * @type {object }
159
+ * @type {ManifestLibraries }
155
160
*/
156
161
this . libsResolved = Object . create ( null ) ;
157
162
this . wasResolved = false ;
158
163
}
159
164
160
165
/**
166
+ * Add library to libsResolved and if already present
167
+ * merge lazy property
161
168
*
162
- * @param {string } libName
169
+ * @param {string } libName library name, e.g. "lib.x"
163
170
* @param {boolean } lazy
164
- * @returns {{lazy: boolean} }
171
+ * @returns {{lazy: boolean} } the added library
165
172
*/
166
173
addResolvedLibDependency ( libName , lazy ) {
167
174
let alreadyResolved = this . libsResolved [ libName ] ;
@@ -219,7 +226,7 @@ class DependencyInfo {
219
226
* Sorts the keys of a given object
220
227
*
221
228
* @param {object } obj the object
222
- * @returns {{} }
229
+ * @returns {{} } the object with sorted keys
223
230
*/
224
231
const sortObjectKeys = ( obj ) => {
225
232
const sortedObject = { } ;
@@ -232,9 +239,10 @@ const sortObjectKeys = (obj) => {
232
239
} ;
233
240
234
241
/**
242
+ * Builds the manifestHints object from the dependencyInfo
235
243
*
236
244
* @param {DependencyInfo } dependencyInfo
237
- * @returns {object } manifestHints
245
+ * @returns {{dependencies: {libs: ManifestLibraries}} } manifestHints
238
246
*/
239
247
const getManifestHints = ( dependencyInfo ) => {
240
248
if ( dependencyInfo && Object . keys ( dependencyInfo . libsResolved ) . length ) {
@@ -307,6 +315,13 @@ class ArtifactInfo {
307
315
}
308
316
}
309
317
318
+ /**
319
+ * Processes the manifest and creates a ManifestInfo and an ArtifactInfo.
320
+ *
321
+ * @param {module:@ui5/fs.Resource } libraryManifest
322
+ * @param {string } [name] library name, if not provided using the ManifestInfo's id
323
+ * @returns {Promise<{manifestInfo: ManifestInfo, libraryArtifactInfo: ArtifactInfo}> }
324
+ */
310
325
async function processManifestAndGetArtifactInfo ( libraryManifest , name ) {
311
326
const manifestInfo = await processManifest ( libraryManifest ) ;
312
327
name = name || manifestInfo . id ;
@@ -340,21 +355,23 @@ const processLibraryInfo = async (libraryInfo) => {
340
355
return getManifestPath ( libraryInfo . libraryManifest . getPath ( ) , embed ) ;
341
356
} ) ;
342
357
// e.g. manifest resource with lib/x/sub/manifest.json
343
- const relevantManifests = libraryInfo . manifestResources . filter ( ( manifestResource ) => {
358
+ let embeddedManifests = libraryInfo . embeddedManifests || [ ] ;
359
+ embeddedManifests = embeddedManifests . filter ( ( manifestResource ) => {
344
360
return embeddedPaths . includes ( manifestResource . getPath ( ) ) ;
345
361
} ) ;
346
362
347
363
// get all embedded manifests
348
- const embeddedManifestPromises = relevantManifests . map ( async ( relevantManifest ) => {
364
+ const embeddedManifestPromises = embeddedManifests . map ( async ( embeddedManifest ) => {
349
365
const { manifestInfo : embeddedManifestInfo , libraryArtifactInfo : embeddedArtifactInfo } =
350
- await processManifestAndGetArtifactInfo ( relevantManifest ) ;
366
+ await processManifestAndGetArtifactInfo ( embeddedManifest ) ;
351
367
352
368
const componentName = embeddedManifestInfo . id ;
353
369
354
- const fullManifestPath = posixPath . dirname ( relevantManifest . getPath ( ) ) ;
355
- const libraryPathPrefix = posixPath . dirname ( libraryInfo . libraryManifest . getPath ( ) ) ;
370
+ const embeddedManifestDirName = posixPath . dirname ( embeddedManifest . getPath ( ) ) ;
371
+ const libraryManifestDirName = posixPath . dirname ( libraryInfo . libraryManifest . getPath ( ) ) ;
356
372
357
- if ( isBundledWithLibrary ( embeddedManifestInfo . embeddedBy , fullManifestPath , libraryPathPrefix + "/" ) ) {
373
+ if ( isBundledWithLibrary ( embeddedManifestInfo . embeddedBy , embeddedManifestDirName ,
374
+ libraryManifestDirName + "/" ) ) {
358
375
bundledComponents . add ( componentName ) ;
359
376
}
360
377
return embeddedArtifactInfo ;
@@ -376,7 +393,7 @@ const processLibraryInfo = async (libraryInfo) => {
376
393
* @property {string } version The library version, e.g. "1.0.0"
377
394
* @property {module:@ui5/fs.Resource } libraryManifest library manifest resource,
378
395
* e.g. resource with path "lib/x/manifest.json"
379
- * @property {module:@ui5/fs.Resource[] } manifestResources list of embedded manifest resources,
396
+ * @property {module:@ui5/fs.Resource[] } embeddedManifests list of embedded manifest resources,
380
397
* e.g. resource with path "lib/x/sub/manifest.json"
381
398
*/
382
399
@@ -395,7 +412,7 @@ const processLibraryInfo = async (libraryInfo) => {
395
412
* name: "lib.x",
396
413
* version: "1.0.0",
397
414
* libraryManifest: module:@ui 5/fs.Resource,
398
- * manifestResources : module:@ui5/fs.Resource[]
415
+ * embeddedManifests : module:@ui5/fs.Resource[]
399
416
* }
400
417
* </pre>
401
418
* @returns {Promise<module:@ui5/fs.Resource[]> } Promise resolving with an array containing the versionInfo resource
@@ -416,7 +433,7 @@ module.exports = async function({options}) {
416
433
const dependencyInfoMap = new Map ( ) ;
417
434
418
435
419
- // gather all manifestHints
436
+ // process library infos
420
437
const librariesPromises = options . libraryInfos . map ( ( libraryInfo ) => {
421
438
return processLibraryInfo ( libraryInfo ) ;
422
439
} ) ;
0 commit comments