Skip to content

Commit 201a036

Browse files
committed
fix(@angular/cli): simplify Angular version compatibility checks and add special handling for local builds of new major versions
Addresses issues with adev version checks. (cherry picked from commit 7ac80a8)
1 parent 7040046 commit 201a036

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

packages/angular/build/src/utils/version.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
import { createRequire } from 'node:module';
1212
import { SemVer, satisfies } from 'semver';
1313

14-
// Matches exactly '0.0.0' or any string ending in '.0.0-next.0'
15-
// This allows FW to bump the package.json to a new major version without requiring a new CLI version.
16-
const angularVersionRegex = /^0\.0\.0$|\.0\.0-next\.0$/;
17-
1814
export function assertCompatibleAngularVersion(projectRoot: string): void | never {
1915
let angularPkgJson;
2016

@@ -41,21 +37,35 @@ export function assertCompatibleAngularVersion(projectRoot: string): void | neve
4137
process.exit(2);
4238
}
4339

40+
const angularCoreSemVer = new SemVer(angularPkgJson['version']);
41+
const { version, build, raw } = angularCoreSemVer;
4442
const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP';
45-
if (
46-
angularVersionRegex.test(angularPkgJson['version']) ||
47-
supportedAngularSemver.startsWith('0.0.0')
48-
) {
43+
44+
if (version.startsWith('0.0.0') || supportedAngularSemver.startsWith('0.0.0')) {
4945
// Internal CLI and FW testing version.
5046
return;
5147
}
5248

53-
const angularVersion = new SemVer(angularPkgJson['version']);
49+
if (build.length && version.endsWith('.0.0-next.0')) {
50+
// Special handle for local builds only when it's prerelease of major version and it's the 0th version.
51+
// This happends when we are bumping to a new major version. and the cli has not releated a verion.
52+
53+
// Example:
54+
// raw: '22.0.0-next.0+sha-c7dc705-with-local-changes',
55+
// major: 22,
56+
// minor: 0,
57+
// patch: 0,
58+
// prerelease: [ 'next', 0 ],
59+
// build: [ 'sha-c7dc705-with-local-changes' ],
60+
// version: '22.0.0-next.0'
61+
62+
return;
63+
}
5464

55-
if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
65+
if (!satisfies(angularCoreSemVer, supportedAngularSemver, { includePrerelease: true })) {
5666
console.error(
5767
`Error: The current version of "@angular/build" supports Angular versions ${supportedAngularSemver},\n` +
58-
`but detected Angular version ${angularVersion} instead.\n` +
68+
`but detected Angular version ${raw} instead.\n` +
5969
'Please visit the link below to find instructions on how to update Angular.\nhttps://update.angular.dev/',
6070
);
6171

0 commit comments

Comments
 (0)