SAP / ui5-tooling

An open and modular toolchain to develop state of the art applications based on the UI5 framework
https://sap.github.io/ui5-tooling
Apache License 2.0
466 stars 68 forks source link

UI5 Tooling: Specifying libraries dependencies in ui5.yaml #949

Closed pubmikeb closed 4 months ago

pubmikeb commented 4 months ago

Playing with UI5 Tooling, I see that the ui5.yaml config file contains a framework library section, where we supposed to specify UI5 app dependencies, e.g. sap.m, sap.ui.core etc.:

specVersion: "3.2"
type: application
metadata:
    name: com.myApp
framework:
    name: OpenUI5
    version: 1.124.0
    libraries:
        -   name: sap.m
        -   name: sap.ui.core

My questions:

  1. Should the framework/libraries section of ui5.yaml be identical to the sap.ui5/dependencies/libs one of manifest.json?

  2. If I understand it correctly, these framework/libraries section is used to incorporate these libs into Component-preload.js. Is it a correct assumption?

  3. Should I specify this libraries section at all in case, if I consume UI5 lib from the CDN?

d3xter666 commented 4 months ago

Hi @pubmikeb ,

  1. Should the framework/libraries section of ui5.yaml be identical to the sap.ui5/dependencies/libs one of manifest.json?

Ideally, yes. The framework part of the ui5.yaml gives hints on how to build you app, while the manifest.json gives "hints" during bootstraping of the UI5 core which libs to download, eventually prefetch or lazy load.

  1. If I understand it correctly, these framework/libraries section is used to incorporate these libs into Component-preload.js. Is it a correct assumption?

    • Not into the Component-preload, but yes, it bundles those libs along with your app, BUT only for self contained build
  2. Should I specify this libraries section at all in case, if I consume UI5 lib from the CDN?

    • Yes, you might need them for local development, for example
pubmikeb commented 4 months ago

@d3xter666, thanks a lot for the detailed explanation!

Regarding the first answer, wouldn't be great to add to UI5 Tooling the possibility to «inherit» the values of manifest.json's sap.ui5/dependencies/libs by default?

So, if nothing is specified in framework/libraries, then UI5 Tooling tries reading sap.ui5/dependencies/libs from manifest.json. This might help to avoid unintentional inconsistency between sap.ui5/dependencies/libs and framework/libraries.

RandomByte commented 3 months ago
  1. Should I specify this libraries section at all in case, if I consume UI5 lib from the CDN?
  • Yes, you might need them for local development, for example

Adding to this statement, when consuming SAPUI5 via CDN during development it is not needed to declare the dependencies in the ui5.yaml.

Actually, I would even advise against it since a miss match in the SAPUI5 version of both sources could cause unexpected behavior. Many UI5 project templates therefore use multiple ui5.yaml configuration files to distinguish between CDN and local SAPUI5 dependency usage.

Regarding the first answer, wouldn't be great to add to UI5 Tooling the possibility to «inherit» the values of manifest.json's sap.ui5/dependencies/libs by default?

So, if nothing is specified in framework/libraries, then UI5 Tooling tries reading sap.ui5/dependencies/libs from manifest.json. This might help to avoid unintentional inconsistency between sap.ui5/dependencies/libs and framework/libraries.

As Yavor outlined we try to have a clear separation between "runtime" and "buildtime" dependencies in the hope that this makes it easier for developers to understand and maintain the two configurations correctly.

Some examples where it might get tricky when using manifest.json as a fallback:

  1. Applications usually need to declare a theme dependency (see for example the openui5-sample-app). While this could also be expressed in manifest.json using the supportedThemes attribute, it is not really the same as explicitly declaring a dependency. So applications would often have to declare at least their theme dependencies in the ui5.yaml. Should we ignore the other dependencies in manifest.json then? (since something is specified in framework/libraries)
  2. The ui5.yaml configuration allows to flag dependencies as "development" dependencies, which are required for the purpose of local testing. For example the sap.ushell library is often required for a local sandbox setup. These dependencies must not be declared in the manifest.json since that might lead to loading of unnecessary libraries at runtime. I fear that by blurring the line between runtime and buildtime dependencies, this mistake is more likely to be made.
  3. The manifest.json configuration might not only list SAPUI5 libraries but also custom or third-party UI5 libraries. I'm not sure how UI5 Tooling could effectively differentiate between the two in order to correctly inform users about missing or misspelled dependencies. Custom UI5 libraries are sometimes not required during development so their absence can be ignored. But what if it's a misspelled framework library?

I agree that inconsistency is an issue. For our framework libraries we therefore have an internal validation that ensures the ui5.yaml contains at least all dependencies listed in the manifest.json. But with regards to 3., such a check might not work for projects relying on custom UI5 libraries.