fix(angular): correctly error scam-to-standalone when used in Angular < 14.1.0 (#14341)
This commit is contained in:
parent
3041b0a227
commit
81211bfc8f
@ -6,7 +6,7 @@
|
|||||||
"$id": "GeneratorAngularScamToStandalone",
|
"$id": "GeneratorAngularScamToStandalone",
|
||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"title": "Convert an Inline SCAM to Standalone Component",
|
"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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"component": {
|
"component": {
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { scamToStandalone } from './scam-to-standalone';
|
|||||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
||||||
import applicationGenerator from '../application/application';
|
import applicationGenerator from '../application/application';
|
||||||
import scamGenerator from '../scam/scam';
|
import scamGenerator from '../scam/scam';
|
||||||
|
import { stripIndents, updateJson } from '@nrwl/devkit';
|
||||||
|
|
||||||
describe('scam-to-standalone', () => {
|
describe('scam-to-standalone', () => {
|
||||||
it('should convert an inline scam to standalone', async () => {
|
it('should convert an inline scam to standalone', async () => {
|
||||||
@ -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.`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
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 type { Schema } from './schema';
|
||||||
import {
|
import {
|
||||||
convertScamToStandalone,
|
convertScamToStandalone,
|
||||||
@ -10,11 +15,20 @@ import {
|
|||||||
verifyIsInlineScam,
|
verifyIsInlineScam,
|
||||||
verifyModuleIsScam,
|
verifyModuleIsScam,
|
||||||
} from './lib';
|
} from './lib';
|
||||||
|
import { getInstalledAngularVersionInfo } from '../utils/angular-version-utils';
|
||||||
|
import { lt } from 'semver';
|
||||||
|
|
||||||
export async function scamToStandalone(
|
export async function scamToStandalone(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
{ component, project: projectName, skipFormat }: Schema
|
{ 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);
|
const projects = getProjects(tree);
|
||||||
let project = getTargetProject(projectName, projects);
|
let project = getTargetProject(projectName, projects);
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
"$id": "GeneratorAngularScamToStandalone",
|
"$id": "GeneratorAngularScamToStandalone",
|
||||||
"cli": "nx",
|
"cli": "nx",
|
||||||
"title": "Convert an Inline SCAM to Standalone Component",
|
"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",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"component": {
|
"component": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user