Skip to content

Commit 93adeeb

Browse files
alan-agius4clydin
authored andcommitted
refactor: move experimental jobs API from @angular-devkit/core to @angular-devkit/architect
With this change we move `jobs` APIs to `@angular-devkit/architect` as this are intended to used with `@angular-devkit/architect`.
1 parent b06421d commit 93adeeb

40 files changed

+570
-594
lines changed

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

Lines changed: 383 additions & 4 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 399 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@
66

77
/// <reference types="node" />
88

9-
import { ErrorObject } from 'ajv';
10-
import { Format } from 'ajv';
119
import { Observable } from 'rxjs';
12-
import { Observer } from 'rxjs';
1310
import { Operator } from 'rxjs';
1411
import { PartialObserver } from 'rxjs';
1512
import { Stats as Stats_2 } from 'fs';
1613
import { Subject } from 'rxjs';
17-
import { SubscribableOrPromise } from 'rxjs';
1814
import { Subscription } from 'rxjs';
19-
import { ValidateFunction } from 'ajv';
2015

2116
// @public
2217
export function createConsoleLogger(verbose?: boolean, stdout?: ProcessOutput, stderr?: ProcessOutput, colors?: Partial<Record<logging.LogLevel, (s: string) => string>>): logging.Logger;
2318

24-
declare namespace experimental {
25-
export {
26-
NodeModuleJobRegistry
27-
}
28-
}
29-
export { experimental }
30-
3119
// @public
3220
export class NodeJsAsyncHost implements virtualFs.Host<Stats_2> {
3321
// (undocumented)
@@ -80,13 +68,6 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats_2> {
8068
write(path: Path, content: virtualFs.FileBuffer): Observable<void>;
8169
}
8270

83-
// @public (undocumented)
84-
class NodeModuleJobRegistry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> implements experimental_2.jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT> {
85-
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: experimental_2.jobs.JobName): Observable<experimental_2.jobs.JobHandler<A, I, O> | null>;
86-
// (undocumented)
87-
protected _resolve(name: string): string | null;
88-
}
89-
9071
// @public (undocumented)
9172
export interface ProcessOutput {
9273
// (undocumented)

packages/angular_devkit/architect/node/BUILD.bazel

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Use of this source code is governed by an MIT-style license that can be
44
# found in the LICENSE file at https://angular.io/license
55

6+
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
67
load("//tools:defaults.bzl", "ts_library")
8+
load("//tools:toolchain_info.bzl", "TOOLCHAINS_NAMES", "TOOLCHAINS_VERSIONS")
79

810
licenses(["notice"])
911

@@ -21,7 +23,35 @@ ts_library(
2123
"//packages/angular_devkit/architect",
2224
"//packages/angular_devkit/core",
2325
"//packages/angular_devkit/core/node",
26+
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
2427
"@npm//@types/node",
2528
"@npm//rxjs",
2629
],
2730
)
31+
32+
ts_library(
33+
name = "node_test_lib",
34+
testonly = True,
35+
srcs = glob(
36+
include = [
37+
"**/*_spec.ts",
38+
],
39+
),
40+
deps = [
41+
":node",
42+
"//packages/angular_devkit/architect",
43+
],
44+
)
45+
46+
[
47+
jasmine_node_test(
48+
name = "node_test_" + toolchain_name,
49+
srcs = [":node_test_lib"],
50+
tags = [toolchain_name],
51+
toolchain = toolchain,
52+
)
53+
for toolchain_name, toolchain in zip(
54+
TOOLCHAINS_NAMES,
55+
TOOLCHAINS_VERSIONS,
56+
)
57+
]

packages/angular_devkit/architect/node/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import * as jobs from './jobs/job-registry';
10+
911
export * from './node-modules-architect-host';
12+
13+
export { jobs };

packages/angular_devkit/core/node/experimental/jobs/job-registry.ts renamed to packages/angular_devkit/architect/node/jobs/job-registry.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import { jobs } from '@angular-devkit/architect';
10+
import { JsonValue, schema } from '@angular-devkit/core';
911
import { Observable, of } from 'rxjs';
10-
import { JsonValue, experimental as core_experimental, schema } from '../../../src';
1112

