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 +1 -1
- package/src/manager/CliMenuManager.tsx +26 -14
package/package.json
CHANGED
|
@@ -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
|
-
//
|
|
293
|
-
|
|
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.
|
|
296
|
-
path.
|
|
297
|
-
path.
|
|
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
|
-
|
|
303
|
-
|
|
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
|
-
//
|
|
311
|
-
|
|
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
|
|