Skip to content

Commit

Permalink
[FIX] Generate sap-ui-custom-dbg.js for self-contained build (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
devtomtom committed Apr 2, 2019
1 parent 732df59 commit d769d98
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 43 deletions.
108 changes: 70 additions & 38 deletions lib/tasks/bundlers/generateStandaloneAppBundle.js
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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)));
};
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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();
34 changes: 30 additions & 4 deletions test/lib/tasks/bundlers/generateStandaloneAppBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand All @@ -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",
Expand Down

0 comments on commit d769d98

Please sign in to comment.