Skip to content

fix(@angular-devkit/build-angular): display incompatibility errors #21331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function buildWebpackBrowser(
let outputPaths: undefined | Map<string, string>;

// Check Angular version.
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
assertCompatibleAngularVersion(context.workspaceRoot);

return from(context.getProjectMetadata(projectName)).pipe(
switchMap(async (projectMetadata) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function serveWebpackBrowser(
): Observable<DevServerBuilderOutput> {
// Check Angular version.
const { logger, workspaceRoot } = context;
assertCompatibleAngularVersion(workspaceRoot, logger);
assertCompatibleAngularVersion(workspaceRoot);

const browserTarget = targetFromTargetString(options.browserTarget);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export async function execute(
},
): Promise<BuildResult> {
// Check Angular version.
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
assertCompatibleAngularVersion(context.workspaceRoot);

const browserTarget = targetFromTargetString(options.browserTarget);
const browserOptions = await context.validateOptions<JsonObject & BrowserBuilderOptions>(
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/src/karma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function execute(
} = {},
): Observable<BuilderOutput> {
// Check Angular version.
assertCompatibleAngularVersion(context.workspaceRoot, context.logger);
assertCompatibleAngularVersion(context.workspaceRoot);

let singleRun: boolean | undefined;
if (options.watch !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/angular_devkit/build_angular/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions packages/angular_devkit/build_angular/src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,15 +24,15 @@ 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.
`);

process.exit(2);
}

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.
`);
Expand Down Expand Up @@ -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.
Expand Down