From 681955526670281847267eeae350d7e298a5fa15 Mon Sep 17 00:00:00 2001 From: Austin Riedhammer <149657881+austin-autify@users.noreply.github.com> Date: Thu, 23 Jan 2025 16:49:47 +0900 Subject: [PATCH] dynamic import ESM module get-port --- src/autify/connect/client-manager/ClientManager.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/autify/connect/client-manager/ClientManager.ts b/src/autify/connect/client-manager/ClientManager.ts index ef3197c4..a62c7a67 100644 --- a/src/autify/connect/client-manager/ClientManager.ts +++ b/src/autify/connect/client-manager/ClientManager.ts @@ -28,9 +28,19 @@ import { } from "./Logger"; import { join } from "node:path"; import TypedEmitter from "typed-emitter"; -import getPort from "get-port"; import { getWebClient } from "../../web/getWebClient"; import { parse } from "shell-quote"; +import type GetPort from "get-port"; + +// Workaround to import get-port, which is an ES module, dynamically and avoid +// having typescript transpile that import into a require. +async function importGetPort(): Promise { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + return new Promise((resolve) => { + // eslint-disable-next-line no-eval + eval(`import("get-port").then((esm) => resolve(esm.default));`); + }); +} export type ClientEvents = TypedEmitter<{ log: (msg: string) => void; @@ -108,6 +118,7 @@ export class ClientManager { try { this.logger.debug("start"); const version = await this.getClientVersion(); + const getPort = await importGetPort(); const debugServerPort = this.options.debugServerPort ?? (await getPort()); this.logger.info( `Starting Autify Connect Client (accessPoint: ${this.accessPointName}, debugServerPort: ${debugServerPort}, path: ${this.clientPath}, version: ${version})`