Skip to content

Commit 43add4c

Browse files
fix: copy all frontend resources from JAR files (#22264) (#22270)
Frontend resources in JAR files are filtered to only copy a hard-coded set of file types like JS, TS, CSS, etc. Since the resources are collected only from specific folders, the filter is most likely unecessary and also makes it impossible to use fronted frameworks that rely on custom extensions (e.g. Vue). This change removes the file extension filter, allowing all files in META-INF/frontend and META-INF/resources/frontend to be copied in the frontend generated folder. Fixes #22208 Co-authored-by: Marco Collovati <marco@vaadin.com>
1 parent 8f89b7b commit 43add4c

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCopyFrontendFiles.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@
3232
import static com.vaadin.flow.server.Constants.RESOURCES_JAR_DEFAULT;
3333

3434
/**
35-
* Copies JavaScript and CSS files from JAR files into a given folder.
35+
* Copies all frontend resources from JAR files into a given folder.
36+
* <p>
37+
* The task considers "frontend resources" all files placed in
38+
* {@literal META-INF/frontend}, {@literal META-INF/resources/frontend} and
39+
* {@literal META-INF/resources/[**]/themes} folders.
3640
* <p>
3741
* For internal use only. May be renamed or removed in a future release.
3842
*
3943
* @since 2.0
4044
*/
4145
public class TaskCopyFrontendFiles
4246
extends AbstractFileGeneratorFallibleCommand {
43-
private static final String[] WILDCARD_INCLUSIONS = new String[] {
44-
"**/*.js", "**/*.js.map", "**/*.css", "**/*.css.map", "**/*.ts",
45-
"**/*.ts.map", "**/*.tsx", "**/*.tsx.map", "**/*.jsx",
46-
"**/*.jsx.map" };
4747
private static final String WILDCARD_INCLUSION_APP_THEME_JAR = "**/themes/**/*";
4848
private final Options options;
49-
private Set<File> resourceLocations = null;
49+
private final Set<File> resourceLocations;
5050

5151
/**
5252
* Scans the jar files given defined by {@code resourcesToScan}.
@@ -97,11 +97,11 @@ public void execute() {
9797
handledFiles.addAll(jarContentsManager
9898
.copyIncludedFilesFromJarTrimmingBasePath(location,
9999
RESOURCES_FRONTEND_DEFAULT, targetDirectory,
100-
WILDCARD_INCLUSIONS));
100+
"**/*"));
101101
handledFiles.addAll(jarContentsManager
102102
.copyIncludedFilesFromJarTrimmingBasePath(location,
103103
COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT,
104-
targetDirectory, WILDCARD_INCLUSIONS));
104+
targetDirectory, "**/*"));
105105
handledFiles.addAll(jarContentsManager
106106
.copyIncludedFilesFromJarTrimmingBasePath(location,
107107
RESOURCES_JAR_DEFAULT, targetDirectory,

flow-server/src/test/java/com/vaadin/flow/server/frontend/FrontendResourcesAreCopiedAfterCleaningTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ public void setup() throws IOException, ExecutionFailedException {
5757
public void frontendResources_should_beCopiedFromJars_when_TaskUpdatePackagesRemovesThem()
5858
throws IOException, ExecutionFailedException {
5959
copyResources();
60-
assertCopiedFrontendFileAmount(10);
60+
assertCopiedFrontendFileAmount(17);
6161

6262
performPackageClean();
6363
assertCopiedFrontendFileAmount(0);
6464

6565
copyResources();
66-
assertCopiedFrontendFileAmount(10);
66+
assertCopiedFrontendFileAmount(17);
6767
}
6868

6969
private void assertCopiedFrontendFileAmount(int fileCount)

flow-server/src/test/java/com/vaadin/flow/server/frontend/TaskCopyFrontendFilesTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ private void should_collectJsAndCssFilesFromJars(String jarFile,
118118
task.execute();
119119

120120
List<String> files = TestUtils.listFilesRecursively(frontendDepsFolder);
121-
Assert.assertEquals(12, files.size());
121+
Assert.assertEquals(19, files.size());
122122

123+
// Check some resources
123124
Assert.assertTrue("TS resource should have been copied from jar file",
124125
files.contains("example.ts"));
125126

@@ -163,6 +164,13 @@ private void should_collectJsAndCssFilesFromJars(String jarFile,
163164
"JSX resource source map should have been copied from jar file",
164165
files.contains("test.jsx.map"));
165166

167+
Assert.assertTrue("HTML resource should have been copied from jar file",
168+
files.contains("ExampleTemplate.html"));
169+
170+
Assert.assertFalse(
171+
"Resource from unsupported frontend folder location should not have been copied from jar file",
172+
files.contains("ignored.js"));
173+
166174
Assert.assertEquals("Generated files should have been tracked",
167175
files.stream()
168176
.map(path -> frontendDepsFolder.toPath().resolve(path))
2 KB
Binary file not shown.
2.15 KB
Binary file not shown.

0 commit comments

Comments
 (0)