GoogleChromeLabs / comlink

Comlink makes WebWorkers enjoyable.
Apache License 2.0
11.41k stars 390 forks source link

Find a way to support Deno and TS with the same code base #553

Open surma opened 3 years ago

surma commented 3 years ago

Currently, you can use Comlink in Deno through one of the npm CDNs (unpkg, skypack etc). But it’d be nice to be able to import the source from GitHub directly. This currently doesn’t work as TypeScript enforces either no file extensions in imports or .js extension, while Deno requires the actual file path (ending in .ts).

zxch3n commented 3 years ago

What about using denoify to build deno-compatible code? Then we can commit the built files by GitHub Actions

mathe42 commented 2 years ago

workaround:

Add

{
  "imports": {
     "https://unpkg.com/comlink@4.3.1/dist/esm/protocol": "https://unpkg.com/comlink@4.3.1/dist/esm/protocol.d.ts"
   }
}

to your importmap and import comlink like this:

// @deno-types="https://unpkg.com/comlink@4.3.1/dist/esm/comlink.d.ts"
import {/*...*/} "https://unpkg.com/comlink@4.3.1/dist/esm/comlink.mjs";

This import can be simplified with a extra file

// @deno-types="https://unpkg.com/comlink@4.3.1/dist/esm/comlink.d.ts"
export * from "https://unpkg.com/comlink@4.3.1/dist/esm/comlink.mjs";

in ./deps/comlink.ts

and also add

{
  "comlink": "./deps/comlink.ts"
}

to the importmap.