Skip to content

Commit

Permalink
fix(angular): ng-add migration should set default project
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Oct 11, 2022
1 parent 142cea8 commit b4a43a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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,13 @@ describe('workspace', () => {
).not.toBeDefined();
});

it('should set the default project correctly', async () => {
await migrateFromAngularCli(tree, {});
expect(readJson(tree, 'nx.json').defaultProject).toMatchInlineSnapshot(
`"myApp"`
);
});

it('should create nx.json', async () => {
await migrateFromAngularCli(tree, { defaultBase: 'main' });
expect(readJson(tree, 'nx.json')).toMatchSnapshot();
Expand Down
14 changes: 14 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,10 @@ export async function migrateFromAngularCli(
const projects = getAllProjects(tree);
const options = normalizeOptions(tree, rawOptions, projects);

const defaultProject = projects.apps.find((app) =>
app.config.sourceRoot?.startsWith('src')
);

if (options.preserveAngularCliLayout) {
addDependenciesToPackageJson(
tree,
Expand Down Expand Up @@ -103,6 +109,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 b4a43a7

Please sign in to comment.