From bc1148c00a8509998ea15f389d0aa251a475b033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 6 Feb 2025 15:25:47 +0800 Subject: [PATCH 1/2] fix: require_dlopen --- src/pty/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pty/index.ts b/src/pty/index.ts index d9cc2e1c..25c969ce 100644 --- a/src/pty/index.ts +++ b/src/pty/index.ts @@ -26,9 +26,4 @@ export function require_dlopen(modulename: string) { process.dlopen(module, path.join(import__dirname, modulename)); // eslint-disable-next-line @typescript-eslint/no-explicit-any return module.exports as any; -} -/** - * Expose the native API when not Windows, note that this is not public API and - * could be removed at any time. - */ -export const native = (process.platform !== 'win32' ? require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node') : null); +} \ No newline at end of file From 95c7d3dfbd490c7a4870dc4189d28edffc3d3b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Thu, 6 Feb 2025 15:28:24 +0800 Subject: [PATCH 2/2] fix: remove __dirname --- src/pty/unixTerminal.ts | 5 +++-- src/pty/windowsPtyAgent.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pty/unixTerminal.ts b/src/pty/unixTerminal.ts index a5ab873f..3e89dadc 100644 --- a/src/pty/unixTerminal.ts +++ b/src/pty/unixTerminal.ts @@ -13,12 +13,13 @@ import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from '@homebridge/node- import { ArgvOrCommandLine } from '@homebridge/node-pty-prebuilt-multiarch/src/types'; import { assign } from '@homebridge/node-pty-prebuilt-multiarch/src/utils'; import { pty_loader } from './prebuild-loader'; +import { fileURLToPath } from 'url'; export const pty = pty_loader(); let helperPath: string; helperPath = '../build/Release/spawn-helper'; - -helperPath = path.resolve(__dirname, helperPath); +const import__dirname = path.dirname(fileURLToPath(import.meta.url)); +helperPath = path.resolve(import__dirname, helperPath); helperPath = helperPath.replace('app.asar', 'app.asar.unpacked'); helperPath = helperPath.replace('node_modules.asar', 'node_modules.asar.unpacked'); diff --git a/src/pty/windowsPtyAgent.ts b/src/pty/windowsPtyAgent.ts index d6a2f71d..8b36780a 100644 --- a/src/pty/windowsPtyAgent.ts +++ b/src/pty/windowsPtyAgent.ts @@ -14,6 +14,8 @@ import { ArgvOrCommandLine } from '@homebridge/node-pty-prebuilt-multiarch/src/t import { fork } from 'child_process'; import { ConoutConnection } from './windowsConoutConnection'; import { require_dlopen } from '.'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; let conptyNative: IConptyNative; let winptyNative: IWinptyNative; @@ -149,7 +151,7 @@ export class WindowsPtyAgent { consoleProcessList.forEach((pid: number) => { try { process.kill(pid); - } catch{ + } catch { // Ignore if process cannot be found (kill ESRCH error) } }); @@ -176,8 +178,9 @@ export class WindowsPtyAgent { } private _getConsoleProcessList(): Promise { + const import__dirname = dirname(fileURLToPath(import.meta.url)); return new Promise(resolve => { - const agent = fork(path.join(__dirname, 'conpty_console_list_agent'), [this._innerPid.toString()]); + const agent = fork(path.join(import__dirname, 'conpty_console_list_agent'), [this._innerPid.toString()]); agent.on('message', message => { clearTimeout(timeout); // @ts-expect-error no need to check if it is null