Flow: Automatically detect the node and npm binaries or download them, if not detected

Created on 4 Apr 2019  路  4Comments  路  Source: vaadin/flow

Currently we either assume that node and other tools are in PATH and run them straight away as in https://github.com/vaadin/flow/blob/2.0/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/NodeUpdateImportsMojo.java#L85

or do some PATH-related magic before and run it straight away, as in https://github.com/vaadin/flow/blob/2.0/flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdatePackages.java#L207

In some corner cases like Eclipse task executor it does not work.
What we need is to analyze the PATH, extract the full path to node and npm and use those instead.

If the tools are not detected, we should be able to download them (the way we do it for a bower version of the plugin), since it is hard to expect all Java devs having or willing to have the node installed

enhancement nodnppnpm

Most helpful comment

If we automatically download Node, maybe we should put it in ~/.vaadin/node-<version> so all the tools know where it can be found.

Also, we should probably check if the node that is found is new enough. If it is not, we should download and use that version

All 4 comments

I agree that we should visit the env-path and also well-known paths to check where the binaries are, in that search I would include also the project/node, /usr/local/bin and $HOME/bin paths

Related with automatic installation, it's done by the frontend-maven plugin, probably instead of having some code in our plugin for doing the same, we can document how to add that feature to user projects if they don't want to have it in their systems, but not enabled by default

The current problem with the node download approach is that some logic that runs node is in the flow-server, in DevModeHandler and some logic that runs node is in the flow-maven-plugin.

flow-server cannot download node, since it can be run in the servlet container and, in general, it just does not know where to download it, since can operate relative paths only.

Even if the node is downloaded, we need to find a way to share the path to it both in flow-server and in flow-maven-plugin.

If we automatically download Node, maybe we should put it in ~/.vaadin/node-<version> so all the tools know where it can be found.

Also, we should probably check if the node that is found is new enough. If it is not, we should download and use that version

This issue was addressed in #5472. Now, if nodejs is not installed an error message including nodejs installation guide is shown.

Was this page helpful?
0 / 5 - 0 ratings