Skip to content

Commit

Permalink
show separate table for incompatible updates
Browse files Browse the repository at this point in the history
  • Loading branch information
korelstar committed Apr 14, 2021
1 parent b8dad8c commit 9778689
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions src/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ const pkg = require('../../package.json');

function createUpdatedModulesTable(modules) {
return createSimpleTable(
_.map(modules, ({name, from, to, toVersion, latestVersion}) => [
_.map(modules, ({name, from, to}) => [
strong(name),
from, '→', colorizeDiff(from, to),
toVersion !== latestVersion ? '(ignored incompatible latest version ' + latestVersion + ')' : ''
from, '→', colorizeDiff(from, to)
])
);
}
Expand Down Expand Up @@ -77,25 +76,29 @@ export const handler = catchAsyncError(async opts => {
.map(({ncuValue}) => ncuValue)
.join(',');
const currentVersions = ncu.getCurrentDependencies(packageJson, {dep: ncuDepGroups});
const latestVersions = await ncu.queryVersions(currentVersions, {versionTarget: 'latest'});
const peerDependencies = ncu.getPeerDependencies(currentVersions, {});
const peerCompatibleVersions = await ncu.queryVersions(
currentVersions,
{versionTarget: 'latest', peerDependencies, loglevel: 'silent'}
);
const upgradedPeerCompatibleVersions = ncu.upgradeDependencies(currentVersions, peerCompatibleVersions);
let upgradedVersions = ncu.upgradeDependencies(currentVersions, latestVersions);
const compatibleVersions = await ncu.queryVersions(currentVersions, {versionTarget: 'latest', peerDependencies});
const latestVersions = await ncu.queryVersions(currentVersions, {versionTarget: 'latest', loglevel: 'silent'});

// Filtering modules that have to be updated
upgradedVersions = _.pickBy(
upgradedVersions,
const upgradedLatestVersions = _.pickBy(
ncu.upgradeDependencies(currentVersions, latestVersions),
(newVersion, moduleName) => filterModuleName(moduleName)
);
const upgradedCompatibleVersions = _.pickBy(
ncu.upgradeDependencies(currentVersions, compatibleVersions),
(newVersion, moduleName) => filterModuleName(moduleName)
);

if (_.isEmpty(upgradedVersions)) {
if (_.isEmpty(upgradedLatestVersions)) {
return console.log(success('All dependencies are up-to-date!'));
}

const incompatibleVersions = _.pickBy(
upgradedLatestVersions,
(newVersion, moduleName) => upgradedCompatibleVersions[moduleName] !== newVersion
);

// Getting the list of ignored modules
const config = new Config();
config.ignore = config.ignore || {};
Expand All @@ -105,15 +108,14 @@ export const handler = catchAsyncError(async opts => {
map.convert({'cap': false})((newVersion, moduleName) => ({
name: moduleName,
from: currentVersions[moduleName],
to: upgradedPeerCompatibleVersions[moduleName] || currentVersions[moduleName],
toVersion: peerCompatibleVersions[moduleName],
latestVersion: latestVersions[moduleName]
to: newVersion,
toVersion: compatibleVersions[moduleName]
})),
partition(module => (
_.has(config.ignore, module.name) &&
semver.satisfies(module.toVersion, config.ignore[module.name].versions)
))
)(upgradedVersions);
)(upgradedCompatibleVersions);

// Moving `@types/*` modules right below their original modules
sortModules(modulesToUpdate);
Expand All @@ -130,6 +132,15 @@ export const handler = catchAsyncError(async opts => {
);
}

if (!_.isEmpty(incompatibleVersions)) {
const rows = _.map(Object.entries(incompatibleVersions), ([name, to]) => [
strong(name),
currentVersions[name], '→', colorizeDiff(currentVersions[name], to)
]);

console.log(`\n${strong('Ignored incompatible updates (peer dependencies):')}\n\n${createSimpleTable(rows)}`);
}

if (!_.isEmpty(ignoredModules)) {
const rows = _.map(ignoredModules, ({name, from, to}) => [
strong(name),
Expand All @@ -151,7 +162,7 @@ export const handler = catchAsyncError(async opts => {
let isUpdateFinished = false;
while (modulesToUpdate.length && !isUpdateFinished) {
const outdatedModule = modulesToUpdate.shift();
const {name, from, to} = outdatedModule;
const {name, from, to, toVersion} = outdatedModule;
let {changelogUrl, homepage} = outdatedModule;

// Adds new line
Expand Down Expand Up @@ -218,7 +229,7 @@ export const handler = catchAsyncError(async opts => {
break;

case 'ignore': {
const {versions, reason} = await askIgnoreFields(latestVersions[name]);
const {versions, reason} = await askIgnoreFields(toVersion);
config.ignore[name] = {versions, reason};
break;
}
Expand Down

0 comments on commit 9778689

Please sign in to comment.