From 1e3efb9d029c0c6ae304c3d7d6f8f756e092579b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 28 Jan 2025 16:17:26 +0000 Subject: [PATCH] refactor(@angular/build): remove outdated version checks Cleaned up legacy version-checking logic. --- packages/angular/build/src/utils/version.ts | 38 +++++++-------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/packages/angular/build/src/utils/version.ts b/packages/angular/build/src/utils/version.ts index 45f5bfee3d2b..f8f87791240c 100644 --- a/packages/angular/build/src/utils/version.ts +++ b/packages/angular/build/src/utils/version.ts @@ -12,7 +12,6 @@ import { createRequire } from 'node:module'; import { SemVer, satisfies } from 'semver'; export function assertCompatibleAngularVersion(projectRoot: string): void | never { - let angularCliPkgJson; let angularPkgJson; // Create a custom require function for ESM compliance. @@ -20,49 +19,36 @@ export function assertCompatibleAngularVersion(projectRoot: string): void | neve const projectRequire = createRequire(projectRoot + '/'); try { - const angularPackagePath = projectRequire.resolve('@angular/core/package.json'); - - angularPkgJson = projectRequire(angularPackagePath); + angularPkgJson = projectRequire('@angular/core/package.json'); } catch { - console.error('You seem to not be depending on "@angular/core". This is an error.'); + console.error( + 'Error: It appears that "@angular/core" is missing as a dependency. Please ensure it is included in your project.', + ); process.exit(2); } - if (!(angularPkgJson && angularPkgJson['version'])) { + if (!angularPkgJson?.['version']) { console.error( - 'Cannot determine versions of "@angular/core".\n' + - 'This likely means your local installation is broken. Please reinstall your packages.', + 'Error: Unable to determine the versions of "@angular/core".\n' + + 'This likely indicates a corrupted local installation. Please try reinstalling your packages.', ); process.exit(2); } - try { - const angularCliPkgPath = projectRequire.resolve('@angular/cli/package.json'); - angularCliPkgJson = projectRequire(angularCliPkgPath); - if (!(angularCliPkgJson && angularCliPkgJson['version'])) { - return; - } - } catch { - // Not using @angular-devkit/build-angular with @angular/cli is ok too. - // In this case we don't provide as many version checks. - return; - } - - if (angularCliPkgJson['version'] === '0.0.0' || angularPkgJson['version'] === '0.0.0') { - // Internal CLI testing version or integration testing in the angular/angular - // repository with the generated development @angular/core npm package which is versioned "0.0.0". + const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP'; + if (supportedAngularSemver.startsWith('0.0.0')) { + // Internal CLI testing version. return; } - const supportedAngularSemver = '0.0.0-ANGULAR-FW-PEER-DEP'; const angularVersion = new SemVer(angularPkgJson['version']); if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) { console.error( - `This version of CLI is only compatible with Angular versions ${supportedAngularSemver},\n` + - `but Angular version ${angularVersion} was found instead.\n` + + `Error: The current version of "@angular/build" supports Angular versions ${supportedAngularSemver},\n` + + `but detected Angular version ${angularVersion} instead.\n` + 'Please visit the link below to find instructions on how to update Angular.\nhttps://update.angular.dev/', );