Skip to content

Commit

Permalink
[INTERNAL] Async bundling for require section (#1048)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent 2337bf5 commit 63a9e82
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 29 deletions.
13 changes: 9 additions & 4 deletions lib/processors/bundlers/moduleBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
* the ui5loader is available.
* </li>
* <li>
* <code>require</code>: A 'require' section is transformed into a sequence of jQuery.sap.require calls. The
* list will be resolved like an include pattern list in any of the other sections and for each of the resolved
* modules, a jQuery.sap.require will be created. In case the ui5loader is available, 'sap.ui.requireSync' is
* used instead.
* <code>require</code>: A `require` section is transformed into a `sap.ui.require` call with all the dependencies
* resolved. This module comes with an `async` flag. When set to false, the modules
* are loaded using `sap.ui.requireSync` instead of `sap.ui.require`.
* **Note:** The `sap.ui.requireSync` API is not available in UI5 version 2.x.
* </li>
* <li>
* <code>bundleInfo</code>: A 'bundleInfo' section describes the content of another named bundle. This information
Expand Down Expand Up @@ -75,6 +75,11 @@ const log = getLogger("builder:processors:bundlers:moduleBundler");
* @property {boolean} [declareRawModules=false] Whether raw modules should be declared after jQuery.sap.global
* became available. With the usage of the ui5loader, this flag should be set to 'false'
* @property {boolean} [sort=true] Whether the modules should be sorted by their dependencies
* @property {boolean} [async=true] Whether the `require` section of the module should be loaded asynchronously.
* When set to true, the modules are loaded using a single `sap.ui.require` call instead of multiple
* `sap.ui.requireSync` calls.
* The latter API is not available in UI5 version 2.x.
* **Note:** This property is available only for `mode=require`.
*/

/* eslint-disable max-len */
Expand Down
8 changes: 6 additions & 2 deletions lib/tasks/bundlers/utils/applyDefaultsToBundleDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ export function applyDefaultsToBundleDefinition(bundleDefinition, taskUtil) {
// Since specVersion: 4.0 "require" section starts loading asynchronously.
// If specVersion cannot be determined, the latest spec is taken into account.
// This is a breaking change in specVersion: 4.0
if (section.mode === "require" && (!taskUtil || taskUtil.getProject().getSpecVersion().gte("4.0"))) {
defaultValues.async = true;
if (section.mode === "require") {
// Builder.js already treats missing async flag as truthy value and builds asynchronously by default

if (taskUtil && taskUtil.getProject().getSpecVersion().lt("4.0")) {
defaultValues.async = false;
}
}

return Object.assign(defaultValues, section);
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.

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.

12 changes: 8 additions & 4 deletions test/lib/tasks/bundlers/generateLibraryPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ test.serial("generateLibraryPreload for sap.ui.core (w/o ui5loader.js)", async (
filters: [
"sap/ui/core/Core.js"
],
async: true,
resolve: false,
sort: true,
resolveConditional: false,
Expand Down Expand Up @@ -257,7 +256,6 @@ test.serial("generateLibraryPreload for sap.ui.core (w/o ui5loader.js)", async (
filters: [
"sap/ui/core/Core.js"
],
async: true,
declareRawModules: false,
renderer: false,
resolve: false,
Expand Down Expand Up @@ -324,7 +322,6 @@ test.serial("generateLibraryPreload for sap.ui.core (w/o ui5loader.js)", async (
filters: [
"sap/ui/core/Core.js"
],
async: true,
declareRawModules: false,
renderer: false,
resolve: false,
Expand Down Expand Up @@ -380,7 +377,6 @@ test.serial("generateLibraryPreload for sap.ui.core (w/o ui5loader.js)", async (
filters: [
"sap/ui/core/Core.js"
],
async: true,
declareRawModules: false,
renderer: false,
resolve: false,
Expand Down Expand Up @@ -582,6 +578,7 @@ test.serial("generateLibraryPreload for sap.ui.core (/w ui5loader.js)", async (t
resolveConditional: false,
renderer: false,
declareRawModules: false,
async: false
}
]
},
Expand Down Expand Up @@ -622,6 +619,7 @@ test.serial("generateLibraryPreload for sap.ui.core (/w ui5loader.js)", async (t
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down Expand Up @@ -690,6 +688,7 @@ test.serial("generateLibraryPreload for sap.ui.core (/w ui5loader.js)", async (t
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down Expand Up @@ -746,6 +745,7 @@ test.serial("generateLibraryPreload for sap.ui.core (/w ui5loader.js)", async (t
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down Expand Up @@ -994,6 +994,7 @@ test.serial("generateLibraryPreload for sap.ui.core with old specVersion defined
resolveConditional: false,
renderer: false,
declareRawModules: false,
async: false
}
]
},
Expand Down Expand Up @@ -1034,6 +1035,7 @@ test.serial("generateLibraryPreload for sap.ui.core with old specVersion defined
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down Expand Up @@ -1102,6 +1104,7 @@ test.serial("generateLibraryPreload for sap.ui.core with old specVersion defined
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down Expand Up @@ -1158,6 +1161,7 @@ test.serial("generateLibraryPreload for sap.ui.core with old specVersion defined
resolve: false,
resolveConditional: false,
sort: true,
async: false
}
]
},
Expand Down
Loading

0 comments on commit 63a9e82

Please sign in to comment.