Skip to content

Commit 005af91

Browse files
committed
feat(@angular-devkit/schematics): use CordHost as the backend for HostTree
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.
1 parent 98469a2 commit 005af91

File tree

7 files changed

+374
-13
lines changed

7 files changed

+374
-13
lines changed

packages/angular_devkit/schematics/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export * from './rules/template';
2525
export * from './rules/url';
2626
export * from './tree/delegate';
2727
export * from './tree/empty';
28+
export * from './tree/host-tree';
2829
export * from './tree/filesystem';
2930
export * from './tree/virtual';
3031
export {UpdateRecorder} from './tree/interface';

packages/angular_devkit/schematics/src/rules/base.ts

Lines changed: 6 additions & 3 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
import { Observable, of as observableOf } from 'rxjs';
9-
import { concatMap, map } from 'rxjs/operators';
9+
import { concatMap, last, map } from 'rxjs/operators';
1010
import { FileOperator, Rule, SchematicContext, Source } from '../engine/interface';
1111
import { FilteredTree } from '../tree/filtered';
1212
import { FileEntry, FilePredicate, MergeStrategy, Tree } from '../tree/interface';
@@ -81,7 +81,7 @@ export function mergeWith(source: Source, strategy: MergeStrategy = MergeStrateg
8181
return (tree: Tree, context: SchematicContext) => {
8282
const result = callSource(source, context);
8383

84-
return result.pipe(map(other => VirtualTree.merge(tree, other, strategy || context.strategy)));
84+
return result.pipe(map(other => staticMerge(tree, other, strategy || context.strategy)));
8585
};
8686
}
8787

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

108108
return callRule(rule, observableOf(branchedTree), context)
109-
.pipe(map(t => staticMerge(tree, t, strategy)));
109+
.pipe(
110+
last(),
111+
map(t => staticMerge(tree, t, strategy)),
112+
);
110113
};
111114
}
112115

packages/angular_devkit/schematics/src/rules/schematic.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { of as observableOf } from 'rxjs';
9+
import { last, map } from 'rxjs/operators';
910
import { Rule, SchematicContext } from '../engine/interface';
10-
import { Tree } from '../tree/interface';
11+
import { MergeStrategy, Tree } from '../tree/interface';
1112
import { branch } from '../tree/static';
1213

1314

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

44-
return schematic.call(options, observableOf(branch(input)), context);
45+
return schematic.call(options, observableOf(branch(input)), context).pipe(
46+
last(),
47+
map(x => {
48+
// We allow overwrite conflict here because they're the only merge conflict we particularly
49+
// don't want to deal with; the input tree might have an OVERWRITE which the sub
50+
input.merge(x, MergeStrategy.AllowOverwriteConflict);
51+
52+
return input;
53+
}),
54+
);
4555
};
4656
}

packages/angular_devkit/schematics/src/tree/filesystem.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ export class FileSystemTree extends VirtualTree {
173173
}
174174

175175

176-
export class HostTree extends FileSystemTree {}
177-
178-
179176
export class FileSystemCreateTree extends FileSystemTree {
180177
constructor(host: virtualFs.Host) {
181178
super(host);

0 commit comments

Comments
 (0)