From 527e576145459f51760a8ec231404b409cf1cabb Mon Sep 17 00:00:00 2001 From: aramissennyeydd Date: Thu, 8 May 2025 22:25:36 -0400 Subject: [PATCH] remove directory if it exists when writing Signed-off-by: aramissennyeydd --- packages/repo-tools/src/commands/package-docs/Cache.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/repo-tools/src/commands/package-docs/Cache.ts b/packages/repo-tools/src/commands/package-docs/Cache.ts index b8e22f65d6..487db81347 100644 --- a/packages/repo-tools/src/commands/package-docs/Cache.ts +++ b/packages/repo-tools/src/commands/package-docs/Cache.ts @@ -18,7 +18,7 @@ import globby from 'globby'; import { dirname, join as joinPath, relative } from 'path'; import crypto from 'crypto'; import { Lockfile } from '@backstage/cli-node'; -import { mkdirp } from 'fs-extra'; +import { exists, rm, mkdirp } from 'fs-extra'; import { z } from 'zod'; import { CACHE_DIR, CACHE_FILE } from './constants'; @@ -140,7 +140,11 @@ export class PackageDocsCache { async write(pkg: string, contentDirectory: string) { const cacheDir = joinPath(this.baseDirectory, CACHE_DIR, pkg); const contentsDir = joinPath(cacheDir, 'contents'); - await mkdirp(contentsDir); + if (await exists(contentsDir)) { + await rm(contentsDir, { recursive: true }); + } else { + await mkdirp(contentsDir); + } const hashString = await this.toKey(pkg); await cp(contentDirectory, contentsDir, { recursive: true }); const cacheEntry: CacheEntry = {