gradle-node-plugin icon indicating copy to clipboard operation
gradle-node-plugin copied to clipboard

NPM task is not causing an expected error if npmVersion is not set

Open gavingolden opened this issue 6 years ago • 8 comments

With the following configuration, I noticed that the gradle npm task is not failing when it should. I tested this by running the npm run test task directly from the same directory and it returned the expected linting error (so there's an error yet the gradle task passes without any of the expected error output).

Command: ./gradlew lint Ouput:

> Task :gateway:lint

> [email protected] debug /my/user/project/modules/gateway
> npx lint


BUILD SUCCESSFUL in 0s
2 actionable tasks: 1 executed, 1 up-to-date

Command: npm run lint Output:

> [email protected] lint /my/user/project/modules/gateway
> npx tslint -p tsconfig.json -c tslint.json


ERROR: /my/user/project/modules/gateway/src/server/user-auth/service.ts:14:61 - Missing semicolon

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] lint: `npx tslint -p tsconfig.json -c tslint.json`
npm ERR! Exit status 2

build.gradle

node {
    version = "10.15.0"
    download = true
}

task lint(type: NpmTask) {
    args = ['run', 'lint']
}

package.json

"scripts": {
    "lint": "npx tslint -p tsconfig.json -c tslint.json"
},

I've tried debugging this with a few scenarios:

  •    "scripts": {
         "lint": "exit 1"
      },
    
    • This failed as expected
  •    "scripts": {
         "lint": "echo $(pwd)"
      },
    
    • This prints the expected root directory of the module

I suspect it might have to do with the gradle output 1 up-to-date, which I believe is part of the incremental build system. If that's the problem how do you recommend getting past it?

gavingolden avatar Jun 13 '19 02:06 gavingolden

I'll see if I can reproduce this when I get home, but the fact that you're getting console output means that you don't have to worry about the up-to-date, nodeSetup is probably the task that's up-to-date. You can use gradle --info or --profile to see what's really being done.

This however seems kinda strange, could you double-check the exit code of npm run lint outside of gradle? (just run it and then see what echo $? says)

deepy avatar Jun 13 '19 08:06 deepy

Thanks for the quick feedback. The exist code of npm run lint is 2.

And I confirmed that the lint task isn't being skipped by gradle

> ./gradlew lint --info
> Task :gateway:lint
Task ':gateway:lint' is not up-to-date because:
  Task has not declared any outputs despite executing actions.

gavingolden avatar Jun 13 '19 23:06 gavingolden

I've reproduced this in https://github.com/deepy/testcase but I can't see why the project.exec() fails in the plugin, but not in the specific tasks I set up. Will continue troubleshooting later on.

deepy avatar Jun 17 '19 19:06 deepy

When changing the testcase like this the problem goes away, further troubleshooting necessary

node {
    version = '10.15.3'
    npmVersion = '6.9.0'
    download = true
}

deepy avatar Jun 19 '19 09:06 deepy

@gavingolden what does npm --version give you? On 6.4.1 the lint task fails for me, on 6.9.0 and 6.5.0 it works Hmm, it works for me if I specify a npmVersion, even if I do npmVersion = '6.4.1' which is the version I get if I do not specify one...

deepy avatar Jun 19 '19 09:06 deepy

I have a global npm version of 6.9.0, which exhibited the broken behavior when npmVersion is not set. However...as you said: after setting that very same version explicitly in build.gradle it worked

gavingolden avatar Jun 20 '19 00:06 gavingolden

We still want to solve the underlying issue here, even if a workaround exists :-)

deepy avatar Jun 25 '19 10:06 deepy

ha oops, I referenced this issue in a private PR and merging it caused it to close automatically

gavingolden avatar Jun 25 '19 16:06 gavingolden