Skip to content

Commit 529cfed

Browse files
committed
refactor(@angular/build): remove outdated version checks
Cleaned up legacy version-checking logic.
1 parent e3aa483 commit 529cfed

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,43 @@ import { createRequire } from 'node:module';
1212
import { SemVer, satisfies } from 'semver';
1313

1414
export function assertCompatibleAngularVersion(projectRoot: string): void | never {
15-
let angularCliPkgJson;
1615
let angularPkgJson;
1716

1817
// Create a custom require function for ESM compliance.
1918
// NOTE: The trailing slash is significant.
2019
const projectRequire = createRequire(projectRoot + '/');
2120

2221
try {
23-
const angularPackagePath = projectRequire.resolve('@angular/core/package.json');
24-
25-
angularPkgJson = projectRequire(angularPackagePath);
22+
angularPkgJson = projectRequire('@angular/core/package.json');
2623
} 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+
);
2827

2928
process.exit(2);
3029
}
3130

32-
if (!(angularPkgJson && angularPkgJson['version'])) {
31+
if (!angularPkgJson?.['version']) {
3332
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.',
3635
);
3736

3837
process.exit(2);
3938
}
4039

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.
5643
return;
5744
}
5845

59-
const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP';
6046
const angularVersion = new SemVer(angularPkgJson['version']);
6147

6248
if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
6349
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` +
6652
'Please visit the link below to find instructions on how to update Angular.\nhttps://update.angular.dev/',
6753
);
6854

0 commit comments

Comments
 (0)