Skip to content
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

fix(angular): correctly error scam-to-standalone when used in Angular < 14.1.0 #14341

Merged
merged 1 commit into from
Jan 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"$id": "GeneratorAngularScamToStandalone",
"cli": "nx",
"title": "Convert an Inline SCAM to Standalone Component",
"description": "Convert an Inline SCAM to a Standalone Component.",
"description": "Convert an Inline SCAM to a Standalone Component. _Note: This generator is only supported with Angular versions >= 14.1.0_.",
"type": "object",
"properties": {
"component": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { scamToStandalone } from './scam-to-standalone';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import applicationGenerator from '../application/application';
import scamGenerator from '../scam/scam';
import { stripIndents, updateJson } from '@nrwl/devkit';

describe('scam-to-standalone', () => {
it('should convert an inline scam to standalone', async () => {
Expand Down Expand Up @@ -80,4 +81,25 @@ describe('scam-to-standalone', () => {
"
`);
});

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(
scamToStandalone(tree, {
component: 'src/app/bar/bar.component.ts',
project: 'foo',
})
).rejects
.toThrow(stripIndents`This generator is only supported with Angular >= 14.1.0. You are currently using 14.0.0.
You can resolve this error by migrating to Angular 14.1.0.`);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Tree } from '@nrwl/devkit';
import { formatFiles, getProjects, joinPathFragments } from '@nrwl/devkit';
import {
formatFiles,
getProjects,
joinPathFragments,
stripIndents,
} from '@nrwl/devkit';
import type { Schema } from './schema';
import {
convertScamToStandalone,
Expand All @@ -10,11 +15,20 @@ import {
verifyIsInlineScam,
verifyModuleIsScam,
} from './lib';
import { getInstalledAngularVersionInfo } from '../utils/angular-version-utils';
import { lt } from 'semver';

export async function scamToStandalone(
tree: Tree,
{ component, project: projectName, skipFormat }: Schema
) {
const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree);

if (lt(installedAngularVersionInfo.version, '14.1.0')) {
throw new Error(stripIndents`This generator is only supported with Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}.
You can resolve this error by migrating to Angular 14.1.0.`);
}

const projects = getProjects(tree);
let project = getTargetProject(projectName, projects);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$id": "GeneratorAngularScamToStandalone",
"cli": "nx",
"title": "Convert an Inline SCAM to Standalone Component",
"description": "Convert an Inline SCAM to a Standalone Component.",
"description": "Convert an Inline SCAM to a Standalone Component. _Note: This generator is only supported with Angular versions >= 14.1.0_.",
"type": "object",
"properties": {
"component": {
Expand Down