Skip to content

Commit

Permalink
fix(angular): fix chalk import and correctly skip invalid projects in…
Browse files Browse the repository at this point in the history
… 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

(cherry picked from commit 8872ca5)
  • Loading branch information
leosvelperez authored and FrozenPandaz committed Jun 26, 2024
1 parent b91e26e commit 8157ecb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import {
arrayToString,
getProjectValidationResultMessage,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from 'chalk';
import chalk = require('chalk');
import type { ValidationError } from './types';

export function arrayToString(array: string[]): string {
Expand Down

0 comments on commit 8157ecb

Please sign in to comment.