fix(build): further isolate dynamic path resolution from Turbopack
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
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.
This commit is contained in:
+11
-3
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user