node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
602 stars 118 forks source link

npmInstall hangs on windows #189

Closed doctorpangloss closed 2 years ago

doctorpangloss commented 3 years ago

On 3.1.0.

Not sure what the best way to provide a reproduction here is.

Something's iffy about npm install in this plugin.

The following works fine:

NodeNpm.java

package com.github.gradle.node.variant;

import com.github.gradle.node.NodeExtension;
import com.github.gradle.node.variant.VariantComputer;
import org.gradle.api.Project;
import org.gradle.api.provider.Provider;

public class NodeNpm {
    private static VariantComputer variantComputer = new VariantComputer();

    public static Provider<String> npmBinary(Project project) {
        var nodeExtension = NodeExtension.get(project);
        var nodeDir = variantComputer.computeNodeDir(NodeExtension.get(project));
        var npmDir = variantComputer.computeNpmDir(nodeExtension, nodeDir);
        var npmBinDir = variantComputer.computeNpmBinDir(npmDir);
        return variantComputer.computeNpmExec(nodeExtension, npmBinDir);
    }
}

build.gradle

task npmInstallEx {
  def binary = NodeNpm.npmBinary(project)
  inputs.file('package.json')
  outputs.dir('node_modules')
  doLast {
    exec {
      commandLine binary.get(), "install"
    }
  }
}

So it looks like the task as you authored it is preventing the task from finishing on Windows.

deepy commented 3 years ago

Not entirely sure on the best way to create a reproducer either, I'm guessing it's one of the packages being installed that's causing this since at home, at work, and on CI we're successfully using npmInstall

But since the major thing we do is just hand parameters to Gradle's Exec it really should behave in the same way in the terminal and in the build and at any point I'd expect at least an error