同步操作将从 ZeroFreeze/claude-code-source-code 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env node/*** prepare-src.mjs — Pre-build source transformation** This script patches the source tree to make it compilable without Bun:* 1. Replace `import { feature } from 'bun:bundle'` with our stub* 2. Replace `MACRO.X` references with runtime values* 3. Create missing type declarations*/import fs from 'node:fs'import path from 'node:path'import { fileURLToPath } from 'node:url'const __dirname = path.dirname(fileURLToPath(import.meta.url))const ROOT = path.resolve(__dirname, '..')const SRC = path.join(ROOT, 'src')const VERSION = '2.1.88'// ── Helpers ──────────────────────────────────────────────────────────────────function walk(dir, ext = '.ts') {const results = []for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {const full = path.join(dir, entry.name)if (entry.isDirectory() && entry.name !== 'node_modules') {results.push(...walk(full, ext))} else if (entry.name.endsWith(ext) || entry.name.endsWith('.tsx')) {results.push(full)}}return results}function patchFile(filePath) {let src = fs.readFileSync(filePath, 'utf8')let changed = false// 1. Replace `import { feature } from 'bun:bundle'` / `"bun:bundle"`if (src.includes("from 'bun:bundle'") || src.includes('from "bun:bundle"')) {src = src.replace(/import\s*\{\s*feature\s*\}\s*from\s*['"]bun:bundle['"]/g,"import { feature } from '../stubs/bun-bundle.js'")// Fix relative depth based on file locationconst rel = path.relative(SRC, path.dirname(filePath))const depth = rel ? '../'.repeat(rel.split('/').length) : ''if (depth) {src = src.replace("from '../stubs/bun-bundle.js'", `from '${depth}stubs/bun-bundle.js'`)}changed = true}// 2. Replace MACRO.X with string literalsconst macroReplacements = {'MACRO.VERSION': `'${VERSION}'`,'MACRO.BUILD_TIME': `'${new Date().toISOString()}'`,'MACRO.FEEDBACK_CHANNEL': `'https://github.com/anthropics/claude-code/issues'`,'MACRO.ISSUES_EXPLAINER': `'https://github.com/anthropics/claude-code/issues/new/choose'`,'MACRO.NATIVE_PACKAGE_URL': `'@anthropic-ai/claude-code'`,'MACRO.PACKAGE_URL': `'@anthropic-ai/claude-code'`,'MACRO.VERSION_CHANGELOG': `''`,}for (const [macro, replacement] of Object.entries(macroReplacements)) {if (src.includes(macro)) {// Don't replace inside stringssrc = src.replace(new RegExp(`(?<![\\w'"])${macro.replace('.', '\\.')}(?![\\w'" ])`, 'g'), replacement)changed = true}}if (changed) {fs.writeFileSync(filePath, src, 'utf8')return true}return false}// ── Main ─────────────────────────────────────────────────────────────────────console.log('🔧 Preparing source files...\n')const files = walk(SRC)let patched = 0for (const file of files) {if (patchFile(file)) {patched++console.log(` patched: ${path.relative(ROOT, file)}`)}}// Create stub for bun:ffi (only used in upstreamproxy)const ffiStub = path.join(ROOT, 'stubs', 'bun-ffi.ts')if (!fs.existsSync(ffiStub)) {fs.writeFileSync(ffiStub, `// Stub for bun:ffi — not available outside Bun runtime\nexport const ffi = {} as any\nexport function dlopen() { return {} }\n`)console.log(' created: stubs/bun-ffi.ts')}// Create global MACRO type declarationconst macroDecl = path.join(ROOT, 'stubs', 'global.d.ts')fs.writeFileSync(macroDecl, `// Global compile-time macros (normally injected by Bun bundler)declare const MACRO: {VERSION: stringBUILD_TIME: stringFEEDBACK_CHANNEL: stringISSUES_EXPLAINER: stringNATIVE_PACKAGE_URL: stringPACKAGE_URL: stringVERSION_CHANGELOG: string}`)console.log(' created: stubs/global.d.ts')console.log(`\n✅ Patched ${patched} / ${files.length} source files`)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。