From f6232f1234cadb805906a4754e88458fdf74a29e Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Tue, 24 Feb 2026 09:13:33 +0000 Subject: [PATCH] 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. --- packages/angular/build/src/utils/version.ts | 32 ++++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/angular/build/src/utils/version.ts b/packages/angular/build/src/utils/version.ts index 01fbbd65236f..b9bbf5cd03b8 100644 --- a/packages/angular/build/src/utils/version.ts +++ b/packages/angular/build/src/utils/version.ts @@ -11,10 +11,6 @@ import { createRequire } from 'node:module'; import { SemVer, satisfies } from 'semver'; -// Matches exactly '0.0.0' or any string ending in '.0.0-next.0' -// This allows FW to bump the package.json to a new major version without requiring a new CLI version. -const angularVersionRegex = /^0\.0\.0$|\.0\.0-next\.0$/; - export function assertCompatibleAngularVersion(projectRoot: string): void | never { let angularPkgJson; @@ -41,21 +37,35 @@ export function assertCompatibleAngularVersion(projectRoot: string): void | neve process.exit(2); } + const angularCoreSemVer = new SemVer(angularPkgJson['version']); + const { version, build, raw } = angularCoreSemVer; const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP'; - if ( - angularVersionRegex.test(angularPkgJson['version']) || - supportedAngularSemver.startsWith('0.0.0') - ) { + + if (version.startsWith('0.0.0') || supportedAngularSemver.startsWith('0.0.0')) { // Internal CLI and FW testing version. return; } - const angularVersion = new SemVer(angularPkgJson['version']); + if (build.length && version.endsWith('.0.0-next.0')) { + // Special handle for local builds only when it's prerelease of major version and it's the 0th version. + // This happends when we are bumping to a new major version. and the cli has not releated a verion. + + // Example: + // raw: '22.0.0-next.0+sha-c7dc705-with-local-changes', + // major: 22, + // minor: 0, + // patch: 0, + // prerelease: [ 'next', 0 ], + // build: [ 'sha-c7dc705-with-local-changes' ], + // version: '22.0.0-next.0' + + return; + } - if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) { + if (!satisfies(angularCoreSemVer, supportedAngularSemver, { includePrerelease: true })) { console.error( `Error: The current version of "@angular/build" supports Angular versions ${supportedAngularSemver},\n` + - `but detected Angular version ${angularVersion} instead.\n` + + `but detected Angular version ${raw} instead.\n` + 'Please visit the link below to find instructions on how to update Angular.\nhttps://update.angular.dev/', );