Skip to content

Commit

Permalink
[FIX] Revert "[INTERNAL] Remove implicit dependencies concept (#913)"
Browse files Browse the repository at this point in the history
This reverts commit 8caaa72.

While we did not expect the initial change to have any impact on
projects it has unfortunately caused a regression for application
projects that make use of custom bundles such as the ui5-evolution-apps
demo: https://github.com/SAP-samples/ui5-evolution-apps/tree/main/app-ui5

While ComponentAnalyzer still finds the application's root view (for
example sap.ui.demo.todo.view.App.view.xml), this will no longer cause
an implicit dependency to sap/ui/core/mvc/XMLView.js. Which is then
missing from the bundle.

Note that self-contained bundles are not affected in case of XML views,
since sap/ui/core/mvc/XMLView.js is already a dependency through the UI5
support tools.
  • Loading branch information
RandomByte committed Jul 19, 2023
1 parent 14388b8 commit 1043714
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 32 deletions.
12 changes: 12 additions & 0 deletions lib/lbt/analyzer/JSModuleAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import escope from "escope";
import {fromUI5LegacyName, fromRequireJSName, resolveRelativeRequireJSName} from "../utils/ModuleName.js";
import moduleInfo from "../resources/ModuleInfo.js";
const ModuleFormat = moduleInfo.Format;
import {MODULE__JQUERY_SAP_GLOBAL, MODULE__UI5LOADER_AUTOCONFIG} from "../UI5ClientConstants.js";
import {
findOwnProperty,
getLocation,
Expand Down Expand Up @@ -334,6 +335,17 @@ class JSModuleAnalyzer {
}
}

// depending on the used module APIs, add an implicit dependency to the loader entry module
if ( info.format === ModuleFormat.UI5_LEGACY ) {
info.addImplicitDependency(MODULE__JQUERY_SAP_GLOBAL);
} else if ( info.format === ModuleFormat.UI5_DEFINE ) {
// Note: the implicit dependency for sap.ui.define modules points to the standard UI5
// loader config module. A more general approach would be to add a dependency to the loader
// only, but then standard configuration would be missed by dependency resolution
// (to be clarified)
info.addImplicitDependency(MODULE__UI5LOADER_AUTOCONFIG);
}

if ( !bIsUi5Module ) {
// when there are no indicators for module APIs, mark the module as 'raw' module
info.rawModule = true;
Expand Down
4 changes: 4 additions & 0 deletions lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class XMLTemplateAnalyzer {
// console.log(result);
// clear();
if ( isFragment ) {
// all fragments implicitly depend on the fragment class
this.info.addImplicitDependency(FRAGMENT_MODULE);
this._analyzeNode(result);
} else {
// views require a special handling of the root node
Expand All @@ -194,6 +196,8 @@ class XMLTemplateAnalyzer {
}

_analyzeViewRootNode(node) {
this.info.addImplicitDependency(XMLVIEW_MODULE);

const controllerName = getAttribute(node, XMLVIEW_CONTROLLERNAME_ATTRIBUTE);
if ( controllerName ) {
this._addDependency( fromUI5LegacyName(controllerName, ".controller.js"), this.conditional );
Expand Down
18 changes: 17 additions & 1 deletion lib/lbt/resources/ModuleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
*/
const STRICT = 0;

/**
* An implicit dependency is also strict, but has not been declared. E.g. each UI5 module depends on
* jquery.sap.global.
*
* @private
*/
const IMPLICIT = 1;

/**
* A conditional dependency has to be resolved only under certain conditions that typically are
* checked at runtime.
Expand Down Expand Up @@ -104,7 +112,7 @@ class ModuleInfo {
// included already as a submodule.
// If the dependency was known already, update the kind
// only when the new kind is stronger than the current one.
// STRICT is stronger than CONDITIONAL
// STRICT is stronger than IMPLICIT, IMPLICIT is stronger than CONDITIONAL
if ( dependency &&
dependency !== this.name &&
this.subModules.indexOf(dependency) < 0 &&
Expand All @@ -113,6 +121,10 @@ class ModuleInfo {
}
}

addImplicitDependency(dependency) {
this._addDependency(dependency, IMPLICIT);
}

addDependency(dependency, conditional) {
this._addDependency(dependency, conditional ? CONDITIONAL : STRICT);
}
Expand Down Expand Up @@ -163,6 +175,10 @@ class ModuleInfo {
return this._dependencies[dependency] === CONDITIONAL;
}

isImplicitDependency(dependency) {
return this._dependencies[dependency] === IMPLICIT;
}

get name() {
return this._name;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/lbt/resources/ResourceCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ResourceCollector {
moduleInfo.dependencies.forEach((dep) => {
if ( moduleInfo.isConditionalDependency(dep) ) {
resourceInfo.condRequired.add(dep);
} else {
} else if ( !moduleInfo.isImplicitDependency(dep) ) {
resourceInfo.required.add(dep);
}
});
Expand Down Expand Up @@ -158,7 +158,7 @@ class ResourceCollector {
if (!resourceInfo.required.has(dep)) {
resourceInfo.condRequired.add(dep);
}
} else {
} else if ( !subModuleInfo.isImplicitDependency(dep) ) {
// Move module from condRequired to required
if (resourceInfo.condRequired.has(dep)) {
resourceInfo.condRequired.delete(dep);
Expand Down
Loading

0 comments on commit 1043714

Please sign in to comment.