Skip to content

Commit 4877e5f

Browse files
fix: Throw exception if Vite and deprecatedV14Bootstrapping are used (#14678) (#14706)
Interrupts application's bootstrapping if Vite + v14 Bootstrapping are detected with the message to fallback to Webpack, sine Vite is not supported yet with this mode. Fixes #14603 Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
1 parent 98154e1 commit 4877e5f

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/BuildFrontendMojoTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.junit.After;
4545
import org.junit.Assert;
4646
import org.junit.Before;
47+
import org.junit.Ignore;
4748
import org.junit.Rule;
4849
import org.junit.Test;
4950
import org.junit.rules.TemporaryFolder;
@@ -563,6 +564,7 @@ public void mavenGoal_generateTsFiles_when_enabled() throws Exception {
563564
Assert.assertTrue(endpointClientApi.exists());
564565
}
565566

567+
@Ignore("Vite is not supported when deprecatedV14Bootstrapping is used")
566568
@Test
567569
public void mavenGoal_notGenerateOpenApiJson_when_usingDeprecatedV14Bootstrapping()
568570
throws Exception {

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,17 @@ public File getFlowResourcesFolder() {
685685
}
686686
}
687687

688+
//@formatter:off
689+
private static final String V14_BOOTSTRAPPING_VITE_ERROR_MESSAGE =
690+
"\n\n************************************************************************************"
691+
+ "\n* Vite build tool is not supported when 'useDeprecatedV14Bootstrapping' is used. *"
692+
+ "\n* Please fallback to Webpack build tool via setting the *"
693+
+ "\n* 'com.vaadin.experimental.webpackForFrontendBuild=true' feature flag *"
694+
+ "\n* in [project-root]/src/main/resources/vaadin-featureflags.properties *"
695+
+ "\n* (you may create the file if not exists) and restart the application. *"
696+
+ "\n************************************************************************************\n\n";
697+
//@formatter:on
698+
688699
// @formatter:off
689700
// This list keeps the tasks in order so that they are executed
690701
// without depending on when they are added.
@@ -790,7 +801,12 @@ private NodeTasks(Builder builder) {
790801
addGenerateTsConfigTask(builder);
791802
}
792803

793-
if (!builder.useLegacyV14Bootstrap) {
804+
if (builder.useLegacyV14Bootstrap) {
805+
if (!featureFlags.isEnabled(FeatureFlags.WEBPACK)) {
806+
throw new IllegalStateException(
807+
V14_BOOTSTRAPPING_VITE_ERROR_MESSAGE);
808+
}
809+
} else {
794810
addBootstrapTasks(builder);
795811

796812
// use the new Hilla generator if enabled, otherwise use the old

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public void init() throws Exception {
5555
// Make a builder that doesn't add any commands.
5656
NodeTasks.Builder builder = new NodeTasks.Builder(
5757
Mockito.mock(Lookup.class), null, TARGET);
58-
builder.useV14Bootstrap(true);
5958
builder.withProductionMode(false);
6059

6160
if (DEV_SERVER_WEBPACK.equals(devServerImpl)) {
61+
builder.useV14Bootstrap(true);
6262
builder.setJavaResourceFolder(temporaryFolder.getRoot());
6363
createFeatureFlagsFile(
6464
"com.vaadin.experimental.webpackForFrontendBuild=true");

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.stream.Collectors;
2727

2828
import org.apache.commons.io.FileUtils;
29+
import org.hamcrest.CoreMatchers;
30+
import org.hamcrest.MatcherAssert;
2931
import org.junit.AfterClass;
3032
import org.junit.Assert;
3133
import org.junit.Before;
@@ -288,17 +290,32 @@ public void should_GenerateTsConfigAndTsDefinitions_When_Vaadin14BootstrapMode()
288290
new DefaultClassFinder(this.getClass().getClassLoader()))
289291
.when(mockedLookup).lookup(ClassFinder.class);
290292
Builder builder = new Builder(mockedLookup, new File(userDir), TARGET)
291-
.enablePackagesUpdate(false).useV14Bootstrap(true)
292-
.enableImportsUpdate(true).runNpmInstall(false)
293-
.withEmbeddableWebComponents(false).useV14Bootstrap(false)
294-
.withFlowResourcesFolder(
293+
.enablePackagesUpdate(false).enableImportsUpdate(true)
294+
.runNpmInstall(false).withEmbeddableWebComponents(false)
295+
.useV14Bootstrap(false).withFlowResourcesFolder(
295296
new File(userDir, TARGET + "flow-frontend"));
296297
builder.build().execute();
297298

298299
Assert.assertTrue(new File(userDir, "tsconfig.json").exists());
299300
Assert.assertTrue(new File(userDir, "types.d.ts").exists());
300301
}
301302

303+
@Test
304+
public void should_failWithMessage_When_Vaadin14BootstrapModeAndViteAreUsed() {
305+
Lookup mockedLookup = mock(Lookup.class);
306+
Mockito.doReturn(
307+
new DefaultClassFinder(this.getClass().getClassLoader()))
308+
.when(mockedLookup).lookup(ClassFinder.class);
309+
Builder builder = new Builder(mockedLookup, new File(userDir), TARGET)
310+
.useV14Bootstrap(true);
311+
312+
IllegalStateException exception = Assert.assertThrows(
313+
IllegalStateException.class, () -> builder.build().execute());
314+
MatcherAssert.assertThat(exception.getMessage(),
315+
CoreMatchers.containsString(
316+
"Vite build tool is not supported when 'useDeprecatedV14Bootstrapping' is used"));
317+
}
318+
302319
@Test
303320
public void should_failWithExecutionFailedException_when_customWebpackConfigFileExist()
304321
throws IOException {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.vaadin.experimental.webpackForFrontendBuild=true

0 commit comments

Comments
 (0)