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

fix: Always use defined node version #12689

Merged
merged 1 commit into from
Jan 13, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
import static com.vaadin.flow.server.Constants.SERVLET_PARAMETER_COMPATIBILITY_MODE;
import static com.vaadin.flow.server.Constants.SERVLET_PARAMETER_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.frontend.FrontendUtils.FRONTEND;
import static com.vaadin.flow.server.frontend.FrontendUtils.NODE_MODULES;
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;
Expand Down Expand Up @@ -218,7 +220,7 @@ private void runWebpack() throws MojoExecutionException {
String nodePath;
FrontendTools tools = new FrontendTools(npmFolder.getAbsolutePath(),
()-> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath(),
nodeVersion, nodeDownloadRootURI);
nodeVersion, nodeDownloadRootURI, requireHomeNodeExec);
if (requireHomeNodeExec) {
nodePath = tools
.forceAlternativeNodeExecutable();
Expand Down Expand Up @@ -292,6 +294,8 @@ private void updateBuildFile() {
buildInfo.remove(NPM_TOKEN);
buildInfo.remove(GENERATED_TOKEN);
buildInfo.remove(FRONTEND_TOKEN);
buildInfo.remove(NODE_VERSION);
buildInfo.remove(NODE_DOWNLOAD_ROOT);
buildInfo.remove(Constants.SERVLET_PARAMETER_ENABLE_PNPM);
buildInfo.remove(Constants.REQUIRE_HOME_NODE_EXECUTABLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import com.vaadin.flow.server.Constants;

import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.frontend.FrontendUtils.FRONTEND;

/**
Expand Down Expand Up @@ -95,7 +97,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* Vaadin, for example `"v14.15.4"`. Defaults to null which uses the
* Vaadin-default node version - see {@link FrontendTools} for details.
*/
@Parameter(property = "node.version", defaultValue = FrontendTools.DEFAULT_NODE_VERSION)
@Parameter(property = NODE_VERSION, defaultValue = FrontendTools.DEFAULT_NODE_VERSION)
protected String nodeVersion;

/**
Expand All @@ -106,7 +108,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* <p></p>
* Example: <code>"https://nodejs.org/dist/"</code>.
*/
@Parameter(property = "node.download.root", defaultValue = NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT)
@Parameter(property = NODE_DOWNLOAD_ROOT, defaultValue = NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT)
protected String nodeDownloadRoot;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
import static com.vaadin.flow.server.Constants.SERVLET_PARAMETER_COMPATIBILITY_MODE;
import static com.vaadin.flow.server.Constants.SERVLET_PARAMETER_PRODUCTION_MODE;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.frontend.FrontendUtils.FRONTEND;
import static com.vaadin.flow.server.frontend.FrontendUtils.TOKEN_FILE;

Expand Down Expand Up @@ -143,7 +145,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
FrontendTools tools = new FrontendTools(npmFolder.getAbsolutePath(),
() -> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath(),
nodeVersion, nodeDownloadRootURI);
nodeVersion, nodeDownloadRootURI, requireHomeNodeExec);
tools.validateNodeAndNpmVersion();
} catch (IllegalStateException exception) {
throw new MojoExecutionException(exception.getMessage(), exception);
Expand Down Expand Up @@ -197,6 +199,8 @@ private void propagateBuildInfo() {
buildInfo.put(Constants.SERVLET_PARAMETER_ENABLE_PNPM, pnpmEnable);
buildInfo.put(Constants.REQUIRE_HOME_NODE_EXECUTABLE,
requireHomeNodeExec);
buildInfo.put(NODE_VERSION, nodeVersion);
buildInfo.put(NODE_DOWNLOAD_ROOT, nodeDownloadRoot);

try {
FileUtils.forceMkdir(token.getParentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
import static com.vaadin.flow.server.Constants.VAADIN_PREFIX;
import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_COMPATIBILITY_MODE;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
Expand Down Expand Up @@ -248,6 +250,15 @@ private static void setInitParametersUsingTokenData(
verifyFolderExists(initParameters, buildInfo.getString(NPM_TOKEN));
}

if (buildInfo.hasKey(NODE_VERSION)) {
initParameters.setProperty(NODE_VERSION,
buildInfo.getString(NODE_VERSION));
}
if (buildInfo.hasKey(NODE_DOWNLOAD_ROOT)) {
initParameters.setProperty(NODE_DOWNLOAD_ROOT,
buildInfo.getString(NODE_DOWNLOAD_ROOT));
}

if (buildInfo.hasKey(FRONTEND_TOKEN)) {
initParameters.setProperty(FrontendUtils.PARAM_FRONTEND_DIR,
buildInfo.getString(FRONTEND_TOKEN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.ServerSocket;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
Expand Down Expand Up @@ -54,8 +55,11 @@
import com.vaadin.flow.server.communication.StreamRequestHandler;
import com.vaadin.flow.server.frontend.FrontendTools;
import com.vaadin.flow.server.frontend.FrontendUtils;
import com.vaadin.flow.server.frontend.installer.NodeInstaller;

import static com.vaadin.flow.server.Constants.VAADIN_MAPPING;
import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_ERROR_PATTERN;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_OPTIONS;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_WEBPACK_SUCCESS_PATTERN;
Expand Down Expand Up @@ -623,11 +627,15 @@ private boolean doStartWebpack(DeploymentConfiguration config,
ProcessBuilder processBuilder = new ProcessBuilder()
.directory(npmFolder);

final String nodeVersion = config.getStringProperty(NODE_VERSION,
FrontendTools.DEFAULT_NODE_VERSION);
final String nodeDownloadRoot = config.getStringProperty(
NODE_DOWNLOAD_ROOT, NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT);
boolean useHomeNodeExec = config.getBooleanProperty(
InitParameters.REQUIRE_HOME_NODE_EXECUTABLE, false);
FrontendTools tools = new FrontendTools(npmFolder.getAbsolutePath(),
() -> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath(),
useHomeNodeExec);
nodeVersion, URI.create(nodeDownloadRoot), useHomeNodeExec);
tools.validateNodeAndNpmVersion();

if (requiresOpenSslLegacyProvider(npmFolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class InitParameters implements Serializable {
public static final String SERVLET_PARAMETER_MAX_MESSAGE_SUSPEND_TIMEOUT = "maxMessageSuspendTimeout";
public static final String SERVLET_PARAMETER_JSBUNDLE = "module.bundle";
public static final String SERVLET_PARAMETER_POLYFILLS = "module.polyfills";
public static final String NODE_VERSION = "node.version";
public static final String NODE_DOWNLOAD_ROOT = "node.download.root";

/**
* Configuration name for the parameter that determines whether Brotli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter,
public String getNodeExecutable() {
Pair<String, String> nodeCommands = getNodeCommands();
File file = getExecutable(baseDir, nodeCommands.getSecond());
if (file == null) {
if (file == null && !forceAlternativeNode) {
file = frontendToolsLocator.tryLocateTool(nodeCommands.getFirst())
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ private void assertNpmCommand(Supplier<String> path) throws IOException {
createStubNode(false, true, vaadinHomeDir);

assertThat(tools.getNodeExecutable(), containsString("node"));
assertThat(tools.getNodeExecutable(),
not(containsString(DEFAULT_NODE)));

List<String> npmExecutable = tools.getNpmExecutable();
assertThat(npmExecutable.get(0), containsString("node"));
assertThat(npmExecutable.get(1), containsString(NPM_CLI_STRING));
Expand Down