@@ -12,57 +12,43 @@ import { createRequire } from 'node:module';
12
12
import { SemVer , satisfies } from 'semver' ;
13
13
14
14
export function assertCompatibleAngularVersion ( projectRoot : string ) : void | never {
15
- let angularCliPkgJson ;
16
15
let angularPkgJson ;
17
16
18
17
// Create a custom require function for ESM compliance.
19
18
// NOTE: The trailing slash is significant.
20
19
const projectRequire = createRequire ( projectRoot + '/' ) ;
21
20
22
21
try {
23
- const angularPackagePath = projectRequire . resolve ( '@angular/core/package.json' ) ;
24
-
25
- angularPkgJson = projectRequire ( angularPackagePath ) ;
22
+ angularPkgJson = projectRequire ( '@angular/core/package.json' ) ;
26
23
} catch {
27
- console . error ( 'You seem to not be depending on "@angular/core". This is an error.' ) ;
24
+ console . error (
25
+ 'Error: It appears that "@angular/core" is missing as a dependency. Please ensure it is included in your project.' ,
26
+ ) ;
28
27
29
28
process . exit ( 2 ) ;
30
29
}
31
30
32
- if ( ! ( angularPkgJson && angularPkgJson [ 'version' ] ) ) {
31
+ if ( ! angularPkgJson ?. [ 'version' ] ) {
33
32
console . error (
34
- 'Cannot determine versions of "@angular/core".\n' +
35
- 'This likely means your local installation is broken . Please reinstall your packages.' ,
33
+ 'Error: Unable to determine the versions of "@angular/core".\n' +
34
+ 'This likely indicates a corrupted local installation. Please try reinstalling your packages.' ,
36
35
) ;
37
36
38
37
process . exit ( 2 ) ;
39
38
}
40
39
41
- try {
42
- const angularCliPkgPath = projectRequire . resolve ( '@angular/cli/package.json' ) ;
43
- angularCliPkgJson = projectRequire ( angularCliPkgPath ) ;
44
- if ( ! ( angularCliPkgJson && angularCliPkgJson [ 'version' ] ) ) {
45
- return ;
46
- }
47
- } catch {
48
- // Not using @angular -devkit/build-angular with @angular/cli is ok too.
49
- // In this case we don't provide as many version checks.
50
- return ;
51
- }
52
-
53
- if ( angularCliPkgJson [ 'version' ] === '0.0.0' || angularPkgJson [ 'version' ] === '0.0.0' ) {
54
- // Internal CLI testing version or integration testing in the angular/angular
55
- // repository with the generated development @angular /core npm package which is versioned "0.0.0".
40
+ const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP' ;
41
+ if ( supportedAngularSemver . startsWith ( '0.0.0' ) ) {
42
+ // Internal CLI testing version.
56
43
return ;
57
44
}
58
45
59
- const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP' ;
60
46
const angularVersion = new SemVer ( angularPkgJson [ 'version' ] ) ;
61
47
62
48
if ( ! satisfies ( angularVersion , supportedAngularSemver , { includePrerelease : true } ) ) {
63
49
console . error (
64
- `This version of CLI is only compatible with Angular versions ${ supportedAngularSemver } ,\n` +
65
- `but Angular version ${ angularVersion } was found instead.\n` +
50
+ `Error: The current version of "@angular/build" supports Angular versions ${ supportedAngularSemver } ,\n` +
51
+ `but detected Angular version ${ angularVersion } instead.\n` +
66
52
'Please visit the link below to find instructions on how to update Angular.\nhttps://update.angular.dev/' ,
67
53
) ;
68
54
0 commit comments