gradle-node-plugin
gradle-node-plugin copied to clipboard
NPM task is not causing an expected error if npmVersion is not set
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?
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)
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.
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.
When changing the testcase like this the problem goes away, further troubleshooting necessary
node {
version = '10.15.3'
npmVersion = '6.9.0'
download = true
}
@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...
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
We still want to solve the underlying issue here, even if a workaround exists :-)
ha oops, I referenced this issue in a private PR and merging it caused it to close automatically