https://github.com/cdaringe/deno-emit-esm-server
Emits ESM from TypeScript URLs via Deno.emit(...)
https://github.com/cdaringe/deno-emit-esm-server
Last synced: about 1 year ago
JSON representation
Emits ESM from TypeScript URLs via Deno.emit(...)
- Host: GitHub
- URL: https://github.com/cdaringe/deno-emit-esm-server
- Owner: cdaringe
- Created: 2022-03-21T01:30:25.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-24T23:16:59.000Z (over 2 years ago)
- Last Synced: 2025-04-22T16:02:47.243Z (about 1 year ago)
- Language: TypeScript
- Size: 31.3 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: readme.md
- Contributing: .github/contributing.md
Awesome Lists containing this project
README
# emit_esm_server
Serve ECMAScript modules given a `deno` GitHub module URL.
Allows an ESM runtime (e.g. a browser!) to import `deno` modules, where deno
modules are otherwise not ready to load in the browser immediately.
[](https://github.com/cdaringe/deno-emit-esm-server/actions/workflows/main.yml)
**input**:
One of:
- denoland URL: `HTTP GET /denoland/x/:pkg[@:version]/path/to/mod.ts`
- github deno URL:
`HTTP GET /github/:owner/:repo/:branch/path/to/mod.ts`
When a module includes a URL to an external module (https://foo.org/bar/mod.ts),
it is rewritten to `?moduleUrl=`
**output**: ESM source code
## Demo
[Import typescript modules directly into the browser](https://observablehq.com/@cdaringe/import-deno-modules-into-the-browser-with-esm_emit_server)
## configuration
- `EMIT_SERVER_ORIGIN` - the origin of where your server is hosted. used to
rewrite HTTP imports back to your server
## warning
Non-production ready :)
## Example
- (optional) build the server:
`docker build --platform linux/arm64/v8 --progress=plain -t cdaringe/deno_emit_server .`
- run the server:
`docker run --platform linux/arm64/v8 --rm -p 7777:7777 cdaringe/deno_emit_server`
- request a TypeScript module as an ECMAScript Module:
`curl localhost:7777/github/denoland/deno_std/main/log/logger.ts`
```js
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { getLevelByName, getLevelName, LogLevels } from "./levels.ts";
export class LogRecord {
msg;
#args;
#datetime;
level;
levelName;
loggerName;
// ...snip snip...
```