mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
Bun/JSC 全量解析单文件大 JS 的 bytecode 和 JIT,17MB 产物导致 RSS 暴涨至 ~1GB(Node/V8 懒解析仅需 ~220MB)。启用代码分割后 Bun 按需加载 chunk,--version RSS 35MB,完整加载 ~500MB。 改动: - vite.config.ts: 移除 codeSplitting:false,添加 chunkFileNames - post-build.ts: 遍历 dist/ + dist/chunks/ 所有文件做 Bun patch - 新建 distRoot.ts 共享工具函数,统一路径定位逻辑 - ripgrep.ts/computerUse/setup.ts/claudeInChrome/setup.ts/updateCCB.ts: 用 distRoot 替换内联 import.meta.url 路径推算
30 lines
835 B
TypeScript
30 lines
835 B
TypeScript
import { fileURLToPath } from 'url'
|
|
import * as path from 'path'
|
|
|
|
/**
|
|
* Resolve the dist root directory from the current module's location.
|
|
*
|
|
* Works across all build layouts:
|
|
* - Single-file: dist/cli.js → dist/
|
|
* - Code-split: dist/chunks/chunk-xxx.js → dist/
|
|
* - Dev mode: src/utils/distRoot.ts → <project_root>/
|
|
*/
|
|
const __filename = fileURLToPath(import.meta.url)
|
|
const __dirname = path.dirname(__filename)
|
|
|
|
const distRoot = (() => {
|
|
const parts = __dirname.split(path.sep)
|
|
const distIdx = parts.lastIndexOf('dist')
|
|
if (distIdx !== -1) {
|
|
return parts.slice(0, distIdx + 1).join(path.sep)
|
|
}
|
|
// Dev mode: from src/utils/ → project root
|
|
const srcIdx = parts.lastIndexOf('src')
|
|
if (srcIdx !== -1) {
|
|
return parts.slice(0, srcIdx).join(path.sep)
|
|
}
|
|
return __dirname
|
|
})()
|
|
|
|
export { distRoot }
|