fix(前端): 启动前清理 Next 缓存
关键改动: - 前端 dev 启动前删除可能残留的 .next 缓存 - 新增安全路径校验,避免清理脚本误删 Web 应用外目录 Co-Authored-By: Codex GPT-5 <codex@openai.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "node --max-old-space-size=4096 node_modules/next/dist/bin/next dev --port 3000",
|
||||
"dev": "node scripts/clean-next-dev-cache.mjs && node --max-old-space-size=4096 node_modules/next/dist/bin/next dev --port 3000",
|
||||
"build": "node --max-old-space-size=4096 node_modules/next/dist/bin/next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
|
||||
16
apps/web/scripts/clean-next-dev-cache.mjs
Normal file
16
apps/web/scripts/clean-next-dev-cache.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const webRoot = path.resolve(scriptDir, '..');
|
||||
const nextDir = path.resolve(webRoot, '.next');
|
||||
|
||||
if (!nextDir.startsWith(`${webRoot}${path.sep}`)) {
|
||||
throw new Error(`Refusing to remove path outside web app: ${nextDir}`);
|
||||
}
|
||||
|
||||
if (fs.existsSync(nextDir)) {
|
||||
fs.rmSync(nextDir, { recursive: true, force: true });
|
||||
console.log('[web dev] removed stale .next cache');
|
||||
}
|
||||
Reference in New Issue
Block a user