refactor: 用 Bun 原生 define 替换 cli.tsx 中的 globalThis 注入

- 删除 cli.tsx 顶部的 globalThis.MACRO / BUILD_* / feature polyfill
- 新增 scripts/defines.ts 作为 MACRO define 映射的单一来源
- 新增 scripts/dev.ts,通过 bun run -d 在转译时注入 MACRO 常量
- build.ts 引用 getMacroDefines() 实现构建时内联
- 清理 global.d.ts (移除 BUILD_*, MACRO 函数声明)
- 55 个 MACRO 消费文件零改动

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-02 09:51:48 +08:00
parent 21ac9e441f
commit 28e40ddc67
7 changed files with 46 additions and 28 deletions

View File

@@ -1,21 +1,5 @@
#!/usr/bin/env bun
// Runtime polyfill for bun:bundle (build-time macros)
const feature = (_name: string) => false;
if (typeof globalThis.MACRO === "undefined") {
(globalThis as any).MACRO = {
VERSION: "2.1.888",
BUILD_TIME: new Date().toISOString(),
FEEDBACK_CHANNEL: "",
ISSUES_EXPLAINER: "",
NATIVE_PACKAGE_URL: "",
PACKAGE_URL: "",
VERSION_CHANGELOG: "",
};
}
// Build-time constants — normally replaced by Bun bundler at compile time
(globalThis as any).BUILD_TARGET = "external";
(globalThis as any).BUILD_ENV = "production";
(globalThis as any).INTERFACE_TYPE = "stdio";
import { feature } from 'bun:bundle'
// Bugfix for corepack auto-pinning, which adds yarnpkg to peoples' package.jsons
// eslint-disable-next-line custom-rules/no-top-level-side-effects