Skip to content

Commit 43f4cd9

Browse files
committed
refactor: simplify Angular version compatibility checks and add special handling for local builds of new major versions
Addresses issues with adev version checks.
1 parent c1a4a76 commit 43f4cd9

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 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

@@ -32,7 +28,8 @@ export function assertCompatibleAngularVersion(projectRoot: string): void | neve
3228
process.exit(2);
3329
}
3430

35-
if (!angularPkgJson?.['version']) {
31+
const angularVersion = angularPkgJson?.['version'];
32+
if (!angularVersion) {
3633
console.error(
3734
'Error: Unable to determine the versions of "@angular/core".\n' +
3835
'This likely indicates a corrupted local installation. Please try reinstalling your packages.',
@@ -42,17 +39,21 @@ export function assertCompatibleAngularVersion(projectRoot: string): void | neve
4239
}
4340

4441
const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP';
45-
if (
46-
angularVersionRegex.test(angularPkgJson['version']) ||
47-
supportedAngularSemver.startsWith('0.0.0')
48-
) {
42+
if (angularVersion.startsWith('0.0.0') || supportedAngularSemver.startsWith('0.0.0')) {
4943
// Internal CLI and FW testing version.
5044
return;
5145
}
5246

53-
const angularVersion = new SemVer(angularPkgJson['version']);
47+
const angularCoreSemVer = new SemVer(angularVersion);
48+
const { version, build } = angularCoreSemVer;
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+
// Example `22.0.0-next.0+sha-c7dc705-with-local-changes`
53+
return;
54+
}
5455

55-
if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
56+
if (!satisfies(angularCoreSemVer, supportedAngularSemver, { includePrerelease: true })) {
5657
console.error(
5758
`Error: The current version of "@angular/build" supports Angular versions ${supportedAngularSemver},\n` +
5859
`but detected Angular version ${angularVersion} instead.\n` +

0 commit comments

Comments
 (0)