import { transformSync } from "@mizchi/mints" ; type FetchEvent = { request : Request ; respondWith ( promise ) : void ; } ; const TARGET_EXTENSIONS = [ ".ts" , ".tsx" ] ; self . addEventListener ( "install" , ( ev ) => ev . waitUntil ( self . skipWaiting ( ) ) ) ; self . addEventListener ( "activate" , ( ev ) => ev . waitUntil ( self . clients . claim ( ) ) ) ; self . addEventListener ( "fetch" , ( event ) => { const req = event . request as Request ; if ( TARGET_EXTENSIONS . some ( ( t ) => req . url . endsWith ( t ) ) ) { event . respondWith ( handleWithTransform ( event ) ) ; } } ) ; const handleWithTransform = async ( event ) : Promise < Response > => { const rawContent = await fetch ( event . request . url ) . then ( ( res ) => res . text ( ) ) ; const compiled = transformSync ( rawContent ) ; if ( compiled . error ) throw new Error ( JSON . stringify ( compiled , null , 2 ) ) ; return new Response ( compiled . code , { mode : "no-cors" , status : 200 , headers : { "Content-Type" : "text/javascript" , } , } ) ; } ;