1111import { createRequire } from 'node:module' ;
1212import { 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 - n e x t \. 0 $ / ;
17-
1814export 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