diff --git a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts index 8863a3d41465..02fb40b869d2 100644 --- a/packages/angular_devkit/core/src/virtual-fs/host/memory.ts +++ b/packages/angular_devkit/core/src/virtual-fs/host/memory.ts @@ -180,7 +180,7 @@ export class SimpleMemoryHost implements Host<{}> { path = this._toAbsolute(path); if (this._isDirectory(path)) { for (const [cachePath] of this._cache.entries()) { - if (path.startsWith(cachePath + NormalizedSep)) { + if (cachePath.startsWith(path + NormalizedSep) || cachePath === path) { this._cache.delete(cachePath); } } diff --git a/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts b/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts index 849829666dc3..45df3e60fb24 100644 --- a/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts +++ b/packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts @@ -65,6 +65,22 @@ describe('SimpleMemoryHost', () => { expect(host.exists(normalize('/sub/file1'))).toBe(false); }); + it('can delete directory', () => { + const host = new SyncDelegateHost(new SimpleMemoryHost()); + + const buffer = stringToFileBuffer('hello'); + + expect(host.exists(normalize('/sub/file1'))).toBe(false); + host.write(normalize('/sub/file1'), buffer); + host.write(normalize('/subfile.2'), buffer); + expect(host.exists(normalize('/sub/file1'))).toBe(true); + expect(host.exists(normalize('/subfile.2'))).toBe(true); + host.delete(normalize('/sub')); + expect(host.exists(normalize('/sub/file1'))).toBe(false); + expect(host.exists(normalize('/sub'))).toBe(false); + expect(host.exists(normalize('/subfile.2'))).toBe(true); + }); + it('can rename', () => { const host = new SyncDelegateHost(new SimpleMemoryHost());