fix(angular): correctly error application when standalone is used in Angular < 14.1.0 (#14338)
This commit is contained in:
parent
0db507394e
commit
3041b0a227
@ -140,7 +140,7 @@
|
|||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"standalone": {
|
"standalone": {
|
||||||
"description": "Generate an application that is setup to use standalone components.",
|
"description": "Generate an application that is setup to use standalone components. _Note: This is only supported in Angular versions >= 14.1.0_",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import {
|
|||||||
readJson,
|
readJson,
|
||||||
readNxJson,
|
readNxJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
|
stripIndents,
|
||||||
updateJson,
|
updateJson,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import {
|
import {
|
||||||
@ -1069,6 +1070,26 @@ describe('app', () => {
|
|||||||
expect(project.targets.build.options['outputPath']).toBe('dist/my-app');
|
expect(project.targets.build.options['outputPath']).toBe('dist/my-app');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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(
|
||||||
|
generateApp(tree, 'my-app', {
|
||||||
|
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.`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
async function generateApp(
|
async function generateApp(
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import {
|
|||||||
installPackagesTask,
|
installPackagesTask,
|
||||||
moveFilesToNewDirectory,
|
moveFilesToNewDirectory,
|
||||||
readNxJson,
|
readNxJson,
|
||||||
|
stripIndents,
|
||||||
Tree,
|
Tree,
|
||||||
updateNxJson,
|
updateNxJson,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
@ -12,7 +13,10 @@ import { join } from 'path';
|
|||||||
import { UnitTestRunner } from '../../utils/test-runners';
|
import { UnitTestRunner } from '../../utils/test-runners';
|
||||||
import { angularInitGenerator } from '../init/init';
|
import { angularInitGenerator } from '../init/init';
|
||||||
import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind';
|
import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind';
|
||||||
import { getGeneratorDirectoryForInstalledAngularVersion } from '../utils/angular-version-utils';
|
import {
|
||||||
|
getGeneratorDirectoryForInstalledAngularVersion,
|
||||||
|
getInstalledAngularVersionInfo,
|
||||||
|
} from '../utils/angular-version-utils';
|
||||||
import {
|
import {
|
||||||
addE2e,
|
addE2e,
|
||||||
addLinting,
|
addLinting,
|
||||||
@ -31,11 +35,19 @@ import {
|
|||||||
updateNxComponentTemplate,
|
updateNxComponentTemplate,
|
||||||
} from './lib';
|
} from './lib';
|
||||||
import type { Schema } from './schema';
|
import type { Schema } from './schema';
|
||||||
|
import { lt } from 'semver';
|
||||||
|
|
||||||
export async function applicationGenerator(
|
export async function applicationGenerator(
|
||||||
tree: Tree,
|
tree: Tree,
|
||||||
schema: Partial<Schema>
|
schema: Partial<Schema>
|
||||||
) {
|
) {
|
||||||
|
const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree);
|
||||||
|
|
||||||
|
if (lt(installedAngularVersionInfo.version, '14.1.0') && schema.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 generatorDirectory =
|
const generatorDirectory =
|
||||||
getGeneratorDirectoryForInstalledAngularVersion(tree);
|
getGeneratorDirectoryForInstalledAngularVersion(tree);
|
||||||
if (generatorDirectory) {
|
if (generatorDirectory) {
|
||||||
|
|||||||
@ -143,7 +143,7 @@
|
|||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
"standalone": {
|
"standalone": {
|
||||||
"description": "Generate an application that is setup to use standalone components.",
|
"description": "Generate an application that is setup to use standalone components. _Note: This is only supported in Angular versions >= 14.1.0_",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user