Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MrChuzzle opened this issue May 27, 2024 · 8 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@MrChuzzle
Copy link

MrChuzzle commented May 27, 2024

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):

  • OS: Windows 11
  • Browser: Chrome
  • Version: 124.0.6367.208
@petermuessig
Copy link
Member

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 petermuessig added bug Something isn't working enhancement New feature or request labels May 28, 2024
@petermuessig
Copy link
Member

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
Copy link
Author

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

@petermuessig
Copy link
Member

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

@MrChuzzle
Copy link
Author

@petermuessig with http

@petermuessig
Copy link
Member

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

@menof36go
Copy link
Contributor

menof36go commented Sep 18, 2024

Any update? I think I might be experiencing the same issue with ui5-tooling-transpile combined with ui5-tooling-modules.
Trying to transpile from module to ui5 amd and run ui5-tooling-modules afterwards, but middleware chain stops after ui5-tooling-transpile

@petermuessig
Copy link
Member

@menof36go - sorry, still no progress here - I need to reserve some time on that but currently there is a pretty busy schedule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants