fix(angular): set default project if not set when creating an application (#10789)

This commit is contained in:
Leosvel Pérez Espinosa 2022-06-17 11:58:01 +01:00 committed by GitHub
parent b215362bdb
commit ca92b7aa0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import {
parseJson,
readJson,
readProjectConfiguration,
readWorkspaceConfiguration,
updateJson,
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
@ -204,6 +205,29 @@ describe('app', () => {
const appTsConfig = readJson(appTree, 'apps/app/tsconfig.json');
expect(appTsConfig.extends).toBe('../../tsconfig.json');
});
it('should set default project', async () => {
// ACT
await generateApp(appTree);
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('my-app');
});
it('should not overwrite default project if already set', async () => {
// ARRANGE
const workspace = readWorkspaceConfiguration(appTree);
workspace.defaultProject = 'some-awesome-project';
devkit.updateWorkspaceConfiguration(appTree, workspace);
// ACT
await generateApp(appTree);
// ASSERT
const { defaultProject } = readWorkspaceConfiguration(appTree);
expect(defaultProject).toBe('some-awesome-project');
});
});
describe('nested', () => {

View File

@ -20,6 +20,7 @@ import {
enableStrictTypeChecking,
normalizeOptions,
setApplicationStrictDefault,
setDefaultProject,
updateAppComponentTemplate,
updateComponentSpec,
updateConfigFiles,
@ -106,6 +107,7 @@ export async function applicationGenerator(
await addUnitTestRunner(host, options);
await addE2e(host, options);
updateEditorTsConfig(host, options);
setDefaultProject(host, options);
if (options.backendProject) {
addProxyConfig(host, options);

View File

@ -12,6 +12,7 @@ export * from './nrwl-home-tpl';
export * from './remove-scaffolded-e2e';
export * from './root-router-config';
export * from './set-app-strict-default';
export * from './set-default-project';
export * from './update-component-spec';
export * from './update-app-component-template';
export * from './update-nx-component-template';

View File

@ -0,0 +1,15 @@
import type { Tree } from '@nrwl/devkit';
import {
readWorkspaceConfiguration,
updateWorkspaceConfiguration,
} from '@nrwl/devkit';
import type { NormalizedSchema } from './normalized-schema';
export function setDefaultProject(tree: Tree, options: NormalizedSchema): void {
const workspace = readWorkspaceConfiguration(tree);
if (!workspace.defaultProject) {
workspace.defaultProject = options.name;
updateWorkspaceConfiguration(tree, workspace);
}
}