* * @param {string} moduleName module name * @param {ModuleInfo} info * @param {@ui5/fs/Resource} resource * @returns {Promise }
(moduleName, info, resource)
| 447 | * @returns {Promise<boolean>} |
| 448 | */ |
| 449 | async writePreloadModule(moduleName, info, resource) { |
| 450 | const outW = this.outW; |
| 451 | |
| 452 | if ( /\.js$/.test(moduleName) && (info == null || !info.requiresTopLevelScope) ) { |
| 453 | outW.writeln(`function(){`); |
| 454 | // The module should be written to a new line in order for dev-tools to map breakpoints to it |
| 455 | outW.ensureNewLine(); |
| 456 | let moduleContent = (await resource.buffer()).toString(); |
| 457 | moduleContent = removeHashbang(moduleContent); |
| 458 | if (this.options.sourceMap) { |
| 459 | let moduleSourceMap; |
| 460 | ({moduleContent, moduleSourceMap} = |
| 461 | await this.getSourceMapForModule({ |
| 462 | moduleName, |
| 463 | moduleContent, |
| 464 | resourcePath: resource.getPath() |
| 465 | })); |
| 466 | |
| 467 | this.addSourceMap(moduleName, moduleSourceMap); |
| 468 | } |
| 469 | outW.write(moduleContent); |
| 470 | this.exportGlobalNames(info); |
| 471 | outW.ensureNewLine(); |
| 472 | outW.write(`}`); |
| 473 | } else if ( /\.js$/.test(moduleName) /* implicitly: && info != null && info.requiresTopLevelScope */ ) { |
| 474 | log.warn( |
| 475 | `Module ${moduleName} requires top level scope and can only be embedded as a string (requires 'eval')`); |
| 476 | let moduleContent = (await resource.buffer()).toString(); |
| 477 | moduleContent = removeHashbang(moduleContent); |
| 478 | if (this.options.sourceMap) { |
| 479 | // We are actually not interested in the source map this module might contain, |
| 480 | // but we should make sure to remove any "sourceMappingURL" from the module content before |
| 481 | // writing it to the bundle. Otherwise browser dev-tools might create unnecessary |
| 482 | // (and likely incorrect) requests for any referenced .map files |
| 483 | ({moduleContent} = |
| 484 | await this.getSourceMapForModule({ |
| 485 | moduleName, |
| 486 | moduleContent, |
| 487 | resourcePath: resource.getPath() |
| 488 | })); |
| 489 | } |
| 490 | outW.write( makeStringLiteral(moduleContent) ); |
| 491 | } else if ( /\.html$/.test(moduleName) ) { |
| 492 | const fileContent = (await resource.buffer()).toString(); |
| 493 | outW.write( makeStringLiteral( fileContent ) ); |
| 494 | } else if ( /\.json$/.test(moduleName) ) { |
| 495 | let fileContent = (await resource.buffer()).toString(); |
| 496 | if ( this.optimize ) { |
| 497 | try { |
| 498 | fileContent = JSON.stringify( JSON.parse( fileContent) ); |
| 499 | } catch (e) { |
| 500 | log.verbose(`Failed to parse JSON file ${moduleName}. Ignoring error, skipping compression.`); |
| 501 | log.verbose(e); |
| 502 | } |
| 503 | } |
| 504 | outW.write(makeStringLiteral(fileContent)); |
| 505 | } else if ( /\.xml$/.test(moduleName) ) { |
| 506 | let fileContent = (await resource.buffer()).toString(); |
no test coverage detected