From b0c6ca92679798f84a34b6bf52bae081e1b28440 Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 11 Jan 2023 12:10:51 +0000 Subject: [PATCH] feat(angular): throw error when --standalone used for setup-mf w/ invalid Ng version (#14270) --- .../src/generators/setup-mf/setup-mf.spec.ts | 29 ++++++++++++++++++- .../src/generators/setup-mf/setup-mf.ts | 9 ++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts index 0c10379ccc133..7f4ec977aba40 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts @@ -1,4 +1,9 @@ -import { readJson, readProjectConfiguration, Tree } from '@nrwl/devkit'; +import { + readJson, + readProjectConfiguration, + Tree, + updateJson, +} from '@nrwl/devkit'; import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing'; import { setupMf } from './setup-mf'; @@ -343,4 +348,26 @@ describe('Init MF', () => { tree.read('apps/app1/src/app/app.routes.ts', 'utf-8') ).toMatchSnapshot(); }); + + it('should throw an error when installed version of angular < 14.1.0 and --standalone is used', async () => { + // ARRANGE + updateJson(tree, 'package.json', (json) => ({ + ...json, + dependencies: { + ...json.dependencies, + '@angular/core': '14.0.0', + }, + })); + + // ACT & ASSERT + await expect( + setupMf(tree, { + appName: 'app1', + mfType: 'host', + standalone: true, + }) + ).rejects.toThrow( + 'The --standalone flag is not supported in your current version of Angular (14.0.0). Please update to a version of Angular that supports Standalone Components (>= 14.1.0).' + ); + }); }); diff --git a/packages/angular/src/generators/setup-mf/setup-mf.ts b/packages/angular/src/generators/setup-mf/setup-mf.ts index f0b6158a5651b..c97e2acc7351d 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.ts @@ -16,8 +16,17 @@ import { updateHostAppRoutes, updateTsConfigTarget, } from './lib'; +import { getInstalledAngularVersionInfo } from '../utils/angular-version-utils'; +import { lt } from 'semver'; export async function setupMf(tree: Tree, options: Schema) { + const installedAngularInfo = getInstalledAngularVersionInfo(tree); + + if (lt(installedAngularInfo.version, '14.1.0') && options.standalone) { + throw new Error( + `The --standalone flag is not supported in your current version of Angular (${installedAngularInfo.version}). Please update to a version of Angular that supports Standalone Components (>= 14.1.0).` + ); + } const projectConfig = readProjectConfiguration(tree, options.appName); options.federationType = options.federationType ?? 'static';