comlink icon indicating copy to clipboard operation
comlink copied to clipboard

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

Open surma opened this issue 4 years ago • 2 comments

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).

surma avatar Jul 13 '21 10:07 surma

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

zxch3n avatar Sep 02 '21 06:09 zxch3n

workaround:

Add

{
  "imports": {
     "https://unpkg.com/[email protected]/dist/esm/protocol": "https://unpkg.com/[email protected]/dist/esm/protocol.d.ts"
   }
}

to your importmap and import comlink like this:

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

This import can be simplified with a extra file

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

in ./deps/comlink.ts

and also add

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

to the importmap.

mathe42 avatar Jan 27 '22 10:01 mathe42