diff --git a/packages/angular_devkit/schematics/src/rules/base.ts b/packages/angular_devkit/schematics/src/rules/base.ts index 94a041a1aec8..8d526b317da7 100644 --- a/packages/angular_devkit/schematics/src/rules/base.ts +++ b/packages/angular_devkit/schematics/src/rules/base.ts @@ -96,9 +96,9 @@ export function noop(): Rule { export function filter(predicate: FilePredicate): Rule { return ((tree: Tree) => { // TODO: Remove VirtualTree usage in 7.0 - if (tree instanceof VirtualTree) { + if (VirtualTree.isVirtualTree(tree)) { return new FilteredTree(tree, predicate); - } else if (tree instanceof HostTree) { + } else if (HostTree.isHostTree(tree)) { return new FilterHostTree(tree, predicate); } else { throw new SchematicsException('Tree type is not supported.'); diff --git a/packages/angular_devkit/schematics/src/tree/host-tree.ts b/packages/angular_devkit/schematics/src/tree/host-tree.ts index 70b4fd710023..6eb8488e439a 100644 --- a/packages/angular_devkit/schematics/src/tree/host-tree.ts +++ b/packages/angular_devkit/schematics/src/tree/host-tree.ts @@ -109,6 +109,18 @@ export class HostTree implements Tree { return this; } + static isHostTree(tree: Tree): tree is HostTree { + if (tree instanceof HostTree) { + return true; + } + + if (typeof tree === 'object' && typeof (tree as HostTree)._ancestry === 'object') { + return true; + } + + return false; + } + constructor(protected _backend: virtualFs.ReadonlyHost<{}> = new virtualFs.Empty()) { this._record = new virtualFs.CordHost(new virtualFs.SafeReadonlyHost(_backend)); this._recordSync = new virtualFs.SyncDelegateHost(this._record); diff --git a/packages/angular_devkit/schematics/src/tree/virtual.ts b/packages/angular_devkit/schematics/src/tree/virtual.ts index e702b1709cc6..d0aa418d6f71 100644 --- a/packages/angular_devkit/schematics/src/tree/virtual.ts +++ b/packages/angular_devkit/schematics/src/tree/virtual.ts @@ -104,7 +104,6 @@ export class VirtualDirEntry implements DirEntry { } } - /** * The root class of most trees. */ @@ -114,6 +113,18 @@ export class VirtualTree implements Tree { protected _root = new VirtualDirEntry(this); protected _tree = new Map(); + static isVirtualTree(tree: Tree): tree is VirtualTree { + if (tree instanceof VirtualTree) { + return true; + } + + if (typeof tree === 'object' && typeof (tree as VirtualTree)._copyTo === 'function') { + return true; + } + + return false; + } + /** * Normalize the path. Made available to subclasses to overload. * @param path The path to normalize.