Skip to content

Commit d7d56dc

Browse files
authored
feat: support hoisted Vite install in production & bundle builds (#21283)
* feat: support hoisted Vite install in production & bundle builds * fix: improve error message
1 parent dd152c2 commit d7d56dc

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/BuildFrontendUtil.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_INITIAL_UIDL;
8484
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
8585
import static com.vaadin.flow.server.frontend.FrontendUtils.GENERATED;
86-
import static com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES;
8786
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;
8887

8988
/**
@@ -521,17 +520,26 @@ public static void runFrontendBuild(PluginAdapterBase adapter)
521520
*/
522521
public static void runVite(PluginAdapterBase adapter,
523522
FrontendTools frontendTools) throws TimeoutException {
524-
runFrontendBuildTool(adapter, frontendTools, "Vite", "vite/bin/vite.js",
523+
runFrontendBuildTool(adapter, frontendTools, "Vite", "vite", "vite",
525524
Collections.emptyMap(), "build");
526525
}
527526

528527
private static void runFrontendBuildTool(PluginAdapterBase adapter,
529-
FrontendTools frontendTools, String toolName, String executable,
530-
Map<String, String> environment, String... params)
531-
throws TimeoutException {
528+
FrontendTools frontendTools, String toolName, String packageName,
529+
String binaryName, Map<String, String> environment,
530+
String... params) throws TimeoutException {
532531

533-
File buildExecutable = new File(adapter.npmFolder(),
534-
NODE_MODULES + executable);
532+
File buildExecutable;
533+
try {
534+
buildExecutable = frontendTools.getNpmPackageExecutable(packageName,
535+
binaryName, adapter.npmFolder()).toFile();
536+
} catch (FrontendUtils.CommandExecutionException e) {
537+
throw new IllegalStateException(String.format("""
538+
Unable to locate %s executable. Expected the "%s" npm \
539+
package to be installed and to provide the "%s" binary. \
540+
Double check that the npm dependencies are installed.""",
541+
toolName, packageName, binaryName));
542+
}
535543
if (!buildExecutable.isFile()) {
536544
throw new IllegalStateException(String.format(
537545
"Unable to locate %s executable by path '%s'. Double"

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void execute() throws ExecutionFailedException {
9696
getLogger().info(
9797
"Creating a new development mode bundle. This can take a while but will only run when the project setup is changed, addons are added or frontend files are modified");
9898

99-
runFrontendBuildTool("Vite", "vite/bin/vite.js", "build");
99+
runFrontendBuildTool("Vite", "vite", "vite", "build");
100100

101101
copyPackageLockToBundleFolder();
102102

@@ -107,8 +107,9 @@ private static Logger getLogger() {
107107
return LoggerFactory.getLogger(TaskRunDevBundleBuild.class);
108108
}
109109

110-
private void runFrontendBuildTool(String toolName, String executable,
111-
String... params) throws ExecutionFailedException {
110+
private void runFrontendBuildTool(String toolName, String packageName,
111+
String binaryName, String... params)
112+
throws ExecutionFailedException {
112113
Logger logger = getLogger();
113114

114115
FrontendToolsSettings settings = new FrontendToolsSettings(
@@ -123,8 +124,17 @@ private void runFrontendBuildTool(String toolName, String executable,
123124
options.isFrontendIgnoreVersionChecks());
124125
FrontendTools frontendTools = new FrontendTools(settings);
125126

126-
File buildExecutable = new File(options.getNpmFolder(),
127-
"node_modules/" + executable);
127+
File buildExecutable;
128+
try {
129+
buildExecutable = frontendTools.getNpmPackageExecutable(packageName,
130+
binaryName, options.getNpmFolder()).toFile();
131+
} catch (FrontendUtils.CommandExecutionException e) {
132+
throw new IllegalStateException(String.format("""
133+
Unable to locate %s executable. Expected the "%s" npm \
134+
package to be installed and to provide the "%s" binary. \
135+
Double check that the npm dependencies are installed.""",
136+
toolName, packageName, binaryName));
137+
}
128138
if (!buildExecutable.isFile()) {
129139
throw new IllegalStateException(String.format(
130140
"Unable to locate %s executable by path '%s'. Double"

0 commit comments

Comments
 (0)