diff --git a/e2e/angular-core/src/ng-add.test.ts b/e2e/angular-core/src/ng-add.test.ts index 6448a93401afd..4c25c0a3f38c6 100644 --- a/e2e/angular-core/src/ng-add.test.ts +++ b/e2e/angular-core/src/ng-add.test.ts @@ -148,6 +148,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => { cli: { packageManager: packageManager, }, + defaultProject: project, implicitDependencies: { '.eslintrc.json': '*', 'package.json': { diff --git a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap index 93c10fffe14a2..aa6e220520722 100644 --- a/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/__snapshots__/migrate-from-angular-cli.spec.ts.snap @@ -44,6 +44,7 @@ Object { "affected": Object { "defaultBase": "main", }, + "defaultProject": "app1", "implicitDependencies": Object { ".eslintrc.json": "*", "package.json": Object { diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts index 52c7adf357894..b98c9c1679446 100644 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.spec.ts @@ -241,6 +241,11 @@ describe('workspace', () => { ).not.toBeDefined(); }); + it('should set the default project correctly', async () => { + await migrateFromAngularCli(tree, {}); + expect(readJson(tree, 'nx.json').defaultProject).toBe('myApp'); + }); + it('should create nx.json', async () => { await migrateFromAngularCli(tree, { defaultBase: 'main' }); expect(readJson(tree, 'nx.json')).toMatchSnapshot(); diff --git a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts index 9d30fea4f6f0f..14ccb3ea393fd 100755 --- a/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts +++ b/packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts @@ -3,8 +3,10 @@ import { formatFiles, installPackagesTask, readJson, + readWorkspaceConfiguration, Tree, updateJson, + updateWorkspaceConfiguration, } from '@nrwl/devkit'; import { nxVersion } from '../../utils/versions'; import type { GeneratorOptions } from './schema'; @@ -36,6 +38,8 @@ export async function migrateFromAngularCli( const projects = getAllProjects(tree); const options = normalizeOptions(tree, rawOptions, projects); + const defaultProject = projects.apps.find((app) => app.config.root === ''); + if (options.preserveAngularCliLayout) { addDependenciesToPackageJson( tree, @@ -103,6 +107,14 @@ export async function migrateFromAngularCli( await formatFiles(tree); } + if (defaultProject) { + const workspaceConfig = readWorkspaceConfiguration(tree); + updateWorkspaceConfiguration(tree, { + ...workspaceConfig, + defaultProject: defaultProject.name, + }); + } + if (!options.skipInstall) { return () => { installPackagesTask(tree);