Skip to content

Commit ca3e74d

Browse files
d3xter666KlattGmatz3
authored
[ui5-builder][INTERNAL] Async bundling for require section (#1048)
Require's section `async` flag has different default values based on the specVersion. However, async require is now build by default. We need to explicitly default `async=false` for specVersions lower than 4.0 --------- Co-authored-by: Günter Klatt <57760635+KlattG@users.noreply.github.com> Co-authored-by: Matthias Oßwald <mat.osswald@sap.com>
1 parent 3602eff commit ca3e74d

16 files changed

Lines changed: 54 additions & 29 deletions

packages/builder/lib/processors/bundlers/moduleBundler.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
3333
* the ui5loader is available.
3434
* </li>
3535
* <li>
36-
* <code>require</code>: A 'require' section is transformed into a sequence of jQuery.sap.require calls. The
37-
* list will be resolved like an include pattern list in any of the other sections and for each of the resolved
38-
* modules, a jQuery.sap.require will be created. In case the ui5loader is available, 'sap.ui.requireSync' is
39-
* used instead.
36+
* <code>require</code>: A `require` section is transformed into a `sap.ui.require` call with all the dependencies
37+
* resolved. This module comes with an `async` flag. When set to false, the modules
38+
* are loaded using `sap.ui.requireSync` instead of `sap.ui.require`.
39+
* **Note:** The `sap.ui.requireSync` API is not available in UI5 version 2.x.
4040
* </li>
4141
* <li>
4242
* <code>bundleInfo</code>: A 'bundleInfo' section describes the content of another named bundle. This information
@@ -75,6 +75,11 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
7575
* @property {boolean} [declareRawModules=false] Whether raw modules should be declared after jQuery.sap.global
7676
* became available. With the usage of the ui5loader, this flag should be set to 'false'
7777
* @property {boolean} [sort=true] Whether the modules should be sorted by their dependencies
78+
* @property {boolean} [async=true] Whether the `require` section of the module should be loaded asynchronously.
79+
* When set to true, the modules are loaded using a single `sap.ui.require` call instead of multiple
80+
* `sap.ui.requireSync` calls.
81+
* The latter API is not available in UI5 version 2.x.
82+
* **Note:** This property is available only for `mode=require`.
7883
*/
7984

8085
/* eslint-disable max-len */

packages/builder/lib/tasks/bundlers/utils/applyDefaultsToBundleDefinition.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ export function applyDefaultsToBundleDefinition(bundleDefinition, taskUtil) {
2020
// Since specVersion: 4.0 "require" section starts loading asynchronously.
2121
// If specVersion cannot be determined, the latest spec is taken into account.
2222
// This is a breaking change in specVersion: 4.0
23-
if (section.mode === "require" && (!taskUtil || taskUtil.getProject().getSpecVersion().gte("4.0"))) {
24-
defaultValues.async = true;
23+
if (section.mode === "require") {
24+
// Builder.js already treats missing async flag as truthy value and builds asynchronously by default
25+
26+
if (taskUtil && taskUtil.getProject().getSpecVersion().lt("4.0")) {
27+
defaultValues.async = false;
28+
}
2529
}
2630

2731
return Object.assign(defaultValues, section);

packages/builder/test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.js

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

packages/builder/test/expected/build/application.b/standalone/resources/sap-ui-custom-dbg.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.

packages/builder/test/expected/build/application.b/standalone/resources/sap-ui-custom.js

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

packages/builder/test/expected/build/application.b/standalone/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.

packages/builder/test/expected/build/sap.ui.core/preload/resources/sap-ui-core-dbg.js

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

packages/builder/test/expected/build/sap.ui.core/preload/resources/sap-ui-core-dbg.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.

packages/builder/test/expected/build/sap.ui.core/preload/resources/sap-ui-core-nojQuery-dbg.js

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

packages/builder/test/expected/build/sap.ui.core/preload/resources/sap-ui-core-nojQuery-dbg.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)