Skip to content

Commit 2ba0fe6

Browse files
authored
fix: copy all frontend resources from JAR files (#22264) (#22276)
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
1 parent cb9dea3 commit 2ba0fe6

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@
2121
import static com.vaadin.flow.server.Constants.RESOURCES_JAR_DEFAULT;
2222

2323
/**
24-
* Copies JavaScript and CSS files from JAR files into a given folder.
24+
* Copies all frontend resources from JAR files into a given folder.
25+
* <p>
26+
* The task considers "frontend resources" all files placed in
27+
* {@literal META-INF/frontend}, {@literal META-INF/resources/frontend} and
28+
* {@literal META-INF/resources/[**]/themes} folders.
2529
* <p>
2630
* For internal use only. May be renamed or removed in a future release.
2731
*
2832
* @since 2.0
2933
*/
3034
public class TaskCopyFrontendFiles implements FallibleCommand {
31-
private static final String[] WILDCARD_INCLUSIONS = new String[] {
32-
"**/*.js", "**/*.js.map", "**/*.css", "**/*.css.map", "**/*.ts",
33-
"**/*.ts.map", "**/*.tsx", "**/*.tsx.map" };
3435
private static final String WILDCARD_INCLUSION_APP_THEME_JAR = "**/themes/**/*";
35-
private File targetDirectory;
36+
private final File targetDirectory;
3637
private Set<File> resourceLocations = null;
3738

3839
/**
@@ -71,10 +72,10 @@ public void execute() {
7172
} else {
7273
jarContentsManager.copyIncludedFilesFromJarTrimmingBasePath(
7374
location, RESOURCES_FRONTEND_DEFAULT, targetDirectory,
74-
WILDCARD_INCLUSIONS);
75+
"**/*");
7576
jarContentsManager.copyIncludedFilesFromJarTrimmingBasePath(
7677
location, COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT,
77-
targetDirectory, WILDCARD_INCLUSIONS);
78+
targetDirectory, "**/*");
7879
jarContentsManager.copyIncludedFilesFromJarTrimmingBasePath(
7980
location, RESOURCES_JAR_DEFAULT, targetDirectory,
8081
WILDCARD_INCLUSION_APP_THEME_JAR);

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
@@ -49,13 +49,13 @@ public void setup() throws IOException, ExecutionFailedException {
4949
public void frontendResources_should_beCopiedFromJars_when_TaskUpdatePackagesRemovesThem()
5050
throws IOException, ExecutionFailedException {
5151
copyResources();
52-
assertCopiedFrontendFileAmount(8);
52+
assertCopiedFrontendFileAmount(17);
5353

5454
performPackageClean();
5555
assertCopiedFrontendFileAmount(0);
5656

5757
copyResources();
58-
assertCopiedFrontendFileAmount(8);
58+
assertCopiedFrontendFileAmount(17);
5959
}
6060

6161
private void assertCopiedFrontendFileAmount(int fileCount)

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

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

9797
List<String> files = TestUtils.listFilesRecursively(frontendDepsFolder);
98-
Assert.assertEquals(10, files.size());
98+
Assert.assertEquals(19, files.size());
9999

100+
// Check some resources
100101
Assert.assertTrue("TS resource should have been copied from jar file",
101102
files.contains("example.ts"));
102103

@@ -132,6 +133,21 @@ private void should_collectJsAndCssFilesFromJars(String jarFile,
132133
Assert.assertTrue(
133134
"TSX resource source map should have been copied from jar file",
134135
files.contains("react.tsx.map"));
136+
137+
Assert.assertTrue("JSX resource should have been copied from jar file",
138+
files.contains("test.jsx"));
139+
140+
Assert.assertTrue(
141+
"JSX resource source map should have been copied from jar file",
142+
files.contains("test.jsx.map"));
143+
144+
Assert.assertTrue("HTML resource should have been copied from jar file",
145+
files.contains("ExampleTemplate.html"));
146+
147+
Assert.assertFalse(
148+
"Resource from unsupported frontend folder location should not have been copied from jar file",
149+
files.contains("ignored.js"));
150+
135151
}
136152

137153
private static Set<File> jars(File... files) {
2.48 KB
Binary file not shown.
2.59 KB
Binary file not shown.

0 commit comments

Comments
 (0)