Skip to content

Commit c92a381

Browse files
alan-agius4clydin
authored andcommitted
refactor(@schematics/angular): improve automatic versions
With this change we improve the versions we set in the users project to be less confusing. Previously, for both stable and next versions we set the versions of Angular packages to the below; ``` "@angular/animations": "~12.2.0-" ``` This might be problematic as one might not immediately notice that they might depend on a prerelease. The `-` is short character and can be missed when having a large set of dependencies. With this can we are more explicate by adding `--next` when it's a prerelease and omit the suffix for stable releases.
1 parent 734e396 commit c92a381

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/schematics/angular/utility/latest-versions.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88

99
/** Retrieve the minor version for the provided version string. */
10-
function getEarliestMinorVersion(version: string) {
11-
const versionMatching = version.match(/^(\d+)\.(\d+)\.*/);
10+
function getAngularEarliestMinorVersion(version: string): string {
11+
const versionMatching = version.match(/^(\d+)\.(\d+)\.\d+(-\w+)?/);
1212

1313
if (versionMatching === null) {
1414
throw Error('Unable to determine the minor version for the provided version');
1515
}
16-
const [_, major, minor] = versionMatching;
16+
const [_, major, minor, prerelease = ''] = versionMatching;
1717

18-
return `${major}.${minor}.0`;
18+
return `~${major}.${minor}.0${prerelease}`;
1919
}
2020

2121
export const latestVersions: Record<string, string> & {
@@ -27,9 +27,7 @@ export const latestVersions: Record<string, string> & {
2727
...require('./latest-versions/package.json')['dependencies'],
2828

2929
// As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
30-
// Angular CLI minor version with earliest prerelease (appended with `-`) will match the latest
31-
// Angular Framework minor.
32-
Angular: `~${getEarliestMinorVersion(require('../package.json')['version'])}-`,
30+
Angular: getAngularEarliestMinorVersion(require('../package.json')['version']),
3331

3432
// Since @angular-devkit/build-angular and @schematics/angular are always
3533
// published together from the same monorepo, and they are both

0 commit comments

Comments
 (0)