fix(angular): fix chalk import and correctly skip invalid projects in ng-add generator (#26667)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26654
This commit is contained in:
Leosvel Pérez Espinosa 2024-06-25 10:37:31 +02:00 committed by GitHub
parent 47dfdcfc6b
commit 8872ca5c8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 6 deletions

View File

@ -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);

View File

@ -103,12 +103,12 @@ export class AppMigrator extends ProjectMigrator<SupportedTargets> {
}
override async migrate(): Promise<void> {
await super.migrate();
if (this.skipMigration === true) {
return;
}
await super.migrate();
this.updateProjectConfiguration();
await this.e2eMigrator.migrate();

View File

@ -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);

View File

@ -41,12 +41,12 @@ export class LibMigrator extends ProjectMigrator {
}
override async migrate(): Promise<void> {
await super.migrate();
if (this.skipMigration === true) {
return;
}
await super.migrate();
await this.updateProjectConfiguration();
this.moveProjectFiles();

View File

@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import {
arrayToString,
getProjectValidationResultMessage,

View File

@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import type { ValidationError } from './types';
export function arrayToString(array: string[]): string {