Skip to content

Commit

Permalink
feat(angular): throw error when --standalone used for setup-mf w/ inv…
Browse files Browse the repository at this point in the history
…alid Ng version
  • Loading branch information
Coly010 committed Jan 11, 2023
1 parent 6579879 commit 7fc2c12
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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).'
);
});
});
9 changes: 9 additions & 0 deletions packages/angular/src/generators/setup-mf/setup-mf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 7fc2c12

Please sign in to comment.