@moneko/core 4.4.1 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{projectName as t,version as e}from"app:info";let a=`${t}-core-${e}`,
|
|
1
|
+
import{projectName as t,version as e}from"app:info";let a=self;export async function precaching(){let i=`${t}-core-${e}`,n=`${t}-runtime-${e}`;async function s(t){let e=await caches.open(n),a=await e.match(t);if(a)return a;let i=await fetch(t);return i.ok&&"basic"===i.type&&e.put(t,i.clone()),i}async function c(t){let e=await caches.open(n);try{let a=await fetch(t);return a.ok&&"basic"===a.type&&e.put(t,a.clone()),a}catch{let a=await e.match(t);if(a)return a;return new Response("Offline",{status:503,statusText:"Offline"})}}a.addEventListener("install",t=>{t.waitUntil((async()=>{let t=await caches.open(i),e=await fetch("/app-resource.json").then(t=>t.json()),n=(await Promise.allSettled(e.map(t=>t.startsWith("/")?t:`/${t}`).map(e=>t.add(e)))).filter(t=>"fulfilled"===t.status).length;console.info(`[SW] Precaching ${n}/${e.length} assets`),await a.skipWaiting()})())}),a.addEventListener("activate",t=>{t.waitUntil((async()=>{let t=await caches.keys();await Promise.all(t.filter(t=>![i,n].includes(t)).map(t=>caches.delete(t))),await a.clients.claim(),(await a.clients.matchAll({type:"window"})).forEach(t=>{t.postMessage({type:"SW_UPDATED",version:e})})})())}),a.addEventListener("fetch",t=>{let{request:e}=t;if("GET"!==e.method)return;let a=new URL(e.url);"navigate"===e.mode?t.respondWith(c(e)):a.origin===location.origin&&/\.(js|css|png|jpg|jpeg|svg|webp|woff2?)$/.test(a.pathname)&&t.respondWith(s(e))}),a.addEventListener("message",t=>{t.data?.type==="SKIP_WAITING"&&a.skipWaiting()})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function precaching(): Promise<void>;
|
package/lib/vm/sw.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join as o}from"node:path";import{loadFileSync as r}from"@moneko/utils";import e from"../commom/reactive-object.mjs";import{paths as m}from"../index.mjs";export const sw_vm=new e({precaching:{type:".ts",source:()=>
|
|
1
|
+
import{join as o}from"node:path";import{loadFileSync as r}from"@moneko/utils";import e from"../commom/reactive-object.mjs";import{paths as m}from"../index.mjs";export const sw_vm=new e({precaching:{type:".ts",source:()=>r(o(m.corePath,"./service-worker/precaching.js"))||""}});
|