Skip to content

Commit

Permalink
move to jsr (#41)
Browse files Browse the repository at this point in the history
* 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
ayame113 authored Dec 11, 2024
1 parent 46e8cbb commit c234bff
Show file tree
Hide file tree
Showing 21 changed files with 332 additions and 201 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/publish.yml
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
4 changes: 2 additions & 2 deletions .github/workflows/suggest_change.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
- name: Git Checkout Module
uses: actions/checkout@v2
- name: Use Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x
- name: 😉 Format
run: deno fmt
- name: Create Suggestion
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
- name: Git Checkout Module
uses: actions/checkout@v2
- name: Use Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x
- name: 😉 Format
run: deno fmt --check
- name: 😋 Lint
Expand All @@ -22,9 +22,9 @@ jobs:
- name: Git Checkout Module
uses: actions/checkout@v2
- name: Use Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x
- name: 🧐 Type Check
run: deno task check
Test:
Expand All @@ -33,15 +33,15 @@ jobs:
- name: Git Checkout Module
uses: actions/checkout@v2
- name: Use Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x
- name: 😎 Test
run: deno task test --coverage=coverage
- name: Create coverage report
run: deno coverage ./coverage --lcov > coverage.lcov
- name: Codecov
uses: codecov/codecov-action@v1.5.2
uses: codecov/codecov-action@v5
with:
file: ./coverage.lcov
files: ./coverage.lcov
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: denoland/setup-deno@v1
- uses: denoland/setup-deno@v2
- name: run deno-udd
id: run-deno-udd
env:
Expand Down
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 16 additions & 2 deletions deno.json
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/": "./"
}
}
16 changes: 8 additions & 8 deletions example/index.html
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>
3 changes: 1 addition & 2 deletions example/serve.ts
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" }));
40 changes: 18 additions & 22 deletions file_server_test.ts
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,
Expand All @@ -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") {
Expand All @@ -42,10 +42,6 @@ Deno.test({
return serveFileWithTs(request, "./test/a.jsx");
}
throw new Error("unreachable");
}, {
signal: controller.signal,
port: 8886,
onListen() {},
});

{
Expand All @@ -56,7 +52,7 @@ Deno.test({
);
assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
"text/javascript; charset=UTF-8",
);
}
{
Expand All @@ -67,7 +63,7 @@ Deno.test({
);
assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
"text/javascript; charset=UTF-8",
);
}
{
Expand All @@ -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;
},
});

Expand Down Expand Up @@ -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",
);
},
});
Expand All @@ -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 }),
);

{
Expand All @@ -147,7 +143,7 @@ Deno.test({
);
assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
"text/javascript; charset=UTF-8",
);
}
{
Expand All @@ -158,7 +154,7 @@ Deno.test({
);
assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
"text/javascript; charset=UTF-8",
);
}
{
Expand All @@ -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;
},
});

Expand Down Expand Up @@ -228,7 +224,7 @@ Deno.test({
);
assertEquals(
res.headers.get("Content-Type"),
"application/javascript; charset=UTF-8",
"text/javascript; charset=UTF-8",
);
},
});
Expand Down
5 changes: 0 additions & 5 deletions import-map.json

This file was deleted.

Loading

0 comments on commit c234bff

Please sign in to comment.