Skip to content

Commit

Permalink
fix(angular): correctly error remote when standalone is used in Angul…
Browse files Browse the repository at this point in the history
…ar < 14.1.0 (#14340)
  • Loading branch information
Coly010 committed Jan 13, 2023
1 parent d20cf91 commit a5ff62f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/angular/generators/remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
"default": false
},
"standalone": {
"description": "Whether to generate a remote application with standalone components.",
"description": "Whether to generate a remote application with standalone components. _Note: This is only supported in Angular versions >= 14.1.0_",
"type": "boolean",
"default": false
},
Expand Down
23 changes: 23 additions & 0 deletions packages/angular/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
getProjects,
readNxJson,
readProjectConfiguration,
stripIndents,
updateJson,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import host from '../host/host';
Expand Down Expand Up @@ -247,4 +249,25 @@ describe('MF Remote App Generator', () => {
expect(project.targets['static-server']).toMatchSnapshot();
});
});

it('should error correctly when Angular version does not support standalone', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
updateJson(tree, 'package.json', (json) => ({
...json,
dependencies: {
'@angular/core': '14.0.0',
},
}));

// ACT & ASSERT
await expect(
remote(tree, {
name: 'test',
standalone: true,
})
).rejects
.toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using 14.0.0.
You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`);
});
});
11 changes: 10 additions & 1 deletion packages/angular/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { formatFiles, getProjects, Tree } from '@nrwl/devkit';
import { formatFiles, getProjects, stripIndents, Tree } from '@nrwl/devkit';
import type { Schema } from './schema';
import applicationGenerator from '../application/application';
import { normalizeProjectName } from '../utils/project';
import { setupMf } from '../setup-mf/setup-mf';
import { E2eTestRunner } from '../../utils/test-runners';
import { addSsr, findNextAvailablePort } from './lib';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
import { getInstalledAngularVersionInfo } from '../utils/angular-version-utils';
import { lt } from 'semver';

export async function remote(tree: Tree, options: Schema) {
const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree);

if (lt(installedAngularVersionInfo.version, '14.1.0') && options.standalone) {
throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}.
You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`);
}

const projects = getProjects(tree);
if (options.host && !projects.has(options.host)) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/remote/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"default": false
},
"standalone": {
"description": "Whether to generate a remote application with standalone components.",
"description": "Whether to generate a remote application with standalone components. _Note: This is only supported in Angular versions >= 14.1.0_",
"type": "boolean",
"default": false
},
Expand Down

1 comment on commit a5ff62f

@vercel
Copy link

@vercel vercel bot commented on a5ff62f Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.