Skip to content

Commit cfbe528

Browse files
committed
fix(@schematics/update): show message when nothing to do
Fix angular/angular-cli#10251
1 parent e7a32db commit cfbe528

File tree

1 file changed

+37
-19
lines changed
  • packages/schematics/update/update

1 file changed

+37
-19
lines changed

packages/schematics/update/update/index.ts

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,30 @@ function _usageMessage(
331331
infoMap: Map<string, PackageInfo>,
332332
logger: logging.LoggerApi,
333333
) {
334+
const packagesToUpdate = [...infoMap.entries()]
335+
.sort()
336+
.map(([name, info]) => {
337+
const tag = options.next ? 'next' : 'latest';
338+
const version = info.npmPackageJson['dist-tags'][tag];
339+
const target = info.npmPackageJson.versions[version];
340+
341+
return [
342+
name,
343+
info,
344+
version,
345+
target,
346+
] as [string, PackageInfo, string, JsonSchemaForNpmPackageJsonFiles];
347+
})
348+
.filter(([name, info, version, target]) => {
349+
return (target && semver.compare(info.installed.version, version) < 0);
350+
});
351+
352+
if (packagesToUpdate.length == 0) {
353+
logger.info('We analyzed your package.json and everything seems to be in order. Good work!');
354+
355+
return of<void>(undefined);
356+
}
357+
334358
logger.info(
335359
'We analyzed your package.json, there are some packages to update:\n',
336360
);
@@ -349,26 +373,20 @@ function _usageMessage(
349373
);
350374
logger.info(' ' + '-'.repeat(namePad * 2 + 35));
351375

352-
[...infoMap.entries()].sort().forEach(([name, info]) => {
353-
const tag = options.next ? 'next' : 'latest';
354-
const version = info.npmPackageJson['dist-tags'][tag];
355-
const target = info.npmPackageJson.versions[version];
356-
357-
if (target && semver.compare(info.installed.version, version) < 0) {
358-
let command = `npm install ${name}`;
359-
if (target && target['ng-update']) {
360-
// Show the ng command only when migrations are supported, otherwise it's a fancy
361-
// npm install, really.
362-
command = `ng update ${name}`;
363-
}
364-
365-
logger.info(
366-
' '
367-
+ name.padEnd(namePad)
368-
+ `${info.installed.version} -> ${version}`.padEnd(25)
369-
+ ' ' + command,
370-
);
376+
packagesToUpdate.forEach(([name, info, version, target]) => {
377+
let command = `npm install ${name}`;
378+
if (target && target['ng-update']) {
379+
// Show the ng command only when migrations are supported, otherwise it's a fancy
380+
// npm install, really.
381+
command = `ng update ${name}`;
371382
}
383+
384+
logger.info(
385+
' '
386+
+ name.padEnd(namePad)
387+
+ `${info.installed.version} -> ${version}`.padEnd(25)
388+
+ ' ' + command,
389+
);
372390
});
373391

374392
logger.info('\n');

0 commit comments

Comments
 (0)