ui5-community / ui5-ecosystem-showcase

A repository showcasing the UI5 tooling extensibility to combine OSS tools for UI5 application development.
https://ui5-community.github.io/ui5-ecosystem-showcase/
Other
188 stars 91 forks source link

[ui5-tooling-transpile] & [ui5-tooling-stringreplace] string replace before transpile don't work #1008

Open MrChuzzle opened 1 month ago

MrChuzzle commented 1 month ago

Hi all,

I used the string replacer to define my app namespace. This works fine with the ui5 module syntax sap.ui.define and Object.extend("namespace.ClassName" {...}). Thanks to ui-tooling-transpile, we can use modern module syntax, now. But when I'm using the transpiler, the string replacer don't work correctly.

I'm using ui5-tooling-transpile version 3.4.1 and ui5-tooling-stringreplace version 3.2.2. and ui5/cli version 3.10.3

My ui5.yaml:

specVersion: "3.2"
metadata:
  name: oct.templates.validator
type: application
server:
  customMiddleware:
    - name: ui5-middleware-livereload
      afterMiddleware: compression
    - name: ui5-middleware-simpleproxy
      afterMiddleware: compression
      mountPath: /resources
      configuration:
        baseUri: "https://sapui5.hana.ondemand.com/1.123.1/resources"
    - name: ui5-tooling-stringreplace-middleware
      afterMiddleware: compression
      configuration:
        debug: true
        prefix: UI5_ENV # default
        path: ./ # default
        separator: "." # default
        files:
          - "**/*.js"
          - "**/*.xml"
        replace:
          - placeholder: ${project.NAMESPACE}
            value: oct.templates.validator
          - placeholder: ${project.VERSION}
            value: 1.0.0-SNAPSHOT
    - name: ui5-tooling-transpile-middleware
      afterMiddleware: compression
      configuration:
        transformModulesToUI5: true

When ui5-tooling-transpiler is used, all .js files are ignored by the string replacer. When the string replacer runs after the transpiler, all .js files getting string replaced correctly, but then the transpiler could not transpile correctly because he transpiled with the placeholders string.

Expected behavior The string replacer don't ignore the *.js files and replace all placesholders before the files getting transpiled. The result should look like the last screenshot, here.

Screenshots When the string replacer runs before the transpiler (*.js files are ignored by the string replacer): image

When the string replacer runs after the transpiler: image

When I remove the string replacer and replace all placesholders with the correct namespace, the transpiler works fine (expected behavior): image

Desktop (please complete the following information):

petermuessig commented 1 month ago

Hi @MrChuzzle

this is a known limitation of the middlewares of the UI5 tooling. Once a middleware handles a resource and sends it back no other middleware will continue to process the resource. Without a bigger change of the UI5 tooling middleware concept, this issue can't be fixed easily.

For the tasks this is no problem as there the tasks run always after each other. There is not interruption.

I'll see what I can do - but I can't promise a quick solution on that...

Cc: @RandomByte @matz3

petermuessig commented 1 month ago

Ah, @MrChuzzle - just noticed one thing - I changed the implementation of the stringreplacer tooling extension a while back to intercept the response and allow to rewrite it.

Can you try one thing: exchange the order of the middlewares ui5-tooling-transpile-middleware and ui5-tooling-stringreplace-middleware? This may ensure that the stringreplace can intercept the response of transpile properly... Just a guess... BTW: the livereload middleware should be always at the bottom to register as the first middleware because by using afterMiddleware compression, the first on is sorted after the compression middleware and the next one will be sorted in between compression and the previously registered one.

MrChuzzle commented 1 month ago

Hi @petermuessig, changing the order didn't solve the issue.

petermuessig commented 1 month ago

@MrChuzzle - do you run the server with https or http?

MrChuzzle commented 1 month ago

@petermuessig with http

petermuessig commented 1 month ago

Ok, thanks - I'll create a small example to verify it and to ensure support in future. I'm still not sure whether I can help without a bigger change in the UI5 tooling