diff --git a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts index 9be7711bf1a66..074795923e044 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.spec.ts @@ -52,6 +52,18 @@ describe('app migrator', () => { jest.clearAllMocks(); }); + it('should not migrate project when validation fails', async () => { + // add project with no root + const project = addProject('app1', {} as any); + const migrator = new AppMigrator(tree, {}, project); + + await migrator.migrate(); + + expect(tree.exists('apps/app1/project.json')).toBe(false); + const { projects } = readJson(tree, 'angular.json'); + expect(projects.app1).toBeDefined(); + }); + describe('validation', () => { it('should fail validation when the project root is not specified', async () => { const project = addProject('app1', {} as any); diff --git a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.ts b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.ts index b96acdc9c974b..20328c4086b54 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/app.migrator.ts @@ -103,12 +103,12 @@ export class AppMigrator extends ProjectMigrator { } override async migrate(): Promise { + await super.migrate(); + if (this.skipMigration === true) { return; } - await super.migrate(); - this.updateProjectConfiguration(); await this.e2eMigrator.migrate(); diff --git a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts index 64cfa4278d746..6e2b5c37ce5df 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.spec.ts @@ -50,6 +50,18 @@ describe('lib migrator', () => { jest.clearAllMocks(); }); + it('should not migrate project when validation fails', async () => { + // add project with no root + const project = addProject('lib1', {} as any); + const migrator = new LibMigrator(tree, {}, project); + + await migrator.migrate(); + + expect(tree.exists('libs/lib1/project.json')).toBe(false); + const { projects } = readJson(tree, 'angular.json'); + expect(projects.lib1).toBeDefined(); + }); + describe('validation', () => { it('should fail validation when the project root is not specified', async () => { const project = addProject('lib1', {} as any); diff --git a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.ts b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.ts index 7a23553664043..d415d0cdf6a50 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.ts +++ b/packages/angular/src/generators/ng-add/migrators/projects/lib.migrator.ts @@ -41,12 +41,12 @@ export class LibMigrator extends ProjectMigrator { } override async migrate(): Promise { + await super.migrate(); + if (this.skipMigration === true) { return; } - await super.migrate(); - await this.updateProjectConfiguration(); this.moveProjectFiles(); diff --git a/packages/angular/src/generators/ng-add/utilities/validation-logging.spec.ts b/packages/angular/src/generators/ng-add/utilities/validation-logging.spec.ts index a78e98454afeb..709a243163fef 100644 --- a/packages/angular/src/generators/ng-add/utilities/validation-logging.spec.ts +++ b/packages/angular/src/generators/ng-add/utilities/validation-logging.spec.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import chalk = require('chalk'); import { arrayToString, getProjectValidationResultMessage, diff --git a/packages/angular/src/generators/ng-add/utilities/validation-logging.ts b/packages/angular/src/generators/ng-add/utilities/validation-logging.ts index a60f7b86ec2e4..1699edd39802d 100644 --- a/packages/angular/src/generators/ng-add/utilities/validation-logging.ts +++ b/packages/angular/src/generators/ng-add/utilities/validation-logging.ts @@ -1,4 +1,4 @@ -import * as chalk from 'chalk'; +import chalk = require('chalk'); import type { ValidationError } from './types'; export function arrayToString(array: string[]): string {