Skip to content

Commit de08a1f

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

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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)) {
184184
this._cache.delete(cachePath);
185185
}
186186
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ 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+
expect(host.exists(normalize('/sub/file1'))).toBe(true);
76+
host.delete(normalize('/sub'));
77+
expect(host.exists(normalize('/sub/file1'))).toBe(false);
78+
expect(host.exists(normalize('/sub'))).toBe(false);
79+
});
80+
6881
it('can rename', () => {
6982
const host = new SyncDelegateHost(new SimpleMemoryHost());
7083

0 commit comments

Comments
 (0)