From 96de9e2c168355a8526d2833a4fb79bb820deae6 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: Mon, 3 Feb 2025 10:40:33 +0800 Subject: [PATCH] =?UTF-8?q?style:=20=E7=AE=80=E5=8C=96loader=20=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E5=85=A8=E5=B1=80error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pty/prebuild-loader.ts | 19 ++++++------------- src/pty/unixTerminal.ts | 17 +++++++++-------- src/pty/windowsPtyAgent.ts | 24 ++---------------------- 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/src/pty/prebuild-loader.ts b/src/pty/prebuild-loader.ts index 9564a88d..61794eb7 100644 --- a/src/pty/prebuild-loader.ts +++ b/src/pty/prebuild-loader.ts @@ -1,17 +1,10 @@ import { require_dlopen } from '.'; - -let pty: any; - -try { - pty = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node'); -} catch (outerError) { +export function pty_loader() { + let pty: any; try { pty = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node'); - } catch (innerError) { - console.error('innerError', innerError); - // Re-throw the exception from the Release require if the Debug require fails as well - throw outerError; + } catch (outerError) { + pty = undefined; } -} - -export default pty; + return pty; +}; diff --git a/src/pty/unixTerminal.ts b/src/pty/unixTerminal.ts index b119b47f..85a8d469 100644 --- a/src/pty/unixTerminal.ts +++ b/src/pty/unixTerminal.ts @@ -11,8 +11,9 @@ import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from '@homebridge/node-pty-prebu import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from '@homebridge/node-pty-prebuilt-multiarch/src/interfaces'; 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'; +export const pty = pty_loader(); -import pty from './prebuild-loader'; let helperPath: string; helperPath = '../build/Release/spawn-helper'; @@ -172,8 +173,8 @@ export class UnixTerminal extends Terminal { get ptsName(): string { return this._pty; } /** - * openpty - */ + * openpty + */ public static open(opt: IPtyOpenOptions): UnixTerminal { const self: UnixTerminal = Object.create(UnixTerminal.prototype); @@ -249,20 +250,20 @@ export class UnixTerminal extends Terminal { } /** - * Gets the name of the process. - */ + * Gets the name of the process. + */ public get process(): string { if (process.platform === 'darwin') { const title = pty.process(this._fd); - return (title !== 'kernel_task' ) ? title : this._file; + return (title !== 'kernel_task') ? title : this._file; } return pty.process(this._fd, this._pty) || this._file; } /** - * TTY - */ + * TTY + */ public resize(cols: number, rows: number): void { if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) { diff --git a/src/pty/windowsPtyAgent.ts b/src/pty/windowsPtyAgent.ts index 74b1bfca..fca9a273 100644 --- a/src/pty/windowsPtyAgent.ts +++ b/src/pty/windowsPtyAgent.ts @@ -63,31 +63,11 @@ export class WindowsPtyAgent { } if (this._useConpty) { if (!conptyNative) { - try { - conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node'); - } catch (outerError) { - try { - conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node'); - } catch (innerError) { - console.error('innerError', innerError); - // Re-throw the exception from the Release require if the Debug require fails as well - throw outerError; - } - } + conptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/conpty.node'); } } else { if (!winptyNative) { - try { - winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node'); - } catch (outerError) { - try { - winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node'); - } catch (innerError) { - console.error('innerError', innerError); - // Re-throw the exception from the Release require if the Debug require fails as well - throw outerError; - } - } + winptyNative = require_dlopen('./pty/' + process.platform + '.' + process.arch + '/pty.node'); } } this._ptyNative = this._useConpty ? conptyNative : winptyNative;