Skip to content
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
387 changes: 383 additions & 4 deletions goldens/public-api/angular_devkit/architect/index.md

Large diffs are not rendered by default.

399 changes: 0 additions & 399 deletions goldens/public-api/angular_devkit/core/index.md

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions goldens/public-api/angular_devkit/core/node/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@

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

import { ErrorObject } from 'ajv';
import { Format } from 'ajv';
import { Observable } from 'rxjs';
import { Observer } from 'rxjs';
import { Operator } from 'rxjs';
import { PartialObserver } from 'rxjs';
import { Stats as Stats_2 } from 'fs';
import { Subject } from 'rxjs';
import { SubscribableOrPromise } from 'rxjs';
import { Subscription } from 'rxjs';
import { ValidateFunction } from 'ajv';

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

declare namespace experimental {
export {
NodeModuleJobRegistry
}
}
export { experimental }

// @public
export class NodeJsAsyncHost implements virtualFs.Host<Stats_2> {
// (undocumented)
Expand Down Expand Up @@ -80,13 +68,6 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats_2> {
write(path: Path, content: virtualFs.FileBuffer): Observable<void>;
}

// @public (undocumented)
class NodeModuleJobRegistry<MinimumArgumentValueT extends JsonValue = JsonValue, MinimumInputValueT extends JsonValue = JsonValue, MinimumOutputValueT extends JsonValue = JsonValue> implements experimental_2.jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT> {
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(name: experimental_2.jobs.JobName): Observable<experimental_2.jobs.JobHandler<A, I, O> | null>;
// (undocumented)
protected _resolve(name: string): string | null;
}

// @public (undocumented)
export interface ProcessOutput {
// (undocumented)
Expand Down
30 changes: 30 additions & 0 deletions packages/angular_devkit/architect/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.io/license

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

licenses(["notice"])

Expand All @@ -21,7 +23,35 @@ ts_library(
"//packages/angular_devkit/architect",
"//packages/angular_devkit/core",
"//packages/angular_devkit/core/node",
"//tests/angular_devkit/architect/node/jobs:jobs_test_lib",
"@npm//@types/node",
"@npm//rxjs",
],
)

ts_library(
name = "node_test_lib",
testonly = True,
srcs = glob(
include = [
"**/*_spec.ts",
],
),
deps = [
":node",
"//packages/angular_devkit/architect",
],
)

[
jasmine_node_test(
name = "node_test_" + toolchain_name,
srcs = [":node_test_lib"],
tags = [toolchain_name],
toolchain = toolchain,
)
for toolchain_name, toolchain in zip(
TOOLCHAINS_NAMES,
TOOLCHAINS_VERSIONS,
)
]
4 changes: 4 additions & 0 deletions packages/angular_devkit/architect/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import * as jobs from './jobs/job-registry';

export * from './node-modules-architect-host';

export { jobs };
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/

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

export class NodeModuleJobRegistry<
MinimumArgumentValueT extends JsonValue = JsonValue,
MinimumInputValueT extends JsonValue = JsonValue,
MinimumOutputValueT extends JsonValue = JsonValue,
> implements
core_experimental.jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>
> implements jobs.Registry<MinimumArgumentValueT, MinimumInputValueT, MinimumOutputValueT>
{
protected _resolve(name: string): string | null {
try {
Expand All @@ -34,8 +34,8 @@ export class NodeModuleJobRegistry<
* @returns A description, or null if the job is not registered.
*/
get<A extends MinimumArgumentValueT, I extends MinimumInputValueT, O extends MinimumOutputValueT>(
name: core_experimental.jobs.JobName,
): Observable<core_experimental.jobs.JobHandler<A, I, O> | null> {
name: jobs.JobName,
): Observable<jobs.JobHandler<A, I, O> | null> {
const [moduleName, exportName] = name.split(/#/, 2);

const resolvedPath = this._resolve(moduleName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/

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

const root = path.join(
path.dirname(require.resolve(__filename)),
'../../../../../../tests/angular_devkit/core/node/jobs',
);
const root = path.join(__dirname, '../../../../../tests/angular_devkit/architect/node/jobs');

describe('NodeModuleJobScheduler', () => {
it('works', async () => {
const registry = new NodeModuleJobRegistry();
const scheduler = new core_experimental.jobs.SimpleScheduler(registry);
const scheduler = new jobs.SimpleScheduler(registry);

const job = scheduler.schedule(path.join(root, 'add'), [1, 2, 3]);
expect(await job.output.toPromise()).toBe(6);
Expand Down
9 changes: 3 additions & 6 deletions packages/angular_devkit/architect/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/

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

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

// Type short hands.
export type BuilderRegistry = experimental.jobs.Registry<
json.JsonObject,
BuilderInput,
BuilderOutput
>;
export type BuilderRegistry = Registry<json.JsonObject, BuilderInput, BuilderOutput>;

/**
* An API typed BuilderProgress. The interface generated from the schema is too permissive,
Expand Down
54 changes: 34 additions & 20 deletions packages/angular_devkit/architect/src/architect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import { analytics, experimental, json, logging } from '@angular-devkit/core';
import { analytics, json, logging } from '@angular-devkit/core';
import { Observable, from, merge, of, onErrorResumeNext } from 'rxjs';
import {
concatMap,
Expand All @@ -28,6 +28,20 @@ import {
targetStringFromTarget,
} from './api';
import { ArchitectHost, BuilderDescription, BuilderJobHandler } from './internal';
import {
FallbackRegistry,
JobHandler,
JobHandlerContext,
JobInboundMessage,
JobInboundMessageKind,
JobName,
JobOutboundMessageKind,
Registry,
Scheduler,
SimpleJobRegistry,
SimpleScheduler,
createJobHandler,
} from './jobs';
import { scheduleByName, scheduleByTarget } from './schedule-by-name';

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

function handler(argument: json.JsonObject, context: experimental.jobs.JobHandlerContext) {
function handler(argument: json.JsonObject, context: JobHandlerContext) {
// Add input validation to the inbound bus.
const inboundBusWithInputValidation = context.inboundBus.pipe(
concatMap((message) => {
if (message.kind === experimental.jobs.JobInboundMessageKind.Input) {
if (message.kind === JobInboundMessageKind.Input) {
const v = message.value as BuilderInput;
const options = {
...baseOptions,
Expand All @@ -73,7 +87,7 @@ function _createJobHandlerFromBuilderInfo(
map((value) => ({ ...message, value })),
);
} else {
return of(message as experimental.jobs.JobInboundMessage<BuilderInput>);
return of(message as JobInboundMessage<BuilderInput>);
}
}),
// Using a share replay because the job might be synchronously sending input, but
Expand All @@ -93,7 +107,7 @@ function _createJobHandlerFromBuilderInfo(

return builder.handler(argument, { ...context, inboundBus }).pipe(
map((output) => {
if (output.kind === experimental.jobs.JobOutboundMessageKind.Output) {
if (output.kind === JobOutboundMessageKind.Output) {
// Add target to it.
return {
...output,
Expand Down Expand Up @@ -198,7 +212,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {

get<A extends json.JsonObject, I extends BuilderInput, O extends BuilderOutput>(
name: string,
): Observable<experimental.jobs.JobHandler<A, I, O> | null> {
): Observable<JobHandler<A, I, O> | null> {
const m = name.match(/^([^:]+):([^:]+)$/i);
if (!m) {
return of(null);
Expand All @@ -207,7 +221,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {
return from(this._resolveBuilder(name)).pipe(
concatMap((builderInfo) => (builderInfo ? this._createBuilder(builderInfo) : of(null))),
first(null, null),
) as Observable<experimental.jobs.JobHandler<A, I, O> | null>;
) as Observable<JobHandler<A, I, O> | null>;
}
}

Expand All @@ -217,7 +231,7 @@ class ArchitectBuilderJobRegistry implements BuilderRegistry {
class ArchitectTargetJobRegistry extends ArchitectBuilderJobRegistry {
override get<A extends json.JsonObject, I extends BuilderInput, O extends BuilderOutput>(
name: string,
): Observable<experimental.jobs.JobHandler<A, I, O> | null> {
): Observable<JobHandler<A, I, O> | null> {
const m = name.match(/^{([^:]+):([^:]+)(?::([^:]*))?}$/i);
if (!m) {
return of(null);
Expand Down Expand Up @@ -251,12 +265,12 @@ class ArchitectTargetJobRegistry extends ArchitectBuilderJobRegistry {
);
}),
first(null, null),
) as Observable<experimental.jobs.JobHandler<A, I, O> | null>;
) as Observable<JobHandler<A, I, O> | null>;
}
}

function _getTargetOptionsFactory(host: ArchitectHost) {
return experimental.jobs.createJobHandler<Target, json.JsonValue, json.JsonObject>(
return createJobHandler<Target, json.JsonValue, json.JsonObject>(
(target) => {
return host.getOptionsForTarget(target).then((options) => {
if (options === null) {
Expand All @@ -275,7 +289,7 @@ function _getTargetOptionsFactory(host: ArchitectHost) {
}

function _getProjectMetadataFactory(host: ArchitectHost) {
return experimental.jobs.createJobHandler<Target, json.JsonValue, json.JsonObject>(
return createJobHandler<Target, json.JsonValue, json.JsonObject>(
(target) => {
return host.getProjectMetadata(target).then((options) => {
if (options === null) {
Expand All @@ -296,7 +310,7 @@ function _getProjectMetadataFactory(host: ArchitectHost) {
}

function _getBuilderNameForTargetFactory(host: ArchitectHost) {
return experimental.jobs.createJobHandler<Target, never, string>(
return createJobHandler<Target, never, string>(
async (target) => {
const builderName = await host.getBuilderNameForTarget(target);
if (!builderName) {
Expand All @@ -314,7 +328,7 @@ function _getBuilderNameForTargetFactory(host: ArchitectHost) {
}

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

export class Architect {
private readonly _scheduler: experimental.jobs.Scheduler;
private readonly _scheduler: Scheduler;
private readonly _jobCache = new Map<string, Observable<BuilderJobHandler>>();
private readonly _infoCache = new Map<string, Observable<BuilderInfo>>();

constructor(
private _host: ArchitectHost,
registry: json.schema.SchemaRegistry = new json.schema.CoreSchemaRegistry(),
additionalJobRegistry?: experimental.jobs.Registry,
additionalJobRegistry?: Registry,
) {
const privateArchitectJobRegistry = new experimental.jobs.SimpleJobRegistry();
const privateArchitectJobRegistry = new SimpleJobRegistry();
// Create private jobs.
privateArchitectJobRegistry.register(_getTargetOptionsFactory(_host));
privateArchitectJobRegistry.register(_getBuilderNameForTargetFactory(_host));
privateArchitectJobRegistry.register(_validateOptionsFactory(_host, registry));
privateArchitectJobRegistry.register(_getProjectMetadataFactory(_host));

const jobRegistry = new experimental.jobs.FallbackRegistry([
const jobRegistry = new FallbackRegistry([
new ArchitectTargetJobRegistry(_host, registry, this._jobCache, this._infoCache),
new ArchitectBuilderJobRegistry(_host, registry, this._jobCache, this._infoCache),
privateArchitectJobRegistry,
...(additionalJobRegistry ? [additionalJobRegistry] : []),
] as experimental.jobs.Registry[]);
] as Registry[]);

this._scheduler = new experimental.jobs.SimpleScheduler(jobRegistry, registry);
this._scheduler = new SimpleScheduler(jobRegistry, registry);
}

has(name: experimental.jobs.JobName) {
has(name: JobName) {
return this._scheduler.has(name);
}

Expand Down
9 changes: 5 additions & 4 deletions packages/angular_devkit/architect/src/create-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import { analytics, experimental, json, logging } from '@angular-devkit/core';
import { analytics, json, logging } from '@angular-devkit/core';
import { Observable, Subscription, from, isObservable, of, throwError } from 'rxjs';
import { mergeMap, tap } from 'rxjs/operators';
import {
Expand All @@ -24,13 +24,14 @@ import {
targetStringFromTarget,
} from './api';
import { Builder, BuilderSymbol, BuilderVersionSymbol } from './internal';
import { JobInboundMessageKind, createJobHandler } from './jobs';
import { scheduleByName, scheduleByTarget } from './schedule-by-name';

// eslint-disable-next-line max-lines-per-function
export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput = BuilderOutput>(
fn: BuilderHandlerFn<OptT>,
): Builder<OptT & json.JsonObject> {
const cjh = experimental.jobs.createJobHandler;
const cjh = createJobHandler;
// eslint-disable-next-line max-lines-per-function
const handler = cjh<json.JsonObject, BuilderInput, OutT>((options, context) => {
const scheduler = context.scheduler;
Expand Down Expand Up @@ -73,15 +74,15 @@ export function createBuilder<OptT = json.JsonObject, OutT extends BuilderOutput

const inputSubscription = context.inboundBus.subscribe((i) => {
switch (i.kind) {
case experimental.jobs.JobInboundMessageKind.Stop:
case JobInboundMessageKind.Stop:
// Run teardown logic then complete.
tearingDown = true;
Promise.all(teardownLogics.map((fn) => fn() || Promise.resolve())).then(
() => observer.complete(),
(err) => observer.error(err),
);
break;
case experimental.jobs.JobInboundMessageKind.Input:
case JobInboundMessageKind.Input:
if (!tearingDown) {
onInput(i.value);
}
Expand Down
Loading