cincheo/jsweet

Feature request: Extra Path config for node.js installation

Closed this issue · 5 comments

Currently there is a requirement for node.js to be installed on the build machine so that node and npm is on the system path. (As mentioned here)

I would like to be able to use gradle-node-plugin to install a local build installation of node.js (it puts it in the .gradle directory) so I don't have to install and manage a node.js installation on every build node myself.

However jsweet-gradle-plugin can't see gradle-node-plugin's node.js installation, as it's not on the system path.

As gradle-node-plugin will never be able to modify the actual system path, I suggest that a solution would be to modify this projects existing EXTRA_PATH static field in ProcessUtil.java to be accessible from the gradle build (via jsweet-gradle-plugin) so that it can be set with the node.js installation path. That will enable all node.js commands to be found by jsweet.

So to do this, add something as simple as this to this projects JSweetConfig.java

        public static void initExtraPath(final String path)
	{
		if (!StringUtils.isBlank(path))
		{
			ProcessUtil.EXTRA_PATH = path;
		}
	}

Then the new initExtraPath method needs to be called from jsweet-gradle-plugin.
E.g. in JSweetTranspileTask.java

JSweetConfig.initExtraPath(configuration.getExtraPath());

And adding an extraPath property to the jsweet-gradle-plugin configuration..
E.g. in JSweetPluginExtension.java add the extraPath property and accessors..

	private String extraPath;
	public String getExtraPath()
	{
		return extraPath;
	}

	public void setExtraPath(final String extraPath)
	{
		this.extraPath = extraPath;
	}

then extraPath can be configured in gradle build script using gradle-node-plugin to download\install node.js. e.g..

	node {
		version = '8.2.1'
		npmVersion = '5.3.0'
		download = true // download = true will download and install node.js in the .gradle directory.
	}

	afterEvaluate
	{
		jsweet.setExtraPath("${node.variant.nodeBinDir}")
	}

I've tried this out locally and tested it on the jsweet-examples project by adding gradle-node-plugin to the gradle build script.

I've raised this issue against this jsweet project, but my suggested solution crosses into the jsweet-gradle-plugin project.

If this change is made to the configuration of the jsweet gradle plugin, then I assume the same change would need to be made to the equivalent maven plugin? (which is referred to from the jsweet-gradle-plugin documentation)

Hello @philwilkinson, thanks for your suggestion which seems fine by me.
Could you please create related issues in both maven and gradle plugin, and I will take a look asap. I hope tomorrow night.

Thanks again.

@renaudpawlak I think this could be integrated in rc2
51e4fad

We may want to add this feature to the command line, dont we?

sure we need the same option for the command line launcher... do you want to add it?
thanks!

If you have time, please do it because I won't be able to do it before next week.