From 5b13014f6863dc7976cd05319d1f7c0c1888e408 Mon Sep 17 00:00:00 2001 From: Tommy Vinh Lam Date: Tue, 2 Apr 2019 10:34:04 +0200 Subject: [PATCH] [FIX] Generate sap-ui-custom-dbg.js for self-contained build --- .../bundlers/generateStandaloneAppBundle.js | 108 ++++++++++++------ .../standalone/resources/sap-ui-custom-dbg.js | 3 + .../standalone/resources/sap-ui-custom.js | 7 +- .../bundlers/generateStandaloneAppBundle.js | 34 +++++- 4 files changed, 109 insertions(+), 43 deletions(-) create mode 100644 test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.js diff --git a/lib/tasks/bundlers/generateStandaloneAppBundle.js b/lib/tasks/bundlers/generateStandaloneAppBundle.js index 2a09bcc64..5a812aa73 100644 --- a/lib/tasks/bundlers/generateStandaloneAppBundle.js +++ b/lib/tasks/bundlers/generateStandaloneAppBundle.js @@ -1,6 +1,49 @@ const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateStandaloneAppBundle"); const moduleBundler = require("../../processors/bundlers/moduleBundler"); +function getBundleDefinition(config) { + const bundleDefinition = { + name: config.name, + defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"], + sections: [] + }; + + // add raw section + bundleDefinition.sections.push({ + // include all 'raw' modules that are needed for the UI5 loader + mode: "raw", + filters: config.filters, + resolve: true, // dependencies for raw modules are taken from shims in .library files + sort: true, // topological sort on raw modules is mandatory + declareModules: false + }); + + // preload section is only relevant for sap-ui-custom.js + if (config.preloadSection) { + bundleDefinition.sections.push({ + mode: "preload", + filters: [ + `${config.namespace|| ""}/`, + `!${config.namespace || ""}/test/`, + `!${config.namespace || ""}/*.html`, + "sap/ui/core/Core.js" + ], + resolve: true, + resolveConditional: true, + renderer: true + }); + } + + bundleDefinition.sections.push({ + mode: "require", + filters: [ + "sap/ui/core/Core.js" + ] + }); + + return bundleDefinition; +} + /** * Task for bundling standalone applications. * @@ -38,44 +81,33 @@ module.exports = async function({workspace, dependencies, options}) { filters = ["jquery.sap.global.js"]; } - const processedResources = await moduleBundler({ - resources, - options: { - bundleDefinition: { - name: "sap-ui-custom.js", - defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"], - sections: [ - { - // include all 'raw' modules that are needed for the UI5 loader - mode: "raw", - filters, - resolve: true, // dependencies for raw modules are taken from shims in .library files - sort: true, // topological sort on raw modules is mandatory - declareModules: false - }, - { - mode: "preload", - filters: [ - `${options.namespace || ""}/`, - `!${options.namespace || ""}/test/`, - `!${options.namespace || ""}/*.html`, - "sap/ui/core/Core.js" - ], - resolve: true, - resolveConditional: true, - renderer: true - }, - // finally require and execute sap/ui/core/Core - { - mode: "require", - filters: [ - "sap/ui/core/Core.js" - ] - } - ] + await Promise.all([ + moduleBundler({ + resources, + options: { + bundleDefinition: getBundleDefinition({ + name: "sap-ui-custom.js", + filters, + namespace: options.namespace, + preloadSection: true + }) } - } + }), + moduleBundler({ + resources, + options: { + bundleDefinition: getBundleDefinition({ + name: "sap-ui-custom-dbg.js", + filters, + namespace: options.namespace + }), + bundleOptions: { + optimize: false + } + } + }) + ]).then((results) => { + const bundles = Array.prototype.concat.apply([], results); + return Promise.all(bundles.map((resource) => workspace.write(resource))); }); - - await Promise.all(processedResources.map((resource) => workspace.write(resource))); }; diff --git a/test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.js b/test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.js new file mode 100644 index 000000000..827fe1cab --- /dev/null +++ b/test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.js @@ -0,0 +1,3 @@ +sap.ui.requireSync("sap/ui/core/Core"); +// as this module contains the Core, we ensure that the Core has been booted +sap.ui.getCore().boot && sap.ui.getCore().boot(); diff --git a/test/expected/build/application.b/standalone/resources/sap-ui-custom.js b/test/expected/build/application.b/standalone/resources/sap-ui-custom.js index 76dc12a67..5da6683a2 100644 --- a/test/expected/build/application.b/standalone/resources/sap-ui-custom.js +++ b/test/expected/build/application.b/standalone/resources/sap-ui-custom.js @@ -9,5 +9,10 @@ jQuery.sap.registerPreloadedModules({ "id1/i18n/i18n.properties":'title=app-i18n', "id1/i18n/i18n_de.properties":'title=app-i18n_de', "id1/i18n/l10n.properties":'title=app-i18n-wrong', - "id1/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"id1","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' + "id1/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"id1","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}', + "sap/ui/core/Core.js":function(){ +} }}); +sap.ui.requireSync("sap/ui/core/Core"); +// as this module contains the Core, we ensure that the Core has been booted +sap.ui.getCore().boot && sap.ui.getCore().boot(); diff --git a/test/lib/tasks/bundlers/generateStandaloneAppBundle.js b/test/lib/tasks/bundlers/generateStandaloneAppBundle.js index 645bb8d31..f59e93e65 100644 --- a/test/lib/tasks/bundlers/generateStandaloneAppBundle.js +++ b/test/lib/tasks/bundlers/generateStandaloneAppBundle.js @@ -46,7 +46,7 @@ test.serial("execute module bundler and write results", async (t) => { }; await generateStandaloneAppBundle(params); - t.deepEqual(t.context.moduleBundlerStub.callCount, 1, "moduleBundler should be called once"); + t.deepEqual(t.context.moduleBundlerStub.callCount, 2, "moduleBundler should be called once"); const {resources, options} = t.context.moduleBundlerStub.getCall(0).args[0]; t.deepEqual(resources.length, 4, "moduleBundler got supplied with 4 resources"); @@ -83,7 +83,7 @@ test.serial("execute module bundler and write results without namespace", async }; await generateStandaloneAppBundle(params); - t.deepEqual(t.context.moduleBundlerStub.callCount, 1, "moduleBundler should be called once"); + t.deepEqual(t.context.moduleBundlerStub.callCount, 2, "moduleBundler should be called once"); const {resources, options} = t.context.moduleBundlerStub.getCall(0).args[0]; t.deepEqual(resources.length, 4, "moduleBundler got supplied with 4 resources"); @@ -122,7 +122,7 @@ test.serial("execute module bundler and write results in evo mode", async (t) => }; await generateStandaloneAppBundle(params); - t.deepEqual(t.context.moduleBundlerStub.callCount, 1, "moduleBundler should be called once"); + t.deepEqual(t.context.moduleBundlerStub.callCount, 2, "moduleBundler should be called once"); const {resources, options} = t.context.moduleBundlerStub.getCall(0).args[0]; t.deepEqual(resources.length, 4, "moduleBundler got supplied with 4 resources"); @@ -144,6 +144,7 @@ const recursive = require("recursive-readdir"); const ui5Builder = require("../../../../"); const builder = ui5Builder.builder; const applicationBPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.b"); +const sapUiCorePath = path.join(__dirname, "..", "..", "..", "fixtures", "sap.ui.core"); const findFiles = (folder) => { return new Promise((resolve, reject) => { @@ -176,7 +177,7 @@ test("integration: build application.b standalone", async (t) => { assert.directoryDeepEqual(destPath, expectedPath, "Result directory structure correct"); // Check for all file contents - t.deepEqual(expectedFiles.length, 10, "10 files are expected"); + t.deepEqual(expectedFiles.length, 11, "11 files are expected"); expectedFiles.forEach((expectedFile) => { const relativeFile = path.relative(expectedPath, expectedFile); const destFile = path.join(destPath, relativeFile); @@ -190,6 +191,31 @@ const applicationBTree = { "version": "1.0.0", "path": applicationBPath, "dependencies": [ + { + "id": "sap.ui.core", + "version": "1.0.0", + "path": sapUiCorePath, + "dependencies": [], + "_level": 1, + "specVersion": "0.1", + "type": "library", + "metadata": { + "name": "sap.ui.core", + "copyright": "Some fancy copyright" + }, + "resources": { + "configuration": { + "paths": { + "src": "main/src", + "test": "main/test" + } + }, + "pathMappings": { + "/resources/": "main/src", + "/test-resources/": "main/test" + } + } + }, { "id": "library.d", "version": "1.0.0",