Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): ng-add migration should set default project #12513

Merged
merged 2 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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