Skip to content

Commit

Permalink
fix(angular): execute wrapped schematics post tasks and log messages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Apr 11, 2024
1 parent f59ed58 commit d7f1b3d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Function: wrapAngularDevkitSchematic

**wrapAngularDevkitSchematic**(`collectionName`, `generatorName`): (`host`: `Tree`, `generatorOptions`: \{ `[k: string]`: `any`; }) => `Promise`\<`any`\>
**wrapAngularDevkitSchematic**(`collectionName`, `generatorName`): (`host`: `Tree`, `generatorOptions`: \{ `[k: string]`: `any`; }) => `Promise`\<`GeneratorCallback`\>

#### Parameters

Expand All @@ -13,7 +13,7 @@

`fn`

▸ (`host`, `generatorOptions`): `Promise`\<`any`\>
▸ (`host`, `generatorOptions`): `Promise`\<`GeneratorCallback`\>

##### Parameters

Expand All @@ -24,4 +24,4 @@

##### Returns

`Promise`\<`any`\>
`Promise`\<`GeneratorCallback`\>
41 changes: 28 additions & 13 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ import { Stats } from 'fs';
import { dirname, extname, join, resolve } from 'path';

import { concat, from, Observable, of, zip } from 'rxjs';
import { catchError, concatMap, map, tap } from 'rxjs/operators';
import {
catchError,
concatMap,
defaultIfEmpty,
last,
map,
tap,
} from 'rxjs/operators';

import type { GenerateOptions } from '../command-line/generate/generate';
import { NxJsonConfiguration } from '../config/nx-json';
Expand Down Expand Up @@ -57,6 +64,7 @@ import {
ExecutorConfig,
ExecutorContext,
ExecutorsJson,
GeneratorCallback,
TaskGraphExecutor,
} from '../config/misc-interfaces';
import { readPluginPackageJson } from '../project-graph/plugins';
Expand Down Expand Up @@ -967,7 +975,10 @@ export function wrapAngularDevkitSchematic(
// were written with Nx in mind, and may care about tags.
require('./compat');

return async (host: Tree, generatorOptions: { [k: string]: any }) => {
return async (
host: Tree,
generatorOptions: { [k: string]: any }
): Promise<GeneratorCallback> => {
const graph = await createProjectGraphAsync();
const { projects } = readProjectsConfigurationFromProjectGraph(graph);

Expand All @@ -981,16 +992,6 @@ export function wrapAngularDevkitSchematic(
);
}

const emptyLogger = {
log: (e) => {},
info: (e) => {},
warn: (e) => {},
debug: () => {},
error: (e) => {},
fatal: (e) => {},
} as any;
emptyLogger.createChild = () => emptyLogger;

const recorder = (
event: import('@angular-devkit/schematics').DryRunEvent
) => {
Expand Down Expand Up @@ -1020,6 +1021,7 @@ export function wrapAngularDevkitSchematic(

const fsHost = new NxScopeHostUsedForWrappedSchematics(host.root, host);

const logger = getLogger(generatorOptions.verbose);
const options = {
generatorOptions,
dryRun: true,
Expand Down Expand Up @@ -1052,7 +1054,7 @@ export function wrapAngularDevkitSchematic(
fsHost,
host.root,
workflow,
emptyLogger,
logger,
options,
schematic,
false,
Expand All @@ -1062,6 +1064,19 @@ export function wrapAngularDevkitSchematic(
if (res.status !== 0) {
throw new Error(res.loggingQueue.join('\n'));
}

const { lastValueFrom } = require('rxjs');
const toPromise = (obs: Observable<any>) =>
lastValueFrom ? lastValueFrom(obs) : obs.toPromise();

return async () => {
// https://github.com/angular/angular-cli/blob/344193f79d880177e421cff85dd3e94338d07420/packages/angular_devkit/schematics/src/workflow/base.ts#L194-L200
await toPromise(
workflow.engine
.executePostTasks()
.pipe(defaultIfEmpty(undefined), last())
);
};
};
}

Expand Down

0 comments on commit d7f1b3d

Please sign in to comment.