diff --git a/packages/package.json b/packages/package.json index 6f4607ec..06aa28f2 100644 --- a/packages/package.json +++ b/packages/package.json @@ -19,7 +19,7 @@ "keywords": [], "author": "Ink & Switch", "dependencies": { - "@inkandswitch/patchwork-filesystem": "^0.1.3", + "@inkandswitch/patchwork-filesystem": "^0.2.7", "@inkandswitch/patchwork-plugins": "^0.0.5", "solid-js": "^1.9.3" }, diff --git a/packages/pnpm-lock.yaml b/packages/pnpm-lock.yaml index 3ffec2fc..72222f69 100644 --- a/packages/pnpm-lock.yaml +++ b/packages/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@inkandswitch/patchwork-filesystem': - specifier: ^0.1.3 - version: 0.1.3(@automerge/automerge-repo@2.5.0)(@automerge/automerge@3.2.1) + specifier: ^0.2.7 + version: 0.2.7(@automerge/automerge-repo@2.5.0)(@automerge/automerge@3.2.1) '@inkandswitch/patchwork-plugins': specifier: ^0.0.5 version: 0.0.5 @@ -351,8 +351,8 @@ packages: '@inkandswitch/patchwork-filesystem@0.0.3': resolution: {integrity: sha512-x6yqX1Xyr05ug4YfRyfKJ7jSm/zjhMxU7g/e70nz4QbxfLmcG98LHB9qAkFI2zd+VvKLnTvSpPGu2UvJzXGciw==} - '@inkandswitch/patchwork-filesystem@0.1.3': - resolution: {integrity: sha512-hanR/YQUAE8aRg9GoYdG8H9muvuYiGYYXzb4ssa9WXDkirqWwShdzM2xVs7t0txja2b1yPbmMUf9uHzSLyyPYQ==} + '@inkandswitch/patchwork-filesystem@0.2.7': + resolution: {integrity: sha512-8tyhW6Y2c5pJurfUfBioPTLwxC8j1Ye4cVQeQyhzeh8iqriklBCQRd5kacWU8tzDw5ZXcd0e/mbRjI4WxkGB2g==} peerDependencies: '@automerge/automerge': '*' '@automerge/automerge-repo': '*' @@ -1352,12 +1352,10 @@ snapshots: transitivePeerDependencies: - supports-color - '@inkandswitch/patchwork-filesystem@0.1.3(@automerge/automerge-repo@2.5.0)(@automerge/automerge@3.2.1)': + '@inkandswitch/patchwork-filesystem@0.2.7(@automerge/automerge-repo@2.5.0)(@automerge/automerge@3.2.1)': dependencies: '@automerge/automerge': 3.2.1 '@automerge/automerge-repo': 2.5.0 - '@types/debug': 4.1.13 - '@types/node': 20.19.43 debug: 4.4.3 resolve.exports: 2.0.3 transitivePeerDependencies: diff --git a/packages/src/discover-plugins.test.ts b/packages/src/discover-plugins.test.ts new file mode 100644 index 00000000..05b867e1 --- /dev/null +++ b/packages/src/discover-plugins.test.ts @@ -0,0 +1,30 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const { importPackageFromHttpUrl } = vi.hoisted(() => ({ + importPackageFromHttpUrl: vi.fn(), +})); + +vi.mock("@inkandswitch/patchwork-filesystem", () => ({ + importPackageFromHttpUrl, +})); + +import { discoverHttpPlugins } from "./discover-plugins.ts"; + +describe("discoverHttpPlugins", () => { + beforeEach(() => { + importPackageFromHttpUrl.mockReset(); + }); + + it("imports HTTP packages through the host package importer", async () => { + importPackageFromHttpUrl.mockResolvedValue({ + plugins: [{ id: "example", load: () => {} }], + }); + + await expect( + discoverHttpPlugins("https://example.com/package/") + ).resolves.toEqual([{ id: "example" }]); + expect(importPackageFromHttpUrl).toHaveBeenCalledWith( + "https://example.com/package/" + ); + }); +}); diff --git a/packages/src/discover-plugins.ts b/packages/src/discover-plugins.ts index eb694dfc..5d6e8b8d 100644 --- a/packages/src/discover-plugins.ts +++ b/packages/src/discover-plugins.ts @@ -127,7 +127,7 @@ function withTimeout(p: Promise, ms: number, what: string): Promise { * Discover the plugins an http(s) package exports by importing its entry module * and reading its `plugins` export — the http counterpart to the worker-based * automerge discovery, and the same thing the host does for suggested/http - * modules (`importModuleFromHttpUrl` → `mod.plugins`). + * modules (`importPackageFromHttpUrl` → `mod.plugins`). * * It runs on the MAIN thread deliberately: there is no host worker that imports * http URLs, and a plain Worker has no importmap to resolve the module's bare @@ -138,15 +138,11 @@ export async function discoverHttpPlugins( url: string, timeoutMs = 15000 ): Promise { - // Reached via the host importmap at runtime; guard so an older filesystem - // bundle degrades to "couldn't preview" instead of a hard module-load error. - const importHttp = filesystem.importModuleFromHttpUrl; - if (typeof importHttp !== "function") { - throw new Error( - "This host build can't import http(s) packages — update @inkandswitch/patchwork-filesystem to 0.1.3+." - ); - } - const mod = await withTimeout(importHttp(url), timeoutMs, "importing the package"); + const mod = await withTimeout( + filesystem.importPackageFromHttpUrl(url), + timeoutMs, + "importing the package" + ); const plugins: any[] = Array.isArray((mod as any)?.plugins) ? (mod as any).plugins : [];