You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2025/07/27 23:24:03 UTC

(tapestry-5) branch feature/requirejs-less updated (95b0b5a1c -> 74120c30f)

This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a change to branch feature/requirejs-less
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git


    from 95b0b5a1c TAP5-2810: fixing ES modules and pageinit relationship
     new f2894a403 TAP5-2804: Fixing dynamic locale message imports
     new 74120c30f TAP5-2810: fixing ES modules imports with function calls

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../services/javascript/EsModuleManagerImpl.java   | 22 ++++----
 .../apache/tapestry5/modules/JavaScriptModule.java | 58 +++++++++++++---------
 .../typescript/src/t5/core/messages-es-module.ts   |  4 ++
 3 files changed, 52 insertions(+), 32 deletions(-)


(tapestry-5) 02/02: TAP5-2810: fixing ES modules imports with function calls

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch feature/requirejs-less
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit 74120c30f88637b92515e282fd0e48a9c9754f00
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Jul 27 20:23:56 2025 -0300

    TAP5-2810: fixing ES modules imports with function calls
---
 .../services/javascript/EsModuleManagerImpl.java   | 22 ++++----
 .../apache/tapestry5/modules/JavaScriptModule.java | 58 +++++++++++++---------
 2 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/EsModuleManagerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/EsModuleManagerImpl.java
index 6c56cbf52..b0f4090d2 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/EsModuleManagerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/EsModuleManagerImpl.java
@@ -281,22 +281,26 @@ public class EsModuleManagerImpl implements EsModuleManager
             // If we have not only the import, but also an automatic function call
             if (arguments != null || functionName != null)
             {
+                
+                // TODO: move this logic to a pageinit call, like AMD does
+                // t5/core/pageinit:loadLibrariesAndInitialize
                 final Element moduleFunctionCall = script.element("script");
                 
                 moduleFunctionCall.moveAfter(script);
                 
                 final String moduleFunctionCallFormat = 
-                        "import %s from '%s';\n"
-                        + "%s(%s);";
-                
-                final String importName = functionName != null ? functionName : GENERIC_IMPORTED_VARIABLE;
-                final String importDeclaration = functionName != null ? 
-                        "{ " + functionName + " }": 
-                            GENERIC_IMPORTED_VARIABLE;
+                        "import m from '%s';\n"
+                        + "import console from 't5/core/console';\n"
+                        + "\nif (console.debugEnabled) {"
+                        + "\n    console.debug('Invoking %1$s:%2$s(' + (Array.from(%4$s).map(function(arg) { return JSON.stringify(arg); })).join(\", \") + ')');"
+                        + "\n    m.%2$s(%3$s);" 
+                        + "\n}\n";
                 
                 moduleFunctionCall.text(String.format(moduleFunctionCallFormat, 
-                        importDeclaration, moduleId, importName,
-                        convertToJsFunctionParameters(arguments, compactJSON)));
+                        moduleId, 
+                        functionName,
+                        convertToJsFunctionParameters(arguments, compactJSON),
+                        arguments));
                 
                 writeAttributes(moduleFunctionCall, init);
                 
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
index 3ea83348c..cbf0120a9 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
@@ -556,28 +556,28 @@ public class JavaScriptModule
         }
     }
     
-    @Contribute(EsModuleManager.class)
-    public static void setupApplicationCatalogEsModules(OrderedConfiguration<EsModuleManagerContribution> configuration,
-                                                        LocalizationSetter localizationSetter,
-                                                        ComponentMessagesSource messagesSource,
-                                                        ResourceChangeTracker resourceChangeTracker,
-                                                        @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON)
-    {
-        
-        EsModuleConfigurationCallback callback = jsonObject -> {
-        
-            for (Locale locale : localizationSetter.getSupportedLocales())
-            {
-                MessageCatalogResource resource = new MessageCatalogResource(false, locale, messagesSource, resourceChangeTracker, compactJSON);
-    
-                jsonObject.put("t5/core/messages/" + locale.toString(), resource.toURL());
-            }
-            
-        };
-        
-        configuration.add("ApplicationCatalog", EsModuleManagerContribution.base(callback));
-        
-    }
+//    @Contribute(EsModuleManager.class)
+//    public static void setupApplicationCatalogEsModules(OrderedConfiguration<EsModuleManagerContribution> configuration,
+//                                                        LocalizationSetter localizationSetter,
+//                                                        ComponentMessagesSource messagesSource,
+//                                                        ResourceChangeTracker resourceChangeTracker,
+//                                                        @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON)
+//    {
+//        
+//        EsModuleConfigurationCallback callback = jsonObject -> {
+//        
+//            for (Locale locale : localizationSetter.getSupportedLocales())
+//            {
+//                MessageCatalogResource resource = new MessageCatalogResource(false, locale, messagesSource, resourceChangeTracker, compactJSON);
+//    
+//                jsonObject.put("t5/core/messages/" + locale.toString(), resource.toURL());
+//            }
+//            
+//        };
+//        
+//        configuration.add("ApplicationCatalog", EsModuleManagerContribution.base(callback));
+//        
+//    }
 
     @Contribute(EsShimManager.class)
     public static void setupBaseEsShims(
@@ -587,7 +587,11 @@ public class JavaScriptModule
             @Path("${tapestry.asset.root}/bootstrap4/js/bootstrap-util.js")
             Resource bootstrapUtil,
             Compatibility compatibility,
-            AssetSource assetSource)
+            AssetSource assetSource,
+            LocalizationSetter localizationSetter,
+            ComponentMessagesSource messagesSource,
+            ResourceChangeTracker resourceChangeTracker,
+            @Symbol(SymbolConstants.COMPACT_JSON) boolean compactJSON)
     {
         
         final Resource jQuery = assetSource.getClasspathAsset("/META-INF/assets/tapestry5/jquery.js")
@@ -647,6 +651,14 @@ public class JavaScriptModule
             final String[] modules = new String[]{"alert", "dropdown", "collapse"};
             addBootstrap3EsShims(configuration, modules, transition);
         }
+        
+        for (Locale locale : localizationSetter.getSupportedLocales())
+        {
+            MessageCatalogResource resource = new MessageCatalogResource(true, locale, messagesSource, resourceChangeTracker, compactJSON);
+            configuration.add("t5/core/messages/" + locale.toString(),
+                    new EsShim(resource).getResource());
+        }
+        
     }
 
     @Contribute(EsModuleManager.class)


(tapestry-5) 01/02: TAP5-2804: Fixing dynamic locale message imports

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch feature/requirejs-less
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit f2894a40352e2d3899fcd9ada29f59e01860eb11
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Jul 27 11:51:39 2025 -0300

    TAP5-2804: Fixing dynamic locale message imports
---
 tapestry-core/src/main/typescript/src/t5/core/messages-es-module.ts | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tapestry-core/src/main/typescript/src/t5/core/messages-es-module.ts b/tapestry-core/src/main/typescript/src/t5/core/messages-es-module.ts
index afd3d4d8a..8b77d441f 100644
--- a/tapestry-core/src/main/typescript/src/t5/core/messages-es-module.ts
+++ b/tapestry-core/src/main/typescript/src/t5/core/messages-es-module.ts
@@ -43,6 +43,10 @@ const locale = (document.documentElement.getAttribute("data-locale")) || "en";
 // @ts-ignore
 let messages: any = await import(`t5/core/messages/${locale}`);
 
+if (messages['default'] != null && typeof messages['default'] === 'object') {
+  messages = messages.default;
+}
+
 // Returns the application message catalog message for the given key. Returns
 // a placeholder if the key is not found.
 const get = function(key: string) {