Skip to content

Commit 2ac8e9c

Browse files
alan-agius4filipesilva
authored andcommitted
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
1 parent 0907b69 commit 2ac8e9c

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

packages/angular_devkit/build_angular/src/browser/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export function buildWebpackBrowser(
171171
let outputPaths: undefined | Map<string, string>;
172172

173173
// Check Angular version.
174-
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
174+
assertCompatibleAngularVersion(context.workspaceRoot);
175175

176176
return from(context.getProjectMetadata(projectName)).pipe(
177177
switchMap(async (projectMetadata) => {

packages/angular_devkit/build_angular/src/dev-server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function serveWebpackBrowser(
112112
): Observable<DevServerBuilderOutput> {
113113
// Check Angular version.
114114
const { logger, workspaceRoot } = context;
115-
assertCompatibleAngularVersion(workspaceRoot, logger);
115+
assertCompatibleAngularVersion(workspaceRoot);
116116

117117
const browserTarget = targetFromTargetString(options.browserTarget);
118118

packages/angular_devkit/build_angular/src/extract-i18n/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export async function execute(
147147
},
148148
): Promise<BuildResult> {
149149
// Check Angular version.
150-
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
150+
assertCompatibleAngularVersion(context.workspaceRoot);
151151

152152
const browserTarget = targetFromTargetString(options.browserTarget);
153153
const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderOptions>(

packages/angular_devkit/build_angular/src/karma/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export function execute(
9191
} = {},
9292
): Observable<BuilderOutput> {
9393
// Check Angular version.
94-
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
94+
assertCompatibleAngularVersion(context.workspaceRoot);
9595

9696
let singleRun: boolean | undefined;
9797
if (options.watch !== undefined) {

packages/angular_devkit/build_angular/src/server/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function execute(
6060
const root = context.workspaceRoot;
6161

6262
// Check Angular version.
63-
assertCompatibleAngularVersion(root, context.logger);
63+
assertCompatibleAngularVersion(root);
6464

6565
const tsConfig = readTsconfig(options.tsConfig, root);
6666
const target = tsConfig.options.target || ScriptTarget.ES5;

packages/angular_devkit/build_angular/src/utils/version.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { logging, tags } from '@angular-devkit/core';
10-
import { SemVer, gte, satisfies } from 'semver';
9+
/* eslint-disable no-console */
1110

12-
export function assertCompatibleAngularVersion(projectRoot: string, logger: logging.LoggerApi) {
11+
import { tags } from '@angular-devkit/core';
12+
import { SemVer, satisfies } from 'semver';
13+
14+
export function assertCompatibleAngularVersion(projectRoot: string): void | never {
1315
let angularCliPkgJson;
1416
let angularPkgJson;
1517
let rxjsPkgJson;
@@ -22,15 +24,15 @@ export function assertCompatibleAngularVersion(projectRoot: string, logger: logg
2224
angularPkgJson = require(angularPackagePath);
2325
rxjsPkgJson = require(rxjsPackagePath);
2426
} catch {
25-
logger.error(tags.stripIndents`
27+
console.error(tags.stripIndents`
2628
You seem to not be depending on "@angular/core" and/or "rxjs". This is an error.
2729
`);
2830

2931
process.exit(2);
3032
}
3133

3234
if (!(angularPkgJson && angularPkgJson['version'] && rxjsPkgJson && rxjsPkgJson['version'])) {
33-
logger.error(tags.stripIndents`
35+
console.error(tags.stripIndents`
3436
Cannot determine versions of "@angular/core" and/or "rxjs".
3537
This likely means your local installation is broken. Please reinstall your packages.
3638
`);
@@ -63,7 +65,7 @@ export function assertCompatibleAngularVersion(projectRoot: string, logger: logg
6365
const supportedAngularSemver = `^${cliMajor}.0.0-next || >=${cliMajor}.0.0 <${cliMajor + 1}.0.0`;
6466

6567
if (!satisfies(angularVersion, supportedAngularSemver, { includePrerelease: true })) {
66-
logger.error(
68+
console.error(
6769
tags.stripIndents`
6870
This version of CLI is only compatible with Angular versions ${supportedAngularSemver},
6971
but Angular version ${angularVersion} was found instead.

0 commit comments

Comments
 (0)