npm-check-updates
npm-check-updates copied to clipboard
upgrade and jsonUpgraded options do not work together (ncu.run)
- [x] I have read the list of known issues before filing issue.
- [ ] I have searched for similiar issues before filing this issue.
- node version: 9.9.0
- npm version: 5.6
- npm-check-updates version: 2.14.1
Code as
const ncu = require('npm-check-updates');
ncu.run({
// Always specify the path to the package file
packageFile: 'package.json',
// Any command-line option can be specified here.
// These are set by default:
silent: true,
jsonUpgraded: true,
upgrade: true
}).then((upgraded) => {
console.log('dependencies to upgrade:', upgraded);
});
I checked the source code ,if upgrade is not set ,it will not call printUpgrades of writePackageFile,if upgrade is set ,then jsonUpgraded is set,then options.json will be true called by initOptions,which will check if it has a parm like 'json%', then printUpgrades will not be called in analyzeProjectDependencies.
So package.json can not be saved forever.
Thanks! That does seem to be an issue. For the time being, you could invoke ncu via a child process.
FYI - I got it to update the package file with options { upgrade: true, upgradeAll: true }, but the moment I use these options (vs no options) it returns null and prints no helpful information, regardless of silent or logLevel settings. It would be beneficial to return a data structure needed to print the equivalent console (before/after versions) or allow reuse of the print methods.
I'm using this integration to manually update my lerna monorepos, it would be fantastic if the npm-check-updates file was broken down into more discrete pieces for reuse. I love the normal command line output, I just need a bit more control so as to not smash together output from 5 processes in an unrecognizable way (which is what happens if you run as a child process or hack it into running as {api: true, args: []}.
I added a test in 9f52fc9 for the OP. @dogHere Does that look right to you? The test is passing without any additional code changes, i.e. it appears to be upgrading the package.json and outputing jsonUpgraded.
@rosskevin There are a lot of methods that are exported, just not documented for official use. Would these help? You can look at the source or the unit tests to see how they work.
getCurrentDependencies,
getInstalledPackages,
getVersionTarget,
isSatisfied,
upgradePackageData,
upgradePackageDefinitions,
getPreferredWildcard,
isUpgradeable,
queryVersions,
upgradeDependencies,
upgradeDependencyDeclaration
Regarding the first point in the original post by @dogHere
if upgrade is not set ,it will not call printUpgrades of writePackageFile...
...if upgrade is not set, writePackageFile will indeed not be called and writing will not occur (as should be expected since that is what upgrade is for and why it is needed for overwriting the file). However, printUpgrades may be called regardless of the upgrade setting--I see no relation between these two, and in any case, printUpgrades doesn't need to be called for saving to occur; that function merely builds non-JSON potentially tabular output.
Regarding your second point:
if upgrade is set ,then jsonUpgraded is set,then options.json will be true called by initOptions,which will check if it has a parm like 'json%', then printUpgrades will not be called in analyzeProjectDependencies.
...while this is accurate, again, printUpgrades is not needed for writing. And you presumably don't want printUpgrades if you have jsonUpgraded or jsonAll set, since JSON options would tend to be used for machine consumption rather than human reading.
So, it seems to me that this issue can be closed.
However, if @rosskevin wants the likes of printUpgrades so potentially tabular console output could be printed after receiving and consuming JSON output, I could see a desire for that, but I think it should be a separate issue, as these two options (upgrade and jsonUpgraded) do work together and saving occurs.
Closing due to inactivity