node-gradle / gradle-node-plugin

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

npmSetup args property immutable #208

Open Gamadril opened 2 years ago

Gamadril commented 2 years ago

When I try to add registry parameter for npmSetup Task according to FAQ:

tasks.npmSetup {
    doFirst {
        args.addAll(['--registry', 'http://myregistry.npm.com'])
    }
}

I get an error running npmSetup:

Execution failed for task ':xxx:npmSetup'.
> The value for task ':xxx:npmSetup' property 'args' is final and cannot be changed any further.

plugin version: 3.1.1

Sineaggi commented 2 years ago

Set the args on the task itself, no need for doFirst

tasks.npmSetup {
    args.addAll(['--registry', 'http://myregistry.npm.com'])
}
Gamadril commented 2 years ago

Without doFirst the args are accepted -> FAQ should be updated for v3. However v3 seems not to work with our nexusIQ server. v2 works.

3.1.1:

npm info using npm@8.1.2
npm info using node@v16.13.1
...
npm verb stack HttpErrorGeneral: 404 Not Found - GET http://nexusiq.local:8081/nexus/content/groups/npm-all/npm

2.2.4:

npm info using npm@8.1.2
npm info using node@v16.13.1
...
npm http fetch GET 200 http://nexusiq.local:8081/nexus/content/groups/npm-all/npm 1094ms (cache updated)

same URL - different behaviour between v2 and v3. URL can be opened in a browser.

deepy commented 2 years ago

Any proxies involved in the mix? Might be worth trying with ProxySettings.OFF

Gamadril commented 2 years ago

Thanks. nodeProxySettings = ProxySettings.OFFdid it.

deepy commented 2 years ago

I can recommend adding your local nexus to nonProxyHosts and turning on proxy support again, even if things work :-)

shorn commented 2 years ago

I have this problem because of the following code:

  // "args" has to be set at exec time, because the schema files won't 
  // have been generated at config time.
  doFirst {
    args = [
      'run', 'dtsgen',
      "--",  // separator, all args after this go to the script
      "--out", "$generatedTsInterfaceFile",
      // can't use fileTree here anymore, too many schema files
      "$generatedTsJsonSchemaDir/*" ]
  }

So this will be easy enough to refactor because I'm not using fileTree any more to enumerate the files at rutime. The comment about "has to be set at exec time" is no longer true, so I can just get rid of the doFirst and the block executes at config time.

Just thought I'd submit it as an example.

Also had a problem where I had code like:

args baseArgs
args += prodArgs

That was reasonably easily refactored though.