@shadcn/registry0.3.16.0 kB
import {b as b$1}from'./chunk-DMPLUZHK.js';import {d as d$1}from'./chunk-XADSAWBY.js';import {execa}from'execa';var m="https://api.github.com",w="2022-11-28",H="application/vnd.github.raw+json",b="application/vnd.github+json",R=/^[a-fA-F0-9]{40}$/,k=["GH_TOKEN","GITHUB_TOKEN"],C=/^[\x21-\x7E]+$/,N=15e3,v=8,A=/\(HTTP (\d{3})\)/,O=5,d=5*1024*1024,o=class extends Error{kind;statusCode;constructor(e,n={}){super(n.message??`GitHub request failed (${e}).`),this.name="GitHubTransportError",this.kind=e,this.statusCode=n.statusCode;}};function I(){for(let t of k){let e=d$1(t)?.trim();if(e&&C.test(e))return e}return null}function c(t){return t.split("/").map(e=>encodeURIComponent(e)).join("/")}function g(t){return typeof t=="string"&&R.test(t)}async function S(t,e=d){let n=Number(t.headers.get("content-length"));if(Number.isFinite(n)&&n>e)throw new o("oversize");if(!t.body){let u=await t.text();if(Buffer.byteLength(u,"utf8")>e)throw new o("oversize");return u}let i=t.body.getReader(),s=[],r=0;for(;;){let{done:u,value:a}=await i.read();if(u)break;if(r+=a.byteLength,r>e)throw await i.cancel(),new o("oversize");s.push(a);}return Buffer.concat(s).toString("utf8")}async function T(t,e,n){let i;try{i=await b$1(`${m}/${t}`,{headers:new Headers({Accept:n,Authorization:`Bearer ${e}`,"User-Agent":"shadcn","X-GitHub-Api-Version":w})});}catch{throw new o("network")}if(!i.ok)throw new o("http",{statusCode:i.status});return i}async function q(t,e,n,i){let s=await T(E(t,e,n),i,H);return S(s)}var l=v,G=[];async function $(t){l>0?l-=1:await new Promise(e=>G.push(e));try{return await t()}finally{let e=G.shift();e?e():l+=1;}}function x(){let t={...process.env};return delete t.GH_TOKEN,delete t.GITHUB_TOKEN,delete t.GH_ENTERPRISE_TOKEN,delete t.GITHUB_ENTERPRISE_TOKEN,delete t.GH_DEBUG,delete t.DEBUG,delete t.GH_FORCE_TTY,delete t.GH_TELEMETRY,t.GH_HOST="github.com",t.GH_PROMPT_DISABLED="1",t.GH_NO_UPDATE_NOTIFIER="1",t.GH_PAGER="cat",t.NO_COLOR="1",t}function U(t){if(typeof t!="object"||t===null)return new o("network");let e=t;if(e.code==="ENOENT")return new o("enoent");if(e.timedOut===true)return new o("timeout");let n=typeof e.stderr=="string"?e.stderr:"";if(/gh auth login|not logged in/i.test(n))return new o("unauthenticated");let i=n.match(A);if(i){let s=Number(i[1]);if(s>=100&&s<=599)return new o("http",{statusCode:s})}return new o("network")}async function y(t,e){return $(async()=>{try{return (await execa("gh",["api","--hostname","github.com",t,"-H",`Accept: ${e}`,"-H",`X-GitHub-Api-Version: ${w}`],{env:x(),extendEnv:!1,timeout:N,maxBuffer:d,stripFinalNewline:!1})).stdout}catch(n){throw U(n)}})}async function D(t,e,n){let i=await y(E(t,e,n),H);if(Buffer.byteLength(i,"utf8")>d)throw new o("oversize");return i}function E(t,e,n){if(!g(e))throw new o("invalid-response");return `repos/${t.owner}/${t.repo}/contents/${c(n)}?ref=${e.toLowerCase()}`}function J(t,e){return t.kind==="enoent"?{detail:"The GitHub CLI (gh) is not installed.",suggestion:'Install the GitHub CLI and run "gh auth login", or set GH_TOKEN to a token with read access.'}:t.kind==="unauthenticated"?e==="token"?{detail:"The configured GitHub token was rejected.",suggestion:"Check that GH_TOKEN or GITHUB_TOKEN is valid and has read access to the repository."}:{detail:"The GitHub CLI is not authenticated.",suggestion:'Run "gh auth login --hostname github.com" and try again.'}:t.kind==="timeout"?{detail:"The GitHub request timed out.",suggestion:"Check your network connection and try again."}:t.kind==="oversize"?{detail:`The file exceeds the ${d} byte registry source file limit.`,suggestion:"Registry source files must be smaller than 5 MiB. Reduce the file size or split the item."}:t.kind==="http"?t.statusCode===401?e==="token"?{detail:"GitHub rejected the configured token (401).",suggestion:"Check that GH_TOKEN or GITHUB_TOKEN is valid and has read access to the repository."}:{detail:"GitHub rejected the stored GitHub CLI credentials (401).",suggestion:'Run "gh auth login --hostname github.com" and try again.'}:t.statusCode===403?{detail:"GitHub denied access to the repository (403).",suggestion:"Check that your credentials have read access to the repository."}:t.statusCode===429?{detail:"GitHub rate limited the request (429).",suggestion:"Wait a few minutes and try again."}:t.statusCode&&t.statusCode>=500?{detail:`GitHub returned an upstream error (${t.statusCode}).`,suggestion:"GitHub may be having issues. Try again later."}:{detail:`GitHub returned an unexpected status${t.statusCode?` (${t.statusCode})`:""}.`,suggestion:"Check the repository and try again."}:t.kind==="invalid-response"?{detail:"GitHub returned an unexpected response.",suggestion:"Try again later."}:{detail:"The GitHub request failed.",suggestion:"Check your network connection and try again."}}function B(t){return async e=>{let n=await T(e,t,b);try{return await n.json()}catch{throw new o("invalid-response")}}}function P(){return async t=>{let e=await y(t,b);try{return JSON.parse(e)}catch{throw new o("invalid-response")}}}async function M(t,e,n){let i=n==="token"?I():null;if(n==="token"&&!i)throw new o("unauthenticated");let s=n==="token"&&i?B(i):P();if(e==="HEAD")return h(t,s,"HEAD");if(e.startsWith("refs/heads/"))return h(t,s,`heads/${c(e.slice(11))}`);if(e.startsWith("refs/tags/"))return h(t,s,`tags/${c(e.slice(10))}`);if(e.startsWith("refs/"))return L(t,s,e);try{return await h(t,s,`heads/${c(e)}`)}catch(r){if(r instanceof o&&r.kind==="http"&&r.statusCode===404)return h(t,s,`tags/${c(e)}`);throw r}}async function h(t,e,n){let i=await e(`repos/${t.owner}/${t.repo}/commits/${n}`),s=typeof i=="object"&&i!==null?i.sha:void 0;if(!g(s))throw new o("invalid-response");return s.toLowerCase()}async function L(t,e,n){let i=c(n.slice(5)),s=await e(`repos/${t.owner}/${t.repo}/git/ref/${i}`),r=typeof s=="object"&&s!==null?s.object:void 0;for(let u=0;u<O;u++){if(!r||!g(r.sha))throw new o("invalid-response");if(r.type!=="tag")return r.sha.toLowerCase();let a=await e(`repos/${t.owner}/${t.repo}/git/tags/${r.sha.toLowerCase()}`);r=typeof a=="object"&&a!==null?a.object:void 0;}throw new o("invalid-response")}
export{d as a,o as b,I as c,c as d,g as e,S as f,q as g,D as h,J as i,M as j};
Shown as plain text from the published tarball, after apm checked it against the version's checksum. Nothing in it runs on this page.