Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vite watchdog #12230

Merged
merged 2 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions flow-server/src/main/resources/vite.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* This file will be overwritten on every run. Any custom changes should be made to vite.config.ts
*/
import path from 'path';
import * as net from 'net';

import { processThemeResources } from '@vaadin/application-theme-plugin/theme-handle.js';
import settings from '#settingsImport#';
Expand Down Expand Up @@ -53,7 +54,29 @@ function updateTheme(contextPath: string) {
}
}

export const vaadinConfig:UserConfigFn = (env) => ({
function runWatchDog(watchDogPort) {
const client = net.Socket();
client.setEncoding('utf8');
client.on('error', function () {
console.log("Watchdog connection error. Terminating vite process...");
client.destroy();
process.exit(0);
});
client.on('close', function () {
client.destroy();
runWatchDog(watchDogPort);
});

client.connect(watchDogPort, 'localhost');
}

export const vaadinConfig:UserConfigFn = (env) => {
if (env.mode === 'development' && process.env.watchDogPort) {
Artur- marked this conversation as resolved.
Show resolved Hide resolved
// Open a connection with the Java dev-mode handler in order to finish
// vite when it exits or crashes.
runWatchDog(process.env.watchDogPort);
}
return ({
root: 'frontend',
base: env.mode === 'production' ? '' : '/VAADIN/',
resolve: {
Expand Down Expand Up @@ -87,7 +110,8 @@ export const vaadinConfig:UserConfigFn = (env) => ({
}
}
]
});
})
};


export const overrideVaadinConfig = (customConfig:UserConfigFn) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ protected Process doStartDevServer() {
}

processBuilder.command(command);
processBuilder.environment().put("watchDogPort",
Integer.toString(getWatchDog().getWatchDogPort()));

try {
Process process = processBuilder.redirectErrorStream(true).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ protected List<String> getServerStartupCommand(String nodeExec) {
command.add(String.valueOf(getPort()));
command.add("--watch-options-stdin"); // Tell wds to stop even if
// watchDog fail
command.add("--env");
command.add("watchDogPort=" + getWatchDog().getWatchDogPort());

String customParameters = getApplicationConfiguration()
.getStringProperty(
InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.vaadin.base.devserver.AbstractDevServerRunner;
import com.vaadin.base.devserver.DevModeHandlerManagerImpl;
import com.vaadin.base.devserver.MockDeploymentConfiguration;
import com.vaadin.base.devserver.WebpackHandler;
import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.di.ResourceProvider;
import com.vaadin.flow.function.DeploymentConfiguration;
Expand Down Expand Up @@ -136,7 +135,7 @@ protected DevModeHandler getDevModeHandler() {
}

protected int getDevServerPort() {
return ((WebpackHandler) handler).getPort();
return ((AbstractDevServerRunner) handler).getPort();
}

protected void waitForDevServer() {
Expand All @@ -145,7 +144,7 @@ protected void waitForDevServer() {

protected static void waitForDevServer(DevModeHandler devModeHandler) {
Assert.assertNotNull(devModeHandler);
((WebpackHandler) (devModeHandler)).waitForDevServer();
((AbstractDevServerRunner) (devModeHandler)).waitForDevServer();
}

protected static boolean hasDevServerProcess(
Expand Down