Skip to content

Commit 86b7670

Browse files
committed
export class fileCache implements CacheType {
1 parent 7ed8918 commit 86b7670

File tree

12 files changed

+70
-25
lines changed

12 files changed

+70
-25
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105-
.vscode/settings.json
105+
.vscode/settings.json
106+
checks.json

lib/index.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { Plugin } from "rollup";
22
export declare type ResolveIdFallback = (
3-
specifier: string,
4-
importer?: string
3+
specifier: string,
4+
importer?: string,
55
) => string | void;
66
declare type HttpResolveOptions = {
7-
cache?: any;
8-
fetcher?: (url: string) => Promise<string>;
9-
onRequest?: (url: string) => void;
10-
onUseCache?: (url: string) => void;
11-
resolveIdFallback?: ResolveIdFallback;
7+
cache?: any;
8+
fetcher?: (url: string) => Promise<string>;
9+
onRequest?: (url: string) => void;
10+
onUseCache?: (url: string) => void;
11+
resolveIdFallback?: ResolveIdFallback;
1212
};
1313
export declare const httpResolve: ({
14-
cache,
15-
onRequest,
16-
onUseCache,
17-
fetcher,
18-
resolveIdFallback,
14+
cache,
15+
onRequest,
16+
onUseCache,
17+
fetcher,
18+
resolveIdFallback,
1919
}?: HttpResolveOptions) => Plugin;
2020
export {};

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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};
1+
import{createHash as d}from"node:crypto";import c from"fs-extra";import{homedir as g}from"node:os";import l from"node:path";import W from"@hattip/polyfills/node-fetch";import u from"path";class ${#e=l.join(g(),"cache","fetch");#t(i){const r=d("sha512");r.update(i);const a=r.digest("base64");return l.join(this.#e,a)}async set(i,r){const a=this.#t(i);return await c.ensureFile(a),await c.writeFile(a,r,{encoding:"utf-8"})}async get(i){const r=this.#t(i);if(c.exists(r))return await c.ensureFile(r),await c.readFile(r,"utf-8")}}function p(s){return s?.startsWith("http://")||s?.startsWith("https://")}const m=new Map,x=function({cache:s=m,onRequest:i,onUseCache:r,fetcher:a,resolveIdFallback:h}={}){return W(),{name:"rollup-plugin-http-resolve",async resolveId(t,n){if(/^https?:\/\//.test(t))return t;if(n&&p(n)){if(t.startsWith("https://"))return t;const{pathname:e,protocol:o,host:f}=new URL(n);if(t.startsWith("/"))return`${o}//${f}${t}`;if(t.startsWith(".")){const w=u.join(u.dirname(e),t);return`${o}//${f}${w}`}}else if(h){const e=h(t,n);if(e)return e}},async load(t){if(t!==null&&p(t)){const n=await s.get(t);if(n)return r?.(t),n;if(i?.(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 o=await e.text();return await s.set(t,o),o}}}}};export{m as defaultCache,$ as fileCache,x as httpResolve};
22
//# sourceMappingURL=index.mjs.map

0 commit comments

Comments
 (0)