( c: Container, plugin: Plugin, )
| 9 | import ResizingIframe from './components/resizingIframe' |
| 10 | |
| 11 | async function registerPluginService( |
| 12 | c: Container, |
| 13 | plugin: Plugin, |
| 14 | ): Promise<Container> { |
| 15 | const script = await blobToBase64(plugin.script) |
| 16 | // A limitation of this import is that it won't resolve other files in the npmPackage.tgz |
| 17 | // Does addressing this even make sense? How could one resolve relative file imports anyway? |
| 18 | // Also, the Plugin table currently only stores a single `script` per Plugin. If we add support for more than 1 file, |
| 19 | // we should consider storing the npmPackage.tgz in sqlite. However, generating npmPackage.tgz for tests (cardHtml.plugin.test.ts) |
| 20 | // is *extremely* annoying, because we use DecompressionStream which only works in browsers, |
| 21 | // and jsdom doesn't support streams https://github.com/jsdom/jsdom/pull/3200 |
| 22 | // Cloudflare's Wrangler discusses a similar issue https://developers.cloudflare.com/workers/wrangler/bundling/ |
| 23 | // grep 2D96EE4E-61BA-4FCA-93C1-863C80E10A93 |
| 24 | // One solution could be to use the service worker to serve the package's files. |
| 25 | const exports = (await import(/* @vite-ignore */ script)) as { |
| 26 | default: PluginExports |
| 27 | } |
| 28 | return getC(c, exports.default) |
| 29 | } |
| 30 | |
| 31 | function getC(c: Container, exports: PluginExports): Container { |
| 32 | if (exports.services === undefined) return c |
no test coverage detected