1213
export class NodeModuleJobRegistry<
1314
MinimumArgumentValueT extends JsonValue = JsonValue,
1415
MinimumInputValueT extends JsonValue = JsonValue,
1516
MinimumOutputValueT extends JsonValue = JsonValue,
16-
> implements
17-
core_experimental.jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>
17+
> implements jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>
1818
{
1919
protected _resolve(name: string): string | null {
2020
try {
@@ -34,8 +34,8 @@ export class NodeModuleJobRegistry<
3434
* @returns A description, or null if the job is not registered.
3535
*/
3636
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(
37-
name: core_experimental.jobs.JobName,
38-
): Observable<core_experimental.jobs.JobHandler<A, I, O> | null> {
37+
name: jobs.JobName,
38+
): Observable<jobs.JobHandler<A, I, O> | null> {
3939
const [moduleName, exportName] = name.split(/#/, 2);
4040

4141
const resolvedPath = this._resolve(moduleName);

packages/angular_devkit/core/node/experimental/jobs/job-registry_spec.ts renamed to packages/angular_devkit/architect/node/jobs/job-registry_spec.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import { jobs } from '@angular-devkit/architect';
910
import * as path from 'path';
10-
import { experimental as core_experimental } from '../../../src';
1111
import { NodeModuleJobRegistry } from './job-registry';
1212

13-
const root = path.join(
14-
path.dirname(require.resolve(__filename)),
15-
'../../../../../../tests/angular_devkit/core/node/jobs',
16-
);
13+
const root = path.join(__dirname, '../../../../../tests/angular_devkit/architect/node/jobs');
1714

1815
describe('NodeModuleJobScheduler', () => {
1916
it('works', async () => {
2017
const registry = new NodeModuleJobRegistry();
21-
const scheduler = new core_experimental.jobs.SimpleScheduler(registry);
18+
const scheduler = new jobs.SimpleScheduler(registry);
2219

2320
const job = scheduler.schedule(path.join(root, 'add'), [1, 2, 3]);
2421
expect(await job.output.toPromise()).toBe(6);

packages/angular_devkit/architect/src/api.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { analytics, experimental, json, logging } from '@angular-devkit/core';
9+
import { analytics, json, logging } from '@angular-devkit/core';
1010
import { Observable, SubscribableOrPromise, Subscriber, from } from 'rxjs';
1111
import { switchMap } from 'rxjs/operators';
1212
import { Schema as RealBuilderInput, Target as RealTarget } from './input-schema';
13+
import { Registry } from './jobs';
1314
import { Schema as RealBuilderOutput } from './output-schema';
1415
import { State as BuilderProgressState, Schema as RealBuilderProgress } from './progress-schema';
1516

1617
export type Target = json.JsonObject & RealTarget;
1718
export { BuilderProgressState };
1819

1920
// Type short hands.
20-
export type BuilderRegistry = experimental.jobs.Registry<
21-
json.JsonObject,
22-
BuilderInput,
23-
BuilderOutput
24-
>;
21+
export type BuilderRegistry = Registry<json.JsonObject, BuilderInput, BuilderOutput>;
2522

2623
/**
2724
* An API typed BuilderProgress. The interface generated from the schema is too permissive,

packages/angular_devkit/architect/src/architect.ts

Lines changed: 34 additions & 20 deletions
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

9-
import { analytics, experimental, json, logging } from '@angular-devkit/core';
9+
import { analytics, json, logging } from '@angular-devkit/core';
1010
import { Observable, from, merge, of, onErrorResumeNext } from 'rxjs';
1111
import {
1212
concatMap,
@@ -28,6 +28,20 @@ import {
2828
targetStringFromTarget,
2929
} from './api';
3030
import { ArchitectHost, BuilderDescription, BuilderJobHandler } from './internal';
31+
import {
32+
FallbackRegistry,
33+
JobHandler,
34+
JobHandlerContext,
35+
JobInboundMessage,
36+
JobInboundMessageKind,
37+
JobName,
38+
JobOutboundMessageKind,
39+
Registry,
40+
Scheduler,
41+
SimpleJobRegistry,
42+
SimpleScheduler,
43+
createJobHandler,
44+
} from './jobs';
3145
import { scheduleByName, scheduleByTarget } from './schedule-by-name';
3246

3347
const inputSchema = require('./input-schema.json');
@@ -48,11 +62,11 @@ function _createJobHandlerFromBuilderInfo(
4862
info,
4963
};
5064

51-
function handler(argument: json.JsonObject, context: experimental.jobs.JobHandlerContext) {
65+
function handler(argument: json.JsonObject, context: JobHandlerContext) {
5266
// Add input validation to the inbound bus.
5367
const inboundBusWithInputValidation = context.inboundBus.pipe(
5468
concatMap((message) => {
55-
if (message.kind === experimental.jobs.JobInboundMessageKind.Input) {
69+
if (message.kind === JobInboundMessageKind.Input) {
5670
const v = message.value as BuilderInput;
5771
const options = {
5872
...baseOptions,
@@ -73,7 +87,7 @@ function _createJobHandlerFromBuilderInfo(
7387
map((value) => ({ ...message, value })),
7488
);
7589
} else {
76-
return of(message as experimental.jobs.JobInboundMessage<BuilderInput>);
90+
return of(message as JobInboundMessage<BuilderInput>);
7791
}
7892
}),
7993
// Using a share replay because the job might be synchronously sending input, but
@@ -93,7 +107,7 @@ function _createJobHandlerFromBuilderInfo(
93107

94108
return builder.handler(argument, { ...context, inboundBus }).pipe(
95109
map((output) => {
96-
if (output.kind === experimental.jobs.JobOutboundMessageKind.Output) {
110+
if (output.kind === JobOutboundMessageKind.Output) {
97111
// Add target to it.
98112
return {
99113
...output,
@@ -198,7 +212,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {
198212

199213
get<A extends json.JsonObject, I extends BuilderInput, O extends BuilderOutput>(
200214
name: string,
201-
): Observable<experimental.jobs.JobHandler<A, I, O> | null> {
215+
): Observable<JobHandler<A, I, O> | null> {
202216
const m = name.match(/^([^:]+):([^:]+)$/i);
203217
if (!m) {
204218
return of(null);
@@ -207,7 +221,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {
207221
return from(this._resolveBuilder(name)).pipe(
208222
concatMap((builderInfo) => (builderInfo ? this._createBuilder(builderInfo) : of(null))),
209223
first(null, null),
210-
) as Observable<experimental.jobs.JobHandler<A, I, O> | null>;
224+
) as Observable<JobHandler<A, I, O> | null>;
211225
}
212226
}
213227

@@ -217,7 +231,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {
217231
class ArchitectTargetJobRegistry extends ArchitectBuilderJobRegistry {
218232
override get<A extends json.JsonObject, I extends BuilderInput, O extends BuilderOutput>(
219233
name: string,
220-
): Observable<experimental.jobs.JobHandler<A, I, O> | null> {
234+
): Observable<JobHandler<A, I, O> | null> {
221235
const m = name.match(/^{([^:]+):([^:]+)(?::([^:]*))?}$/i);
222236
if (!m) {
223237
return of(null);
@@ -251,12 +265,12 @@ class ArchitectTargetJobRegistry extends ArchitectBuilderJobRegistry {
251265
);
252266
}),
253267
first(null, null),
254-
) as Observable<experimental.jobs.JobHandler<A, I, O> | null>;
268+
) as Observable<JobHandler<A, I, O> | null>;
255269
}
256270
}
257271

258272
function _getTargetOptionsFactory(host: ArchitectHost) {
259-
return experimental.jobs.createJobHandler<Target, json.JsonValue, json.JsonObject>(
273+
return createJobHandler<Target, json.JsonValue, json.JsonObject>(
260274
(target) => {
261275
return host.getOptionsForTarget(target).then((options) => {
262276
if (options === null) {
@@ -275,7 +289,7 @@ function _getTargetOptionsFactory(host: ArchitectHost) {
275289
}
276290

277291
function _getProjectMetadataFactory(host: ArchitectHost) {
278-
return experimental.jobs.createJobHandler<Target, json.JsonValue, json.JsonObject>(
292+
return createJobHandler<Target, json.JsonValue, json.JsonObject>(
279293
(target) => {
280294
return host.getProjectMetadata(target).then((options) => {
281295
if (options === null) {
@@ -296,7 +310,7 @@ function _getProjectMetadataFactory(host: ArchitectHost) {
296310
}
297311

298312
function _getBuilderNameForTargetFactory(host: ArchitectHost) {
299-
return experimental.jobs.createJobHandler<Target, never, string>(
313+
return createJobHandler<Target, never, string>(
300314
async (target) => {
301315
const builderName = await host.getBuilderNameForTarget(target);
302316
if (!builderName) {
@@ -314,7 +328,7 @@ function _getBuilderNameForTargetFactory(host: ArchitectHost) {
314328
}
315329

316330
function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.SchemaRegistry) {
317-
return experimental.jobs.createJobHandler<[string, json.JsonObject], never, json.JsonObject>(
331+
return createJobHandler<[string, json.JsonObject], never, json.JsonObject>(
318332
async ([builderName, options]) => {
319333
// Get option schema from the host.
320334
const builderInfo = await host.resolveBuilder(builderName);
@@ -348,33 +362,33 @@ function _validateOptionsFactory(host: ArchitectHost, registry: json.schema.Sche
348362
}
349363

350364
export class Architect {
351-
private readonly _scheduler: experimental.jobs.Scheduler;
365+
private readonly _scheduler: Scheduler;
352366
private readonly _jobCache = new Map<string, Observable<BuilderJobHandler>>();
353367
private readonly _infoCache = new Map<string, Observable<BuilderInfo>>();
354368

355369
constructor(
356370
private _host: ArchitectHost,
357371
registry: json.schema.SchemaRegistry = new json.schema.CoreSchemaRegistry(),
358-
additionalJobRegistry?: experimental.jobs.Registry,
372+
additionalJobRegistry?: Registry,
359373
) {
360-
const privateArchitectJobRegistry = new experimental.jobs.SimpleJobRegistry();
374+
const privateArchitectJobRegistry = new SimpleJobRegistry();
361375
// Create private jobs.
362376
privateArchitectJobRegistry.register(_getTargetOptionsFactory(_host));
363377
privateArchitectJobRegistry.register(_getBuilderNameForTargetFactory(_host));
364378
privateArchitectJobRegistry.register(_validateOptionsFactory(_host, registry));
365379
privateArchitectJobRegistry.register(_getProjectMetadataFactory(_host));
366380

367-
const jobRegistry = new experimental.jobs.FallbackRegistry([
381+
const jobRegistry = new FallbackRegistry([
368382
new ArchitectTargetJobRegistry(_host, registry, this._jobCache, this._infoCache),
369383
new ArchitectBuilderJobRegistry(_host, registry, this._jobCache, this._infoCache),
370384
privateArchitectJobRegistry,
371385
...(additionalJobRegistry ? [additionalJobRegistry] : []),
372-
] as experimental.jobs.Registry[]);
386+
] as Registry[]);
373387

374-
this._scheduler = new experimental.jobs.SimpleScheduler(jobRegistry, registry);
388+
this._scheduler = new SimpleScheduler(jobRegistry, registry);
375389
}
376390

377-
has(name: experimental.jobs.JobName) {
391+
has(name: JobName) {
378392
return this._scheduler.has(name);
379393
}
380394

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

Lines changed: 5 additions & 4 deletions
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

9-
import { analytics, experimental, json, logging } from '@angular-devkit/core';
9+
import { analytics, json, logging } from '@angular-devkit/core';
1010
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
1111
import { mergeMap, tap } from 'rxjs/operators';
1212
import {
@@ -24,13 +24,14 @@ import {
2424
targetStringFromTarget,
2525
} from './api';
2626
import { Builder, BuilderSymbol, BuilderVersionSymbol } from './internal';
27+
import { JobInboundMessageKind, createJobHandler } from './jobs';
2728
import { scheduleByName, scheduleByTarget } from './schedule-by-name';
2829

2930
// eslint-disable-next-line max-lines-per-function
3031
export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput = BuilderOutput>(
3132
fn: BuilderHandlerFn<OptT>,
3233
): Builder<OptT & json.JsonObject> {
33-
const cjh = experimental.jobs.createJobHandler;
34+
const cjh = createJobHandler;
3435
// eslint-disable-next-line max-lines-per-function
3536
const handler = cjh<json.JsonObject, BuilderInput, OutT>((options, context) => {
3637
const scheduler = context.scheduler;
@@ -73,15 +74,15 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput
7374

7475
const inputSubscription = context.inboundBus.subscribe((i) => {
7576
switch (i.kind) {
76-
case experimental.jobs.JobInboundMessageKind.Stop:
77+
case JobInboundMessageKind.Stop:
7778
// Run teardown logic then complete.
7879
tearingDown = true;
7980
Promise.all(teardownLogics.map((fn) => fn() || Promise.resolve())).then(
8081
() => observer.complete(),
8182
(err) => observer.error(err),
8283
);
8384
break;
84-
case experimental.jobs.JobInboundMessageKind.Input:
85+
case JobInboundMessageKind.Input:
8586
if (!tearingDown) {
8687
onInput(i.value);
8788
}

0 commit comments

Comments
 (0)