Skip to content

Commit

Permalink
refactor(@schematics/angular): automatically determine the version st…
Browse files Browse the repository at this point in the history
…ring to match latest Angular

Automatically determine the latest compatible Angular Framework version by using `~` matching
for the current minor version of @schematics/angular.
  • Loading branch information
josephperrott committed Jul 21, 2021
1 parent 04e9ffe commit 487486a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/schematics/angular/utility/latest-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 487486a

Please sign in to comment.