Skip to content

Commit f113f3a

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 d9fed6a commit f113f3a

File tree

122 files changed

+596
-474
lines changed

Some content is hidden

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

122 files changed

+596
-474
lines changed

bin/devkit-admin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let logger = null;
3535
try {
3636
logger = new (require('@angular-devkit/core').logging.IndentLogger)('root');
3737
const colors = require('ansi-colors').create();
38-
const filter = require('rxjs/operators').filter;
38+
const filter = require('rxjs').filter;
3939

4040
logger
4141
.pipe(filter(entry => (entry.level !== 'debug' || args.verbose)))

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
@@ -194,7 +194,7 @@
194194
"puppeteer": "18.2.1",
195195
"quicktype-core": "21.0.13",
196196
"resolve-url-loader": "5.0.0",
197-
"rxjs": "6.6.7",
197+
"rxjs": "7.8.0",
198198
"sass": "1.58.0",
199199
"sass-loader": "13.2.0",
200200
"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/builders/all-of.ts

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

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

packages/angular_devkit/architect/builders/concat.ts

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

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

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
":node",
4141
"//packages/angular_devkit/architect",
4242
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
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.8.0"
1111
},
1212
"builders": "./builders/builders.json"
1313
}

packages/angular_devkit/architect/src/api.ts

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

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

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

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

packages/angular_devkit/architect/src/architect.ts

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

99
import { json, logging } from '@angular-devkit/core';
10-
import { Observable, from, merge, of, onErrorResumeNext } from 'rxjs';
1110
import {
11+
Observable,
1212
concatMap,
1313
first,
14+
firstValueFrom,
15+
from,
1416
ignoreElements,
1517
last,
1618
map,
19+
merge,
20+
of,
21+
onErrorResumeNext,
1722
shareReplay,
1823
switchMap,
1924
takeUntil,
20-
} from 'rxjs/operators';
25+
} from 'rxjs';
2126
import {
2227
BuilderInfo,
2328
BuilderInput,
@@ -335,9 +340,8 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
335340
throw new Error(`No builder info were found for builder ${JSON.stringify(builderName)}.`);
336341
}
337342

338-
return registry
339-
.compile(builderInfo.optionSchema)
340-
.pipe(
343+
return firstValueFrom(
344+
registry.compile(builderInfo.optionSchema).pipe(
341345
concatMap((validation) => validation(options)),
342346
switchMap(({ data, success, errors }) => {
343347
if (success) {
@@ -346,8 +350,8 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
346350

347351
throw new json.schema.SchemaValidationException(errors);
348352
}),
349-
)
350-
.toPromise();
353+
),
354+
);
351355
},
352356
{
353357
name: '..validateOptions',

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

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

99
import { json, logging } from '@angular-devkit/core';
10-
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
11-
import { defaultIfEmpty, mergeMap, tap } from 'rxjs/operators';
10+
import {
11+
Observable,
12+
Subscription,
13+
defaultIfEmpty,
14+
firstValueFrom,
15+
from,
16+
isObservable,
17+
mergeMap,
18+
of,
19+
tap,
20+
throwError,
21+
} from 'rxjs';
1222
import {
1323
BuilderContext,
1424
BuilderHandlerFn,
@@ -141,33 +151,39 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput
141151
return run;
142152
},
143153
async getTargetOptions(target: Target) {
144-
return scheduler
145-
.schedule<Target, json.JsonValue, json.JsonObject>('..getTargetOptions', target)
146-
.output.toPromise();
154+
return firstValueFrom(
155+
scheduler.schedule<Target, json.JsonValue, json.JsonObject>(
156+
'..getTargetOptions',
157+
target,
158+
).output,
159+
);
147160
},
148161
async getProjectMetadata(target: Target | string) {
149-
return scheduler
150-
.schedule<Target | string, json.JsonValue, json.JsonObject>(
162+
return firstValueFrom(
163+
scheduler.schedule<Target | string, json.JsonValue, json.JsonObject>(
151164
'..getProjectMetadata',
152165
target,
153-
)
154-
.output.toPromise();
166+
).output,
167+
);
155168
},
156169
async getBuilderNameForTarget(target: Target) {
157-
return scheduler
158-
.schedule<Target, json.JsonValue, string>('..getBuilderNameForTarget', target)
159-
.output.toPromise();
170+
return firstValueFrom(
171+
scheduler.schedule<Target, json.JsonValue, string>(
172+
'..getBuilderNameForTarget',
173+
target,
174+
).output,
175+
);
160176
},
161177
async validateOptions<T extends json.JsonObject = json.JsonObject>(
162178
options: json.JsonObject,
163179
builderName: string,
164180
) {
165-
return scheduler
166-
.schedule<[string, json.JsonObject], json.JsonValue, T>('..validateOptions', [
167-
builderName,
168-
options,
169-
])
170-
.output.toPromise();
181+
return firstValueFrom(
182+
scheduler.schedule<[string, json.JsonObject], json.JsonValue, T>(
183+
'..validateOptions',
184+
[builderName, options],
185+
).output,
186+
);
171187
},
172188
reportRunning() {
173189
switch (currentState) {

0 commit comments

Comments
 (0)