Skip to content

Commit 25e2d3c

Browse files
committed
build: update to rxjs 7
G3 is now using RXJS version 7 which makes it possible for the CLI to also be updated to RXJS 7. NB: this change does not remove all usages of the deprecated APIs. Closes #24371
1 parent fbfbca5 commit 25e2d3c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+385
-339
lines changed

goldens/public-api/angular_devkit/architect/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { JsonObject } from '@angular-devkit/core';
1010
import { JsonValue } from '@angular-devkit/core';
1111
import { logging } from '@angular-devkit/core';
1212
import { Observable } from 'rxjs';
13+
import { ObservableInput } from 'rxjs';
1314
import { Observer } from 'rxjs';
1415
import { schema } from '@angular-devkit/core';
15-
import { SubscribableOrPromise } from 'rxjs';
1616

1717
// @public (undocumented)
1818
export class Architect {
@@ -67,7 +67,7 @@ export type BuilderInput = json.JsonObject & Schema;
6767
export type BuilderOutput = json.JsonObject & Schema_2;
6868

6969
// @public
70-
export type BuilderOutputLike = AsyncIterable<BuilderOutput> | SubscribableOrPromise<BuilderOutput> | BuilderOutput;
70+
export type BuilderOutputLike = ObservableInput<BuilderOutput> | BuilderOutput;
7171

7272
// @public (undocumented)
7373
export type BuilderProgress = json.JsonObject & Schema_3 & TypedBuilderProgress;
@@ -97,6 +97,7 @@ export type BuilderRegistry = Registry<json.JsonObject, BuilderInput, BuilderOut
9797
export interface BuilderRun {
9898
id: number;
9999
info: BuilderInfo;
100+
lastOutput: Promise<BuilderOutput>;
100101
output: Observable<BuilderOutput>;
101102
progress: Observable<BuilderProgressReport>;
102103
result: Promise<BuilderOutput>;

goldens/public-api/angular_devkit/core/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import { ErrorObject } from 'ajv';
88
import { Format } from 'ajv';
99
import { Observable } from 'rxjs';
10+
import { ObservableInput } from 'rxjs';
1011
import { Operator } from 'rxjs';
1112
import { PartialObserver } from 'rxjs';
1213
import { Position } from 'source-map';
1314
import { Subject } from 'rxjs';
14-
import { SubscribableOrPromise } from 'rxjs';
1515
import { Subscription } from 'rxjs';
1616
import { ValidateFunction } from 'ajv';
1717

@@ -715,7 +715,7 @@ interface PromptDefinition {
715715
}
716716

717717
// @public (undocumented)
718-
type PromptProvider = (definitions: Array<PromptDefinition>) => SubscribableOrPromise<{
718+
type PromptProvider = (definitions: Array<PromptDefinition>) => ObservableInput<{
719719
[id: string]: JsonValue;
720720
}>;
721721

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@
191191
"puppeteer": "18.2.1",
192192
"quicktype-core": "6.0.69",
193193
"resolve-url-loader": "5.0.0",
194-
"rxjs": "6.6.7",
194+
"rxjs": "7.6.0",
195195
"sass": "1.56.2",
196196
"sass-loader": "13.2.0",
197197
"sauce-connect-proxy": "https://saucelabs.com/downloads/sc-4.8.1-linux.tar.gz",

packages/angular/cli/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ ts_library(
142142
"//packages/angular_devkit/schematics",
143143
"//packages/angular_devkit/schematics/testing",
144144
"@npm//@types/semver",
145-
"@npm//rxjs",
146145
],
147146
)
148147

packages/angular/cli/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
"symbol-observable": "4.0.0",
4242
"yargs": "17.6.2"
4343
},
44-
"devDependencies": {
45-
"rxjs": "6.6.7"
46-
},
4744
"ng-update": {
4845
"migrations": "@schematics/angular/migrations/migration-collection.json",
4946
"packageGroup": {

packages/angular/cli/src/command-builder/architect-base-command-module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ export abstract class ArchitectBaseCommandModule<T extends object>
8585
}
8686

8787
try {
88-
const { error, success } = await run.output.toPromise();
89-
88+
const { error, success } = await run.lastOutput;
9089
if (error) {
9190
logger.error(error);
9291
}

packages/angular/cli/src/command-builder/utilities/json-schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { json } from '@angular-devkit/core';
10+
import assert from 'node:assert';
1011
import yargs from 'yargs';
1112

1213
/**
@@ -198,6 +199,8 @@ export async function parseJsonSchemaToOptions(
198199
}
199200

200201
const flattenedSchema = await registry.flatten(schema).toPromise();
202+
// TODO(RXJS): temporary assert to avoid adding rxjs dependency.
203+
assert(flattenedSchema);
201204
json.schema.visitJsonSchema(flattenedSchema, visitor);
202205

203206
// Sort by positional and name.

packages/angular/cli/src/utilities/config.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { json, workspaces } from '@angular-devkit/core';
1010
import { existsSync, promises as fs } from 'fs';
11+
import assert from 'node:assert';
1112
import * as os from 'os';
1213
import * as path from 'path';
1314
import { PackageManager } from '../../lib/config/workspace-schema';
@@ -254,8 +255,12 @@ export async function validateWorkspace(data: json.JsonObject, isGlobal: boolean
254255
const { formats } = await import('@angular-devkit/schematics');
255256
const registry = new json.schema.CoreSchemaRegistry(formats.standardFormats);
256257
const validator = await registry.compile(schemaToValidate).toPromise();
257-
258-
const { success, errors } = await validator(data).toPromise();
258+
// TODO(RXJS): temporary assert to avoid adding rxjs dependency.
259+
assert(validator);
260+
const result = await validator(data).toPromise();
261+
// TODO(RXJS): temporary assert to avoid adding rxjs dependency.
262+
assert(result);
263+
const { success, errors } = result;
259264
if (!success) {
260265
throw new json.schema.SchemaValidationException(errors);
261266
}

packages/angular_devkit/architect/node/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ts_library(
4040
deps = [
4141
":node",
4242
"//packages/angular_devkit/architect",
43+
"@npm//rxjs",
4344
],
4445
)
4546

packages/angular_devkit/architect/node/jobs/job-registry_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import { jobs } from '@angular-devkit/architect';
1010
import * as path from 'path';
11+
import { lastValueFrom } from 'rxjs';
1112
import { NodeModuleJobRegistry } from './job-registry';
1213

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

2021
const job = scheduler.schedule(path.join(root, 'add'), [1, 2, 3]);
21-
expect(await job.output.toPromise()).toBe(6);
22+
expect(await lastValueFrom(job.output)).toBe(6);
2223
});
2324
});

packages/angular_devkit/architect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"typings": "src/index.d.ts",
88
"dependencies": {
99
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
10-
"rxjs": "6.6.7"
10+
"rxjs": "7.6.0"
1111
},
1212
"builders": "./builders/builders.json"
1313
}

packages/angular_devkit/architect/src/api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { json, logging } from '@angular-devkit/core';
10-
import { Observable, SubscribableOrPromise, Subscriber, from } from 'rxjs';
10+
import { Observable, ObservableInput, Subscriber, from } from 'rxjs';
1111
import { switchMap } from 'rxjs/operators';
1212
import { Schema as RealBuilderInput, Target as RealTarget } from './input-schema';
1313
import { Registry } from './jobs';
@@ -77,6 +77,12 @@ export interface BuilderRun {
7777
*/
7878
result: Promise<BuilderOutput>;
7979

80+
/**
81+
* The last output from a builder. This is recommended when scheduling a builder and only being
82+
* interested in the result of that last run.
83+
*/
84+
lastOutput: Promise<BuilderOutput>;
85+
8086
/**
8187
* The output(s) from the builder. A builder can have multiple outputs.
8288
* This always replay the last output when subscribed.
@@ -248,10 +254,7 @@ export interface BuilderContext {
248254
/**
249255
* An accepted return value from a builder. Can be either an Observable, a Promise or a vector.
250256
*/
251-
export type BuilderOutputLike =
252-
| AsyncIterable<BuilderOutput>
253-
| SubscribableOrPromise<BuilderOutput>
254-
| BuilderOutput;
257+
export type BuilderOutputLike = ObservableInput<BuilderOutput> | BuilderOutput;
255258

256259
// eslint-disable-next-line @typescript-eslint/no-explicit-any
257260
export function isBuilderOutput(obj: any): obj is BuilderOutput {

packages/angular_devkit/architect/src/architect.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { json, logging } from '@angular-devkit/core';
10-
import { Observable, from, merge, of, onErrorResumeNext } from 'rxjs';
10+
import { Observable, firstValueFrom, from, merge, of, onErrorResumeNext } from 'rxjs';
1111
import {
1212
concatMap,
1313
first,
@@ -335,9 +335,8 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
335335
throw new Error(`No builder info were found for builder ${JSON.stringify(builderName)}.`);
336336
}
337337

338-
return registry
339-
.compile(builderInfo.optionSchema)
340-
.pipe(
338+
return firstValueFrom(
339+
registry.compile(builderInfo.optionSchema).pipe(
341340
concatMap((validation) => validation(options)),
342341
switchMap(({ data, success, errors }) => {
343342
if (success) {
@@ -346,8 +345,8 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
346345

347346
throw new json.schema.SchemaValidationException(errors);
348347
}),
349-
)
350-
.toPromise();
348+
),
349+
);
351350
},
352351
{
353352
name: '..validateOptions',

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { json, logging } from '@angular-devkit/core';
10-
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
10+
import { Observable, Subscription, firstValueFrom, from, isObservable, of, throwError } from 'rxjs';
1111
import { defaultIfEmpty, mergeMap, tap } from 'rxjs/operators';
1212
import {
1313
BuilderContext,
@@ -141,33 +141,39 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput
141141
return run;
142142
},
143143
async getTargetOptions(target: Target) {
144-
return scheduler
145-
.schedule<Target, json.JsonValue, json.JsonObject>('..getTargetOptions', target)
146-
.output.toPromise();
144+
return firstValueFrom(
145+
scheduler.schedule<Target, json.JsonValue, json.JsonObject>(
146+
'..getTargetOptions',
147+
target,
148+
).output,
149+
);
147150
},
148151
async getProjectMetadata(target: Target | string) {
149-
return scheduler
150-
.schedule<Target | string, json.JsonValue, json.JsonObject>(
152+
return firstValueFrom(
153+
scheduler.schedule<Target | string, json.JsonValue, json.JsonObject>(
151154
'..getProjectMetadata',
152155
target,
153-
)
154-
.output.toPromise();
156+
).output,
157+
);
155158
},
156159
async getBuilderNameForTarget(target: Target) {
157-
return scheduler
158-
.schedule<Target, json.JsonValue, string>('..getBuilderNameForTarget', target)
159-
.output.toPromise();
160+
return firstValueFrom(
161+
scheduler.schedule<Target, json.JsonValue, string>(
162+
'..getBuilderNameForTarget',
163+
target,
164+
).output,
165+
);
160166
},
161167
async validateOptions<T extends json.JsonObject = json.JsonObject>(
162168
options: json.JsonObject,
163169
builderName: string,
164170
) {
165-
return scheduler
166-
.schedule<[string, json.JsonObject], json.JsonValue, T>('..validateOptions', [
167-
builderName,
168-
options,
169-
])
170-
.output.toPromise();
171+
return firstValueFrom(
172+
scheduler.schedule<[string, json.JsonObject], json.JsonValue, T>(
173+
'..validateOptions',
174+
[builderName, options],
175+
).output,
176+
);
171177
},
172178
reportRunning() {
173179
switch (currentState) {

packages/angular_devkit/architect/src/index_spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { json, logging, schema } from '@angular-devkit/core';
10-
import { timer } from 'rxjs';
10+
import { firstValueFrom, lastValueFrom, timer } from 'rxjs';
1111
import { map, take, tap, toArray } from 'rxjs/operators';
1212
import { promisify } from 'util';
1313
import { TestingArchitectHost } from '../testing/testing-architect-host';
@@ -173,7 +173,7 @@ describe('architect', () => {
173173
expect(called).toBe(1);
174174
expect(results).toBe(1);
175175

176-
const all = await run.output.pipe(toArray()).toPromise();
176+
const all = await lastValueFrom(run.output.pipe(toArray()));
177177
expect(called).toBe(1);
178178
expect(results).toBe(10);
179179
expect(all.length).toBe(10);
@@ -200,7 +200,7 @@ describe('architect', () => {
200200
expect(called).toBe(1);
201201
expect(results).toBe(1);
202202

203-
const all = await run.output.pipe(toArray()).toPromise();
203+
const all = await lastValueFrom(run.output.pipe(toArray()));
204204
expect(called).toBe(1);
205205
expect(results).toBe(10);
206206
expect(all.length).toBe(10);
@@ -325,7 +325,7 @@ describe('architect', () => {
325325
);
326326

327327
const run = await architect.scheduleBuilder('package:getTargetOptions', {});
328-
const output = await run.output.toPromise();
328+
const output = await lastValueFrom(run.output);
329329
expect(output.success).toBe(true);
330330
expect(options).toEqual(goldenOptions);
331331
await run.stop();
@@ -339,7 +339,7 @@ describe('architect', () => {
339339

340340
// But this should.
341341
try {
342-
await run2.output.toPromise();
342+
await lastValueFrom(run2.output);
343343
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
344344
} catch {}
345345
await run2.stop();
@@ -369,7 +369,7 @@ describe('architect', () => {
369369
);
370370

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

384384
// But this should.
385385
try {
386-
await run2.output.toPromise();
386+
await lastValueFrom(run2.output);
387387
expect('THE ABOVE LINE SHOULD NOT ERROR').toBe('false');
388388
} catch {}
389389
await run2.stop();
@@ -416,7 +416,7 @@ describe('architect', () => {
416416
);
417417

418418
const run = await architect.scheduleBuilder('package:do-it', { p1: 'hello' });
419-
const output = await run.output.toPromise();
419+
const output = await firstValueFrom(run.output);
420420
expect(output.success).toBe(true);
421421
expect(actualOptions).toEqual({
422422
p0: 123,
@@ -427,7 +427,7 @@ describe('architect', () => {
427427
// Should also error.
428428
const run2 = await architect.scheduleBuilder('package:do-it', {});
429429

430-
await expectAsync(run2.output.toPromise()).toBeRejectedWith(
430+
await expectAsync(lastValueFrom(run2.output)).toBeRejectedWith(
431431
jasmine.objectContaining({ message: jasmine.stringMatching('p1') }),
432432
);
433433

packages/angular_devkit/architect/src/jobs/dispatcher_spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import { JsonValue } from '@angular-devkit/core';
10+
import { lastValueFrom } from 'rxjs';
1011
import { JobHandler } from './api';
1112
import { createJobHandler } from './create-job-handler';
1213
import { createDispatcher } from './dispatcher';
@@ -36,6 +37,6 @@ describe('createDispatcher', () => {
3637

3738
dispatcher.setDefaultJob(add0 as JobHandler<JsonValue, JsonValue, number>);
3839
const sum = scheduler.schedule('add', [1, 2, 3, 4]);
39-
expect(await sum.output.toPromise()).toBe(10);
40+
expect(await lastValueFrom(sum.output)).toBe(10);
4041
});
4142
});

0 commit comments

Comments
 (0)