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';