Skip to content

Commit 13abfd0

Browse files
clydinalexeagle
authored andcommitted
fix(@angular-devkit/schematics): fully support async rules
1 parent 790a962 commit 13abfd0

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

etc/api/angular_devkit/schematics/src/_golden-api.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export interface RequiredWorkflowExecutionContext {
426426
schematic: string;
427427
}
428428

429-
export declare type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void> | void;
429+
export declare type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | Rule | Promise<void> | Promise<Rule> | void;
430430

431431
export declare type RuleFactory<T extends object> = (options: T) => Rule;
432432

packages/angular_devkit/schematics/src/engine/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,4 @@ export type AsyncFileOperator = (tree: FileEntry) => Observable<FileEntry | null
231231
*/
232232
export type Source = (context: SchematicContext) => Tree | Observable<Tree>;
233233
export type Rule = (tree: Tree, context: SchematicContext) =>
234-
Tree | Observable<Tree> | Rule | Promise<void> | void;
234+
Tree | Observable<Tree> | Rule | Promise<void> | Promise<Rule> | void;

packages/angular_devkit/schematics/src/rules/call.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,16 @@ export function callRule(
9797
}),
9898
);
9999
} else if (isPromise(result)) {
100-
return from(result).pipe(map(() => inputTree));
100+
return from(result).pipe(
101+
mergeMap(inner => {
102+
if (typeof inner === 'function') {
103+
// This is considered a Rule, chain the rule and return its output.
104+
return callRule(inner, observableOf(inputTree), context);
105+
} else {
106+
return observableOf(inputTree);
107+
}
108+
}),
109+
);
101110
} else if (TreeSymbol in result) {
102111
return observableOf(result);
103112
} else {

0 commit comments

Comments
 (0)