From c8c3aeb761d194d669be888f3cee4aa5cfc0e267 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sun, 7 Jul 2024 14:54:55 -0700 Subject: [PATCH] clean up settransport --- package.json | 3 +-- pnpm-lock.yaml | 3 --- src/worker.ts | 15 +++++++++++---- tsconfig.json | 6 +----- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 77ecdde..7339255 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-replace": "^5.0.5", "rollup": "^4.9.6", - "rollup-plugin-typescript2": "^0.36.0", - "tslib": "^2.6.3" + "rollup-plugin-typescript2": "^0.36.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 739cef1..3e22ab8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,9 +20,6 @@ importers: rollup-plugin-typescript2: specifier: ^0.36.0 version: 0.36.0(rollup@4.18.0)(typescript@5.5.3) - tslib: - specifier: ^2.6.3 - version: 2.6.3 packages: diff --git a/src/worker.ts b/src/worker.ts index 32bd621..5cf37e6 100644 --- a/src/worker.ts +++ b/src/worker.ts @@ -8,10 +8,17 @@ function handleConnection(port: MessagePort) { const port = event.data.port; const message: WorkerMessage = event.data.message; if (message.type === "set") { - const func = new Function("return (async ()=>{" + message.client + "})()"); - currentTransport = await func(); - console.log("set transport to ", currentTransport); - port.postMessage({ type: "set" }); + try { + const AsyncFunction = (async function () {}).constructor; + // @ts-expect-error + const func = new AsyncFunction(message.client); + console.log(func); + currentTransport = await func(); + console.log("set transport to ", currentTransport); + port.postMessage({ type: "set" }); + } catch(err) { + port.postMessage({ type: "error", error: err }); + } } else if (message.type === "fetch") { try { if (!currentTransport) throw new Error("No BareTransport was set. Try creating a BareMuxConnection and calling set() on it."); diff --git a/tsconfig.json b/tsconfig.json index 567c79e..7bb5a47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,10 @@ { "compilerOptions": { + "target": "es2021", "lib": [ "es2021", "DOM" ], - "paths": { - "tslib": [ - "./node_modules/tslib/tslib.d.ts" - ] - }, "declaration": true } }