-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: move to jsr * fix slow types * 1.4.5 * fix typo * 1.5.1 * 1.5.2 * fix ci * fix ci!!! * fix ci!!!!!!!!!!!!!!!!!!!!!!! * try ci * test ci
- Loading branch information
Showing
21 changed files
with
332 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Deno | ||
uses: denoland/setup-deno@v2 | ||
with: | ||
deno-version: v2.x | ||
|
||
- name: Publish package | ||
run: deno publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,10 @@ TypeScript + ES Modules | |
|
||
Transpile TypeScript on the fly and serve it from your server as ES Modules. | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { serveDirWithTs } from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { serveDirWithTs } from "@ayame113/ts-serve"; | ||
|
||
serve((request) => serveDirWithTs(request)); | ||
Deno.serve((request) => serveDirWithTs(request)); | ||
``` | ||
|
||
```tsx ignore | ||
|
@@ -37,9 +36,9 @@ console.log(1); | |
|
||
As oak middleware: | ||
|
||
```ts | ||
import { Application } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { tsMiddleware } from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { Application } from "@oak/oak"; | ||
import { tsMiddleware } from "@ayame113/ts-serve"; | ||
|
||
const app = new Application(); | ||
|
||
|
@@ -61,39 +60,36 @@ As a replacement for the | |
[serveDir](https://doc.deno.land/https://deno.land/[email protected]/http/file_server.ts/~/serveDir) | ||
function in the Deno standard library: | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { serveDirWithTs } from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { serveDirWithTs } from "@ayame113/ts-serve"; | ||
|
||
serve((request) => serveDirWithTs(request)); | ||
Deno.serve((request) => serveDirWithTs(request)); | ||
``` | ||
|
||
As a replacement for the | ||
[serveFile](https://doc.deno.land/https://deno.land/[email protected]/http/file_server.ts/~/serveFile) | ||
function in the Deno standard library: | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { serveFileWithTs } from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { serveFileWithTs } from "@ayame113/ts-serve"; | ||
|
||
serve((request) => serveFileWithTs(request, "./mod.ts")); | ||
Deno.serve((request) => serveFileWithTs(request, "./mod.ts")); | ||
``` | ||
|
||
As [Hono](https://honojs.dev/)'s handler: | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { Hono } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { serveDirWithTs } from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { Hono } from "@hono/hono"; | ||
import { serveDirWithTs } from "@ayame113/ts-serve"; | ||
|
||
const app = new Hono(); | ||
app.get("*", (c) => { | ||
return serveDirWithTs(c.req.raw); | ||
}); | ||
serve(app.fetch); | ||
Deno.serve(app.fetch); | ||
``` | ||
|
||
#### `fourceInstantiateWasm` function | ||
#### `forceInstantiateWasm` function | ||
|
||
Calling this function will load the wasm file used in the deno_emit of the | ||
dependency. Even if you don't call this function, if you call the transpile | ||
|
@@ -103,16 +99,12 @@ However, performance can be an issue on the server as loading the wasm file | |
takes time. In that case, calling this function in advance can speed up later | ||
calls to the transpile function. | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { | ||
fourceInstantiateWasm, | ||
serveDirWithTs, | ||
} from "https://deno.land/x/ts_serve@$MODULE_VERSION/mod.ts"; | ||
```ts ignore | ||
import { forceInstantiateWasm, serveDirWithTs } from "@ayame113/ts-serve"; | ||
|
||
// load the wasm file in the background when the server starts. | ||
fourceInstantiateWasm(); | ||
serve((request) => serveDirWithTs(request)); | ||
forceInstantiateWasm(); | ||
Deno.serve((request) => serveDirWithTs(request)); | ||
``` | ||
|
||
## develop | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
{ | ||
"name": "@ayame113/ts-serve", | ||
"version": "1.5.2", | ||
"license": "MIT", | ||
"exports": "./mod.ts", | ||
"tasks": { | ||
"test": "deno test --doc --parallel --shuffle --allow-net=deno.land,localhost,0.0.0.0 --allow-read=.", | ||
"test": "deno test --doc --parallel --shuffle --allow-net=deno.land,localhost,0.0.0.0,jsr.io:443 --allow-read=.", | ||
"check": "deno check ./mod.ts" | ||
}, | ||
"importMap": "./import-map.json" | ||
"imports": { | ||
"@deno/emit": "jsr:@deno/emit@^0.46.0", | ||
"@oak/oak": "jsr:@oak/oak@^17.1.3", | ||
"@std/assert": "jsr:@std/assert@^1.0.9", | ||
"@std/async": "jsr:@std/async@^1.0.9", | ||
"@std/http": "jsr:@std/http@^1.0.12", | ||
"@std/media-types": "jsr:@std/media-types@^1.1.0", | ||
"@std/testing": "jsr:@std/testing@^1.0.6", | ||
"@ayame113/ts-serve": "./mod.ts", | ||
"@ayame113/ts-serve/": "./" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
<script src="./main.ts" type="module"></script> | ||
</head> | ||
<body> | ||
hello world | ||
</body> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title></title> | ||
<script src="./main.ts" type="module"></script> | ||
</head> | ||
<body> | ||
hello world | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { serveDirWithTs } from "../mod.ts"; | ||
serve((req) => serveDirWithTs(req, { fsRoot: "example" })); | ||
Deno.serve((req) => serveDirWithTs(req, { fsRoot: "example" })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import { | ||
assertEquals, | ||
fail, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { serve } from "https://deno.land/[email protected]/http/mod.ts"; | ||
import { assertEquals, fail } from "@std/assert"; | ||
import { | ||
MediaType, | ||
serveDirWithTs, | ||
|
@@ -29,7 +25,11 @@ Deno.test({ | |
name: "file server - serveFileWithTs", | ||
async fn() { | ||
const controller = new AbortController(); | ||
const serverPromise = serve((request) => { | ||
const serverPromise = Deno.serve({ | ||
signal: controller.signal, | ||
port: 8886, | ||
onListen() {}, | ||
}, (request) => { | ||
const { pathname } = new URL(request.url); | ||
|
||
if (pathname === "/mod.ts") { | ||
|
@@ -42,10 +42,6 @@ Deno.test({ | |
return serveFileWithTs(request, "./test/a.jsx"); | ||
} | ||
throw new Error("unreachable"); | ||
}, { | ||
signal: controller.signal, | ||
port: 8886, | ||
onListen() {}, | ||
}); | ||
|
||
{ | ||
|
@@ -56,7 +52,7 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
{ | ||
|
@@ -67,7 +63,7 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
{ | ||
|
@@ -78,12 +74,12 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
|
||
controller.abort(); | ||
await serverPromise; | ||
await serverPromise.finished; | ||
}, | ||
}); | ||
|
||
|
@@ -121,7 +117,7 @@ Deno.test({ | |
assertEquals(res.status, 200); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
}, | ||
}); | ||
|
@@ -130,13 +126,13 @@ Deno.test({ | |
name: "file server - serveDirWithTs", | ||
async fn() { | ||
const controller = new AbortController(); | ||
const serverPromise = serve( | ||
(request) => serveDirWithTs(request, { quiet: true }), | ||
const serverPromise = Deno.serve( | ||
{ | ||
signal: controller.signal, | ||
port: 8887, | ||
onListen() {}, | ||
}, | ||
(request) => serveDirWithTs(request, { quiet: true }), | ||
); | ||
|
||
{ | ||
|
@@ -147,7 +143,7 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
{ | ||
|
@@ -158,7 +154,7 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
{ | ||
|
@@ -169,12 +165,12 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
} | ||
|
||
controller.abort(); | ||
await serverPromise; | ||
await serverPromise.finished; | ||
}, | ||
}); | ||
|
||
|
@@ -228,7 +224,7 @@ Deno.test({ | |
); | ||
assertEquals( | ||
res.headers.get("Content-Type"), | ||
"application/javascript; charset=UTF-8", | ||
"text/javascript; charset=UTF-8", | ||
); | ||
}, | ||
}); | ||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.