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 69 forks source link

Files imported by UniversalDate missing from self-contained build output #357

Open jbragiel opened 5 years ago

jbragiel commented 5 years ago

Expected Behavior

There are no missing JavaScript files in sap-ui-custom.js used by an application.

Current Behavior

sap/ui/core/date/(Buddhist|Gregorian|Islamic|Japanese|Persian).js is not being included.

Steps to reproduce the issue

  1. Take a look at the sap/ui/core/date/UniversalDate.js source from the openui5 repo: https://github.com/SAP/openui5/blob/6478939c8d4a89b3197647d6bcb99e3cb54f3047/src/sap.ui.core/src/sap/ui/core/date/UniversalDate.js#L90

  2. There is a sap.ui.requireSync call on line 90 that loads a computed filepath: sap.ui.requireSync("sap/ui/core/date/" + sCalendarType)

  3. Due to the dynamic nature of this import, the build of sap-ui-custom.js won't include any of the possible files. I'm not sure if a fix would go into the build tools or into the SDK source code...

Context

Affected components (if known)

Log Output / Stack Trace

N/A
BenReim commented 1 year ago

Due to this issue, the ui5 bootstrap will currently fail if the project has been build as self-contained, but does not include all project dependencies.

ui5 build self-contained
RandomByte commented 1 year ago

The problematic dynamic require in sap.ui.core has since moved to https://github.com/SAP/openui5/blob/c1b7517b7857b58879c3e3473bbaeced10ea55a2/src/sap.ui.core/src/sap/ui/core/date/_Calendars.js#L18

BohanLiu commented 1 year ago

Build with --include-all-dependencies solved the issue for me with UI5 tooling v3.

matz3 commented 1 year ago

Build with --include-all-dependencies solved the issue for me with UI5 tooling v3.

Do you mean that it now bundles the files, or that the app still works because the single files are loaded successfully? I don't see from the code how the bundling part would work now, even with v3.

BohanLiu commented 11 months ago

Build with --include-all-dependencies solved the issue for me with UI5 tooling v3.

Do you mean that it now bundles the files, or that the app still works because the single files are loaded successfully? I don't see from the code how the bundling part would work now, even with v3.

I didn't check the build content after I checked the application can run successfully... It actually packaged everything and I ended up with a nearly 300 MB web app with all the lib files that I did not need. The --include-all-dependencies doesn't really help.

CLVNSwan commented 1 month ago

The self-contained build is unusable because this issue is persistent. The website fails to load as it requires Gregorian.js, which is not included in the build.

@matz3, @RandomByte, is there an alternative solution to copying all scripts with the --include-all-dependencies option?

codeworrior commented 1 month ago

An easy, but cumbersome short-term workaround is to add an explicit dependency to any missing module (e.g. Gregorian) to your Component.js (or any other module of your app). Due to that dependency, the tooling will package the calendar in the self-contained bundle and it can be loaded at runtime.

If you want to avoid the (otherwise unnecessary) dependency in your application code, you might add a dedicate module DependencyDummy.js to your app namespace which contains the missing dependencies in a sap.ui.define call. As the self-contained bundle includes all resources from the app namespace (even if there's no path to them), this will also include the necessary dependencies.

Again, to emphasise it: this is a proposal for a workaround, not a solution. OpenUI5 itself hopefully soon chooses a different approach for calendar loading which then would make the workaround obsolete. But I can't name a due date for this.

CLVNSwan commented 1 month ago

Thanks @codeworrior for that workaround. The workaround seemed to work, but revealed another problem. The self-contained build doesn't include the language JSON files (for excample "en.json").

Without that file, the initialization of ODataV4-Model crashs with the message Cannot read properties of null (reading 'ca-gregorian')

So my current workaround to use the self-contained functionality is:

  1. Including the Dummy-Dependencies as you mentioned.
  2. Build self-contained AND all dependencies ui5 build self-contained --clean-dest --all
  3. Remove the entire "test-resources" folder and all files from the "resource" folder except for file types like "css, json, properties". find dist/resources -type f ! \\( -name \\*.woff* -o -name \\*.json -o -name \\*.properties -o -name \\*.css -o -path \\*/chart.js/* -o -name \\*sap-ui-custom\\* \\) -exec rm {} + && find dist/resources -type d -empty -delete

This keeps my resources as low as possible and keeps the missing files in my build. I know that's not a nice workaround, but as I see, it's currently the only possible way.