@shadcn/registry0.3.11.8 kB
import {SocksClient}from'socks';import {EnvHttpProxyAgent,Agent}from'undici';var y=["HTTPS_PROXY","https_proxy","HTTP_PROXY","http_proxy"],g=["ALL_PROXY","all_proxy"],l={"socks:":5,"socks4:":4,"socks4a:":4,"socks5:":5,"socks5h:":5};function S(e){let n;try{n=new URL(e);}catch{return}let t=l[n.protocol];if(!t)return;let r=Number(n.port)||1080;return {host:n.hostname,port:r,type:t,...n.username?{userId:decodeURIComponent(n.username)}:void 0,...n.password?{password:decodeURIComponent(n.password)}:void 0}}function m(e){return new Agent({connect:(n,t)=>{SocksClient.createConnection({proxy:e,command:"connect",destination:{host:n.hostname??"",port:Number(n.port)}}).then(({socket:r})=>t(null,r)).catch(r=>t(r,null));}})}function P(e=process.env){for(let t of g){let r=e[t];if(!r)continue;let o=S(r);if(o)return m(o)}return y.some(t=>e[t])?new EnvHttpProxyAgent:void 0}var _=P(),x=5,k=new Set(["accept","user-agent"]);async function O(e,n){let t=new URL(e).origin,r=new Headers(n?.headers),o=new URL(e).toString(),s=r;for(let i=0;i<=x;i++){let c=await A(o,n,s);if(!(c.status>=300&&c.status<400&&c.headers.has("location")))return c;let p=c.headers.get("location"),a=new URL(p,o);if(a.origin!==t){let d=new Headers;r.forEach((h,u)=>{k.has(u.toLowerCase())&&d.set(u,h);}),s=d;}else s=r;o=a.toString();}throw new Error(`Too many redirects while fetching ${e}`)}async function A(e,n,t){try{return await fetch(e,{...n,headers:t,redirect:"manual",dispatcher:_})}catch(r){let o=r instanceof TypeError?r.cause:void 0;if(o){let s=new Error(`Request to ${e} failed, reason: ${f(o)}`);throw s.cause=o,s}throw r}}function f(e){if(e instanceof Error&&"errors"in e){let n=e.errors;if(Array.isArray(n)&&n.length)return f(n[0])}return e instanceof Error?e.message||e.code||"unknown error":String(e)}export{P as a,O as b};
Shown as plain text from the published tarball, after apm checked it against the version's checksum. Nothing in it runs on this page.