Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Add bundling sap-ui-core-noJQuery.js and sap-ui-core-noJQuery-dbg.js #227

Merged
merged 7 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 82 additions & 59 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,76 @@ function getBundleDefinition(namespace) {
};
}

function getModuleBundlerOptions(config) {
const moduleBundlerOptions = {};

// required in sap-ui-core-nojQuery.js and sap-ui-core-nojQuery-dbg.js
const providedSection = {
mode: "provided",
filters: [
"jquery-ui-core.js",
"jquery-ui-datepicker.js",
"jquery-ui-position.js",
"sap/ui/thirdparty/jquery.js",
"sap/ui/thirdparty/jquery/*",
"sap/ui/thirdparty/jqueryui/*"
]
};

moduleBundlerOptions.bundleOptions = {
optimize: config.preload,
decorateBootstrapModule: config.preload,
addTryCatchRestartWrapper: config.preload,
usePredefineCalls: config.preload
};

moduleBundlerOptions.bundleDefinition = getSapUiCoreBunDef(config.name, config.filters, config.preload);

if (config.provided) {
moduleBundlerOptions.bundleDefinition.sections.unshift(providedSection);
}

return moduleBundlerOptions;
}

function getSapUiCoreBunDef(name, filters, preload) {
const bundleDefinition = {
name,
sections: []
};

// add raw section
bundleDefinition.sections.push({
// 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
});

if (preload) {
// add preload section
bundleDefinition.sections.push({
mode: "preload",
filters: [
"sap/ui/core/Core.js"
],
resolve: true
});
}

// add require section
bundleDefinition.sections.push({
mode: "require",
filters: [
"sap/ui/core/Core.js"
]
});

return bundleDefinition;
}

/**
* Task for library bundling.
*
Expand All @@ -84,6 +154,7 @@ module.exports = function({workspace, dependencies, options}) {
name: `libraryBundler - prioritize workspace over dependencies: ${options.projectName}`,
readers: [workspace, dependencies]
});

return combo.byGlob("/**/*.{js,json,xml,html,properties,library}").then((resources) => {
// Find all libraries and create a library-preload.js bundle

Expand All @@ -110,69 +181,21 @@ module.exports = function({workspace, dependencies, options}) {

p = Promise.all([
moduleBundler({
options: {
bundleOptions: {
optimize: true,
decorateBootstrapModule: true,
addTryCatchRestartWrapper: true,
usePredefineCalls: true
},
bundleDefinition: {
name: "sap-ui-core.js",
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: [
"sap/ui/core/Core.js"
],
resolve: true
},
{
mode: "require",
filters: [
"sap/ui/core/Core.js"
]
}
]
}
},
options: getModuleBundlerOptions({name: "sap-ui-core.js", filters, preload: true}),
resources
}),
moduleBundler({
options: {
bundleOptions: {
optimize: false
},
bundleDefinition: {
name: "sap-ui-core-dbg.js",
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: "require",
filters: [
"sap/ui/core/Core.js"
]
}
]
}
},
options: getModuleBundlerOptions({name: "sap-ui-core-dbg.js", filters, preload: false}),
resources
})
}),
moduleBundler({
options: getModuleBundlerOptions({name: "sap-ui-core-nojQuery.js", filters, preload: true, provided: true}),
resources
}),
moduleBundler({
options: getModuleBundlerOptions({name: "sap-ui-core-nojQuery-dbg.js", filters, preload: false, provided: true}),
resources
}),
]).then((results) => {
const bundles = Array.prototype.concat.apply([], results);
return Promise.all(bundles.map((bundle) => workspace.write(bundle)));
Expand Down
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
@@ -0,0 +1,9 @@
jQuery.sap.registerPreloadedModules({
"version":"2.0",
"modules":{
"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();
2 changes: 1 addition & 1 deletion test/lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test("integration: build sap.ui.core with library preload", async (t) => {
assert.directoryDeepEqual(destPath, expectedPath);

// Check for all file contents
t.deepEqual(expectedFiles.length, 7, "7 files are expected");
t.deepEqual(expectedFiles.length, 9, "9 files are expected");
expectedFiles.forEach((expectedFile) => {
const relativeFile = path.relative(expectedPath, expectedFile);
const destFile = path.join(destPath, relativeFile);
Expand Down