From 487486ae66766c593bda64e147caf03cbcc40bdd Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Wed, 21 Jul 2021 14:52:48 -0700 Subject: [PATCH] refactor(@schematics/angular): automatically determine the version string to match latest Angular Automatically determine the latest compatible Angular Framework version by using `~` matching for the current minor version of @schematics/angular. --- .../angular/utility/latest-versions.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/schematics/angular/utility/latest-versions.ts b/packages/schematics/angular/utility/latest-versions.ts index 9e72bb148bab..58a08680b674 100644 --- a/packages/schematics/angular/utility/latest-versions.ts +++ b/packages/schematics/angular/utility/latest-versions.ts @@ -6,14 +6,30 @@ * found in the LICENSE file at https://angular.io/license */ +/** Retrieve the minor version for the provided version string. */ +function getEarliestMinorVersion(version: string) { + const versionMatching = version.match(/^(\d+)\.(\d+)\.*/); + + if (versionMatching === null) { + throw Error('Unable to determine the minor version for the provided version'); + } + const [_, major, minor] = versionMatching; + + return `${major}.${minor}.0`; +} + export const latestVersions = { // These versions should be kept up to date with latest Angular peer dependencies. - Angular: '~12.1.2', RxJs: '~6.6.0', ZoneJs: '~0.11.4', TypeScript: '~4.3.2', TsLib: '^2.2.0', + // As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current + // Angular CLI minor version with earliest prerelease (appended with `-`) will match the latest + // Angular Framework minor. + Angular: `~${getEarliestMinorVersion(require('../package.json')['version'])}-`, + // Since @angular-devkit/build-angular and @schematics/angular are always // published together from the same monorepo, and they are both // non-experimental, they will always have the same version.