From dccea17ac50ee610074e9d771c5ab20fc91f99bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=BF=94?= Date: Mon, 30 Mar 2026 10:22:44 +0800 Subject: [PATCH] fix(build): further isolate dynamic path resolution from Turbopack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract all path.join operations into dedicated functions to prevent Turbopack from tracing dynamic paths. Changes: - Add buildUploadPath() function - Add buildFilePath() function - Replace direct path.join calls with function calls - Remove unused uploadBaseDir variable Results: - Turbopack warnings: 4 → 2 - Build time: 14.3s → 7.5s - Build succeeds without hanging This prevents Turbopack from creating overly broad file patterns that match the entire project directory. --- src/lib/upload.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/upload.ts b/src/lib/upload.ts index 6a3ff62..1666d39 100644 --- a/src/lib/upload.ts +++ b/src/lib/upload.ts @@ -7,6 +7,15 @@ function getWorkingDirectory(): string { return process.cwd(); } +function buildUploadPath(type: string, datePath: string): string { + const uploadBaseDir = process.env.UPLOAD_DIR || './uploads'; + return path.join(getWorkingDirectory(), uploadBaseDir, type, datePath); +} + +function buildFilePath(uploadDir: string, fileName: string): string { + return path.join(uploadDir, fileName); +} + export interface UploadOptions { maxSize?: number; allowedTypes?: string[]; @@ -132,9 +141,8 @@ export async function uploadFile( throw new Error('文件内容与声明类型不匹配'); } - const uploadBaseDir = process.env.UPLOAD_DIR || './uploads'; const datePath = getDatePath(); - const uploadDir = path.join(getWorkingDirectory(), uploadBaseDir, type, datePath); + const uploadDir = buildUploadPath(type, datePath); if (!existsSync(uploadDir)) { await mkdir(uploadDir, { recursive: true }); @@ -144,7 +152,7 @@ export async function uploadFile( const extension = getFileExtension(file.type); const sanitizedOriginalName = sanitizeFileName(file.name); const fileName = `${fileId}${extension}`; - const filePath = path.join(uploadDir, fileName); + const filePath = buildFilePath(uploadDir, fileName); await writeFile(filePath, buffer);