ui5-community / babel-plugin-transform-modules-ui5

A Babel transformer plugin for OpenUI5/SAPUI5. It allows you to develop UI5 applications by using the latest ECMAScript or TypeScript, including new syntax and objective oriented programming technology.
MIT License
34 stars 16 forks source link

Files with TS only assets still get transpiled #90

Closed dfenerski closed 1 year ago

dfenerski commented 1 year ago

Problem: Suppose a TS app has a interfaces directory. After transpilation to JS, those files are too transpiled but left empty. UI5 tooling then bundles them but that's another thing.

The predefined setup does not handle this case out-of-the box. I've searched for babel plugins / settings but the results were not very good.

Babel does have ignore property, but when --copy-files is enabled, then the interfaces are properly not processed but still copied in the dist, which is bad. There's also this issue but the additional flag also does not function perfectly.

To handle the issue therefore an additional build step can be added (e.g filtering or deleting unneeded files).

Before doing this however, I wanted to know whether there's possibility to add this behavior in this plugin. Otherwise additional customization steps for the building of TS UI5 apps need to be taken.

Thanks for any info in advance & BR

petermuessig commented 1 year ago

Hi @dfenerski ,

why does it need to be a .ts file at all? Can't it just be a .d.ts file? The ui5-tooling-transpile doesn't copy the .d.ts files when the generateDts option is disabled.

In general, if you have files only including type definitions, AFAICS, the recommendation is to use .d.ts files (https://stackoverflow.com/questions/37263357/how-to-declare-and-import-typescript-interfaces-in-a-separate-file). I found a small bug in the ui5-tooling-transpile in case of generateDts the relative names need to be made absolute. But this one I tackle independently.

WDYT?

Cheers, Peter

petermuessig commented 1 year ago

BTW: for the issue in ui5-tooling-transpile, I created an issue: https://github.com/ui5-community/ui5-ecosystem-showcase/issues/743

dfenerski commented 1 year ago

Thanks for reaching out @petermuessig,

the described solution does indeed solve the problem, so I think this issue can be closed.

In my case however we also have TS for the backend so implementing this would require changing some naming conventions for all **/interfaces/**/*.ts & **/types/**/*.ts files across the codebase to have .d.ts extension instead of the current .ts one. Filtering those files in the builder section of ui5.yaml files has in the same time worked out fine.

Maybe in the future the .d.ts solution is to be implemented, however I would like to research it some more beforehand (read more about ambient modules).

Thanks & BR,

Dimitar