Skip to content

Commit aa68944

Browse files
committed
feat: add Deno build to WASM
1 parent 6306ccc commit aa68944

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target/
22
.DS_Store
33
*.svg
44
!assets/*.svg
5+
pkg/

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 5.1.3 / 2024-11-13
4+
5+
- feat: add Deno build to WASM
6+
37
## 5.1.0 / 2024-11-13
48

59
- feat: add WASM build

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "githubchart-rust"
3-
version = "5.1.0"
3+
version = "5.1.3"
44
authors = ["frytg"]
55
edition = "2021"
66
license = "MIT"

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ This project is already configured to build for Web with `wasm-pack`. Run this c
5656
wasm-pack build --target web
5757
```
5858

59+
or [specifically for Deno](https://rustwasm.github.io/docs/wasm-bindgen/reference/deployment.html#deno):
60+
61+
```sh
62+
wasm-pack build --target deno --out-dir pkg-deno
63+
```
64+
65+
or a combined version for both:
66+
67+
```sh
68+
rm -rf pkg && wasm-pack build --target deno --out-name githubchart_rust_deno && wasm-pack build --target web && rm pkg/.gitignore
69+
```
70+
71+
For the combined version, you will need to remove `files` from [`pkg/package.json`](./pkg/package.json) to publish all files (web+deno) to NPM.
72+
5973
There's also an example in [`web/example.html`](./web/example.html) that you can run locally.
6074

6175
More docs about this:

web/deno.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as BunnySDK from "https://esm.sh/@bunny.net/[email protected]";
2+
import { generate_github_chart } from "https://esm.sh/[email protected]/githubchart_rust_deno.js";
3+
4+
/**
5+
* Executes a WASM binary and returns the response value
6+
* @param {Request} request - The Fetch API Request object.
7+
* @return {Response} The HTTP response or string.
8+
*/
9+
BunnySDK.net.http.serve(async (req: Request): Promise<Response> => {
10+
try {
11+
// parse incoming request
12+
const url = new URL(req.url);
13+
14+
// extract username from path
15+
const username = url.pathname.split("/")[1];
16+
17+
// check if username is provided
18+
if (!username) return new Response("No username provided", { status: 400 });
19+
20+
// generate chart
21+
const chart = await generate_github_chart(username, "default");
22+
23+
// return response
24+
return new Response(chart, {
25+
headers: {
26+
"Content-Type": "image/svg+xml",
27+
"Cache-Control": "max-age=300",
28+
"x-generated-by": "githubchart-rust",
29+
"x-username": username,
30+
},
31+
});
32+
} catch (error) {
33+
console.log(req.method, req.url, error);
34+
return new Response("Internal Server Error", { status: 500 });
35+
}
36+
});

0 commit comments

Comments
 (0)