Skip to content

build: update to rxjs 7 #24377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/devkit-admin
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let logger = null;
try {
logger = new (require('@angular-devkit/core').logging.IndentLogger)('root');
const colors = require('ansi-colors').create();
const filter = require('rxjs/operators').filter;
const filter = require('rxjs').filter;

logger
.pipe(filter(entry => (entry.level !== 'debug' || args.verbose)))
Expand Down
5 changes: 3 additions & 2 deletions goldens/public-api/angular_devkit/architect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { JsonObject } from '@angular-devkit/core';
import { JsonValue } from '@angular-devkit/core';
import { logging } from '@angular-devkit/core';
import { Observable } from 'rxjs';
import { ObservableInput } from 'rxjs';
import { Observer } from 'rxjs';
import { schema } from '@angular-devkit/core';
import { SubscribableOrPromise } from 'rxjs';

// @public (undocumented)
export class Architect {
Expand Down Expand Up @@ -67,7 +67,7 @@ export type BuilderInput = json.JsonObject & Schema;
export type BuilderOutput = json.JsonObject & Schema_2;

// @public
export type BuilderOutputLike = AsyncIterable<BuilderOutput> | SubscribableOrPromise<BuilderOutput> | BuilderOutput;
export type BuilderOutputLike = ObservableInput<BuilderOutput> | BuilderOutput;

// @public (undocumented)
export type BuilderProgress = json.JsonObject & Schema_3 & TypedBuilderProgress;
Expand Down Expand Up @@ -97,6 +97,7 @@ export type BuilderRegistry = Registry<json.JsonObject, BuilderInput, BuilderOut
export interface BuilderRun {
id: number;
info: BuilderInfo;
lastOutput: Promise<BuilderOutput>;
output: Observable<BuilderOutput>;
progress: Observable<BuilderProgressReport>;
result: Promise<BuilderOutput>;
Expand Down
4 changes: 2 additions & 2 deletions goldens/public-api/angular_devkit/core/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import { ErrorObject } from 'ajv';
import { Format } from 'ajv';
import { Observable } from 'rxjs';
import { ObservableInput } from 'rxjs';
import { Operator } from 'rxjs';
import { PartialObserver } from 'rxjs';
import { Position } from 'source-map';
import { Subject } from 'rxjs';
import { SubscribableOrPromise } from 'rxjs';
import { Subscription } from 'rxjs';
import { ValidateFunction } from 'ajv';

Expand Down Expand Up @@ -714,7 +714,7 @@ interface PromptDefinition {
}

// @public (undocumented)
type PromptProvider = (definitions: Array<PromptDefinition>) => SubscribableOrPromise<{
type PromptProvider = (definitions: Array<PromptDefinition>) => ObservableInput<{
[id: string]: JsonValue;
}>;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
"puppeteer": "18.2.1",
"quicktype-core": "22.0.0",
"resolve-url-loader": "5.0.0",
"rxjs": "6.6.7",
"rxjs": "7.8.0",
"sass": "1.58.1",
"sass-loader": "13.2.0",
"sauce-connect-proxy": "https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz",
Expand Down
1 change: 0 additions & 1 deletion packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ ts_library(
"//packages/angular_devkit/schematics",
"//packages/angular_devkit/schematics/testing",
"@npm//@types/semver",
"@npm//rxjs",
],
)

Expand Down
3 changes: 0 additions & 3 deletions packages/angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
"symbol-observable": "4.0.0",
"yargs": "17.6.2"
},
"devDependencies": {
"rxjs": "6.6.7"
},
"ng-update": {
"migrations": "@schematics/angular/migrations/migration-collection.json",
"packageGroup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export abstract class ArchitectBaseCommandModule<T extends object>
}

try {
const { error, success } = await run.output.toPromise();

const { error, success } = await run.lastOutput;
if (error) {
logger.error(error);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/angular_devkit/architect/builders/all-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { json } from '@angular-devkit/core';
import { EMPTY, from, of } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
import { EMPTY, from, map, mergeMap, of } from 'rxjs';
import { BuilderOutput, BuilderRun, createBuilder } from '../src';
import { Schema as OperatorSchema } from './operator-schema';

Expand Down
3 changes: 1 addition & 2 deletions packages/angular_devkit/architect/builders/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { json } from '@angular-devkit/core';
import { from, of } from 'rxjs';
import { concatMap, first, last, map, switchMap } from 'rxjs/operators';
import { concatMap, first, from, last, map, of, switchMap } from 'rxjs';
import { BuilderOutput, BuilderRun, createBuilder } from '../src';
import { Schema as OperatorSchema } from './operator-schema';

Expand Down
1 change: 1 addition & 0 deletions packages/angular_devkit/architect/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ts_library(
":node",
"//packages/angular_devkit/architect",
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
"@npm//rxjs",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import { jobs } from '@angular-devkit/architect';
import * as path from 'path';
import { lastValueFrom } from 'rxjs';
import { NodeModuleJobRegistry } from './job-registry';

const root = path.join(__dirname, '../../../../../tests/angular_devkit/architect/node/jobs');
Expand All @@ -18,6 +19,6 @@ describe('NodeModuleJobScheduler', () => {
const scheduler = new jobs.SimpleScheduler(registry);

const job = scheduler.schedule(path.join(root, 'add'), [1, 2, 3]);
expect(await job.output.toPromise()).toBe(6);
expect(await lastValueFrom(job.output)).toBe(6);
});
});
2 changes: 1 addition & 1 deletion packages/angular_devkit/architect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typings": "src/index.d.ts",
"dependencies": {
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
"rxjs": "6.6.7"
"rxjs": "7.8.0"
},
"builders": "./builders/builders.json"
}
14 changes: 8 additions & 6 deletions packages/angular_devkit/architect/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { json, logging } from '@angular-devkit/core';
import { Observable, SubscribableOrPromise, Subscriber, from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { Observable, ObservableInput, Subscriber, from, switchMap } from 'rxjs';
import { Schema as RealBuilderInput, Target as RealTarget } from './input-schema';
import { Registry } from './jobs';
import { Schema as RealBuilderOutput } from './output-schema';
Expand Down Expand Up @@ -77,6 +76,12 @@ export interface BuilderRun {
*/
result: Promise<BuilderOutput>;

/**
* The last output from a builder. This is recommended when scheduling a builder and only being
* interested in the result of that last run.
*/
lastOutput: Promise<BuilderOutput>;

/**
* The output(s) from the builder. A builder can have multiple outputs.
* This always replay the last output when subscribed.
Expand Down Expand Up @@ -248,10 +253,7 @@ export interface BuilderContext {
/**
* An accepted return value from a builder. Can be either an Observable, a Promise or a vector.
*/
export type BuilderOutputLike =
| AsyncIterable<BuilderOutput>
| SubscribableOrPromise<BuilderOutput>
| BuilderOutput;
export type BuilderOutputLike = ObservableInput<BuilderOutput> | BuilderOutput;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isBuilderOutput(obj: any): obj is BuilderOutput {
Expand Down
8 changes: 6 additions & 2 deletions packages/angular_devkit/architect/src/architect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
*/

import { json, logging } from '@angular-devkit/core';
import { Observable, from, merge, of, onErrorResumeNext } from 'rxjs';
import {
Observable,
concatMap,
first,
from,
ignoreElements,
last,
map,
merge,
of,
onErrorResumeNext,
shareReplay,
takeUntil,
} from 'rxjs/operators';
} from 'rxjs';
import {
BuilderInfo,
BuilderInput,
Expand Down
52 changes: 34 additions & 18 deletions packages/angular_devkit/architect/src/create-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
*/

import { json, logging } from '@angular-devkit/core';
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
import { defaultIfEmpty, mergeMap, tap } from 'rxjs/operators';
import {
Observable,
Subscription,
defaultIfEmpty,
firstValueFrom,
from,
isObservable,
mergeMap,
of,
tap,
throwError,
} from 'rxjs';
import {
BuilderContext,
BuilderHandlerFn,
Expand Down Expand Up @@ -141,33 +151,39 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput
return run;
},
async getTargetOptions(target: Target) {
return scheduler
.schedule<Target, json.JsonValue, json.JsonObject>('..getTargetOptions', target)
.output.toPromise();
return firstValueFrom(
scheduler.schedule<Target, json.JsonValue, json.JsonObject>(
'..getTargetOptions',
target,
).output,
);
},
async getProjectMetadata(target: Target | string) {
return scheduler
.schedule<Target | string, json.JsonValue, json.JsonObject>(
return firstValueFrom(
scheduler.schedule<Target | string, json.JsonValue, json.JsonObject>(
'..getProjectMetadata',
target,
)
.output.toPromise();
).output,
);
},
async getBuilderNameForTarget(target: Target) {
return scheduler
.schedule<Target, json.JsonValue, string>('..getBuilderNameForTarget', target)
.output.toPromise();
return firstValueFrom(
scheduler.schedule<Target, json.JsonValue, string>(
'..getBuilderNameForTarget',
target,
).output,
);
},
async validateOptions<T extends json.JsonObject = json.JsonObject>(
options: json.JsonObject,
builderName: string,
) {
return scheduler
.schedule<[string, json.JsonObject], json.JsonValue, T>('..validateOptions', [
builderName,
options,
])
.output.toPromise();
return firstValueFrom(
scheduler.schedule<[string, json.JsonObject], json.JsonValue, T>(
'..validateOptions',
[builderName, options],
).output,
);
},
reportRunning() {
switch (currentState) {
Expand Down
19 changes: 9 additions & 10 deletions packages/angular_devkit/architect/src/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/

import { json, logging, schema } from '@angular-devkit/core';
import { timer } from 'rxjs';
import { map, take, tap, toArray } from 'rxjs/operators';
import { firstValueFrom, lastValueFrom, map, take, tap, timer, toArray } from 'rxjs';
import { promisify } from 'util';
import { TestingArchitectHost } from '../testing/testing-architect-host';
import { BuilderOutput, BuilderRun } from './api';
Expand Down Expand Up @@ -173,7 +172,7 @@ describe('architect', () => {
expect(called).toBe(1);
expect(results).toBe(1);

const all = await run.output.pipe(toArray()).toPromise();
const all = await lastValueFrom(run.output.pipe(toArray()));
expect(called).toBe(1);
expect(results).toBe(10);
expect(all.length).toBe(10);
Expand All @@ -200,7 +199,7 @@ describe('architect', () => {
expect(called).toBe(1);
expect(results).toBe(1);

const all = await run.output.pipe(toArray()).toPromise();
const all = await lastValueFrom(run.output.pipe(toArray()));
expect(called).toBe(1);
expect(results).toBe(10);
expect(all.length).toBe(10);
Expand Down Expand Up @@ -325,7 +324,7 @@ describe('architect', () => {
);

const run = await architect.scheduleBuilder('package:getTargetOptions', {});
const output = await run.output.toPromise();
const output = await lastValueFrom(run.output);
expect(output.success).toBe(true);
expect(options).toEqual(goldenOptions);
await run.stop();
Expand All @@ -339,7 +338,7 @@ describe('architect', () => {

// But this should.
try {
await run2.output.toPromise();
await lastValueFrom(run2.output);
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
} catch {}
await run2.stop();
Expand Down Expand Up @@ -369,7 +368,7 @@ describe('architect', () => {
);

const run = await architect.scheduleBuilder('package:do-it', {});
const output = await run.output.toPromise();
const output = await lastValueFrom(run.output);
expect(output.success).toBe(true);
expect(actualBuilderName).toEqual(builderName);
await run.stop();
Expand All @@ -383,7 +382,7 @@ describe('architect', () => {

// But this should.
try {
await run2.output.toPromise();
await lastValueFrom(run2.output);
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
} catch {}
await run2.stop();
Expand Down Expand Up @@ -416,7 +415,7 @@ describe('architect', () => {
);

const run = await architect.scheduleBuilder('package:do-it', { p1: 'hello' });
const output = await run.output.toPromise();
const output = await firstValueFrom(run.output);
expect(output.success).toBe(true);
expect(actualOptions).toEqual({
p0: 123,
Expand All @@ -427,7 +426,7 @@ describe('architect', () => {
// Should also error.
const run2 = await architect.scheduleBuilder('package:do-it', {});

await expectAsync(run2.output.toPromise()).toBeRejectedWith(
await expectAsync(lastValueFrom(run2.output)).toBeRejectedWith(
jasmine.objectContaining({ message: jasmine.stringMatching('p1') }),
);

Expand Down
13 changes: 11 additions & 2 deletions packages/angular_devkit/architect/src/jobs/create-job-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@
*/

import { BaseException, JsonValue, isPromise, logging } from '@angular-devkit/core';
import { Observable, Observer, Subject, Subscription, from, isObservable, of } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import {
Observable,
Observer,
Subject,
Subscription,
from,
isObservable,
of,
switchMap,
tap,
} from 'rxjs';
import {
JobDescription,
JobHandler,
Expand Down
Loading