node-gradle / gradle-node-plugin

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

Cannot run NpxTask with different package name since 3.0.0 #165

Open cwrau opened 3 years ago

cwrau commented 3 years ago

Npx has the feature to call a command from a package whose name differs from the command.

This can be achieved with the npx flag --package as seen on https://www.npmjs.com/package/npx

Before 3.0.0 I accessed the runner property of the NpxTask to set the argument;

        @Suppress("UNCHECKED_CAST")
        (runner.arguments as MutableList<Any>).addAll(
            listOf(
                "--package",
                npxPackage
            )
        )

Since the 3.0.0 release, the runner property of the NpxTask is not available anymore

Could you implement this feature into the task or show me a way to set this argument again?

deepy commented 3 years ago

There's a getArgs() you can use instead

cwrau commented 3 years ago

As I understand, that method only sets args for the command, not npx itself

deepy commented 3 years ago

hmm, I'll have to think a little bit about that, but in the meantime a not-so-pretty-workaround is to set --package as command and args.addAll(npxPackage) the way that it's done is that the full command is added by taking command and then adding args: https://github.com/node-gradle/gradle-node-plugin/blob/1d9259d/src/main/kotlin/com/github/gradle/node/npm/task/NpxTask.kt#L67-L68

cwrau commented 3 years ago

Nice, that workaround works!

bsautel commented 3 years ago

The workaround suggested by deepy works but it would be nice if we could add support of this correctly by adding a packageName optional property for instance. I did not know about this option when I started working on this NpxTask.