From f3b2dc46e91e8cb97cc2f5aef32b701cd527c589 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 12 Jul 2021 12:43:58 +0200 Subject: [PATCH] fix(@angular-devkit/build-angular): display incompatibility errors The logger API writes logs in an async fasion which previously caused messages not to be printed in the terminal when `process.exit` was invoked. Closes #21322 (cherry picked from commit 2ac8e9c0e131bf7fcb2c6e92500eeaa112efcefb) --- .../build_angular/src/browser/index.ts | 2 +- .../build_angular/src/dev-server/index.ts | 2 +- .../build_angular/src/extract-i18n/index.ts | 2 +- .../build_angular/src/karma/index.ts | 2 +- .../build_angular/src/server/index.ts | 2 +- .../build_angular/src/utils/version.ts | 14 ++++++++------ 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/browser/index.ts b/packages/angular_devkit/build_angular/src/browser/index.ts index 00fe9a354050..b526e7660904 100644 --- a/packages/angular_devkit/build_angular/src/browser/index.ts +++ b/packages/angular_devkit/build_angular/src/browser/index.ts @@ -171,7 +171,7 @@ export function buildWebpackBrowser( let outputPaths: undefined | Map; // Check Angular version. - assertCompatibleAngularVersion(context.workspaceRoot, context.logger); + assertCompatibleAngularVersion(context.workspaceRoot); return from(context.getProjectMetadata(projectName)).pipe( switchMap(async (projectMetadata) => { diff --git a/packages/angular_devkit/build_angular/src/dev-server/index.ts b/packages/angular_devkit/build_angular/src/dev-server/index.ts index 7ecc1b8e516b..bbf8371358fa 100644 --- a/packages/angular_devkit/build_angular/src/dev-server/index.ts +++ b/packages/angular_devkit/build_angular/src/dev-server/index.ts @@ -112,7 +112,7 @@ export function serveWebpackBrowser( ): Observable { // Check Angular version. const { logger, workspaceRoot } = context; - assertCompatibleAngularVersion(workspaceRoot, logger); + assertCompatibleAngularVersion(workspaceRoot); const browserTarget = targetFromTargetString(options.browserTarget); diff --git a/packages/angular_devkit/build_angular/src/extract-i18n/index.ts b/packages/angular_devkit/build_angular/src/extract-i18n/index.ts index 02fd75210770..220330ce5953 100644 --- a/packages/angular_devkit/build_angular/src/extract-i18n/index.ts +++ b/packages/angular_devkit/build_angular/src/extract-i18n/index.ts @@ -147,7 +147,7 @@ export async function execute( }, ): Promise { // Check Angular version. - assertCompatibleAngularVersion(context.workspaceRoot, context.logger); + assertCompatibleAngularVersion(context.workspaceRoot); const browserTarget = targetFromTargetString(options.browserTarget); const browserOptions = await context.validateOptions( diff --git a/packages/angular_devkit/build_angular/src/karma/index.ts b/packages/angular_devkit/build_angular/src/karma/index.ts index 2d6fc8cadeef..39b986558c41 100644 --- a/packages/angular_devkit/build_angular/src/karma/index.ts +++ b/packages/angular_devkit/build_angular/src/karma/index.ts @@ -91,7 +91,7 @@ export function execute( } = {}, ): Observable { // Check Angular version. - assertCompatibleAngularVersion(context.workspaceRoot, context.logger); + assertCompatibleAngularVersion(context.workspaceRoot); let singleRun: boolean | undefined; if (options.watch !== undefined) { diff --git a/packages/angular_devkit/build_angular/src/server/index.ts b/packages/angular_devkit/build_angular/src/server/index.ts index b167b3b7a8d9..edd3760014e6 100644 --- a/packages/angular_devkit/build_angular/src/server/index.ts +++ b/packages/angular_devkit/build_angular/src/server/index.ts @@ -60,7 +60,7 @@ export function execute( const root = context.workspaceRoot; // Check Angular version. - assertCompatibleAngularVersion(root, context.logger); + assertCompatibleAngularVersion(root); const tsConfig = readTsconfig(options.tsConfig, root); const target = tsConfig.options.target || ScriptTarget.ES5; diff --git a/packages/angular_devkit/build_angular/src/utils/version.ts b/packages/angular_devkit/build_angular/src/utils/version.ts index 879f94c1e539..2638c3d40e97 100644 --- a/packages/angular_devkit/build_angular/src/utils/version.ts +++ b/packages/angular_devkit/build_angular/src/utils/version.ts @@ -6,10 +6,12 @@ * found in the LICENSE file at https://angular.io/license */ -import { logging, tags } from '@angular-devkit/core'; -import { SemVer, gte, satisfies } from 'semver'; +/* eslint-disable no-console */ -export function assertCompatibleAngularVersion(projectRoot: string, logger: logging.LoggerApi) { +import { tags } from '@angular-devkit/core'; +import { SemVer, satisfies } from 'semver'; + +export function assertCompatibleAngularVersion(projectRoot: string): void | never { let angularCliPkgJson; let angularPkgJson; let rxjsPkgJson; @@ -22,7 +24,7 @@ export function assertCompatibleAngularVersion(projectRoot: string, logger: logg angularPkgJson = require(angularPackagePath); rxjsPkgJson = require(rxjsPackagePath); } catch { - logger.error(tags.stripIndents` + console.error(tags.stripIndents` You seem to not be depending on "@angular/core" and/or "rxjs". This is an error. `); @@ -30,7 +32,7 @@ export function assertCompatibleAngularVersion(projectRoot: string, logger: logg } if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) { - logger.error(tags.stripIndents` + console.error(tags.stripIndents` Cannot determine versions of "@angular/core" and/or "rxjs". This likely means your local installation is broken. Please reinstall your packages. `); @@ -63,7 +65,7 @@ export function assertCompatibleAngularVersion(projectRoot: string, logger: logg const supportedAngularSemver = `^${cliMajor}.0.0-next || >=${cliMajor}.0.0 <${cliMajor + 1}.0.0`; if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) { - logger.error( + console.error( tags.stripIndents` This version of CLI is only compatible with Angular versions ${supportedAngularSemver}, but Angular version ${angularVersion} was found instead.