[X] I have read the list of known issues before filing this issue.
[X] I have searched for similiar issues before filing this issue.
No idea if this is an ncu issue or not.
When I run ncu from the command line I can get the correct error code in $?. But when that same command line is run via teamcity the $? status code is always 0.
The script snippet looks like
ncu --error-level 2
check_status=$?
echo "check_status=${check_status}"
Any clues would be much appreciated.
A bit more context
The entire script:
#!/bin/bash
nvm install
npx npm-check-updates -e 2
check_status=$?
echo "check_status=${check_status}"
The output in teamcity
Found '/data/teamcity-agent-data/work/759230b22c4dd873/.nvmrc' with version <10.13.0>
v10.13.0 is already installed.
Now using node v10.13.0 (npm v6.4.1)
npx: installed 383 in 9.065s
Using /data/teamcity-agent-data/work/759230b22c4dd873/package.json
babel-jest 23.6.0 ��� 24.0.0
eslint-config-prettier ^3.6.0 ��� ^4.0.0
eslint-plugin-jsx-a11y 6.1.2 ��� 6.2.0
jest 23.6.0 ��� 24.0.0
The following dependencies are satisfied by their declared version range, but the installed versions are behind. You can install the latest versions without modifying your package file by using npm update. If you want to update the dependencies in your package file anyway, run ncu -a.
joi ^14.1.0 ��� ^14.3.1
mongoose ^5.4.6 ��� ^5.4.7
node-microservice ^3.5.191 ��� ^3.5.211
check_status=0
The output on the command line (running on the same teamcity build agent)
Found '/data/teamcity-agent-data/work/759230b22c4dd873/.nvmrc' with version <10.13.0>
v10.13.0 is already installed.
Now using node v10.13.0 (npm v6.4.1)
[INFO]: You can also use ncu as an alias
Using /data/teamcity-agent-data/work/759230b22c4dd873/package.json
[..................] \ :
babel-jest 23.6.0 → 24.0.0
eslint-config-prettier ^3.6.0 → ^4.0.0
eslint-plugin-jsx-a11y 6.1.2 → 6.2.0
jest 23.6.0 → 24.0.0
Dependencies not up-to-date
check_status=1
I see just a bit difference in the output. The command line version is showing the npm progress bar; The teamcity version is showiing additional packages to update.
Clearly different code is running. I've changed the command to
npx npm-check-updates@next --error-level INVALID
and it happily runs just as if the command was not specified. On the command this will result in invalid argument error.
Well, I was able to get a non-zero status by specifying a bogus argument flag
error: unknown option `--error-levelxxx'
check_status=1
I've tried every permutation I can imagine. But it is very clear that a different version is running in tc (even though the same version number is printed) or a different code path is executing (because outside of tc -- on the command line, via script, or in a subshell -- I get the final line "Dependencies not up-to-date" where in tc I never get that line).
@memelet Sorry for the trouble! Can you confirm that the output is different even when the node_modules folder has been deleted in both places? If not, that may be the issue (to be fixed in v3).
By deleted you mean deleted then again npm install? Yes, I have done that.
But I get different results from the exact same node_modules -- when teamcity runs the script vs when I run it manually as the teamcity user in the same checkout directory as the build. I just can't find what would be different. I don't see anything in the code that could possibly distinguish between the two.
I have also used the 3.x alpha. Do you expect that work?
@memelet No, I mean deleting the node_modules folder in your local folder and not running npm install. Just to see if there is still a difference. ncu v2 has some odd behavior here.
v3 is a larger rewrite than 3.x alpha which has not been updated in a while. It is worth trying when it comes out, but I am not aware of a specific change that would address your issue (other than that cited above). Given that ncu works correctly for you when you run it manually, it seems like the problem may lie with teamcity, but I can't know for sure.
FWIW, all errors are output via this function:
function programError(options, message) {
if (options.cli) {
print(options, message, null, 'error');
process.exit(1);
} else {
throw new Error(message);
}
}
https://github.com/tjunnone/npm-check-updates/blob/master/lib/npm-check-updates.js#L55-L62
I had the same problem, but with a gitlab runner and ncu 3.0.8
The verbose log showed me the following
Initializing...
Running in local mode...
Finding package file data...
Waiting for package data on stdin...
Using /...../package.json
Fetching latest versions...
I think this is a bug in the function getPackageDataFromFile arround the line https://github.com/tjunnone/npm-check-updates/blob/f7cd4e2539684389a8c516f34e68bd1c53a50614/lib/npm-check-updates.js#L358 as here the Promise pkgFile isn't set, so that https://github.com/tjunnone/npm-check-updates/blob/f7cd4e2539684389a8c516f34e68bd1c53a50614/lib/npm-check-updates.js#L218 is always false.
This seems to be supported by the fact, that i cannot see none of the outputs Dependencies not up-to-date, Upgraded package.json. Run 'npm install' to install new versions. or Run 'ncu -u' to upgrade package.json.
My workaround is to specifiy the package.json with --packageFile /.../package.json so that stdin is not used.
This behavior has occurred earlier and it seems not to get fixed: https://github.com/tjunnone/npm-check-updates/issues/136#issuecomment-347689346
Thank you @Novaal for the detailed explanation. It really helped me track down the issue. Hopefully it is fixed now with the v3.0.10 release!
With v3.0.11 i do not need to specifying the package.json. :+1:
ncu --error-level 2 --loglevel verbose
Initializing...
Running in local mode...
Finding package file data...
Waiting for package data on stdin...
Checking /.../package.json
Fetching latest versions...
...
Dependencies not up-to-date
ERROR: Job failed: exit code 1
Most helpful comment
Thank you @Novaal for the detailed explanation. It really helped me track down the issue. Hopefully it is fixed now with the v3.0.10 release!