Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Browser Builder output path', () => {
});
afterEach(async () => host.restore().toPromise());

it('deletes output path', async () => {
it('deletes output path content', async () => {
// Write a file to the output path to later verify it was deleted.
await host
.write(join(host.root(), 'dist/file.txt'), virtualFs.stringToFileBuffer('file'))
Expand All @@ -34,14 +34,14 @@ describe('Browser Builder output path', () => {
const run = await architect.scheduleTarget(target);
const output = await run.result;
expect(output.success).toBe(false);
expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
expect(await host.exists(join(host.root(), 'dist/file.txt')).toPromise()).toBe(false);
await run.stop();
});

it('deletes output path and unlink symbolic link', async () => {
it('deletes output path content and unlink symbolic link', async () => {
// Write a file to the output path to later verify it was deleted.
host.writeMultipleFiles({
'src-link/dummy.txt': '',
'src-link/a.txt': '',
'dist/file.txt': virtualFs.stringToFileBuffer('file'),
});

Expand All @@ -63,8 +63,8 @@ describe('Browser Builder output path', () => {
const output = await run.result;
expect(output.success).toBe(false);

expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
expect(await host.exists(join(host.root(), 'src-link')).toPromise()).toBe(true);
expect(await host.exists(join(host.root(), 'dist/file.txt')).toPromise()).toBe(false);
expect(await host.exists(join(host.root(), 'src-link/a.txt')).toPromise()).toBe(true);
await run.stop();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import * as fs from 'fs';
import { resolve } from 'path';
import { join, resolve } from 'path';

/**
* Delete an output directory, but error out if it's the root of the project.
Expand All @@ -18,5 +18,19 @@ export function deleteOutputDir(root: string, outputPath: string): void {
throw new Error('Output path MUST not be project root directory!');
}

fs.rmSync(resolvedOutputPath, { force: true, recursive: true, maxRetries: 3 });
// Avoid removing the actual directory to avoid errors in cases where the output
// directory is mounted or symlinked. Instead the contents are removed.
let entries;
try {
entries = fs.readdirSync(resolvedOutputPath);
} catch (error) {
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
return;
}
throw error;
}

for (const entry of entries) {
fs.rmSync(join(resolvedOutputPath, entry), { force: true, recursive: true, maxRetries: 3 });
}
}