Skip to content

Commit 4bda728

Browse files
authored
[BREAKING] Bundling: Enforce usage of sap.ui.predefine instead function wrappers (#1021)
Up until UI5 Tooling v3, the bundle option "usePredefineCalls" defaults to "false" and has to be activated explicitly in a custom bundle configuration. For default bundles, such as Component-preload or self-contained bundle (sap-ui-custom.js), there is no way to use the option apart from re-defining the whole bundle via custom bundle definition. With UI5 Tooling v4 bundles are generated with the usage sap.ui.predefine calls instead of the former default function wrapper. This leads to smaller bundle sizes and less overhead at runtime. As the option only affects the internal handling of bundling without affecting the actual users, the option is removed completely, instead of just changing the default value of the option. Documentation update covered in UI5/cli#957. JIRA: CPOUI5FOUNDATION-760 BREAKING CHANGE: Created bundles use sap.ui.predefine instead function wrappers. For projects this is a compatible change. Only the produced bundle content changes.
1 parent 9040875 commit 4bda728

File tree

89 files changed

+212
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+212
-412
lines changed

lib/lbt/bundle/Builder.js

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -375,52 +375,50 @@ class BundleBuilder {
375375
}
376376

377377
async rewriteAMDModules(sequence) {
378-
if ( this.options.usePredefineCalls ) {
379-
const outW = this.outW;
380-
381-
const remaining = [];
382-
for ( const moduleName of sequence ) {
383-
if ( /\.js$/.test(moduleName) ) {
384-
// console.log("Processing " + moduleName);
385-
const resource = await this.pool.findResourceWithInfo(moduleName);
386-
let moduleContent = (await resource.buffer()).toString();
387-
let moduleSourceMap;
388-
if (this.options.sourceMap) {
389-
({moduleContent, moduleSourceMap} =
390-
await this.getSourceMapForModule({
391-
moduleName,
392-
moduleContent,
393-
resourcePath: resource.getPath()
394-
}));
395-
}
378+
const outW = this.outW;
396379

397-
const rewriteRes = await rewriteDefine({
398-
moduleName, moduleContent, moduleSourceMap
399-
});
400-
if (rewriteRes) {
401-
const {moduleContent, moduleSourceMap} = rewriteRes;
402-
outW.startSegment(moduleName);
403-
outW.ensureNewLine();
404-
if (moduleSourceMap) {
405-
this.addSourceMap(moduleName, moduleSourceMap);
406-
}
407-
outW.write(moduleContent);
408-
outW.ensureNewLine();
409-
const compressedSize = outW.endSegment();
410-
log.verbose(
411-
` ${moduleName} (${resource.info != null ? resource.info.size : -1},${compressedSize})`);
412-
} else {
413-
// keep unprocessed modules
414-
remaining.push(moduleName);
380+
const remaining = [];
381+
for ( const moduleName of sequence ) {
382+
if ( /\.js$/.test(moduleName) ) {
383+
// console.log("Processing " + moduleName);
384+
const resource = await this.pool.findResourceWithInfo(moduleName);
385+
let moduleContent = (await resource.buffer()).toString();
386+
let moduleSourceMap;
387+
if (this.options.sourceMap) {
388+
({moduleContent, moduleSourceMap} =
389+
await this.getSourceMapForModule({
390+
moduleName,
391+
moduleContent,
392+
resourcePath: resource.getPath()
393+
}));
394+
}
395+
396+
const rewriteRes = await rewriteDefine({
397+
moduleName, moduleContent, moduleSourceMap
398+
});
399+
if (rewriteRes) {
400+
const {moduleContent, moduleSourceMap} = rewriteRes;
401+
outW.startSegment(moduleName);
402+
outW.ensureNewLine();
403+
if (moduleSourceMap) {
404+
this.addSourceMap(moduleName, moduleSourceMap);
415405
}
406+
outW.write(moduleContent);
407+
outW.ensureNewLine();
408+
const compressedSize = outW.endSegment();
409+
log.verbose(
410+
` ${moduleName} (${resource.info != null ? resource.info.size : -1},${compressedSize})`);
416411
} else {
417412
// keep unprocessed modules
418413
remaining.push(moduleName);
419414
}
415+
} else {
416+
// keep unprocessed modules
417+
remaining.push(moduleName);
420418
}
421-
422-
Array.prototype.splice.apply(sequence, [0, sequence.length].concat(remaining));
423419
}
420+
421+
Array.prototype.splice.apply(sequence, [0, sequence.length].concat(remaining));
424422
}
425423

426424
afterWriteFunctionPreloadSection() {

lib/processors/bundlers/moduleBundler.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
101101
* with an optimization marker
102102
* @property {boolean} [addTryCatchRestartWrapper=false] Whether to wrap bootable bundles with
103103
* a try/catch to filter out "Restart" errors
104-
* @property {boolean} [usePredefineCalls=false] If set to 'true', sap.ui.predefine is used for UI5 modules
105104
* @property {number} [numberOfParts=1] The number of parts the module bundle should be splitted
106105
* @property {boolean} [ignoreMissingModules=false] When searching for modules which are optional for further
107106
* processing, do not throw in case they are missing
@@ -144,7 +143,6 @@ export default function({resources, options: {bundleDefinition, bundleOptions, m
144143
sourceMap: true,
145144
decorateBootstrapModule: false,
146145
addTryCatchRestartWrapper: false,
147-
usePredefineCalls: false,
148146
numberOfParts: 1,
149147
ignoreMissingModules: false
150148
}, bundleOptions);

lib/tasks/bundlers/generateLibraryPreload.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ function getModuleBundlerOptions(config) {
164164
moduleBundlerOptions.bundleOptions = {
165165
optimize: config.preload,
166166
decorateBootstrapModule: config.preload,
167-
addTryCatchRestartWrapper: config.preload,
168-
usePredefineCalls: config.preload
167+
addTryCatchRestartWrapper: config.preload
169168
};
170169

171170
moduleBundlerOptions.bundleDefinition = getSapUiCoreBunDef(config.name, config.filters, config.preload);
@@ -390,7 +389,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
390389
bundleDefinition: getBundleDefinition(libraryNamespace, excludes),
391390
bundleOptions: {
392391
optimize: true,
393-
usePredefineCalls: true,
394392
ignoreMissingModules: true
395393
}
396394
},
@@ -401,7 +399,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
401399
bundleDefinition: getDesigntimeBundleDefinition(libraryNamespace),
402400
bundleOptions: {
403401
optimize: true,
404-
usePredefineCalls: true,
405402
ignoreMissingModules: true,
406403
skipIfEmpty: true
407404
}
@@ -413,7 +410,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
413410
bundleDefinition: getSupportFilesBundleDefinition(libraryNamespace),
414411
bundleOptions: {
415412
optimize: false,
416-
usePredefineCalls: true,
417413
ignoreMissingModules: true,
418414
skipIfEmpty: true
419415
}

test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js

Lines changed: 5 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.a/dest-self/resources/sap-ui-custom.js

Lines changed: 6 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.a/dest-self/resources/sap-ui-custom.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.g/cachebuster/Component-preload.js

Lines changed: 3 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/expected/build/application.g/cachebuster/Component-preload.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)