Skip to content

Commit

Permalink
feat(misc): implement nx repair and prettify migrate output (nrwl#11288)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz authored Jul 26, 2022
1 parent f2222ff commit 3c2ad25
Show file tree
Hide file tree
Showing 17 changed files with 242 additions and 95 deletions.
2 changes: 2 additions & 0 deletions docs/generated/cli/affected-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/affected-graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/affected-libs.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/format-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/format-write.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
2 changes: 2 additions & 0 deletions docs/generated/cli/print-affected.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ Untracked changes

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
36 changes: 36 additions & 0 deletions docs/generated/cli/repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: 'repair - CLI command'
description: 'Repair any configuration that is no longer supported by Nx.'
---

# repair

Repair any configuration that is no longer supported by Nx.

## Usage

```bash
nx repair
```

[Install `nx` globally](/getting-started/nx-setup#install-nx) to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpx nx`.

## Options

### help

Type: boolean

Show help

### verbose

Type: boolean

Print additional error stack trace on failure

### version

Type: boolean

Show version number
2 changes: 2 additions & 0 deletions docs/generated/cli/run-many.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Task to run for affected projects

### verbose

Type: boolean

Print additional error stack trace on failure

### version
Expand Down
22 changes: 14 additions & 8 deletions docs/generated/packages/nx.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion docs/map.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,12 @@
"id": "connect-to-nx-cloud",
"file": "generated/cli/connect-to-nx-cloud"
},
{ "name": "reset", "id": "reset", "file": "generated/cli/reset" }
{ "name": "reset", "id": "reset", "file": "generated/cli/reset" },
{
"name": "repair",
"id": "repair",
"file": "generated/cli/repair"
}
]
},
{
Expand Down
17 changes: 13 additions & 4 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function createWorkflow(
fsHost: virtualFs.Host<Stats>,
root: string,
opts: any
) {
): import('@angular-devkit/schematics/tools').NodeWorkflow {
const NodeWorkflow = require('@angular-devkit/schematics/tools').NodeWorkflow;
const workflow = new NodeWorkflow(fsHost, {
force: false,
Expand Down Expand Up @@ -880,7 +880,11 @@ export async function runMigration(
const fsHost = new NxScopedHost(root);
const workflow = createWorkflow(fsHost, root, {});
const collection = resolveMigrationsCollection(packageName);
return workflow

const record = { loggingQueue: [] as string[], error: false };
workflow.reporter.subscribe(await createRecorder(fsHost, record, logger));

await workflow
.execute({
collection,
schematic: migrationName,
Expand All @@ -889,6 +893,11 @@ export async function runMigration(
logger: logger as any,
})
.toPromise();

return {
loggingQueue: record.loggingQueue,
madeChanges: record.loggingQueue.length > 0,
};
}

function resolveMigrationsCollection(name: string): string {
Expand Down Expand Up @@ -1094,8 +1103,8 @@ export function wrapAngularDevkitSchematic(

// used for testing
if (collectionResolutionOverrides) {
const r = workflow.engineHost.resolve;
workflow.engineHost.resolve = (collection, b, c) => {
const r = (workflow.engineHost as any).resolve;
(workflow.engineHost as any).resolve = (collection, b, c) => {
if (collectionResolutionOverrides[collection]) {
return collectionResolutionOverrides[collection];
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/command-line/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface GenerateOptions {
defaults: boolean;
}

function printChanges(fileChanges: FileChange[]) {
export function printChanges(fileChanges: FileChange[]) {
fileChanges.forEach((f) => {
if (f.type === 'CREATE') {
console.log(`${chalk.green('CREATE')} ${f.path}`);
Expand Down
Loading

0 comments on commit 3c2ad25

Please sign in to comment.