@@ -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 - z 0 - 9 ] [ - a - z 0 - 9 ] * [ a - z 0 - 9 ] \/ [ a - z 0 - 9 ] [ - a - z 0 - 9 ] * [ a - z 0 - 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