/
githubmirror
/
angular-cli
Обзор
Документация
Войти
/
githubmirror
/
angular-cli
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/angular/build/src/utils/delete-output-dir.ts
52 строки
2 KB
Ash Ramirez
refactor(@angular/cli): update aio links -> adev links
06 июн 2024, 12:12
06 июн 2024, 12:12
434a374
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import { readdir, rm } from 'node:fs/promises'; import { join, resolve } from 'node:path'; /** * Delete an output directory, but error out if it's the root of the project. */ export async function deleteOutputDir( root: string, outputPath: string, emptyOnlyDirectories?: string[], ): Promise<void> { const resolvedOutputPath = resolve(root, outputPath); if (resolvedOutputPath === root) { throw new Error('Output path MUST not be project root directory!'); } const directoriesToEmpty = emptyOnlyDirectories ? new Set(emptyOnlyDirectories.map((directory) => join(resolvedOutputPath, directory))) : undefined; // 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 = await readdir(resolvedOutputPath); } catch (error) { if (error instanceof Error && 'code' in error && error.code === 'ENOENT') { return; } throw error; } for (const entry of entries) { const fullEntry = join(resolvedOutputPath, entry); // Leave requested directories. This allows symlinks to continue to function. if (directoriesToEmpty?.has(fullEntry)) { await deleteOutputDir(resolvedOutputPath, fullEntry); continue; } await rm(fullEntry, { force: true, recursive: true, maxRetries: 3 }); } }