// Resolve the `Lacuna` class from `@tlecommunity/client` in a plain Node process // (CLI + tests). // // `@tlecommunity/client@1.4.0` ships a broken `exports` map (it points at // `./dist/client.mjs` / `./dist/client.umd.js`, neither of which it ships), so a // bare `import '@tlecommunity/client'` throws under Node. Walk the `node_modules` // search path (which never consults `exports`) and load the shipped ESM bundle by // its real location instead, so this works from a dev checkout, a hoisted global // install and a nested install alike. // // `require()` is used rather than `await import()` so this module stays // synchronous - a top-level `await` here would make every `@tlecommunity/super-core` // importer an async module, which breaks mocha's CommonJS `require()` of the // tests. Node >= 22 loads ESM through `require()`. // // The browser build never runs this file: `package.json`'s `browser` field maps // it to `./load-lacuna.browser.js`, where Vite resolves the bare specifier via // the package `module` field. import { createRequire } from 'module' import { existsSync } from 'fs' import path from 'path' const require = createRequire(import.meta.url) function loadLacuna() { const searchPaths = require.resolve.paths('@tlecommunity/client') || [] for (const base of searchPaths) { const bundle = path.join(base, '@tlecommunity', 'client', 'dist', 'client.js') if (existsSync(bundle)) { return require(bundle).Lacuna } } return require('@tlecommunity/client').Lacuna } export const Lacuna = loadLacuna()