Skip to content

Commit

Permalink
feat(@angular-devkit/schematics): use CordHost as the backend for Hos…
Browse files Browse the repository at this point in the history
…tTree

This removes the need for VirtualTree although it is not yet removed. This should fix
a lot of merging/branching bugs seen in VirtualTree, AND align the branch/merging with
what is actually _meant_ to be. It will also streamline documentation.
  • Loading branch information
hansl committed May 31, 2018
1 parent bd8ba6e commit bee9f67
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 13 deletions.
1 change: 1 addition & 0 deletions packages/angular_devkit/schematics/src/index.ts
Expand Up @@ -25,6 +25,7 @@ export * from './rules/template';
export * from './rules/url';
export * from './tree/delegate';
export * from './tree/empty';
export * from './tree/host-tree';
export * from './tree/filesystem';
export * from './tree/virtual';
export {UpdateRecorder} from './tree/interface';
Expand Down
9 changes: 6 additions & 3 deletions packages/angular_devkit/schematics/src/rules/base.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import { Observable, of as observableOf } from 'rxjs';
import { concatMap, map } from 'rxjs/operators';
import { concatMap, last, map } from 'rxjs/operators';
import { FileOperator, Rule, SchematicContext, Source } from '../engine/interface';
import { FilteredTree } from '../tree/filtered';
import { FileEntry, FilePredicate, MergeStrategy, Tree } from '../tree/interface';
Expand Down Expand Up @@ -81,7 +81,7 @@ export function mergeWith(source: Source, strategy: MergeStrategy = MergeStrateg
return (tree: Tree, context: SchematicContext) => {
const result = callSource(source, context);

return result.pipe(map(other => VirtualTree.merge(tree, other, strategy || context.strategy)));
return result.pipe(map(other => staticMerge(tree, other, strategy || context.strategy)));
};
}

Expand All @@ -106,7 +106,10 @@ export function branchAndMerge(rule: Rule, strategy = MergeStrategy.Default): Ru
const branchedTree = branch(tree);

return callRule(rule, observableOf(branchedTree), context)
.pipe(map(t => staticMerge(tree, t, strategy)));
.pipe(
last(),
map(t => staticMerge(tree, t, strategy)),
);
};
}

Expand Down
14 changes: 12 additions & 2 deletions packages/angular_devkit/schematics/src/rules/schematic.ts
Expand Up @@ -6,8 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import { of as observableOf } from 'rxjs';
import { last, map } from 'rxjs/operators';
import { Rule, SchematicContext } from '../engine/interface';
import { Tree } from '../tree/interface';
import { MergeStrategy, Tree } from '../tree/interface';
import { branch } from '../tree/static';


Expand Down Expand Up @@ -41,6 +42,15 @@ export function schematic<OptionT extends object>(schematicName: string, options
const collection = context.schematic.collection;
const schematic = collection.createSchematic(schematicName, true);

return schematic.call(options, observableOf(branch(input)), context);
return schematic.call(options, observableOf(branch(input)), context).pipe(
last(),
map(x => {
// We allow overwrite conflict here because they're the only merge conflict we particularly
// don't want to deal with; the input tree might have an OVERWRITE which the sub
input.merge(x, MergeStrategy.AllowOverwriteConflict);

return input;
}),
);
};
}
3 changes: 0 additions & 3 deletions packages/angular_devkit/schematics/src/tree/filesystem.ts
Expand Up @@ -173,9 +173,6 @@ export class FileSystemTree extends VirtualTree {
}


export class HostTree extends FileSystemTree {}


export class FileSystemCreateTree extends FileSystemTree {
constructor(host: virtualFs.Host) {
super(host);
Expand Down

0 comments on commit bee9f67

Please sign in to comment.