Class BundleUtils

java.lang.Object
com.vaadin.flow.internal.BundleUtils

public final class BundleUtils extends Object
Utility class for bundle operations.

For internal use only. May be renamed or removed in a future release.

Since:
25.1
  • Field Details

    • JS_DEFINITION_FUNCTION_IDS_STATS_KEY

      public static final String JS_DEFINITION_FUNCTION_IDS_STATS_KEY
      The key of the stats.json entry that lists the identifiers of the functions the bundle registers for JavaScript definitions, event data and event filters.
      Since:
      25.4
      See Also:
    • JS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEY

      public static final String JS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEY
      The key of the stats.json entry that maps the identifier of each function the bundle leaves out, because a module its JavaScript imports could not be found when the bundle was built, to that module as it is declared.
      See Also:
    • JS_DEFINITION_UNRESOLVED_IMPORTS_KEY

      public static final String JS_DEFINITION_UNRESOLVED_IMPORTS_KEY
      The key of the same map in FrontendUtils.JS_DEFINITION_IDS_FILE_NAME, which a development server reads, as it is written again while the application runs.
      See Also:
  • Method Details

    • loadBundleImports

      public static Set<String> loadBundleImports()
      Loads stats.json from the classpath (from the production bundle) and returns the "bundleImports" part of it.
      Returns:
      the bundle imports as a set
    • getChunkId

      public static String getChunkId(Class<? extends Component> componentClass)
      Gets the id for a chunk defined by the given class.
      Parameters:
      componentClass - the class
      Returns:
      an identifier for the component class that does not reveal the name of the component class
    • getChunkId

      public static String getChunkId(String className)
      Gets the id for a chunk defined by the given class.
      Parameters:
      className - the name of the class
      Returns:
      an identifier for the component class that does not reveal the name of the component class
    • getChunkHash

      public static String getChunkHash(List<String> chunkLines)
      Calculates a hash for bundle JavaScript chunk containing given string lines.
      Parameters:
      chunkLines - content of the chunk, collection of string lines
      Returns:
      chunk's hash
    • isPreCompiledProductionBundle

      public static boolean isPreCompiledProductionBundle()
      Returns whether the application uses pre-compiled production bundle or a custom bundle.
      Returns:
      true in case of pre-compiled bundle, false otherwise
    • checkJsFunctionsBundled

      public static void checkJsFunctionsBundled(Class<?> declaringType, Supplier<Collection<String>> functionIds)
      Logs an error when the production bundle does not carry a function that the given class declares JavaScript for, the way a missing @JsModule of a component is reported. The browser can not run such a function, and in production mode it does not log why, so the server says which class is missing and how to get it into the bundle.

      Checks a class once, and only in production mode with a bundle whose stats list the functions it registers. A function that the bundle leaves out because a module it imports could not be found is not reported here: the class is reached, and calling the function says what is missing.

      Calls that a @JsStringFallback interface stands in for are not checked: the build always keeps those interfaces in the bundle, as they are found by the string an add-on sends rather than through a class reference, so naming them in @Uses would not help.

      Parameters:
      declaringType - the JavaScript definition or event type that declares the functions, not null
      functionIds - the identifiers of the functions that the class declares, asked for only when the class is checked, not null
      Since:
      25.4
    • getUnresolvedJsImports

      public static Map<String,String> getUnresolvedJsImports()
      Gets the functions that the frontend build left out because a module that their JavaScript imports with @JsDefinitionImport could not be found, so that calling one of them can fail on the server with the reason rather than in the browser.

      In production mode they are read from the stats of the bundle. In development mode they are read from the file the build writes next to the generated JavaScript, which is written again when a JavaScript definition is hotswapped, so the answer follows it.

      Returns:
      the module as it is declared by the identifier of each function that was left out, empty when nothing was or when there is no running service to tell the mode by
    • parseUnresolvedJsImports

      public static Map<String,String> parseUnresolvedJsImports(tools.jackson.databind.JsonNode node)
      Reads the functions left out of a bundle because a module they import could not be found, as the stats or the file next to the generated JavaScript list them.
      Parameters:
      node - the value of JS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEY or JS_DEFINITION_UNRESOLVED_IMPORTS_KEY, or null when there is none
      Returns:
      the module as it is declared by the identifier of each function, empty when the value lists none or is not an object