Skip to content

Commit 0b8d70f

Browse files
committed
fix(@angular-devkit/core): fix cannot delete directory
1 parent 7c00838 commit 0b8d70f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: packages/angular_devkit/core/src/virtual-fs/host/memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export class SimpleMemoryHost implements Host<{}> {
180180
path = this._toAbsolute(path);
181181
if (this._isDirectory(path)) {
182182
for (const [cachePath] of this._cache.entries()) {
183-
if (path.startsWith(cachePath + NormalizedSep)) {
183+
if (cachePath.startsWith(path + NormalizedSep) || cachePath === path) {
184184
this._cache.delete(cachePath);
185185
}
186186
}

Diff for: packages/angular_devkit/core/src/virtual-fs/host/memory_spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ describe('SimpleMemoryHost', () => {
6565
expect(host.exists(normalize('/sub/file1'))).toBe(false);
6666
});
6767

68+
it('can delete directory', () => {
69+
const host = new SyncDelegateHost(new SimpleMemoryHost());
70+
71+
const buffer = stringToFileBuffer('hello');
72+
73+
expect(host.exists(normalize('/sub/file1'))).toBe(false);
74+
host.write(normalize('/sub/file1'), buffer);
75+
host.write(normalize('/subfile.2'), buffer);
76+
expect(host.exists(normalize('/sub/file1'))).toBe(true);
77+
expect(host.exists(normalize('/subfile.2'))).toBe(true);
78+
host.delete(normalize('/sub'));
79+
expect(host.exists(normalize('/sub/file1'))).toBe(false);
80+
expect(host.exists(normalize('/sub'))).toBe(false);
81+
expect(host.exists(normalize('/subfile.2'))).toBe(true);
82+
});
83+
6884
it('can rename', () => {
6985
const host = new SyncDelegateHost(new SimpleMemoryHost());
7086

0 commit comments

Comments
 (0)