MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / p17

Function p17

package/cli.js:4711–4713  ·  view source on GitHub ↗
(q,K)

Source from the content-addressed store, hash-verified

4709
4710Technical details: ${J.message}`);if(J.response)throw Error(`HTTP ${J.response.status} error while downloading marketplace from ${$}. The marketplace file may not exist at this URL.
4711
4712Technical details: ${J.message}`)}throw Error(`Failed to download marketplace from ${$}: ${d6(J)}`)}Cb(z,"Validating marketplace data");let j=de().safeParse(O.data);if(!j.success)throw KD("marketplace_url",q,"failure",performance.now()-w,"invalid_schema"),new hT(`Invalid marketplace schema from URL: ${j.error.issues.map((J)=>`${J.path.join(".")}: ${J.message}`).join(", ")}`,$,O.data);KD("marketplace_url",q,"success",performance.now()-w),Cb(z,"Saving marketplace to cache");let H=dX(K,"..");await Y.mkdir(H),$j(K,g6(j.data,null,2),{encoding:"utf-8",flush:!0})}function azY(q){return q.source==="github"?q.repo.replace("/","-"):q.source==="npm"?q.package.replace("@","").replace("/","-"):q.source==="file"?rfK(q.path).replace(".json",""):q.source==="directory"?rfK(q.path):"temp_"+Date.now()}async function m17(q,K){let z=await X8().readFile(q,{encoding:"utf-8"}),Y;try{Y=r8(z)}catch(A){throw new hT(`Invalid JSON in ${q}: ${d6(A)}`,q,z)}let $=K.safeParse(Y);if(!$.success)throw new hT(`Invalid schema: ${q} ${$.error?.issues.map((A)=>`${A.path.join(".")}: ${A.message}`).join(", ")}`,q,Y);return $.data}async function p17(q,K){let _=X8(),z=sK6();await _.mkdir(z);let Y,$,A=!1,O=azY(q);try{switch(q.source){case"url":{Y=dX(z,`${O}.json`),A=!0,await efK(q.url,Y,q.headers,K),$=Y;break}case"github":{let M=`git@github.com:${q.repo}.git`,X=`https://github.com/${q.repo}.git`;Y=dX(z,O),A=!0;let P=null;if(await tfK()){Cb(K,`Cloning via SSH: ${M}`);try{await Ba(M,Y,q.ref,q.sparsePaths,K)}catch(D){P=x1(D),H6(P),Cb(K,`SSH clone failed, retrying with HTTPS: ${X}`),N(`SSH clone failed for ${q.repo} despite SSH being configured, falling back to HTTPS`,{level:"info"}),await _.rm(Y,{recursive:!0,force:!0});try{await Ba(X,Y,q.ref,q.sparsePaths,K),P=null}catch(f){P=x1(f),H6(P)}}}else{Cb(K,`SSH not configured, cloning via HTTPS: ${X}`),N(`SSH not configured for GitHub, using HTTPS for ${q.repo}`,{level:"info"});try{await Ba(X,Y,q.ref,q.sparsePaths,K)}catch(D){P=x1(D),H6(P),Cb(K,`HTTPS clone failed, retrying with SSH: ${M}`),N(`HTTPS clone failed for ${q.repo} (${P.message}), falling back to SSH`,{level:"info"}),await _.rm(Y,{recursive:!0,force:!0});try{await Ba(M,Y,q.ref,q.sparsePaths,K),P=null}catch(f){P=x1(f),H6(P)}}}if(P)throw P;$=dX(Y,q.path||".claude-plugin/marketplace.json");break}case"git":{Y=dX(z,O),A=!0,await Ba(q.url,Y,q.ref,q.sparsePaths,K),$=dX(Y,q.path||".claude-plugin/marketplace.json");break}case"npm":throw Error("NPM marketplace sources not yet implemented");case"file":{let M=Kd(q.path);$=M,Y=u17(u17(M)),A=!1;break}case"directory":{let M=Kd(q.path);$=dX(M,".claude-plugin","marketplace.json"),Y=M,A=!1;break}case"settings":{Y=dX(z,q.name),$=dX(Y,".claude-plugin","marketplace.json"),A=!1,await _.mkdir(u17($)),await FzY($,g6({name:q.name,owner:q.owner??{name:"settings"},plugins:q.plugins},null,2));break}default:throw Error("Unsupported marketplace source type")}N(`Reading marketplace from ${$}`);let w;try{w=await m17($,de())}catch(M){if(_7(M))throw Error(`Marketplace file not found at ${$}`);throw Error(`Failed to parse marketplace file at ${$}: ${d6(M)}`)}let j=dX(z,w.name),H=Kd(j),J=Kd(z);if(!H.startsWith(J+fB8))throw Error(`Marketplace name '${w.name}' resolves to a path outside the cache directory`);if(Y!==j&&!SB(q))try{try{K?.("Cleaning up old marketplace cache…")}catch(M){N(`Progress callback error: ${d6(M)}`,{level:"warn"})}await _.rm(j,{recursive:!0,force:!0}),await _.rename(Y,j),Y=j,A=!1}catch(M){let X=d6(M);throw Error(`Failed to finalize marketplace cache. Please manually delete the directory at ${j} if it exists and try again.
4713
4714Technical details: ${X}`)}return{marketplace:w,cachePath:Y}}catch(w){if(A&&Y&&!SB(q))try{await _.rm(Y,{recursive:!0,force:!0})}catch(j){N(`Warning: Failed to clean up temporary marketplace cache at ${Y}: ${d6(j)}`,{level:"warn"})}throw w}}async function Yd(q,K){let _=q;if(SB(q)&&!sfK(q.path))_={...q,path:Kd(q.path)};if(!NH6(_)){if(S18(_))throw Error(`Marketplace source '${yH6(_)}' is blocked by enterprise policy.`);let j=aK6()||[],H=FfK(),J=b17(_),M=`Marketplace source '${yH6(_)}'`;if(J)M+=` (${J})`;if(M+=" is blocked by enterprise policy.",j.length>0)M+=` Allowed sources: ${j.map((X)=>yH6(X)).join(", ")}`;else M+=" No external marketplaces are allowed.";if(_.source==="github"&&H.length>0)M+=`
4715
4716Tip: The shorthand "${_.repo}" assumes github.com. For internal GitHub Enterprise, use the full URL:

Callers 3

YdFunction · 0.85
q0KFunction · 0.85
cli.jsFile · 0.85

Calls 15

X8Function · 0.85
sK6Function · 0.85
azYFunction · 0.85
efKFunction · 0.85
tfKFunction · 0.85
CbFunction · 0.85
BaFunction · 0.85
x1Function · 0.85
H6Function · 0.85
NFunction · 0.85
g6Function · 0.85
m17Function · 0.85

Tested by

no test coverage detected