From 1777dd16067baa83d4bd58382b6d7b50731583fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Mon, 30 Mar 2026 10:11:01 +0800 Subject: [PATCH] fix(build): resolve Turbopack performance issue with process.cwd() The Turbopack build was matching 29409+ files due to dynamic path resolution in upload.ts. This caused the CI build to hang. Root cause: Turbopack traces process.cwd() and creates overly broad file patterns, leading to performance issues. Solution: Extract process.cwd() into a separate function to prevent Turbopack from tracing the entire project directory. This fix reduces build time and prevents CI timeout issues. --- src/lib/upload.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/upload.ts b/src/lib/upload.ts index e589f6e..6a3ff62 100644 --- a/src/lib/upload.ts +++ b/src/lib/upload.ts @@ -3,6 +3,10 @@ import { existsSync } from 'fs'; import path from 'path'; import { nanoid } from 'nanoid'; +function getWorkingDirectory(): string { + return process.cwd(); +} + export interface UploadOptions { maxSize?: number; allowedTypes?: string[]; @@ -130,7 +134,7 @@ export async function uploadFile( const uploadBaseDir = process.env.UPLOAD_DIR || './uploads'; const datePath = getDatePath(); - const uploadDir = path.join(process.cwd(), uploadBaseDir, type, datePath); + const uploadDir = path.join(getWorkingDirectory(), uploadBaseDir, type, datePath); if (!existsSync(uploadDir)) { await mkdir(uploadDir, { recursive: true }); @@ -184,7 +188,7 @@ export async function getFileInfo(filePath: string) { createdAt: stats.birthtime, modifiedAt: stats.mtime, }; - } catch (error) { + } catch { return null; } }