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

Support using node from other project #61

Open
daosavaj opened this issue Jan 20, 2020 · 10 comments
Open

Support using node from other project #61

daosavaj opened this issue Jan 20, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@daosavaj
Copy link

daosavaj commented Jan 20, 2020

Original question
So i have a multi module project with two subprojects that have Node dependencies. What is the best way to have Node only download once.

/subproject1
...build.gradle
/subproject2
...build.gradle
build.gradle

@deepy
Copy link
Member

deepy commented Jan 20, 2020

I guess what you really want is just one instance of node/npm, to which I unfortunately don't have a good answer.
But with gradle's caching and such it should only download node once, even though it unpacks twice.

@daosavaj
Copy link
Author

Ah okay, Thanks for the quick reply!

@deepy
Copy link
Member

deepy commented Jan 20, 2020

This is a feature we probably want to support in the future though, so I'm editing the title and re-opening this issue :-)
Although for multiple reasons it's going to be tough to implement, but at worst we should be able to provide a hacky way to do it.

@deepy deepy changed the title Multi Module Project Question Support using node from other project Jan 20, 2020
@deepy deepy reopened this Jan 20, 2020
@deepy deepy added the enhancement New feature or request label Jan 23, 2020
@myronu
Copy link

myronu commented Feb 21, 2020

I am able to make this work to an extent. All you really have to do is set the workDir and npmWorkDir to the same directory like this:

workDir = file("${rootDir}/nodejs")
npmWorkDir = file("${rootDir}/npm")
download = true

This fails if you make any attempt to run the build in parallel, however, because it still wants to unpack npm and nodejs every time. I was hoping it would detect that node was already installed and not try to do it a second time, but that is not the case. What I found is that if download=true, it always unpacks it. If download=false, it uses your system copy.

@deepy
Copy link
Member

deepy commented Feb 21, 2020

I guess the easiest way forward would be to add an option to download = false to specify where node is, that'd let you work around this one by having one download = true and multiple = false pointing to that

@eekboom
Copy link

eekboom commented Apr 9, 2020

Can't you just always install in the rootProject's .gradle directory instead of the sub-project's .gradle directory?

@bsautel
Copy link
Contributor

bsautel commented Apr 29, 2020

This idea may be a good solution, but it would be necessary to ensure that there can be no conflict in case of multiple projects of the same multi-project build using different Node.js configurations (for instance different version). Or maybe we should force all projects to use the same Node.js configuration?

@loganmzz
Copy link

@bsautel Just add distinct installation directories per version ?

@michkot
Copy link

michkot commented Apr 16, 2024

At least with version 3.5 (not sure about the newer ones), it seems that when node { .... download = false .... } is used in a project, the paths to the node/npm commands are not resolved correctly (according the specified version & current platform), so NpmTask and NodeTask end-up calling just "npm" or "node" respectively, and either fail (no such command) or use binaries from PATH (not what you want)

However, it seem that setting up node in all the projects the sameway (with download = true and setting workDir / npmWorkDir to the same fixed location ) and then setting the tasks named nodeSetup npmSetup as disabled (e.g. enabled = false) in all projects but one will do the trick - the node/npm paths are correctly resolved everywhere, and the actuall downloading/unpacking will happen just once (in the non-disabled tasks)

Note: you can alternatively locate tasks of type com.github.gradle.node.task.NodeSetupTask / com.github.gradle.node.npm.task.NpmSetupTask instead of going by name

@deepy
Copy link
Member

deepy commented Apr 17, 2024

There's two specific ways of working that this plugin supports, one is "always use this specific version of node" (download = true) and the other is "Use my own installation of node" (download = false)

Disabling nodeSetup and npmSetup is a nifty way of doing this, I suspect thanks to inputs/outputs it should work fine.
And thinking about it, maybe it's fine to wire things up that way, but I have to look into this a bit closer

But as long as you use the same version of node everywhere thanks to Gradle's dependency mechanism you should only be downloading nodejs once (and if you use a blank npm version you download npm 0 times 🎉) so you'll be saving space from unpacking node but still have the same amount of downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants