Files
bare-operating-system/packages/bare-os-booter/lib/bare-holesail-loader.js
T

30 lines
976 B
JavaScript

/**
* Resolve the upstream `holesail` class for bare-holesail / managed tunnels.
*
* This follows the same pattern as `bare-openssh` / `bare-ssh2`: keep `holesail`
* as a booter-owned dependency and import it directly so Pear stages the package.
* Upstream is AGPL-3.0.
*/
import Holesail from 'holesail'
/** ESM import so Pear stages `holesail` and its traced package deps. */
let holesailCache = null
/**
* @param {Record<string, unknown>} ctx
* @returns {Promise<new (opts?: object) => { ready: () => Promise<void>, close: () => Promise<void>, pause?: () => Promise<void>, resume?: () => Promise<void>, info?: unknown }>}
*/
export async function loadHolesailConstructor(ctx) {
void ctx
if (!holesailCache) {
const Ho = Holesail && Holesail.default ? Holesail.default : Holesail
if (typeof Ho !== 'function') {
throw new Error('holesail: expected default export to be a constructor')
}
holesailCache = Ho
}
return holesailCache
}