Skip to content

Commit 9572804

Browse files
committed
fix(@angular-devkit/architect): support all observable types as build results
Fixes angular#14579
1 parent 3afdab2 commit 9572804

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

packages/angular_devkit/architect/src/api.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { analytics, experimental, json, logging } from '@angular-devkit/core';
9-
import { Observable, from } from 'rxjs';
9+
import { Observable, SubscribableOrPromise, from } from 'rxjs';
1010
import { switchMap } from 'rxjs/operators';
1111
import { Schema as RealBuilderInput, Target as RealTarget } from './input-schema';
1212
import { Schema as RealBuilderOutput } from './output-schema';
@@ -250,8 +250,16 @@ export interface BuilderContext {
250250
/**
251251
* An accepted return value from a builder. Can be either an Observable, a Promise or a vector.
252252
*/
253-
export type BuilderOutputLike = Observable<BuilderOutput> | Promise<BuilderOutput> | BuilderOutput;
253+
export type BuilderOutputLike = SubscribableOrPromise<BuilderOutput> | BuilderOutput;
254254

255+
// tslint:disable-next-line:no-any
256+
export function isBuilderOutput(obj: any): obj is BuilderOutput {
257+
if (!obj || typeof obj.then === 'function' || typeof obj.subscribe === 'function') {
258+
return false;
259+
}
260+
261+
return typeof obj.success === 'boolean';
262+
}
255263

256264
/**
257265
* A builder handler function. The function signature passed to `createBuilder()`.

packages/angular_devkit/architect/src/create-builder.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { analytics, experimental, isPromise, json, logging } from '@angular-devkit/core';
9-
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
8+
import { analytics, experimental, json, logging } from '@angular-devkit/core';
9+
import { Observable, Subscription, from, of, throwError } from 'rxjs';
1010
import { tap } from 'rxjs/operators';
1111
import {
1212
BuilderContext,
1313
BuilderHandlerFn,
1414
BuilderInfo,
1515
BuilderInput,
1616
BuilderOutput,
17-
BuilderOutputLike,
1817
BuilderProgressState,
1918
ScheduleOptions,
2019
Target,
2120
TypedBuilderProgress,
21+
isBuilderOutput,
2222
targetStringFromTarget,
2323
} from './api';
2424
import { Builder, BuilderSymbol, BuilderVersionSymbol } from './internal';
@@ -189,19 +189,18 @@ export function createBuilder<
189189
};
190190

191191
context.reportRunning();
192-
let result: BuilderOutputLike;
192+
let result;
193193
try {
194194
result = fn(i.options as OptT, context);
195+
if (isBuilderOutput(result)) {
196+
result = of(result);
197+
} else {
198+
result = from(result);
199+
}
195200
} catch (e) {
196201
result = throwError(e);
197202
}
198203

199-
if (isPromise(result)) {
200-
result = from(result);
201-
} else if (!isObservable(result)) {
202-
result = of(result);
203-
}
204-
205204
// Manage some state automatically.
206205
progress({ state: BuilderProgressState.Running, current: 0, total: 1 }, context);
207206
subscriptions.push(result.pipe(

0 commit comments

Comments
 (0)