diff --git a/src/index.ts b/src/index.ts index d0e3228..6de892f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { execSync } from "node:child_process" import { readFileSync } from "node:fs" import { homedir } from "node:os" import { join } from "node:path" +import { LSOF_LISTEN_RE } from "./lsof.js" import { notify, setStatus, @@ -16,8 +17,6 @@ import { type SplitDirection, } from "./cmux.js" -export const LSOF_LISTEN_RE = /:(\d+)\s+\(LISTEN\)/ - const plugin: Plugin = async ({ client, $ }) => { const pendingPermissions = new Set() const pendingQuestions = new Set() diff --git a/src/lsof.ts b/src/lsof.ts new file mode 100644 index 0000000..2145516 --- /dev/null +++ b/src/lsof.ts @@ -0,0 +1 @@ +export const LSOF_LISTEN_RE = /:(\d+)\s+\(LISTEN\)/ \ No newline at end of file diff --git a/test/lsof-parse.test.ts b/test/lsof-parse.test.ts index e0979b9..e026671 100644 --- a/test/lsof-parse.test.ts +++ b/test/lsof-parse.test.ts @@ -1,5 +1,5 @@ import { test, expect } from "bun:test" -import { LSOF_LISTEN_RE } from "../src/index" +import { LSOF_LISTEN_RE } from "../src/lsof" test("LSOF_LISTEN_RE captures the port from a real lsof line", () => { const line = diff --git a/test/plugin-export.test.ts b/test/plugin-export.test.ts new file mode 100644 index 0000000..7e8f5b4 --- /dev/null +++ b/test/plugin-export.test.ts @@ -0,0 +1,27 @@ +import { test, expect } from "bun:test" +import { existsSync } from "node:fs" +import { execFileSync } from "node:child_process" +import plugin from "../src/index" +import * as pluginModule from "../src/index" + +async function loadBuiltPluginModule() { + const builtPluginPath = new URL("../dist/index.js", import.meta.url) + + if (!existsSync(builtPluginPath)) { + execFileSync("bun", ["run", "build"], { stdio: "inherit" }) + } + + return import("../dist/index.js") +} + +test("public plugin module only exposes a default function export", () => { + expect(typeof plugin).toBe("function") + expect(Object.keys(pluginModule)).toEqual(["default"]) +}) + +test("built plugin module only exposes a default function export", async () => { + const builtPluginModule = await loadBuiltPluginModule() + + expect(typeof builtPluginModule.default).toBe("function") + expect(Object.keys(builtPluginModule)).toEqual(["default"]) +}) \ No newline at end of file