Skip to content

Commit

Permalink
fix(angular): ng-add migration should set default project (#12513)
Browse files Browse the repository at this point in the history
* fix(angular): ng-add migration should set default project

* fix(angular): add pr suggestions

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
(cherry picked from commit 66a0864)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Oct 11, 2022
1 parent 640cfba commit 38509cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions e2e/angular-core/src/ng-add.test.ts
Expand Up @@ -148,6 +148,7 @@ describe('convert Angular CLI workspace to an Nx workspace', () => {
cli: {
packageManager: packageManager,
},
defaultProject: project,
implicitDependencies: {
'.eslintrc.json': '*',
'package.json': {
Expand Down
Expand Up @@ -44,6 +44,7 @@ Object {
"affected": Object {
"defaultBase": "main",
},
"defaultProject": "app1",
"implicitDependencies": Object {
".eslintrc.json": "*",
"package.json": Object {
Expand Down
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions packages/angular/src/generators/ng-add/migrate-from-angular-cli.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 38509cc

Please sign in to comment.