Skip to content

Commit

Permalink
[BREAKING] Bundling: Enforce usage of sap.ui.predefine instead functi…
Browse files Browse the repository at this point in the history
…on 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
SAP/ui5-tooling#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.
  • Loading branch information
flovogt authored May 28, 2024
1 parent 9040875 commit 4bda728
Show file tree
Hide file tree
Showing 89 changed files with 212 additions and 412 deletions.
74 changes: 36 additions & 38 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,52 +375,50 @@ class BundleBuilder {
}

async rewriteAMDModules(sequence) {
if ( this.options.usePredefineCalls ) {
const outW = this.outW;

const remaining = [];
for ( const moduleName of sequence ) {
if ( /\.js$/.test(moduleName) ) {
// console.log("Processing " + moduleName);
const resource = await this.pool.findResourceWithInfo(moduleName);
let moduleContent = (await resource.buffer()).toString();
let moduleSourceMap;
if (this.options.sourceMap) {
({moduleContent, moduleSourceMap} =
await this.getSourceMapForModule({
moduleName,
moduleContent,
resourcePath: resource.getPath()
}));
}
const outW = this.outW;

const rewriteRes = await rewriteDefine({
moduleName, moduleContent, moduleSourceMap
});
if (rewriteRes) {
const {moduleContent, moduleSourceMap} = rewriteRes;
outW.startSegment(moduleName);
outW.ensureNewLine();
if (moduleSourceMap) {
this.addSourceMap(moduleName, moduleSourceMap);
}
outW.write(moduleContent);
outW.ensureNewLine();
const compressedSize = outW.endSegment();
log.verbose(
` ${moduleName} (${resource.info != null ? resource.info.size : -1},${compressedSize})`);
} else {
// keep unprocessed modules
remaining.push(moduleName);
const remaining = [];
for ( const moduleName of sequence ) {
if ( /\.js$/.test(moduleName) ) {
// console.log("Processing " + moduleName);
const resource = await this.pool.findResourceWithInfo(moduleName);
let moduleContent = (await resource.buffer()).toString();
let moduleSourceMap;
if (this.options.sourceMap) {
({moduleContent, moduleSourceMap} =
await this.getSourceMapForModule({
moduleName,
moduleContent,
resourcePath: resource.getPath()
}));
}

const rewriteRes = await rewriteDefine({
moduleName, moduleContent, moduleSourceMap
});
if (rewriteRes) {
const {moduleContent, moduleSourceMap} = rewriteRes;
outW.startSegment(moduleName);
outW.ensureNewLine();
if (moduleSourceMap) {
this.addSourceMap(moduleName, moduleSourceMap);
}
outW.write(moduleContent);
outW.ensureNewLine();
const compressedSize = outW.endSegment();
log.verbose(
` ${moduleName} (${resource.info != null ? resource.info.size : -1},${compressedSize})`);
} else {
// keep unprocessed modules
remaining.push(moduleName);
}
} else {
// keep unprocessed modules
remaining.push(moduleName);
}

Array.prototype.splice.apply(sequence, [0, sequence.length].concat(remaining));
}

Array.prototype.splice.apply(sequence, [0, sequence.length].concat(remaining));
}

afterWriteFunctionPreloadSection() {
Expand Down
2 changes: 0 additions & 2 deletions lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
* with an optimization marker
* @property {boolean} [addTryCatchRestartWrapper=false] Whether to wrap bootable bundles with
* a try/catch to filter out "Restart" errors
* @property {boolean} [usePredefineCalls=false] If set to 'true', sap.ui.predefine is used for UI5 modules
* @property {number} [numberOfParts=1] The number of parts the module bundle should be splitted
* @property {boolean} [ignoreMissingModules=false] When searching for modules which are optional for further
* processing, do not throw in case they are missing
Expand Down Expand Up @@ -144,7 +143,6 @@ export default function({resources, options: {bundleDefinition, bundleOptions, m
sourceMap: true,
decorateBootstrapModule: false,
addTryCatchRestartWrapper: false,
usePredefineCalls: false,
numberOfParts: 1,
ignoreMissingModules: false
}, bundleOptions);
Expand Down
6 changes: 1 addition & 5 deletions lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ function getModuleBundlerOptions(config) {
moduleBundlerOptions.bundleOptions = {
optimize: config.preload,
decorateBootstrapModule: config.preload,
addTryCatchRestartWrapper: config.preload,
usePredefineCalls: config.preload
addTryCatchRestartWrapper: config.preload
};

moduleBundlerOptions.bundleDefinition = getSapUiCoreBunDef(config.name, config.filters, config.preload);
Expand Down Expand Up @@ -390,7 +389,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
bundleDefinition: getBundleDefinition(libraryNamespace, excludes),
bundleOptions: {
optimize: true,
usePredefineCalls: true,
ignoreMissingModules: true
}
},
Expand All @@ -401,7 +399,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
bundleDefinition: getDesigntimeBundleDefinition(libraryNamespace),
bundleOptions: {
optimize: true,
usePredefineCalls: true,
ignoreMissingModules: true,
skipIfEmpty: true
}
Expand All @@ -413,7 +410,6 @@ export default async function({workspace, taskUtil, options: {skipBundles = [],
bundleDefinition: getSupportFilesBundleDefinition(libraryNamespace),
bundleOptions: {
optimize: false,
usePredefineCalls: true,
ignoreMissingModules: true,
skipIfEmpty: true
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bda728

Please sign in to comment.