fix(build): resolve Turbopack performance issue with process.cwd()
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/push/woodpecker Pipeline failed
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.
This commit is contained in:
+6
-2
@@ -3,6 +3,10 @@ import { existsSync } from 'fs';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
|
||||||
|
function getWorkingDirectory(): string {
|
||||||
|
return process.cwd();
|
||||||
|
}
|
||||||
|
|
||||||
export interface UploadOptions {
|
export interface UploadOptions {
|
||||||
maxSize?: number;
|
maxSize?: number;
|
||||||
allowedTypes?: string[];
|
allowedTypes?: string[];
|
||||||
@@ -130,7 +134,7 @@ export async function uploadFile(
|
|||||||
|
|
||||||
const uploadBaseDir = process.env.UPLOAD_DIR || './uploads';
|
const uploadBaseDir = process.env.UPLOAD_DIR || './uploads';
|
||||||
const datePath = getDatePath();
|
const datePath = getDatePath();
|
||||||
const uploadDir = path.join(process.cwd(), uploadBaseDir, type, datePath);
|
const uploadDir = path.join(getWorkingDirectory(), uploadBaseDir, type, datePath);
|
||||||
|
|
||||||
if (!existsSync(uploadDir)) {
|
if (!existsSync(uploadDir)) {
|
||||||
await mkdir(uploadDir, { recursive: true });
|
await mkdir(uploadDir, { recursive: true });
|
||||||
@@ -184,7 +188,7 @@ export async function getFileInfo(filePath: string) {
|
|||||||
createdAt: stats.birthtime,
|
createdAt: stats.birthtime,
|
||||||
modifiedAt: stats.mtime,
|
modifiedAt: stats.mtime,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user