Class BundleUtils
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe key of the stats.json entry that lists the identifiers of the functions the bundle registers for JavaScript definitions, event data and event filters.static final StringThe key of the same map inFrontendUtils.JS_DEFINITION_IDS_FILE_NAME, which a development server reads, as it is written again while the application runs.static final StringThe 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. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckJsFunctionsBundled(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@JsModuleof a component is reported.static StringgetChunkHash(List<String> chunkLines) Calculates a hash for bundle JavaScript chunk containing given string lines.static StringgetChunkId(Class<? extends Component> componentClass) Gets the id for a chunk defined by the given class.static StringgetChunkId(String className) Gets the id for a chunk defined by the given class.Gets the functions that the frontend build left out because a module that their JavaScript imports with@JsDefinitionImportcould not be found, so that calling one of them can fail on the server with the reason rather than in the browser.static booleanReturns whether the application uses pre-compiled production bundle or a custom bundle.Loads stats.json from the classpath (from the production bundle) and returns the "bundleImports" part of it.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.
-
Field Details
-
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
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
The key of the same map inFrontendUtils.JS_DEFINITION_IDS_FILE_NAME, which a development server reads, as it is written again while the application runs.- See Also:
-
-
Method Details
-
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
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
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
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:
truein case of pre-compiled bundle,falseotherwise
-
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@JsModuleof 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
@JsStringFallbackinterface 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@Useswould not help.- Parameters:
declaringType- the JavaScript definition or event type that declares the functions, notnullfunctionIds- the identifiers of the functions that the class declares, asked for only when the class is checked, notnull- Since:
- 25.4
-
getUnresolvedJsImports
Gets the functions that the frontend build left out because a module that their JavaScript imports with@JsDefinitionImportcould 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
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 ofJS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEYorJS_DEFINITION_UNRESOLVED_IMPORTS_KEY, ornullwhen 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
-