refactor(@angular-devkit/schematics): remove several deprecated APIs

BREAKING CHANGE:

Removed several deprecated APIs:

- EngineHost `listSchematics` has been removed in favour of `listSchematicNames`.
- `FileSystemSink` - Use the new virtualFs.Host classes from `@angular-devkit/core`.
- `optimize` function has been remove as trees are automaticlly optimized.
- `DryRunSink` deprecated constructor that allowed to provide a directory path has been removed. Provide a `virtualFs.Host` instead.
This commit is contained in:
Alan Agius 2019-10-23 14:44:19 +02:00 committed by vikerman
parent 1404e50c7f
commit 341b18d8a6
12 changed files with 10 additions and 70 deletions

View File

@ -176,7 +176,6 @@ export declare class DryRunSink extends HostSink {
protected _fileDoesNotExistExceptionSet: Set<string>;
protected _subject: Subject<DryRunEvent>;
readonly reporter: Observable<DryRunEvent>;
constructor(dir: string, force?: boolean);
constructor(host: virtualFs.Host, force?: boolean);
_done(): Observable<void>;
protected _fileAlreadyExistException(path: string): void;
@ -215,7 +214,6 @@ export interface EngineHost<CollectionMetadataT extends object, SchematicMetadat
getSchematicRuleFactory<OptionT extends object>(schematic: SchematicDescription<CollectionMetadataT, SchematicMetadataT>, collection: CollectionDescription<CollectionMetadataT>): RuleFactory<OptionT>;
hasTaskExecutor(name: string): boolean;
listSchematicNames(collection: CollectionDescription<CollectionMetadataT>): string[];
listSchematics(collection: Collection<CollectionMetadataT, SchematicMetadataT>): string[];
transformContext(context: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): TypedSchematicContext<CollectionMetadataT, SchematicMetadataT> | void;
transformOptions<OptionT extends object, ResultT extends object>(schematic: SchematicDescription<CollectionMetadataT, SchematicMetadataT>, options: OptionT, context?: TypedSchematicContext<CollectionMetadataT, SchematicMetadataT>): Observable<ResultT>;
}
@ -246,10 +244,6 @@ export interface FilePredicate<T> {
(path: Path, entry?: Readonly<FileEntry> | null): T;
}
export declare class FileSystemSink extends HostSink {
constructor(dir: string, force?: boolean);
}
export declare type FileVisitor = FilePredicate<void>;
export declare const FileVisitorCancelToken: symbol;

View File

@ -67,7 +67,6 @@ export declare abstract class FileSystemEngineHostBase implements FileSystemEngi
getSchematicRuleFactory<OptionT extends object>(schematic: FileSystemSchematicDesc, _collection: FileSystemCollectionDesc): RuleFactory<OptionT>;
hasTaskExecutor(name: string): boolean;
listSchematicNames(collection: FileSystemCollectionDesc): string[];
listSchematics(collection: FileSystemCollection): string[];
registerContextTransform(t: ContextTransform): void;
registerOptionsTransform<T extends object, R extends object>(t: OptionTransform<T, R>): void;
registerTaskExecutor<T>(factory: TaskExecutorFactory<T>, options?: T): void;

View File

