fix: node-pty

This commit is contained in:
bietiaop
2025-02-02 14:33:39 +08:00
parent b4e07aacfe
commit 8dc6da56a7
5 changed files with 28 additions and 6 deletions

View File

@@ -0,0 +1,21 @@
import path from 'path';
Object.defineProperty(global, '__dirname', {
get() {
const err = new Error();
const stack = err.stack?.split('\n') || [];
let callerFile = '';
// 遍历错误堆栈,跳过当前文件所在行
// 注意:堆栈格式可能不同,请根据实际环境调整索引及正则表达式
for (const line of stack) {
const match = line.match(/\((.*):\d+:\d+\)/);
if (match) {
callerFile = match[1];
if (!callerFile.includes('init-dynamic-dirname.ts')) {
break;
}
}
}
return callerFile ? path.dirname(callerFile) : '';
},
});

View File

@@ -1,9 +1,10 @@
import './init-dynamic-dirname';
import { WebUiConfig } from '@/webui';
import { AuthHelper } from '../helper/SignToken';
import { LogWrapper } from '@/common/log';
import { WebSocket, WebSocketServer } from 'ws';
import os from 'os';
import { IPty, spawn as ptySpawn } from '@homebridge/node-pty-prebuilt-multiarch';
import { type IPty, spawn as ptySpawn } from '@homebridge/node-pty-prebuilt-multiarch';
import { randomUUID } from 'crypto';
interface TerminalInstance {