Skip to content
Open
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
13 changes: 10 additions & 3 deletions packages/angular/build/src/builders/application/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,21 @@ export async function normalizeOptions(
}

const outputPath = options.outputPath ?? path.join(workspaceRoot, 'dist', projectName);
const resolvedOutputBase = path.resolve(
workspaceRoot,
typeof outputPath === 'string' ? outputPath : outputPath.base,
);
if (!resolvedOutputBase.startsWith(workspaceRoot + path.sep)) {
throw new Error(
`Output path '${resolvedOutputBase}' must be inside the project root directory '${workspaceRoot}'.`,
);
}
const outputOptions: NormalizedOutputOptions = {
browser: 'browser',
server: 'server',
media: 'media',
...(typeof outputPath === 'string' ? undefined : outputPath),
base: normalizeDirectoryPath(
path.resolve(workspaceRoot, typeof outputPath === 'string' ? outputPath : outputPath.base),
),
base: normalizeDirectoryPath(resolvedOutputBase),
clean: options.deleteOutputPath ?? true,
// For app-shell and SSG server files are not required by users.
// Omit these when SSR is not enabled.
Expand Down
12 changes: 9 additions & 3 deletions packages/angular/build/src/utils/delete-output-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
*/

import { readdir, rm } from 'node:fs/promises';
import { join, resolve } from 'node:path';
import { join, resolve, sep } from 'node:path';

/**
* Delete an output directory, but error out if it's the root of the project.
* Delete an output directory, but error out if it's the root of the project or outside it.
*/
export async function deleteOutputDir(
root: string,
outputPath: string,
emptyOnlyDirectories?: string[],
): Promise<void> {
const resolvedRoot = resolve(root);
const resolvedOutputPath = resolve(root, outputPath);
if (resolvedOutputPath === root) {
if (resolvedOutputPath === resolvedRoot) {
throw new Error('Output path MUST not be project root directory!');
}
if (!resolvedOutputPath.startsWith(resolvedRoot + sep)) {
throw new Error(
`Output path '${resolvedOutputPath}' MUST be inside the project root '${resolvedRoot}'.`,
);
}

const directoriesToEmpty = emptyOnlyDirectories
? new Set(emptyOnlyDirectories.map((directory) => join(resolvedOutputPath, directory)))
Expand Down
Loading