Skip to content

Commit 3b21896

Browse files
committed
chore: client builds
1 parent d778ec1 commit 3b21896

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

@mizu/render/client/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export type * from "./client.ts"
1010
export default Client.default as Client
1111

1212
// Start the client-side renderer if this module is the main entry point
13-
if (import.meta.main) {
13+
if ((import.meta.main) && (globalThis.window?.document)) {
1414
Client.default.render()
1515
}

deno.jsonc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
// Cache dependencies
2525
"cache": "deno cache **/mod.ts www/*.ts && deno test --no-run",
2626
// Serve website locally
27-
"serve": "deno serve --allow-read --allow-env --allow-net --allow-run --port=4649 --location=http://localhost:4649 --watch www/serve.ts",
27+
"serve": "deno serve --allow-read --allow-env --allow-net --allow-run --allow-write=/tmp --port=4649 --location=http://localhost:4649 --watch www/serve.ts",
2828
// Build project
2929
"build": "deno task build:clean && deno task build:www && deno task build:coverage",
3030
// Clean build artifacts
3131
"build:clean": "rm -rf .pages && mkdir -p .pages",
3232
// Build website
33-
"build:www": "deno run --allow-read --allow-env --allow-net --allow-run --allow-write=.pages --location=http://localhost:4649 www/build.ts",
33+
"build:www": "deno run --allow-read --allow-env --allow-net --allow-run --allow-write=.pages,/tmp --location=http://localhost:4649 www/build.ts",
3434
// Build coverage report
3535
"build:coverage": "deno task test:only --filter='/DENO/' --clean --coverage --fail-fast --reporter=dot && deno coverage --html && mv coverage/html .pages/coverage && deno run --allow-read --allow-net=img.shields.io --allow-write=.pages/coverage jsr:@libs/bundle/ts/cli/coverage --root=.pages/coverage"
3636
},
@@ -60,8 +60,7 @@
6060
"@libs/run": "jsr:@libs/run@3",
6161
"@libs/testing": "jsr:@libs/testing@3",
6262
"@libs/typing": "jsr:@libs/typing@3",
63-
"@npm/jsdom": "npm:jsdom@25",
64-
"canvas": "node:canvas"
63+
"@npm/jsdom": "npm:jsdom@25"
6564
},
6665
"workspace": [
6766
"@mizu/bind",

www/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Imports
22
import Mizu from "@mizu/render/static"
3-
import { default as serve, html } from "./serve.ts"
3+
import { default as serve, html, js } from "./serve.ts"
44
import { fromFileUrl, join } from "@std/path"
55

66
await using _ = Deno.serve({ port: Number(new URL(globalThis.location.href).port) }, serve.fetch)
@@ -9,6 +9,10 @@ await Mizu.generate([
99
{ source: () => html("index"), destination: "index.html", render: {} },
1010
{ source: () => html("build"), destination: "build.html", render: {} },
1111
{ source: () => html("playground"), destination: "playground.html", render: {} },
12+
{ source: () => js("@mizu/render/client", { format: "iife" }), destination: "client.js" },
13+
{ source: () => js("@mizu/render/client", { format: "esm" }), destination: "client.mjs" },
14+
// { source: () => js("@mizu/render/server", { server: true }), destination: "server.mjs" },
15+
// { source: () => js("@mizu/render/static", { server: true }), destination: "static.mjs" },
1216
{ source: new URL("/matcha.css", globalThis.location.href), destination: "matcha.css" },
1317
{ source: new URL("/highlight.js", globalThis.location.href), destination: "highlight.js" },
1418
{ source: "*.{svg,css,png,js}", directory: fromFileUrl(import.meta.resolve("./static")), destination: "." },

www/serve.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ function config(name: string, { parse = true } = {} as { parse?: boolean }) {
4545
}
4646

4747
/** Generate JS. */
48-
export function js(exported: string, options?: Pick<NonNullable<Arg<typeof bundle, 1>>, "format"> & { server?: boolean }) {
48+
export function js(exported: string, options?: Pick<NonNullable<Arg<typeof bundle, 1>>, "format"> & { server?: boolean; raw?: Record<PropertyKey, unknown> }) {
4949
const name = exported.match(/^(?<name>@[a-z0-9][-a-z0-9]*[a-z0-9]\/[a-z0-9][-a-z0-9]*[a-z0-9]).*$/)?.groups?.name ?? exported
5050
const url = import.meta.resolve(exported)
5151
log.with({ name, url }).debug("bundling javascript")
5252
if (options?.server) {
53-
Object.assign(options, { external: ["node:canvas"] })
53+
options.raw ??= {}
54+
options.raw.external = ["canvas", "node:canvas", "node:url", "utf-8-validate", "bufferutil", "supports-color"]
55+
options.raw.platform = "node"
5456
}
5557
if (options?.format === "iife") {
56-
Object.assign(options, { raw: { define: { "import.meta.main": "true" } } })
58+
options.raw ??= {}
59+
options.raw.define = { "import.meta.main": "true" }
5760
}
5861
return bundle(new URL(url), { ...options, banner })
5962
}
@@ -97,9 +100,13 @@ export default {
97100
handler: async () => new Response(await js("@mizu/render/client", { format: "esm" }), { headers: { "Content-Type": "application/javascript; charset=utf-8", "Access-Control-Allow-Origin": "*" } }),
98101
},
99102
{
100-
pattern: new URLPattern({ pathname: "/server.js" }),
103+
pattern: new URLPattern({ pathname: "/server.mjs" }),
101104
handler: async () => new Response(await js("@mizu/render/server", { server: true }), { headers: { "Content-Type": "application/javascript; charset=utf-8" } }),
102105
},
106+
{
107+
pattern: new URLPattern({ pathname: "/static.mjs" }),
108+
handler: async () => new Response(await js("@mizu/render/static", { server: true }), { headers: { "Content-Type": "application/javascript; charset=utf-8" } }),
109+
},
103110
{
104111
pattern: new URLPattern({ pathname: "/about/phases" }),
105112
handler: () => new Response(JSON.stringify(Object.fromEntries(Object.entries(Phase).filter(([_, value]) => Number.isFinite(value)))), { headers: { "content-type": "application/json; charset=utf-8" } }),

0 commit comments

Comments
 (0)