+import c from"path";import l from"@hattip/polyfills/node-fetch";function h(s){return s?.startsWith("http://")||s?.startsWith("https://")}const w=new Map,m=function({cache:s=w,onRequest:f,onUseCache:p,fetcher:a,resolveIdFallback:i}={}){return l(),{name:"rollup-plugin-http-resolve",async resolveId(t,r){if(/^https?:\/\//.test(t))return t;if(r&&h(r)){if(t.startsWith("https://"))return t;const{pathname:e,protocol:n,host:o}=new URL(r);if(t.startsWith("/"))return`${n}//${o}${t}`;if(t.startsWith(".")){const u=c.join(c.dirname(e),t);return`${n}//${o}${u}`}}else if(i){const e=i(t,r);if(e)return e}},async load(t){if(t!==null&&h(t)){const r=await s.get(t);if(r)return p?.(t),r;if(f?.(t),a){const e=await a(t);return await s.set(t,e),e}else{const e=await fetch(t,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54"}});if(!e.ok)throw e.statusText;const n=await e.text();return await s.set(t,n),n}}}}};export{m as httpResolve};
0 commit comments