Class FrontendTools
- java.lang.Object
-
- com.vaadin.flow.server.frontend.FrontendTools
-
public class FrontendTools extends Object
Provides access to frontend tools (Node.js and npm, pnpm) and optionally installs the tools if needed.WARNING: This class is intended for internal usage only. May be renamed or removed in a future release.
- Author:
- Vaadin Ltd
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_NODE_VERSIONThis is the version that is installed if there is no node installed or the installed version is older thanSUPPORTED_NODE_VERSION, i.e.static StringDEFAULT_NPM_VERSIONThis is the version shipped with the default Node version.static StringDEFAULT_PNPM_VERSIONstatic StringINSTALL_NODE_LOCALLYstatic StringNPM_BIN_PATH
-
Constructor Summary
Constructors Constructor Description FrontendTools(FrontendToolsSettings settings)Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.FrontendTools(ApplicationConfiguration applicationConfiguration, File projectRoot)Creates an instance using the the given project directory and application configuration.FrontendTools(String baseDir, Supplier<String> alternativeDirGetter)Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, boolean forceAlternativeNode)Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot)Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot, boolean forceAlternativeNode, boolean useGlobalPnpm)Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot, boolean forceAlternativeNode, boolean useGlobalPnpm, boolean autoUpdate)Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringforceAlternativeNodeExecutable()Locatenodeexecutable from the alternative directory given.StringgetNodeBinary()Gets a path to the used node binary.StringgetNodeExecutable()Locatenodeexecutable.FrontendVersiongetNodeVersion()Gets the version of the node executable.List<String>getNpmExecutable()Locatenpmexecutable.FrontendVersiongetNpmVersion()Executesnpm --versionto and parses the result.List<String>getPnpmExecutable()Locatepnpmexecutable.protected List<ProxyConfig.Proxy>getProxies()Read list of configured proxies in order from system properties, .npmrc file in the project root folder, .npmrc file in user root folder and system environment variables.Map<String,String>getWebpackNodeEnvironment()Returns flags required to pass to Node for Webpack to function.protected StringinstallNode(String nodeVersion, URI downloadRoot)Install node and npm.voidvalidateNodeAndNpmVersion()Validate that the found node and npm versions are new enough.
-
-
-
Field Detail
-
DEFAULT_NODE_VERSION
public static final String DEFAULT_NODE_VERSION
This is the version that is installed if there is no node installed or the installed version is older thanSUPPORTED_NODE_VERSION, i.e. 20.0.- See Also:
- Constant Field Values
-
DEFAULT_NPM_VERSION
public static final String DEFAULT_NPM_VERSION
This is the version shipped with the default Node version.- See Also:
- Constant Field Values
-
DEFAULT_PNPM_VERSION
public static final String DEFAULT_PNPM_VERSION
- See Also:
- Constant Field Values
-
INSTALL_NODE_LOCALLY
public static final String INSTALL_NODE_LOCALLY
- See Also:
- Constant Field Values
-
NPM_BIN_PATH
public static final String NPM_BIN_PATH
-
-
Constructor Detail
-
FrontendTools
public FrontendTools(FrontendToolsSettings settings)
Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.Note: settings for this object can not be changed through the settings object after creation.
- Parameters:
settings- tooling settings to use
-
FrontendTools
public FrontendTools(ApplicationConfiguration applicationConfiguration, File projectRoot)
Creates an instance using the the given project directory and application configuration.- Parameters:
projectRoot- the project root directoryapplicationConfiguration- the configuration for the application
-
FrontendTools
@Deprecated public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter)
Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.- Parameters:
baseDir- the base directory to locate the tools, notnullalternativeDirGetter- the getter for a directory where tools will be installed if they are not found globally or in thebaseDir, may benull
-
FrontendTools
@Deprecated public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, boolean forceAlternativeNode)
Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.- Parameters:
baseDir- the base directory to locate the tools, notnullalternativeDirGetter- the getter for a directory where tools will be installed if they are not found globally or in thebaseDir, may benullforceAlternativeNode- force usage of node executable from alternative directory
-
FrontendTools
@Deprecated public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot)
Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.- Parameters:
baseDir- the base directory to locate the tools, notnullalternativeDirGetter- the getter for a directory where tools will be installed if they are not found globally or in thebaseDir, may benullnodeVersion- The Node.js version to be used when Node.js is installed automatically by Vaadin, for example"v16.0.0". Use "v22.15.1" by default.nodeDownloadRoot- Download Node.js from this URL. Handy in heavily firewalled corporate environments where the Node.js download can be provided from an intranet mirror. UseNodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOTby default.
-
FrontendTools
@Deprecated public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot, boolean forceAlternativeNode, boolean useGlobalPnpm)
Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.- Parameters:
baseDir- the base directory to locate the tools, notnullalternativeDirGetter- the getter for a directory where tools will be installed if they are not found globally or in thebaseDir, may benullnodeVersion- The Node.js version to be used when Node.js is installed automatically by Vaadin, for example"v16.0.0". Use "v22.15.1" by default.nodeDownloadRoot- Download Node.js from this URL. Handy in heavily firewalled corporate environments where the Node.js download can be provided from an intranet mirror. UseNodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOTby default.forceAlternativeNode- force usage of node executable from alternative directoryuseGlobalPnpm- use globally installed pnpm instead of the default one (seeDEFAULT_PNPM_VERSION)
-
FrontendTools
@Deprecated public FrontendTools(String baseDir, Supplier<String> alternativeDirGetter, String nodeVersion, URI nodeDownloadRoot, boolean forceAlternativeNode, boolean useGlobalPnpm, boolean autoUpdate)
Deprecated.useFrontendTools(FrontendToolsSettings)instead, as it simplifies configuring the frontend tools and gives the default values to configuration parameters.Creates an instance of the class using thebaseDiras a base directory to locate the tools and the directory returned by thealternativeDirGetteras a directory to install tools if they are not found and use it as an alternative tools location.If
alternativeDirisnulltools won't be installed.- Parameters:
baseDir- the base directory to locate the tools, notnullalternativeDirGetter- the getter for a directory where tools will be installed if they are not found globally or in thebaseDir, may benullnodeVersion- The Node.js version to be used when Node.js is installed automatically by Vaadin, for example"v16.0.0". Use "v22.15.1" by default.nodeDownloadRoot- Download Node.js from this URL. Handy in heavily firewalled corporate environments where the Node.js download can be provided from an intranet mirror. UseNodeInstaller.DEFAULT_NODEJS_DOWNLOAD_ROOTby default.forceAlternativeNode- force usage of node executable from alternative directoryuseGlobalPnpm- use globally installed pnpm instead of the default one (seeDEFAULT_PNPM_VERSION)autoUpdate- update node inalternativeDirGetterif version older than the current default "v22.15.1"
-
-
Method Detail
-
getNodeExecutable
public String getNodeExecutable()
Locatenodeexecutable.- Returns:
- the full path to the executable
-
forceAlternativeNodeExecutable
public String forceAlternativeNodeExecutable()
Locatenodeexecutable from the alternative directory given.The difference between
getNodeExecutable()and this method in a search algorithm:getNodeExecutable()first searches executable in the base/alternative directory and fallbacks to the globally installed if it's not found there. TheforceAlternativeNodeExecutable()doesn't search for globally installed executable. It tries to find it in the installation directory and if it's not found it downloads and installs it there.- Returns:
- the full path to the executable
- See Also:
getNodeExecutable()
-
getNpmExecutable
public List<String> getNpmExecutable()
Locatenpmexecutable.- Returns:
- the list of all commands in sequence that need to be executed to have npm running
-
getPnpmExecutable
public List<String> getPnpmExecutable()
Locatepnpmexecutable.In case pnpm is not available it will be installed.
- Returns:
- the list of all commands in sequence that need to be executed to have pnpm running
-
validateNodeAndNpmVersion
public void validateNodeAndNpmVersion()
Validate that the found node and npm versions are new enough. Throws an exception with a descriptive message if a version is too old.
-
getNodeVersion
public FrontendVersion getNodeVersion() throws FrontendUtils.UnknownVersionException
Gets the version of the node executable.
-
installNode
protected String installNode(String nodeVersion, URI downloadRoot)
Install node and npm.- Parameters:
nodeVersion- node version to installdownloadRoot- optional download root for downloading node. May be a filesystem file or a URL seeNodeInstaller.setNodeDownloadRoot(URI).- Returns:
- node installation path
-
getProxies
protected List<ProxyConfig.Proxy> getProxies()
Read list of configured proxies in order from system properties, .npmrc file in the project root folder, .npmrc file in user root folder and system environment variables.- Returns:
- list of configured proxies
-
getNpmVersion
public FrontendVersion getNpmVersion() throws FrontendUtils.UnknownVersionException
Executesnpm --versionto and parses the result.- Returns:
- the version of npm.
- Throws:
FrontendUtils.UnknownVersionException- if the npm command fails or returns unexpected output.
-
getWebpackNodeEnvironment
public Map<String,String> getWebpackNodeEnvironment()
Returns flags required to pass to Node for Webpack to function. Determine whether webpack requires Node.js to be started with the --openssl-legacy-provider parameter. This is a webpack 4 workaround of the issue https://github.com/webpack/webpack/issues/14532 See: https://github.com/vaadin/flow/issues/12649- Returns:
- the flags
-
getNodeBinary
public String getNodeBinary()
Gets a path to the used node binary. The return value can be used when executing node commands, as the first part of a process builder command.- Returns:
- the path to the node binary
-
-