@ -77,10 +77,6 @@ export type SchematicDescription<CollectionMetadataT extends object,
*/
export interface EngineHost<CollectionMetadataT extends object, SchematicMetadataT extends object> {
createCollectionDescription(name: string): CollectionDescription<CollectionMetadataT>;
/**
* @deprecated Use `listSchematicNames`.
*/
listSchematics(collection: Collection<CollectionMetadataT, SchematicMetadataT>): string[];
listSchematicNames(collection: CollectionDescription<CollectionMetadataT>): string[];
createSchematicDescription(

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import { FilePredicate, MergeStrategy, Tree as TreeInterface } from './tree/interface';
import { branch, empty, merge, optimize, partition } from './tree/static';
import { branch, empty, merge, partition } from './tree/static';
export { SchematicsException } from './exception/exception';
@ -28,7 +28,6 @@ export * from './tree/host-tree';
export { UpdateRecorder } from './tree/interface';
export * from './engine/schematic';
export * from './sink/dryrun';
export * from './sink/filesystem';
export * from './sink/host';
export * from './sink/sink';
@ -58,5 +57,5 @@ export const Tree: TreeConstructor = {
partition(tree: TreeInterface, predicate: FilePredicate<boolean>) {
return partition(tree, predicate);
},
optimize(tree: TreeInterface) { return optimize(tree); },
optimize(tree: TreeInterface) { return tree; },
};

View File

@ -50,11 +50,6 @@ export class DryRunSink extends HostSink {
readonly reporter: Observable<DryRunEvent> = this._subject.asObservable();
/**
* @deprecated Use the virtualFs.Host constructor instead.
*/
constructor(dir: string, force?: boolean);
/**
* @param {host} dir The host to use to output. This should be scoped.
* @param {boolean} force Whether to force overwriting files that already exist.

View File

@ -9,7 +9,6 @@
import { Path, normalize, virtualFs } from '@angular-devkit/core';
import { toArray } from 'rxjs/operators';
import { HostCreateTree, HostTree } from '../tree/host-tree';
import { optimize } from '../tree/static';
import { DryRunSink } from './dryrun';
@ -47,7 +46,7 @@ describe('DryRunSink', () => {
})
.then(done, done.fail);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise().then(done, done.fail);
});
@ -78,7 +77,7 @@ describe('DryRunSink', () => {
})
.then(done, done.fail);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise().then(done, done.fail);
});
});

View File

@ -1,19 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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
*/
import { normalize, virtualFs } from '@angular-devkit/core';
import { NodeJsSyncHost } from '@angular-devkit/core/node';
import { HostSink } from './host';
/**
* @deprecated Use the new virtualFs.Host classes from @angular-devkit/core.
*/
export class FileSystemSink extends HostSink {
constructor(dir: string, force = false) {
super(new virtualFs.ScopedHost(new NodeJsSyncHost(), normalize(dir)), force);
}
}

View File

@ -9,7 +9,6 @@
import { normalize, virtualFs } from '@angular-devkit/core';
import { HostSink } from '@angular-devkit/schematics';
import { HostCreateTree, HostTree } from '../tree/host-tree';
import { optimize } from '../tree/static';
describe('FileSystemSink', () => {
@ -34,7 +33,7 @@ describe('FileSystemSink', () => {
const outputHost = new virtualFs.test.TestHost();
const sink = new HostSink(outputHost);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(() => {
const tmpFiles = outputHost.files.sort();
@ -57,7 +56,7 @@ describe('FileSystemSink', () => {
const outputHost = new virtualFs.test.TestHost();
const sink = new HostSink(outputHost);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(done, done.fail);
});
@ -70,7 +69,7 @@ describe('FileSystemSink', () => {
tree.rename('/file0', '/file1');
const sink = new HostSink(host);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(() => {
expect(host.sync.exists(normalize('/file0'))).toBe(false);
@ -88,7 +87,7 @@ describe('FileSystemSink', () => {
tree.rename('/sub/directory/file2', '/another-directory/file2');
const sink = new HostSink(host);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(() => {
expect(host.sync.exists(normalize('/sub/directory/file2'))).toBe(false);
@ -106,7 +105,7 @@ describe('FileSystemSink', () => {
tree.create('/file0', 'hello');
const sink = new HostSink(host);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(() => {
expect(host.sync.read(normalize('/file0')).toString()).toBe('hello');
@ -128,7 +127,7 @@ describe('FileSystemSink', () => {
expect(tree.exists('/file0')).toBeTruthy();
const sink = new HostSink(host);
sink.commit(optimize(tree))
sink.commit(tree)
.toPromise()
.then(() => {
expect(host.sync.read(normalize('/file0')).toString()).toBe('hello');

View File

@ -34,8 +34,3 @@ export function partition(tree: Tree, predicate: FilePredicate<boolean>): [Tree,
throw new SchematicsException('Tree type is not supported.');
}
}
/** @deprecated Tree's are automically optimized */
export function optimize(tree: Tree) {
return tree;
}

View File

@ -16,7 +16,6 @@ import { HostSink } from '../sink/host';
import { Sink } from '../sink/sink';
import { HostTree } from '../tree/host-tree';
import { Tree } from '../tree/interface';
import { optimize } from '../tree/static';
import {
LifeCycleEvent,
RequiredWorkflowExecutionContext,
@ -165,7 +164,6 @@ export abstract class BaseWorkflow implements Workflow {
of(new HostTree(this._host)),
{ logger: context.logger },
).pipe(
map(tree => optimize(tree)),
concatMap((tree: Tree) => {
// Process all sinks.
return concat(

View File

@ -109,15 +109,6 @@ export class FallbackEngineHost implements EngineHost<{}, {}> {
return result;
}
/**
* @deprecated Use `listSchematicNames`.
*/
listSchematics(
collection: Collection<FallbackCollectionDescription, FallbackSchematicDescription>,
): string[] {
return this.listSchematicNames(collection.description);
}
listSchematicNames(collection: CollectionDescription<FallbackCollectionDescription>): string[] {
const allNames = new Set<string>();
this._hosts.forEach(host => {

View File

@ -124,12 +124,6 @@ export abstract class FileSystemEngineHostBase implements FileSystemEngineHost {
private _contextTransforms: ContextTransform[] = [];
private _taskFactories = new Map<string, () => Observable<TaskExecutor>>();
/**
* @deprecated Use `listSchematicNames`.
*/
listSchematics(collection: FileSystemCollection): string[] {
return this.listSchematicNames(collection.description);
}
listSchematicNames(collection: FileSystemCollectionDesc) {
const schematics: string[] = [];
for (const key of Object.keys(collection.schematics)) {