Skip to content

Commit

Permalink
fix: Always use defined node version
Browse files Browse the repository at this point in the history
If defined always use the node version
and download root url is defined.

Closes #12686
  • Loading branch information
caalador committed Jan 11, 2022
1 parent bcf4b12 commit 981f4c6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
* </p>
* Example: <code>"https://nodejs.org/dist/"</code>.
*/
@Parameter(property = "node.download.root", defaultValue = NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT)
@Parameter(property = InitParameters.NODE_DOWNLOAD_ROOT, defaultValue = NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT)
private String nodeDownloadRoot;

/**
* The node.js version to be used when node.js is installed automatically by
* Vaadin, for example `"v16.0.0"`. 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 = InitParameters.NODE_VERSION, defaultValue = FrontendTools.DEFAULT_NODE_VERSION)
private String nodeVersion;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import static com.vaadin.flow.server.Constants.GENERATED_TOKEN;
import static com.vaadin.flow.server.Constants.NPM_TOKEN;
import static com.vaadin.flow.server.Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN;
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_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_INITIAL_UIDL;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
Expand Down Expand Up @@ -194,7 +196,8 @@ private static FrontendToolsSettings getFrontendToolsSettings(
* - the PluginAdapterBase.
* @return the Token {@link File}.
*/
public static File propagateBuildInfo(PluginAdapterBase adapter) {
public static File propagateBuildInfo(PluginAdapterBase adapter)
throws URISyntaxException {

// For forked processes not accessing to System.properties we leave a
// token file with the information about the build
Expand All @@ -208,6 +211,8 @@ public static File propagateBuildInfo(PluginAdapterBase adapter) {
buildInfo.put(SERVLET_PARAMETER_INITIAL_UIDL,
adapter.eagerServerLoad());
buildInfo.put(NPM_TOKEN, adapter.npmFolder().getAbsolutePath());
buildInfo.put(NODE_VERSION, adapter.nodeVersion());
buildInfo.put(NODE_DOWNLOAD_ROOT, adapter.nodeDownloadRoot().toString());
buildInfo.put(GENERATED_TOKEN,
adapter.generatedFolder().getAbsolutePath());
buildInfo.put(FRONTEND_TOKEN,
Expand Down Expand Up @@ -462,6 +467,8 @@ public static void updateBuildFile(PluginAdapterBuild adapter) {
JsonObject buildInfo = JsonUtil.parse(json);

buildInfo.remove(NPM_TOKEN);
buildInfo.remove(NODE_VERSION);
buildInfo.remove(NODE_DOWNLOAD_ROOT);
buildInfo.remove(GENERATED_TOKEN);
buildInfo.remove(FRONTEND_TOKEN);
buildInfo.remove(Constants.SERVLET_PARAMETER_ENABLE_PNPM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 @@ -44,6 +44,9 @@
import com.vaadin.flow.server.frontend.installer.ProxyConfig;
import com.vaadin.flow.server.startup.ApplicationConfiguration;

import static com.vaadin.flow.server.InitParameters.NODE_DOWNLOAD_ROOT;
import static com.vaadin.flow.server.InitParameters.NODE_VERSION;

/**
* Provides access to frontend tools (node.js and npm, pnpm) and optionally
* installs the tools if needed.
Expand Down Expand Up @@ -428,13 +431,19 @@ private static FrontendToolsSettings createSettings(
.getBooleanProperty(InitParameters.NODE_AUTO_UPDATE, false);
boolean useGlobalPnpm = applicationConfiguration.getBooleanProperty(
InitParameters.SERVLET_PARAMETER_GLOBAL_PNPM, false);
final String nodeVersion = applicationConfiguration.getStringProperty(NODE_VERSION,
FrontendTools.DEFAULT_NODE_VERSION);
final String nodeDownloadRoot = applicationConfiguration.getStringProperty(
NODE_DOWNLOAD_ROOT, NodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOT);

FrontendToolsSettings settings = new FrontendToolsSettings(
projectRoot.getAbsolutePath(),
() -> FrontendUtils.getVaadinHomeDirectory().getAbsolutePath());
settings.setForceAlternativeNode(useHomeNodeExec);
settings.setAutoUpdate(nodeAutoUpdate);
settings.setUseGlobalPnpm(useGlobalPnpm);
settings.setNodeVersion(nodeVersion);
settings.setNodeDownloadRoot(URI.create(nodeDownloadRoot));
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import static com.vaadin.flow.server.Constants.PROJECT_FRONTEND_GENERATED_DIR_TOKEN;
import static com.vaadin.flow.server.Constants.VAADIN_PREFIX;
import static com.vaadin.flow.server.InitParameters.BUILD_FOLDER;
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_ENABLE_DEV_SERVER;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_INITIAL_UIDL;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_PRODUCTION_MODE;
Expand Down Expand Up @@ -115,6 +117,15 @@ protected Map<String, String> getConfigParametersUsingTokenData(
verifyFolderExists(params, buildInfo.getString(NPM_TOKEN));
}

if (buildInfo.hasKey(NODE_VERSION)) {
params.put(NODE_VERSION,
buildInfo.getString(NODE_VERSION));
}
if (buildInfo.hasKey(NODE_DOWNLOAD_ROOT)) {
params.put(NODE_DOWNLOAD_ROOT,
buildInfo.getString(NODE_DOWNLOAD_ROOT));
}

if (buildInfo.hasKey(FRONTEND_TOKEN)) {
params.put(FrontendUtils.PARAM_FRONTEND_DIR,
buildInfo.getString(FRONTEND_TOKEN));
Expand Down

0 comments on commit 981f4c6

Please sign in to comment.