bingocode 1.1.56 → 1.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bingocode",
3
- "version": "1.1.56",
3
+ "version": "1.1.58",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "claude": "bin/claude-win.cjs",
@@ -17,6 +17,8 @@ import { TopToolbar } from '../manager/TopToolbar.tsx';
17
17
 
18
18
  // 主题切换(Hook)
19
19
  import { useTheme } from '../components/design-system/ThemeProvider.js';
20
+ import { createRequire } from 'module';
21
+ const require = createRequire(import.meta.url);
20
22
  // Markdown 渲染(纯函数,不依赖 AppStateProvider context)
21
23
  import { applyMarkdown } from '../utils/markdown.js';
22
24
  import { Ansi } from '../ink/Ansi.js';
@@ -289,30 +291,40 @@ export const CliMenuManager: React.FC = () => {
289
291
  // 动态定位 server 入口,兼容开发环境 (.ts) 和打包环境 (.js)
290
292
  let entry = "";
291
293
  try {
292
- // 尝试从当前文件位置向上寻找 server 目录
293
- const currentDir = path.dirname(new URL(import.meta.url).pathname);
294
+ // 利用 Node.js 的模块解析机制寻找 bingocode 包的根目录
295
+ // 这种方法在 npm install -g 这种复杂路径下最可靠
296
+ const bingoPkgPath = require.resolve('bingocode/package.json');
297
+ const root = path.dirname(bingoPkgPath);
298
+
294
299
  const possiblePaths = [
295
- path.resolve(currentDir, '../server/index.ts'), // 开发源码路径
296
- path.resolve(currentDir, '../server/index.js'), // 编译后路径
297
- path.resolve(currentDir, '../../src/server/index.ts'), // 嵌套结构
298
- path.join(process.cwd(), 'node_modules/bingocode/src/server/index.ts') // npm 安装路径备选
300
+ path.join(root, 'src/server/index.ts'),
301
+ path.join(root, 'src/server/index.js'),
302
+ path.join(root, 'dist/server.js')
299
303
  ];
300
304
 
301
305
  for (const p of possiblePaths) {
302
- // Windows 路径兼容处理:如果是以 /C:/ 开头的路径需要处理
303
- const formattedPath = process.platform === 'win32' && p.startsWith('/') ? p.substring(1) : p;
304
- if (fs.existsSync(formattedPath)) {
305
- entry = formattedPath;
306
+ if (fs.existsSync(p)) {
307
+ entry = p;
306
308
  break;
307
309
  }
308
310
  }
309
311
  } catch (e) {
310
- // fallback to old logic if path detection fails
311
- entry = path.resolve(process.cwd(), 'src/server/index.ts');
312
+ // Fallback: 如果 require.resolve 失败(比如还没发布为包),使用现有的路径逻辑
313
+ const __filename = fileURLToPath(import.meta.url);
314
+ const __dirname = path.dirname(__filename);
315
+ const pkgRoot = path.resolve(__dirname, '../../');
316
+
317
+ const fbPaths = [
318
+ path.join(__dirname, '../server/index.ts'),
319
+ path.join(pkgRoot, 'src/server/index.ts'),
320
+ ];
321
+ for (const p of fbPaths) {
322
+ if (fs.existsSync(p)) { entry = p; break; }
323
+ }
312
324
  }
313
325
 
314
- if (!entry) {
315
- setBootErr('无法定位服务器入口文件');
326
+ if (!entry || !fs.existsSync(entry)) {
327
+ setBootErr(`无法定位服务器入口文件。\n最后尝试路径: ${entry || '未探测到'}`);
316
328
  return;
317
329
  }
318
330