Skip to content

Commit 9d3f5d4

Browse files
fix(@angular/build): handle Windows absolute paths in output dir check
1 parent a2b1fab commit 9d3f5d4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/angular/build/src/utils/delete-output-dir.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { readdir, rm } from 'node:fs/promises';
10-
import { join, relative, resolve } from 'node:path';
10+
import { isAbsolute, join, relative, resolve } from 'node:path';
1111

1212
/**
1313
* Delete an output directory, but error out if it's the root of the project.
@@ -19,7 +19,9 @@ export async function deleteOutputDir(
1919
): Promise<void> {
2020
const resolvedOutputPath = resolve(root, outputPath);
2121
const relativePath = relative(resolvedOutputPath, root);
22-
if (!relativePath || !relativePath.startsWith('..')) {
22+
// When relative() returns an absolute path, the paths are on different drives/roots
23+
// (e.g. Windows drive letters or UNC paths), so it cannot be an ancestor.
24+
if (!relativePath || (!isAbsolute(relativePath) && !relativePath.startsWith('..'))) {
2325
throw new Error(
2426
`Output path "${resolvedOutputPath}" MUST not be the project root directory or its parent.`,
2527
);

packages/angular/build/src/utils/delete-output-dir_spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,11 @@ describe('deleteOutputDir', () => {
5858
it('should not throw when output directory does not exist', async () => {
5959
await expectAsync(deleteOutputDir(root, 'nonexistent')).toBeResolved();
6060
});
61+
62+
it('should not throw when output path is an absolute path outside the project', async () => {
63+
const externalDir = await mkdtemp(join(tmpdir(), 'ng-test-external-'));
64+
await writeFile(join(externalDir, 'old-file.txt'), 'content');
65+
66+
await expectAsync(deleteOutputDir(root, externalDir)).toBeResolved();
67+
});
6168
});

0 commit comments

Comments
 (0)