diff --git a/packages/schematics/update/update/index.ts b/packages/schematics/update/update/index.ts index a0ce8cbd7343..e30b99ab9e76 100644 --- a/packages/schematics/update/update/index.ts +++ b/packages/schematics/update/update/index.ts @@ -459,10 +459,39 @@ function _usageMessage( const packageGroups = new Map(); const packagesToUpdate = [...infoMap.entries()] .map(([name, info]) => { - const tag = options.next - ? (info.npmPackageJson['dist-tags']['next'] ? 'next' : 'latest') : 'latest'; - const version = info.npmPackageJson['dist-tags'][tag]; - const target = info.npmPackageJson.versions[version]; + let tag = options.next + ? info.npmPackageJson['dist-tags']['next'] + ? 'next' + : 'latest' + : 'latest'; + let version = info.npmPackageJson['dist-tags'][tag]; + let target = info.npmPackageJson.versions[version]; + + const versionDiff = semver.diff(info.installed.version, version); + if ( + versionDiff !== 'patch' && + versionDiff !== 'minor' && + /^@(?:angular|nguniversal)\//.test(name) + ) { + const installedMajorVersion = semver.parse(info.installed.version)?.major; + const toInstallMajorVersion = semver.parse(version)?.major; + if ( + installedMajorVersion !== undefined && + toInstallMajorVersion !== undefined && + installedMajorVersion < toInstallMajorVersion - 1 + ) { + const nextMajorVersion = `${installedMajorVersion + 1}.`; + const nextMajorVersions = Object.keys(info.npmPackageJson.versions) + .filter((v) => v.startsWith(nextMajorVersion)) + .sort((a, b) => (a > b ? -1 : 1)); + + if (nextMajorVersions.length) { + version = nextMajorVersions[0]; + target = info.npmPackageJson.versions[version]; + tag = ''; + } + } + } return { name, @@ -496,7 +525,9 @@ function _usageMessage( } let command = `ng update ${name}`; - if (tag == 'next') { + if (!tag) { + command += `@${semver.parse(version)?.major || version}`; + } else if (tag == 'next') { command += ' --next'; }