@micro-lc/preview 0.5.0-rc3 → 0.5.0-rc4

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micro-lc/preview",
3
- "version": "0.5.0-rc3",
3
+ "version": "0.5.0-rc4",
4
4
  "module": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "files": [
@@ -95,5 +95,11 @@ self.addEventListener("fetch", (event) => {
95
95
  } catch (e) {
96
96
  finalUrl = url;
97
97
  }
98
- event.respondWith(self.fetch(finalUrl, { ...event.request, headers }));
98
+ console.log({ clientId, clientSourceMap, finalUrl });
99
+ event.respondWith(
100
+ self.fetch(finalUrl, { ...event.request, headers }).catch((error) => {
101
+ console.error(error);
102
+ return Promise.reject(error);
103
+ })
104
+ );
99
105
  });
@@ -1 +1 @@
1
- const k=new Map,S=new Map,M=new Map,y=(e,o)=>{const t=o.keys();let r,{done:s=!1,value:i}=t.next();for(;!s&&r===void 0;){i!==void 0&&e.startsWith(i)&&(r=i,s=!0);const{value:l,done:n=!1}=t.next();s=n,i=l}return r},v=(e,o)=>{self.clients.get(e).then(t=>t==null?void 0:t.postMessage(o)).catch(t=>console.error(`[SW]: error on ${e} - ${String(t)}`))},x=e=>e!==null&&"id"in e;self.addEventListener("install",()=>{self.skipWaiting().catch(e=>console.error(`[SW] error while skipWaiting - ${String(e)}`))});self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())});self.addEventListener("message",({data:e,source:o})=>{if(!x(o))return;const{id:t}=o,r=e;switch(r.type){case"set-source-map":{const{content:{scope:s,dictionary:i}}=r,l=s??t,n=Object.entries(i).reduce((u,[a,c])=>{const{clientSourceMap:g,clientTosMap:p}=u;return Object.keys(c.headers).length>0&&p.set(c.to,c.headers),g.set(a,c),u},{clientSourceMap:new Map,clientTosMap:new Map});s?M.set(t,s):M.delete(t),k.set(l,n.clientSourceMap),S.set(l,n.clientTosMap),v(t,{content:{clientId:t},type:"source-map-ack"});break}case"unload-client":{M.delete(t);break}}});self.addEventListener("fetch",e=>{var o,t,r;const s=e.clientId!==""?e.clientId:e.resultingClientId,i=M.get(s),l=i??s,n=k.get(l);if(!n)return e.respondWith(self.fetch(e.request));const u=S.get(l);let{request:{url:a}}=e;const c=y(a,n),g=y(a,u),p=new Headers(e.request.headers);let b={};if(c!==void 0){const d=(o=n.get(c))==null?void 0:o.to,f=(t=n.get(c))==null?void 0:t.headers,h=a.substring(c.length);b=(r=n.get(c))==null?void 0:r.query,a=`${d}${h}`,Object.entries(f).forEach(([I,W])=>p.set(I,W))}if(g!==void 0){const d=u.get(g);Object.entries(d).forEach(([f,h])=>p.set(f,h))}let w;try{const d=new URL(a);Object.entries(b).forEach(([f,h])=>d.searchParams.set(f,h)),w=d.href}catch{w=a}e.respondWith(self.fetch(w,{...e.request,headers:p}))});
1
+ const k=new Map,S=new Map,w=new Map,y=(e,r)=>{const t=r.keys();let i,{done:s=!1,value:a}=t.next();for(;!s&&i===void 0;){a!==void 0&&e.startsWith(a)&&(i=a,s=!0);const{value:d,done:n=!1}=t.next();s=n,a=d}return i},v=(e,r)=>{self.clients.get(e).then(t=>t==null?void 0:t.postMessage(r)).catch(t=>console.error(`[SW]: error on ${e} - ${String(t)}`))},x=e=>e!==null&&"id"in e;self.addEventListener("install",()=>{self.skipWaiting().catch(e=>console.error(`[SW] error while skipWaiting - ${String(e)}`))});self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())});self.addEventListener("message",({data:e,source:r})=>{if(!x(r))return;const{id:t}=r,i=e;switch(i.type){case"set-source-map":{const{content:{scope:s,dictionary:a}}=i,d=s??t,n=Object.entries(a).reduce((u,[l,c])=>{const{clientSourceMap:g,clientTosMap:p}=u;return Object.keys(c.headers).length>0&&p.set(c.to,c.headers),g.set(l,c),u},{clientSourceMap:new Map,clientTosMap:new Map});s?w.set(t,s):w.delete(t),k.set(d,n.clientSourceMap),S.set(d,n.clientTosMap),v(t,{content:{clientId:t},type:"source-map-ack"});break}case"unload-client":{w.delete(t);break}}});self.addEventListener("fetch",e=>{var r,t,i;const s=e.clientId!==""?e.clientId:e.resultingClientId,a=w.get(s),d=a??s,n=k.get(d);if(!n)return e.respondWith(self.fetch(e.request));const u=S.get(d);let{request:{url:l}}=e;const c=y(l,n),g=y(l,u),p=new Headers(e.request.headers);let b={};if(c!==void 0){const o=(r=n.get(c))==null?void 0:r.to,h=(t=n.get(c))==null?void 0:t.headers,f=l.substring(c.length);b=(i=n.get(c))==null?void 0:i.query,l=`${o}${f}`,Object.entries(h).forEach(([I,W])=>p.set(I,W))}if(g!==void 0){const o=u.get(g);Object.entries(o).forEach(([h,f])=>p.set(h,f))}let M;try{const o=new URL(l);Object.entries(b).forEach(([h,f])=>o.searchParams.set(h,f)),M=o.href}catch{M=l}console.log({clientId:s,clientSourceMap:n,finalUrl:M}),e.respondWith(self.fetch(M,{...e.request,headers:p}).catch(o=>(console.error(o),Promise.reject(o))))});