jsrepo 1.46.1 → 1.46.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.js +1 -1
- package/dist/chunk-6BJA5YI6.js +32 -0
- package/dist/chunk-6BJA5YI6.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/chunk-6C5BZIRY.js +0 -32
- package/dist/chunk-6C5BZIRY.js.map +0 -1
package/dist/api/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{m as CONFIG_FILE,l as MANIFEST_FILE,o as azure,p as bitbucket,d as blockSchema,e as categorySchema,h as configFileSchema,w as fetchManifest,v as fetchRaw,q as github,r as gitlab,s as http,i as manifestConfigFileSchema,f as manifestMeta,j as manifestSchema,g as peerDependencySchema,t as providers,u as selectProvider}from'../chunk-
|
|
1
|
+
export{m as CONFIG_FILE,l as MANIFEST_FILE,o as azure,p as bitbucket,d as blockSchema,e as categorySchema,h as configFileSchema,w as fetchManifest,v as fetchRaw,q as github,r as gitlab,s as http,i as manifestConfigFileSchema,f as manifestMeta,j as manifestSchema,g as peerDependencySchema,t as providers,u as selectProvider}from'../chunk-6BJA5YI6.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import*as o from'valibot';import y from'chalk';import {Octokit}from'octokit';var W=o.object({name:o.string(),category:o.string(),localDependencies:o.array(o.string()),dependencies:o.array(o.string()),devDependencies:o.array(o.string()),tests:o.boolean(),list:o.optional(o.boolean(),true),directory:o.string(),subdirectory:o.boolean(),files:o.array(o.string()),_imports_:o.record(o.string(),o.string())}),A=o.object({name:o.string(),blocks:o.array(W)}),Y=o.object({authors:o.optional(o.array(o.string())),bugs:o.optional(o.string()),description:o.optional(o.string()),homepage:o.optional(o.string()),repository:o.optional(o.string()),tags:o.optional(o.array(o.string()))}),G=o.record(o.string(),o.union([o.string(),o.object({version:o.string(),message:o.string()})])),Q=o.object({name:o.string(),path:o.string(),expectedPath:o.optional(o.string()),optional:o.optional(o.boolean(),false)}),J=o.object({...Q.entries,dependencies:o.optional(o.array(o.string())),devDependencies:o.optional(o.array(o.string()))}),N=o.object({meta:o.optional(Y),peerDependencies:o.optional(G),configFiles:o.optional(o.array(J)),categories:o.array(A)});var L="jsrepo-manifest.json",oe="jsrepo.json";var K="main",b={name:"azure",matches:r=>r.toLowerCase().startsWith("azure"),parse:(r,e)=>{let t=T(r,e);return {url:t.url,specifier:t.specifier}},baseUrl:r=>{let{owner:e,repoName:t}=T(r,{fullyQualified:false});return `https://dev.azure.com/${e}/_git/${t}`},state:async r=>{let{url:e,owner:t,project:s,repoName:c,ref:n,refs:i}=T(r,{fullyQualified:false});return {owner:t,repoName:c,ref:n,refs:i,project:s,url:e,provider:b}},resolveRaw:async(r,e)=>{if(r.provider.name!==b.name)throw new Error(`You passed the incorrect state object (${r.provider.name}) to the ${b.name} provider.`);let{owner:t,repoName:s,project:c,ref:n,refs:i}=r,a=i==="tags"?"tag":"branch";return new URL(`https://dev.azure.com/${t}/${c}/_apis/git/repositories/${s}/items?path=${e}&api-version=7.2-preview.1&versionDescriptor.version=${n}&versionDescriptor.versionType=${a}`)},authHeader:r=>["Authorization",`Bearer ${r}`],formatFetchError:(r,e)=>`There was an error fetching \`${y.bold(e)}\` from ${y.bold(r.url)}.
|
|
2
|
+
|
|
3
|
+
${y.bold("This may be for one of the following reasons:")}
|
|
4
|
+
1. Either \`${y.bold(e)}\` or the containing repository doesn't exist
|
|
5
|
+
2. Your repository path is incorrect (wrong branch, wrong tag)
|
|
6
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
7
|
+
4. The cached state for this git provider is incorrect (try using ${y.bold("--no-cache")})
|
|
8
|
+
`},T=(r,{fullyQualified:e})=>{let t=r.replaceAll(/(azure\/)/g,""),[s,c,n,...i]=t.split("/"),a;e&&(a=i.slice(i.length-2).join("/"),i=i.slice(0,i.length-2));let p=K,l="heads";return ["tags","heads"].includes(i[0])&&(l=i[0],i[1]&&i[1]!==""&&(p=i[1])),{url:`azure/${s}/${c}/${n}${p?`/${l}/${p}`:""}`,owner:s,repoName:n,project:c,ref:p,refs:l,specifier:a}};var h=(r,e)=>{for(let t of e)if(r.startsWith(t))return true;return false},ae=(r,e)=>{for(let t of e)if(r.endsWith(t))return true;return false};var F="master",m={name:"bitbucket",matches:r=>h(r.toLowerCase(),["bitbucket","https://bitbucket.org"]),parse:(r,e)=>{let t=O(r,e);return {url:t.url,specifier:t.specifier}},baseUrl:r=>{let{owner:e,repoName:t}=O(r,{fullyQualified:false});return `https://bitbucket.org/${e}/${t}`},state:async(r,{token:e,fetch:t=fetch}={})=>{let{url:s,owner:c,repoName:n,ref:i}=O(r,{fullyQualified:false});if(i===void 0)try{let a=new Headers;if(e!==void 0){let[l,g]=m.authHeader(e);a.append(l,g);}let p=await t(`https://api.bitbucket.org/2.0/repositories/${c}/${n}`,{headers:a});p.ok?i=(await p.json()).mainbranch.name:i=F;}catch{i=F;}return {owner:c,ref:i,repoName:n,url:s,provider:m}},resolveRaw:async(r,e)=>{if(r.provider.name!==m.name)throw new Error(`You passed the incorrect state object (${r.provider.name}) to the ${m.name} provider.`);let{owner:t,repoName:s,ref:c}=r;return new URL(e,`https://api.bitbucket.org/2.0/repositories/${t}/${s}/src/${c}/`)},authHeader:r=>["Authorization",`Bearer ${r}`],formatFetchError:(r,e)=>`There was an error fetching \`${y.bold(e)}\` from ${y.bold(r.url)}.
|
|
9
|
+
|
|
10
|
+
${y.bold("This may be for one of the following reasons:")}
|
|
11
|
+
1. Either \`${y.bold(e)}\` or the containing repository doesn't exist
|
|
12
|
+
2. Your repository path is incorrect (wrong branch, wrong tag)
|
|
13
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
14
|
+
4. The cached state for this git provider is incorrect (try using ${y.bold("--no-cache")})
|
|
15
|
+
`},O=(r,{fullyQualified:e=false})=>{let t=r.replaceAll(/(https:\/\/bitbucket.org\/)|(bitbucket\/)/g,""),[s,c,...n]=t.split("/"),i;e&&(i=n.slice(n.length-2).join("/"),n=n.slice(0,n.length-2));let a;return n[0]==="src"&&(a=n[1]),{url:`bitbucket/${s}/${c}${a?`/src/${a}`:""}`,specifier:i,owner:s,repoName:c,ref:a}};var _="main",E={name:"github",matches:r=>h(r.toLowerCase(),["github","https://github.com"]),parse:(r,e)=>{let t=k(r,e);return {url:t.url,specifier:t.specifier}},baseUrl:r=>{let{owner:e,repoName:t}=k(r,{fullyQualified:false});return `https://github.com/${e}/${t}`},state:async(r,{token:e}={})=>{let{url:t,owner:s,repoName:c,ref:n}=k(r,{fullyQualified:false}),i=new Octokit({auth:e}),a="heads";if(n===void 0)try{let{data:p}=await i.rest.repos.get({owner:s,repo:c});n=p.default_branch;}catch{n=_;}else if(n!==_)try{let{data:p}=await i.rest.git.listMatchingRefs({owner:s,repo:c,ref:"tags"});p.some(l=>l.ref===`refs/tags/${n}`)&&(a="tags");}catch{a="heads";}return {owner:s,refs:a,ref:n,repoName:c,url:t,provider:E}},resolveRaw:async(r,e)=>{if(r.provider.name!==E.name)throw new Error(`You passed the incorrect state object (${r.provider.name}) to the ${E.name} provider.`);let{owner:t,repoName:s,refs:c,ref:n}=r;return new URL(e,`https://raw.githubusercontent.com/${t}/${s}/refs/${c}/${n}/`)},authHeader:r=>["Authorization",`token ${r}`],formatFetchError:(r,e)=>`There was an error fetching \`${y.bold(e)}\` from ${y.bold(r.url)}.
|
|
16
|
+
|
|
17
|
+
${y.bold("This may be for one of the following reasons:")}
|
|
18
|
+
1. Either \`${y.bold(e)}\` or the containing repository doesn't exist
|
|
19
|
+
2. Your repository path is incorrect (wrong branch, wrong tag)
|
|
20
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
21
|
+
4. The cached state for this git provider is incorrect (try using ${y.bold("--no-cache")})
|
|
22
|
+
`},k=(r,{fullyQualified:e=false})=>{let t=r.replaceAll(/(https:\/\/github.com\/)|(github\/)/g,""),[s,c,...n]=t.split("/"),i;e&&(i=n.slice(n.length-2).join("/"),n=n.slice(0,n.length-2));let a;return n.length>0&&n[0]==="tree"&&(a=n[1]),{url:`github/${s}/${c}${a?`/tree/${a}`:""}`,specifier:i,owner:s,repoName:c,ref:a}};var f=(...r)=>r.map(e=>q(e)).filter(Boolean).join("/"),q=r=>{let e=X(r);return Z(e)};var X=r=>{let e=r;return e.startsWith("/")&&(e=e.slice(1)),e};var Z=r=>{let e=r;return e.endsWith("/")&&(e=e.slice(0,e.length-1)),e},B=r=>{let e=r;return e.endsWith("/")||(e=`${e}/`),e};var z="main",I="https://gitlab.com",v={name:"gitlab",matches:r=>h(r.toLowerCase(),["gitlab/","gitlab:","https://gitlab.com"]),parse:(r,e)=>{let t=j(r,e);return {url:t.url,specifier:t.specifier}},baseUrl:r=>{let{baseUrl:e,owner:t,repoName:s}=j(r,{fullyQualified:false});return f(e,t,s)},state:async(r,{token:e,fetch:t=fetch}={})=>{let{baseUrl:s,url:c,owner:n,repoName:i,ref:a}=j(r,{fullyQualified:false});if(a===void 0)try{let p=new Headers;if(e!==void 0){let[g,D]=v.authHeader(e);p.append(g,D);}let l=await t(f(s,`api/v4/projects/${encodeURIComponent(`${n}/${i}`)}`),{headers:p});l.ok?a=(await l.json()).default_branch:a=z;}catch{a=z;}return {owner:n,repoName:i,ref:a,baseUrl:s,url:c,provider:v}},resolveRaw:async(r,e)=>{if(r.provider.name!==v.name)throw new Error(`You passed the incorrect state object (${r.provider.name}) to the ${v.name} provider.`);let{baseUrl:t,owner:s,repoName:c,ref:n}=r;return new URL(f(t,`api/v4/projects/${encodeURIComponent(`${s}/${c}`)}`,`repository/files/${encodeURIComponent(e)}/raw?ref=${n}`))},authHeader:r=>["PRIVATE-TOKEN",r],formatFetchError:(r,e,t)=>`There was an error fetching \`${y.bold(e)}\` from ${y.bold(r.url)}: ${t}.
|
|
23
|
+
|
|
24
|
+
${y.bold("This may be for one of the following reasons:")}
|
|
25
|
+
1. Either \`${y.bold(e)}\` or the containing repository doesn't exist
|
|
26
|
+
2. Your repository path is incorrect (wrong branch, wrong tag)
|
|
27
|
+
3. You are using an expired access token or a token that doesn't have access to this repository
|
|
28
|
+
4. The cached state for this git provider is incorrect (try using ${y.bold("--no-cache")})
|
|
29
|
+
`},j=(r,{fullyQualified:e})=>{let t=I;r.startsWith("gitlab:")&&(t=new URL(r.slice(7)).origin);let s=r.replaceAll(/gitlab\/|https:\/\/gitlab\.com\/|gitlab:https?:\/\/[^/]+\//g,""),[c,n,...i]=s.split("/"),a;e&&(a=i.slice(i.length-2).join("/"),i=i.slice(0,i.length-2));let p;if(i[0]==="-"&&i[1]==="tree")if(i[2].includes("?")){let[g]=i[2].split("?");p=g;}else p=i[2];return {url:f(t!==I?`gitlab:${t}`:t,`${c}/${n}${p?`/-/tree/${p}`:""}`),baseUrl:t,owner:c,repoName:n,ref:p,specifier:a}};var R={name:"http",matches:r=>{try{return new URL(r),!0}catch{return false}},parse:(r,e)=>{let t=U(r,e);return {url:t.url,specifier:t.specifier}},baseUrl:r=>{let{url:e}=U(r,{fullyQualified:false});return new URL(e).origin},state:async r=>{let{url:e}=U(r,{fullyQualified:false});return {url:e,provider:R}},resolveRaw:async(r,e)=>{if(r.provider.name!==R.name)throw new Error(`You passed the incorrect state object (${r.provider.name}) to the ${R.name} provider.`);return new URL(e,r.url)},authHeader:r=>["Authorization",`Bearer ${r}`],formatFetchError:(r,e,t)=>`There was an error fetching ${y.bold(new URL(e,r.url).toString())}
|
|
30
|
+
|
|
31
|
+
${y.bold(t)}`},U=(r,{fullyQualified:e})=>{let t=new URL(r),s=t.pathname.split("/"),c;return e&&(c=s.slice(s.length-2).join("/"),s=s.slice(0,s.length-2)),{url:B(f(t.origin,...s)),specifier:c}};var x=class{_result;constructor(e){this._result=e;}match(e,t){return this._result.ok?e(this._result.val):t(this._result.err)}map(e){return this.match(t=>d(e(t)),t=>u(t))}mapOr(e,t){return this.match(s=>t(s),s=>e)}mapOrElse(e,t){return this.match(s=>t(s),s=>e(s))}mapErr(e){return this.match(t=>d(t),t=>u(e(t)))}mapErrOr(e,t){return this.match(s=>e,s=>t(s))}mapErrOrElse(e,t){return this.match(s=>e(s),s=>t(s))}isOk(){return this.match(()=>true,()=>false)}isErr(){return this.match(()=>false,()=>true)}unwrap(){return this.match(e=>e,()=>{throw new Error("Attempted to call `.unwrap()` on a non `Ok` value.")})}unwrapErr(){return this.match(()=>{throw new Error("Attempted to call `.unwrapErr()` on a non `Err` value.")},e=>e)}unwrapOr(e){return this.match(t=>t,t=>e)}unwrapErrOr(e){return this.match(()=>e,t=>t)}unwrapOrElse(e){return this.match(t=>t,t=>e(t))}unwrapErrOrElse(e){return this.match(t=>e(t),t=>t)}expect(e){return this.match(t=>t,()=>{throw new Error(e)})}expectErr(e){return this.match(()=>{throw new Error(e)},t=>t)}},d=r=>new x({ok:true,val:r}),u=r=>new x({ok:false,err:r});var M=r=>{let e;try{e=JSON.parse(r);}catch(s){return u(`Error parsing manifest json ${s}`)}if(Array.isArray(e)){let s=o.safeParse(o.array(A),e);return s.success?d({categories:s.output}):u(`Error parsing categories (array-based config) ${s.issues.join(" ")}`)}let t=o.safeParse(N,e);return t.success?d(t.output):u(`Error parsing manifest ${t.issues.join(" ")}`)};var ee=[E,v,m,b,R],Ne=r=>ee.find(t=>t.matches(r)),re=async(r,e,{verbose:t,fetch:s=fetch,token:c}={})=>{let n=await r.provider.resolveRaw(r,e);t?.(`Trying to fetch from ${n}`);try{let i=new Headers;if(c!==void 0&&r.provider.authHeader){let[p,l]=r.provider.authHeader(c);i.append(p,l);}let a=await s(n,{headers:i});return t?.(`Got a response from ${n} ${a.status} ${a.statusText}`),a.ok?d(await a.text()):u(r.provider.formatFetchError(r,e,`${a.status} ${a.statusText}`))}catch(i){return u(r.provider.formatFetchError(r,e,i))}},Le=async(r,{fetch:e=fetch,...t}={})=>{let s=await re(r,L,{fetch:e,...t});return s.isErr()?u(s.unwrapErr()):M(s.unwrap())};export{d as a,u as b,f as c,W as d,A as e,Y as f,G as g,Q as h,J as i,N as j,ae as k,L as l,oe as m,M as n,b as o,m as p,E as q,v as r,R as s,ee as t,Ne as u,re as v,Le as w};//# sourceMappingURL=chunk-6BJA5YI6.js.map
|
|
32
|
+
//# sourceMappingURL=chunk-6BJA5YI6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/constants.ts","../src/utils/registry-providers/azure.ts","../src/utils/blocks/ts/strings.ts","../src/utils/registry-providers/bitbucket.ts","../src/utils/registry-providers/github.ts","../src/utils/blocks/ts/url.ts","../src/utils/registry-providers/gitlab.ts","../src/utils/registry-providers/http.ts","../src/utils/blocks/ts/result.ts","../src/utils/manifest.ts","../src/utils/registry-providers/index.ts"],"names":["blockSchema","categorySchema","manifestMeta","peerDependencySchema","configFileSchema","manifestConfigFileSchema","manifestSchema","MANIFEST_FILE","CONFIG_FILE","DEFAULT_BRANCH","azure","url","opts","parsed","parseUrl","owner","repoName","normalizedUrl","project","ref","refs","state","resourcePath","versionType","token","filePath","color","fullyQualified","repo","rest","specifier","startsWithOneOf","str","strings","s","endsWithOneOf","bitbucket","f","headers","key","value","response","github","octokit","Octokit","tags","tag","join","segments","removeLeadingAndTrailingSlash","segment","newSegment","removeLeadingSlash","removeTrailingSlash","addTrailingSlash","BASE_URL","gitlab","baseUrl","error","tempRef","http","u","parsedUrl","Result","result","success","failure","fn","val","Ok","err","Err","defaultVal","_","def","message","parseManifest","json","validated","P","providers","selectProvider","p","fetchRaw","verbose","fetchManifest","manifest"],"mappings":"6EAEaA,IAAAA,CAAAA,CAAgB,SAAO,CACnC,IAAA,CAAQ,UACR,CAAA,QAAA,CAAY,UACZ,CAAA,iBAAA,CAAqB,QAAQ,CAAO,CAAA,MAAA,EAAC,EACrC,YAAgB,CAAA,CAAA,CAAA,KAAA,CAAQ,UAAQ,CAAA,CAChC,gBAAmB,CAAQ,CAAA,KAAA,CAAA,CAA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CAAS6B,MAAAA,CAAAA,CAAK,CACb,OAAOC,EAAIlD,CAAM,CAAA,QAAA,CAAS,gBAAiBA,CAAAA,CAAAA,CAAOC,EAAcgD,CAAG,CAAC,CACrE,CACD,EAEae,EAAgB,CAAA,MAC5BhE,CACA,CAAA,CAAE,KAAOgB,CAAAA,CAAAA,CAAI,KAAO,CAAA,GAAGR,CAAK,CAA2B,CAAA,EAChB,GAAA,CACvC,IAAMyD,CAAW,CAAA,MAAMH,EAAS9D,CAAAA,CAAAA,CAAOd,EAAe,CAAE,KAAA,CAAO8B,CAAG,CAAA,GAAGR,CAAK,CAAC,CAAA,CAE3E,OAAIyD,CAAAA,CAAS,OAAgBf,CAAAA,CAAAA,CAAIe,CAAS,CAAA,SAAA,EAAW,CAE9CV,CAAAA,CAAAA,CAAcU,CAAS,CAAA,MAAA,EAAQ,CACvC","file":"chunk-6BJA5YI6.js","sourcesContent":["import * as v from 'valibot';\n\nexport const blockSchema = v.object({\n\tname: v.string(),\n\tcategory: v.string(),\n\tlocalDependencies: v.array(v.string()),\n\tdependencies: v.array(v.string()),\n\tdevDependencies: v.array(v.string()),\n\ttests: v.boolean(),\n\tlist: v.optional(v.boolean(), true),\n\t/** Where to find the block relative to root */\n\tdirectory: v.string(),\n\tsubdirectory: v.boolean(),\n\tfiles: v.array(v.string()),\n\t_imports_: v.record(v.string(), v.string()),\n});\n\nexport const categorySchema = v.object({\n\tname: v.string(),\n\tblocks: v.array(blockSchema),\n});\n\nexport const manifestMeta = v.object({\n\tauthors: v.optional(v.array(v.string())),\n\tbugs: v.optional(v.string()),\n\tdescription: v.optional(v.string()),\n\thomepage: v.optional(v.string()),\n\trepository: v.optional(v.string()),\n\ttags: v.optional(v.array(v.string())),\n});\n\nexport const peerDependencySchema = v.record(\n\tv.string(),\n\tv.union([\n\t\tv.string(),\n\t\tv.object({\n\t\t\tversion: v.string(),\n\t\t\tmessage: v.string(),\n\t\t}),\n\t])\n);\n\nexport type PeerDependency = v.InferOutput<typeof peerDependencySchema>;\n\nexport const configFileSchema = v.object({\n\tname: v.string(),\n\tpath: v.string(),\n\texpectedPath: v.optional(v.string()),\n\toptional: v.optional(v.boolean(), false),\n});\n\nexport type ConfigFile = v.InferOutput<typeof configFileSchema>;\n\nexport const manifestConfigFileSchema = v.object({\n\t...configFileSchema.entries,\n\tdependencies: v.optional(v.array(v.string())),\n\tdevDependencies: v.optional(v.array(v.string())),\n});\n\nexport const manifestSchema = v.object({\n\tmeta: v.optional(manifestMeta),\n\tpeerDependencies: v.optional(peerDependencySchema),\n\tconfigFiles: v.optional(v.array(manifestConfigFileSchema)),\n\tcategories: v.array(categorySchema),\n});\n\nexport type Meta = v.InferOutput<typeof manifestMeta>;\n\nexport type Category = v.InferOutput<typeof categorySchema>;\n\nexport type Block = v.InferOutput<typeof blockSchema>;\n\nexport type Manifest = v.InferOutput<typeof manifestSchema>;\n","export const MANIFEST_FILE = 'jsrepo-manifest.json';\nexport const CONFIG_FILE = 'jsrepo.json';\n","import color from 'chalk';\nimport type { ParseOptions, RegistryProvider, RegistryProviderState } from './types';\n\nconst DEFAULT_BRANCH = 'main';\n\nexport interface AzureProviderState extends RegistryProviderState {\n\towner: string;\n\trepoName: string;\n\tproject: string;\n\trefs: 'heads' | 'tags';\n\tref: string;\n}\n\n/** Valid paths\n *\n * `azure/<org>/<project>/<repo>/(tags|heads)/<ref>`\n */\nexport const azure: RegistryProvider = {\n\tname: 'azure',\n\n\tmatches: (url) => url.toLowerCase().startsWith('azure'),\n\n\tparse: (url, opts) => {\n\t\tconst parsed = parseUrl(url, opts);\n\n\t\treturn {\n\t\t\turl: parsed.url,\n\t\t\tspecifier: parsed.specifier,\n\t\t};\n\t},\n\n\tbaseUrl: (url) => {\n\t\tconst { owner, repoName } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn `https://dev.azure.com/${owner}/_git/${repoName}`;\n\t},\n\n\tstate: async (url) => {\n\t\tconst {\n\t\t\turl: normalizedUrl,\n\t\t\towner,\n\t\t\tproject,\n\t\t\trepoName,\n\t\t\tref,\n\t\t\trefs,\n\t\t} = parseUrl(url, { fullyQualified: false });\n\n\t\treturn {\n\t\t\towner,\n\t\t\trepoName,\n\t\t\tref,\n\t\t\trefs,\n\t\t\tproject,\n\t\t\turl: normalizedUrl,\n\t\t\tprovider: azure,\n\t\t} satisfies AzureProviderState;\n\t},\n\n\tresolveRaw: async (state, resourcePath) => {\n\t\t// essentially assert that we are using the correct state\n\t\tif (state.provider.name !== azure.name) {\n\t\t\tthrow new Error(\n\t\t\t\t`You passed the incorrect state object (${state.provider.name}) to the ${azure.name} provider.`\n\t\t\t);\n\t\t}\n\n\t\tconst { owner, repoName, project, ref, refs } = state as AzureProviderState;\n\n\t\tconst versionType = refs === 'tags' ? 'tag' : 'branch';\n\n\t\treturn new URL(\n\t\t\t`https://dev.azure.com/${owner}/${project}/_apis/git/repositories/${repoName}/items?path=${resourcePath}&api-version=7.2-preview.1&versionDescriptor.version=${ref}&versionDescriptor.versionType=${versionType}`\n\t\t);\n\t},\n\n\tauthHeader: (token) => ['Authorization', `Bearer ${token}`],\n\n\tformatFetchError: (state, filePath) => {\n\t\treturn `There was an error fetching \\`${color.bold(filePath)}\\` from ${color.bold(state.url)}.\n\n${color.bold('This may be for one of the following reasons:')}\n1. Either \\`${color.bold(filePath)}\\` or the containing repository doesn't exist\n2. Your repository path is incorrect (wrong branch, wrong tag)\n3. You are using an expired access token or a token that doesn't have access to this repository\n4. The cached state for this git provider is incorrect (try using ${color.bold('--no-cache')})\n`;\n\t},\n};\n\nconst parseUrl = (\n\turl: string,\n\t{ fullyQualified }: ParseOptions\n): {\n\turl: string;\n\towner: string;\n\tproject: string;\n\trepoName: string;\n\tref: string;\n\trefs: 'tags' | 'heads';\n\tspecifier?: string;\n} => {\n\tconst repo = url.replaceAll(/(azure\\/)/g, '');\n\n\tlet [owner, project, repoName, ...rest] = repo.split('/');\n\n\tlet specifier: string | undefined = undefined;\n\n\tif (fullyQualified) {\n\t\tspecifier = rest.slice(rest.length - 2).join('/');\n\n\t\trest = rest.slice(0, rest.length - 2);\n\t}\n\n\tlet ref: string = DEFAULT_BRANCH;\n\n\t// checks if the type of the ref is tags or heads\n\tlet refs: 'heads' | 'tags' = 'heads';\n\n\tif (['tags', 'heads'].includes(rest[0])) {\n\t\trefs = rest[0] as 'heads' | 'tags';\n\n\t\tif (rest[1] && rest[1] !== '') {\n\t\t\tref = rest[1];\n\t\t}\n\t}\n\n\treturn {\n\t\turl: `azure/${owner}/${project}/${repoName}${ref ? `/${refs}/${ref}` : ''}`,\n\t\towner: owner,\n\t\trepoName: repoName,\n\t\tproject,\n\t\tref,\n\t\trefs,\n\t\tspecifier,\n\t};\n};\n","/*\n\tInstalled from github/ieedan/std\n*/\n\n/** Returns true if `str` starts with one of the provided `strings`.\n *\n * ## Usage\n * ```ts\n * startsWithOneOf('ab', 'a', 'c'); // true\n * startsWithOneOf('cc', 'a', 'b'); // false\n * ```\n *\n * @param str\n * @param strings\n * @returns\n */\nexport const startsWithOneOf = (str: string, strings: string[]): boolean => {\n\tfor (const s of strings) {\n\t\tif (str.startsWith(s)) return true;\n\t}\n\n\treturn false;\n};\n\n/** Returns true if `str` starts with one of the provided `strings`.\n *\n * ## Usage\n * ```ts\n * endsWithOneOf('cb', 'a', 'b'); // true\n * endsWithOneOf('cc', 'a', 'b'); // false\n * ```\n *\n * @param str\n * @param strings\n * @returns\n */\nexport const endsWithOneOf = (str: string, strings: string[]): boolean => {\n\tfor (const s of strings) {\n\t\tif (str.endsWith(s)) return true;\n\t}\n\n\treturn false;\n};\n","import color from 'chalk';\nimport { startsWithOneOf } from '../blocks/ts/strings';\nimport type { ParseOptions, RegistryProvider, RegistryProviderState } from './types';\n\nconst DEFAULT_BRANCH = 'master';\n\nexport interface BitBucketProviderState extends RegistryProviderState {\n\towner: string;\n\trepoName: string;\n\tref: string;\n}\n\n/** Valid paths\n *\n * `bitbucket/ieedan/std`\n *\n * `https://bitbucket.org/ieedan/std/src/main/`\n *\n * `https://bitbucket.org/ieedan/std/src/next/`\n *\n * `https://bitbucket.org/ieedan/std/src/v2.0.0/`\n *\n */\nexport const bitbucket: RegistryProvider = {\n\tname: 'bitbucket',\n\n\tmatches: (url) => startsWithOneOf(url.toLowerCase(), ['bitbucket', 'https://bitbucket.org']),\n\n\tparse: (url, opts) => {\n\t\tconst parsed = parseUrl(url, opts);\n\n\t\treturn {\n\t\t\turl: parsed.url,\n\t\t\tspecifier: parsed.specifier,\n\t\t};\n\t},\n\n\tbaseUrl: (url) => {\n\t\tconst { owner, repoName } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn `https://bitbucket.org/${owner}/${repoName}`;\n\t},\n\n\tstate: async (url, { token, fetch: f = fetch } = {}) => {\n\t\tlet { url: normalizedUrl, owner, repoName, ref } = parseUrl(url, { fullyQualified: false });\n\n\t\t// fetch default branch if ref was not provided\n\t\tif (ref === undefined) {\n\t\t\ttry {\n\t\t\t\tconst headers = new Headers();\n\n\t\t\t\tif (token !== undefined) {\n\t\t\t\t\tconst [key, value] = bitbucket.authHeader!(token);\n\n\t\t\t\t\theaders.append(key, value);\n\t\t\t\t}\n\n\t\t\t\tconst response = await f(\n\t\t\t\t\t`https://api.bitbucket.org/2.0/repositories/${owner}/${repoName}`,\n\t\t\t\t\t{\n\t\t\t\t\t\theaders,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif (response.ok) {\n\t\t\t\t\tconst data = await response.json();\n\n\t\t\t\t\t// @ts-ignore yes but we know\n\t\t\t\t\tref = data.mainbranch.name as string;\n\t\t\t\t} else {\n\t\t\t\t\tref = DEFAULT_BRANCH;\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// well find out it isn't correct later with a better error\n\t\t\t\tref = DEFAULT_BRANCH;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\towner,\n\t\t\tref,\n\t\t\trepoName,\n\t\t\turl: normalizedUrl,\n\t\t\tprovider: bitbucket,\n\t\t} satisfies BitBucketProviderState;\n\t},\n\n\tresolveRaw: async (state, resourcePath) => {\n\t\t// essentially assert that we are using the correct state\n\t\tif (state.provider.name !== bitbucket.name) {\n\t\t\tthrow new Error(\n\t\t\t\t`You passed the incorrect state object (${state.provider.name}) to the ${bitbucket.name} provider.`\n\t\t\t);\n\t\t}\n\n\t\tconst { owner, repoName, ref } = state as BitBucketProviderState;\n\n\t\treturn new URL(\n\t\t\tresourcePath,\n\t\t\t`https://api.bitbucket.org/2.0/repositories/${owner}/${repoName}/src/${ref}/`\n\t\t);\n\t},\n\n\tauthHeader: (token) => ['Authorization', `Bearer ${token}`],\n\n\tformatFetchError: (state, filePath) => {\n\t\treturn `There was an error fetching \\`${color.bold(filePath)}\\` from ${color.bold(state.url)}.\n\n${color.bold('This may be for one of the following reasons:')}\n1. Either \\`${color.bold(filePath)}\\` or the containing repository doesn't exist\n2. Your repository path is incorrect (wrong branch, wrong tag)\n3. You are using an expired access token or a token that doesn't have access to this repository\n4. The cached state for this git provider is incorrect (try using ${color.bold('--no-cache')})\n`;\n\t},\n};\n\nconst parseUrl = (\n\turl: string,\n\t{ fullyQualified = false }: ParseOptions\n): { url: string; owner: string; repoName: string; ref?: string; specifier?: string } => {\n\tconst repo = url.replaceAll(/(https:\\/\\/bitbucket.org\\/)|(bitbucket\\/)/g, '');\n\n\tlet [owner, repoName, ...rest] = repo.split('/');\n\n\tlet specifier: string | undefined;\n\n\tif (fullyQualified) {\n\t\tspecifier = rest.slice(rest.length - 2).join('/');\n\n\t\trest = rest.slice(0, rest.length - 2);\n\t}\n\n\tlet ref: string | undefined;\n\n\tif (rest[0] === 'src') {\n\t\tref = rest[1];\n\t}\n\n\treturn {\n\t\turl: `bitbucket/${owner}/${repoName}${ref ? `/src/${ref}` : ''}`,\n\t\tspecifier,\n\t\towner,\n\t\trepoName: repoName,\n\t\tref,\n\t};\n};\n","import color from 'chalk';\nimport { Octokit } from 'octokit';\nimport { startsWithOneOf } from '../blocks/ts/strings';\nimport type { ParseOptions, RegistryProvider, RegistryProviderState } from './types';\n\nconst DEFAULT_BRANCH = 'main';\n\nexport interface GitHubProviderState extends RegistryProviderState {\n\towner: string;\n\trepoName: string;\n\trefs: 'tags' | 'heads';\n\tref: string;\n}\n\n/** Valid paths\n *\n * `https://github.com/<owner>/<repo>`\n *\n * `github/<owner>/<repo>`\n *\n * `github/<owner>/<repo>/tree/<ref>`\n */\nexport const github: RegistryProvider = {\n\tname: 'github',\n\n\tmatches: (url) => startsWithOneOf(url.toLowerCase(), ['github', 'https://github.com']),\n\n\tparse: (url, opts) => {\n\t\tconst parsed = parseUrl(url, opts);\n\n\t\treturn {\n\t\t\turl: parsed.url,\n\t\t\tspecifier: parsed.specifier,\n\t\t};\n\t},\n\n\tbaseUrl: (url) => {\n\t\tconst { owner, repoName } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn `https://github.com/${owner}/${repoName}`;\n\t},\n\n\tstate: async (url, { token } = {}) => {\n\t\tlet { url: normalizedUrl, owner, repoName, ref } = parseUrl(url, { fullyQualified: false });\n\n\t\tconst octokit = new Octokit({ auth: token });\n\n\t\t// checks if the type of the ref is tags or heads\n\t\tlet refs: 'heads' | 'tags' = 'heads';\n\n\t\t// fetch default branch if ref was not provided\n\t\tif (ref === undefined) {\n\t\t\ttry {\n\t\t\t\tconst { data: repo } = await octokit.rest.repos.get({ owner, repo: repoName });\n\n\t\t\t\tref = repo.default_branch;\n\t\t\t} catch {\n\t\t\t\t// we just want to continue on blissfully unaware the user will get an error later\n\t\t\t\tref = DEFAULT_BRANCH;\n\t\t\t}\n\t\t} else {\n\t\t\t// no need to check if ref is main\n\n\t\t\t// this isn't a double case it's possible that DEFAULT_BRANCH and repo.default_branch are not equal\n\t\t\tif (ref !== DEFAULT_BRANCH) {\n\t\t\t\ttry {\n\t\t\t\t\tconst { data: tags } = await octokit.rest.git.listMatchingRefs({\n\t\t\t\t\t\towner,\n\t\t\t\t\t\trepo: repoName,\n\t\t\t\t\t\tref: 'tags',\n\t\t\t\t\t});\n\n\t\t\t\t\tif (tags.some((tag) => tag.ref === `refs/tags/${ref}`)) {\n\t\t\t\t\t\trefs = 'tags';\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\trefs = 'heads';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\towner,\n\t\t\trefs,\n\t\t\tref,\n\t\t\trepoName,\n\t\t\turl: normalizedUrl,\n\t\t\tprovider: github,\n\t\t} satisfies GitHubProviderState;\n\t},\n\n\tresolveRaw: async (state, resourcePath) => {\n\t\t// essentially assert that we are using the correct state\n\t\tif (state.provider.name !== github.name) {\n\t\t\tthrow new Error(\n\t\t\t\t`You passed the incorrect state object (${state.provider.name}) to the ${github.name} provider.`\n\t\t\t);\n\t\t}\n\n\t\tconst { owner, repoName, refs, ref } = state as GitHubProviderState;\n\n\t\treturn new URL(\n\t\t\tresourcePath,\n\t\t\t`https://raw.githubusercontent.com/${owner}/${repoName}/refs/${refs}/${ref}/`\n\t\t);\n\t},\n\n\tauthHeader: (token) => ['Authorization', `token ${token}`],\n\n\tformatFetchError: (state, filePath) => {\n\t\treturn `There was an error fetching \\`${color.bold(filePath)}\\` from ${color.bold(state.url)}.\n\n${color.bold('This may be for one of the following reasons:')}\n1. Either \\`${color.bold(filePath)}\\` or the containing repository doesn't exist\n2. Your repository path is incorrect (wrong branch, wrong tag)\n3. You are using an expired access token or a token that doesn't have access to this repository\n4. The cached state for this git provider is incorrect (try using ${color.bold('--no-cache')})\n`;\n\t},\n};\n\nconst parseUrl = (\n\turl: string,\n\t{ fullyQualified = false }: ParseOptions\n): { url: string; owner: string; repoName: string; ref?: string; specifier?: string } => {\n\tconst repo = url.replaceAll(/(https:\\/\\/github.com\\/)|(github\\/)/g, '');\n\n\tlet [owner, repoName, ...rest] = repo.split('/');\n\n\tlet specifier: string | undefined;\n\n\tif (fullyQualified) {\n\t\tspecifier = rest.slice(rest.length - 2).join('/');\n\n\t\trest = rest.slice(0, rest.length - 2);\n\t}\n\n\tlet ref: string | undefined;\n\n\tif (rest.length > 0) {\n\t\tif (rest[0] === 'tree') {\n\t\t\tref = rest[1];\n\t\t}\n\t}\n\n\treturn {\n\t\turl: `github/${owner}/${repoName}${ref ? `/tree/${ref}` : ''}`,\n\t\tspecifier,\n\t\towner,\n\t\trepoName: repoName,\n\t\tref,\n\t};\n};\n","/*\n\tInstalled from github/ieedan/std\n*/\n\n/** Joins the segments into a single url correctly handling leading and trailing slashes in each segment.\n *\n * ## Usage\n * ```ts\n * const url = join('https://example.com', '', 'api/', '/examples/');\n *\n * console.log(url); // https://example.com/api/examples\n * ```\n *\n * @param segments\n * @returns\n */\nconst join = (...segments: string[]) => {\n\treturn segments\n\t\t.map((s) => removeLeadingAndTrailingSlash(s))\n\t\t.filter(Boolean)\n\t\t.join('/');\n};\n\n/** Removes the leading and trailing slash from the segment (if they exist)\n * ## Usage\n * ```ts\n * const segment = removeLeadingAndTrailingSlash('/example/');\n *\n * console.log(segment); // 'example'\n * ```\n *\n * @param segment\n * @returns\n */\nconst removeLeadingAndTrailingSlash = (segment: string) => {\n\tconst newSegment = removeLeadingSlash(segment);\n\treturn removeTrailingSlash(newSegment);\n};\n\n/** Adds a leading and trailing to the beginning and end of the segment (if it doesn't already exist)\n *\n * ## Usage\n * ```ts\n * const segment = addLeadingAndTrailingSlash('example');\n *\n * console.log(segment); // '/example/'\n * ```\n *\n * @param segment\n * @returns\n */\nconst addLeadingAndTrailingSlash = (segment: string) => {\n\t// this is a weird case so feel free to handle it however you think it makes the most sense\n\tif (segment === '') return '//';\n\n\tconst newSegment = addLeadingSlash(segment);\n\treturn addTrailingSlash(newSegment);\n};\n\n/** Removes the leading slash from the beginning of the segment (if it exists)\n *\n * ## Usage\n * ```ts\n * const segment = removeLeadingSlash('/example');\n *\n * console.log(segment); // 'example'\n * ```\n *\n * @param segment\n * @returns\n */\nconst removeLeadingSlash = (segment: string): string => {\n\tlet newSegment = segment;\n\tif (newSegment.startsWith('/')) {\n\t\tnewSegment = newSegment.slice(1);\n\t}\n\n\treturn newSegment;\n};\n\n/** Adds a leading slash to the beginning of the segment (if it doesn't already exist)\n *\n * ## Usage\n * ```ts\n * const segment = addLeadingSlash('example');\n *\n * console.log(segment); // '/example'\n * ```\n *\n * @param segment\n * @returns\n */\nconst addLeadingSlash = (segment: string): string => {\n\tlet newSegment = segment;\n\tif (!newSegment.startsWith('/')) {\n\t\tnewSegment = `/${newSegment}`;\n\t}\n\n\treturn newSegment;\n};\n\n/** Removes the trailing slash from the end of the segment (if it exists)\n *\n * ## Usage\n * ```ts\n * const segment = removeTrailingSlash('example/');\n *\n * console.log(segment); // 'example'\n * ```\n * @param segment\n * @returns\n */\nconst removeTrailingSlash = (segment: string): string => {\n\tlet newSegment = segment;\n\tif (newSegment.endsWith('/')) {\n\t\tnewSegment = newSegment.slice(0, newSegment.length - 1);\n\t}\n\n\treturn newSegment;\n};\n\n/** Adds a trailing slash to the end of the segment (if it doesn't already exist)\n *\n * ## Usage\n * ```ts\n * const segment = addTrailingSlash('example');\n *\n * console.log(segment); // 'example/'\n * ```\n *\n * @param segment\n * @returns\n */\nconst addTrailingSlash = (segment: string): string => {\n\tlet newSegment = segment;\n\tif (!newSegment.endsWith('/')) {\n\t\tnewSegment = `${newSegment}/`;\n\t}\n\n\treturn newSegment;\n};\n\n/** Removes the last segment of the url.\n *\n * ## Usage\n * ```ts\n * const url = upOneLevel('/first/second');\n *\n * console.log(url); // '/first'\n * ```\n *\n * @param url\n */\nconst upOneLevel = (url: string): string => {\n\tif (url === '/') return url;\n\n\tconst lastIndex = removeTrailingSlash(url).lastIndexOf('/');\n\n\treturn url.slice(0, url.length - lastIndex - 1);\n};\n\nexport {\n\tjoin,\n\tremoveLeadingSlash,\n\tremoveTrailingSlash,\n\taddTrailingSlash,\n\taddLeadingSlash,\n\taddLeadingAndTrailingSlash,\n\tremoveLeadingAndTrailingSlash,\n\tupOneLevel,\n};\n","import color from 'chalk';\nimport { startsWithOneOf } from '../blocks/ts/strings';\nimport * as u from '../blocks/ts/url';\nimport type { ParseOptions, RegistryProvider, RegistryProviderState } from './types';\n\nconst DEFAULT_BRANCH = 'main';\nconst BASE_URL = 'https://gitlab.com';\n\nexport interface GitLabProviderState extends RegistryProviderState {\n\tbaseUrl: string;\n\towner: string;\n\trepoName: string;\n\tref: string;\n}\n\n/** Valid paths\n *\n * `https://gitlab.com/ieedan/std`\n *\n * `https://gitlab.com/ieedan/std/-/tree/next`\n *\n * `https://gitlab.com/ieedan/std/-/tree/v2.0.0`\n *\n * `https://gitlab.com/ieedan/std/-/tree/v2.0.0?ref_type=tags`\n *\n * Self hosted:\n *\n * `gitlab:https://example.com/ieedan/std`\n */\nexport const gitlab: RegistryProvider = {\n\tname: 'gitlab',\n\n\tmatches: (url) =>\n\t\tstartsWithOneOf(url.toLowerCase(), ['gitlab/', 'gitlab:', 'https://gitlab.com']),\n\n\tparse: (url, opts) => {\n\t\tconst parsed = parseUrl(url, opts);\n\n\t\treturn {\n\t\t\turl: parsed.url,\n\t\t\tspecifier: parsed.specifier,\n\t\t};\n\t},\n\n\tbaseUrl: (url) => {\n\t\tconst { baseUrl, owner, repoName } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn u.join(baseUrl, owner, repoName);\n\t},\n\n\tstate: async (url, { token, fetch: f = fetch } = {}) => {\n\t\tlet {\n\t\t\tbaseUrl,\n\t\t\turl: normalizedUrl,\n\t\t\towner,\n\t\t\trepoName,\n\t\t\tref,\n\t\t} = parseUrl(url, { fullyQualified: false });\n\n\t\t// fetch default branch if ref was not provided\n\t\tif (ref === undefined) {\n\t\t\ttry {\n\t\t\t\tconst headers = new Headers();\n\n\t\t\t\tif (token !== undefined) {\n\t\t\t\t\tconst [key, value] = gitlab.authHeader!(token);\n\n\t\t\t\t\theaders.append(key, value);\n\t\t\t\t}\n\n\t\t\t\tconst response = await f(\n\t\t\t\t\tu.join(\n\t\t\t\t\t\tbaseUrl,\n\t\t\t\t\t\t`api/v4/projects/${encodeURIComponent(`${owner}/${repoName}`)}`\n\t\t\t\t\t),\n\t\t\t\t\t{\n\t\t\t\t\t\theaders,\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tif (response.ok) {\n\t\t\t\t\tconst data = await response.json();\n\n\t\t\t\t\t// @ts-ignore yes but we know\n\t\t\t\t\tref = data.default_branch as string;\n\t\t\t\t} else {\n\t\t\t\t\tref = DEFAULT_BRANCH;\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// well find out it isn't correct later with a better error\n\t\t\t\tref = DEFAULT_BRANCH;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\towner,\n\t\t\trepoName,\n\t\t\tref,\n\t\t\tbaseUrl,\n\t\t\turl: normalizedUrl,\n\t\t\tprovider: gitlab,\n\t\t} satisfies GitLabProviderState;\n\t},\n\n\tresolveRaw: async (state, resourcePath) => {\n\t\t// essentially assert that we are using the correct state\n\t\tif (state.provider.name !== gitlab.name) {\n\t\t\tthrow new Error(\n\t\t\t\t`You passed the incorrect state object (${state.provider.name}) to the ${gitlab.name} provider.`\n\t\t\t);\n\t\t}\n\n\t\tconst { baseUrl, owner, repoName, ref } = state as GitLabProviderState;\n\n\t\treturn new URL(\n\t\t\tu.join(\n\t\t\t\tbaseUrl,\n\t\t\t\t`api/v4/projects/${encodeURIComponent(`${owner}/${repoName}`)}`,\n\t\t\t\t`repository/files/${encodeURIComponent(resourcePath)}/raw?ref=${ref}`\n\t\t\t)\n\t\t);\n\t},\n\n\tauthHeader: (token) => ['PRIVATE-TOKEN', token],\n\n\tformatFetchError: (state, filePath, error) => {\n\t\treturn `There was an error fetching \\`${color.bold(filePath)}\\` from ${color.bold(state.url)}: ${error}.\n\n${color.bold('This may be for one of the following reasons:')}\n1. Either \\`${color.bold(filePath)}\\` or the containing repository doesn't exist\n2. Your repository path is incorrect (wrong branch, wrong tag)\n3. You are using an expired access token or a token that doesn't have access to this repository\n4. The cached state for this git provider is incorrect (try using ${color.bold('--no-cache')})\n`;\n\t},\n};\n\nconst parseUrl = (\n\turl: string,\n\t{ fullyQualified }: ParseOptions\n): {\n\turl: string;\n\tbaseUrl: string;\n\towner: string;\n\trepoName: string;\n\tref?: string;\n\tspecifier?: string;\n} => {\n\tlet baseUrl = BASE_URL;\n\n\tif (url.startsWith('gitlab:')) {\n\t\tbaseUrl = new URL(url.slice(7)).origin;\n\t}\n\n\tconst repo = url.replaceAll(/gitlab\\/|https:\\/\\/gitlab\\.com\\/|gitlab:https?:\\/\\/[^/]+\\//g, '');\n\n\tlet [owner, repoName, ...rest] = repo.split('/');\n\n\tlet specifier: string | undefined;\n\n\tif (fullyQualified) {\n\t\tspecifier = rest.slice(rest.length - 2).join('/');\n\n\t\trest = rest.slice(0, rest.length - 2);\n\t}\n\n\tlet ref: string | undefined;\n\n\tif (rest[0] === '-' && rest[1] === 'tree') {\n\t\tif (rest[2].includes('?')) {\n\t\t\tconst [tempRef] = rest[2].split('?');\n\n\t\t\tref = tempRef;\n\t\t} else {\n\t\t\tref = rest[2];\n\t\t}\n\t}\n\n\tconst isCustom = baseUrl !== BASE_URL;\n\n\treturn {\n\t\t// if the url is custom instance of gitlab we must append gitlab: so that the url can be parsed correctly\n\t\turl: u.join(\n\t\t\tisCustom ? `gitlab:${baseUrl}` : baseUrl,\n\t\t\t`${owner}/${repoName}${ref ? `/-/tree/${ref}` : ''}`\n\t\t),\n\t\tbaseUrl,\n\t\towner: owner,\n\t\trepoName: repoName,\n\t\tref,\n\t\tspecifier,\n\t};\n};\n","import color from 'chalk';\nimport * as u from '../blocks/ts/url';\nimport type { ParseOptions, RegistryProvider, RegistryProviderState } from './types';\n\nexport interface HttpProviderState extends RegistryProviderState {}\n\n/** Valid paths\n *\n * `(https|http)://example.com`\n */\nexport const http: RegistryProvider = {\n\tname: 'http',\n\n\tmatches: (url) => {\n\t\t// if parsing is a success then it's a match\n\t\ttry {\n\t\t\tnew URL(url);\n\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t},\n\n\tparse: (url, opts) => {\n\t\tconst parsed = parseUrl(url, opts);\n\n\t\treturn {\n\t\t\turl: parsed.url,\n\t\t\tspecifier: parsed.specifier,\n\t\t};\n\t},\n\n\tbaseUrl: (url) => {\n\t\tconst { url: u } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn new URL(u).origin;\n\t},\n\n\tstate: async (url) => {\n\t\tconst { url: normalizedUrl } = parseUrl(url, { fullyQualified: false });\n\n\t\treturn {\n\t\t\turl: normalizedUrl,\n\t\t\tprovider: http,\n\t\t} satisfies HttpProviderState;\n\t},\n\n\tresolveRaw: async (state, resourcePath) => {\n\t\t// essentially assert that we are using the correct state\n\t\tif (state.provider.name !== http.name) {\n\t\t\tthrow new Error(\n\t\t\t\t`You passed the incorrect state object (${state.provider.name}) to the ${http.name} provider.`\n\t\t\t);\n\t\t}\n\n\t\treturn new URL(resourcePath, state.url);\n\t},\n\n\tauthHeader: (token) => ['Authorization', `Bearer ${token}`],\n\n\tformatFetchError: (state, filePath, error) => {\n\t\treturn `There was an error fetching ${color.bold(new URL(filePath, state.url).toString())}\n\t\n${color.bold(error)}`;\n\t},\n};\n\nconst parseUrl = (\n\turl: string,\n\t{ fullyQualified }: ParseOptions\n): {\n\turl: string;\n\tspecifier?: string;\n} => {\n\tconst parsedUrl = new URL(url);\n\n\tlet segments = parsedUrl.pathname.split('/');\n\n\tlet specifier: string | undefined;\n\n\tif (fullyQualified) {\n\t\tspecifier = segments.slice(segments.length - 2).join('/');\n\n\t\tsegments = segments.slice(0, segments.length - 2);\n\t}\n\n\treturn {\n\t\turl: u.addTrailingSlash(u.join(parsedUrl.origin, ...segments)),\n\t\tspecifier,\n\t};\n};\n","/*\n\tInstalled from github/ieedan/std\n*/\n\n/** This is just a helper type used only within this file */\ntype _Result<T, E> = { ok: true; val: T } | { ok: false; err: E };\n\n/** Result allows you to show to a consumer that a function might throw and force them to handle it.\n *\n * `T` Value type\n *\n * `E` Error type\n *\n * ## Usage\n *\n * ```ts\n * function functionThatMightFail(): Result<T, E>;\n * ```\n *\n * ## Examples\n *\n * ```ts\n * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello, World!\");\n *\n * const result = functionThatMightFail();\n *\n * console.log(result.unwrap()); // \"Hello, World!\"\n * ```\n */\nclass Result<T, E> {\n\tprivate readonly _result: _Result<T, E>;\n\n\tconstructor(result: _Result<T, E>) {\n\t\tthis._result = result;\n\t}\n\n\t/** Allows you to run callbacks based on the result.\n\t *\n\t * @param success callback to be run when result is success\n\t * @param failure callback to be run when result is failure\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.match(\n\t * \t(val) => val,\n\t * \t() => {\n\t * \t\tthrow new Error('oops!')\n\t * \t}\n\t * );\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello, World!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const val = result.match(\n\t * \t(val) => val,\n\t * \t() => {\n\t * \t\tthrow new Error('oops!')\n\t * \t}\n\t * );\n\t *\n\t * console.log(val); // \"Hello, World!\"\n\t * ```\n\t */\n\tmatch<A, B = A>(success: (val: T) => A, failure: (err: E) => B): A | B {\n\t\tif (!this._result.ok) {\n\t\t\treturn failure(this._result.err);\n\t\t}\n\n\t\treturn success(this._result.val);\n\t}\n\n\t/** Maps `Result<T, E>` to `Result<A, E>` using the passed mapping function\n\t *\n\t * @param fn Mapping function\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.map((val) => val.length);\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello, World!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const hello = result.map((val) => val.slice(0, 5));\n\t *\n\t * console.log(hello.unwrap()); // \"Hello\"\n\t * ```\n\t */\n\tmap<A>(fn: (val: T) => A): Result<A, E> {\n\t\treturn this.match(\n\t\t\t(val) => Ok(fn(val)),\n\t\t\t(err) => Err(err)\n\t\t);\n\t}\n\n\t/** In the `Ok` case returns the mapped value using the function else returns `defaultVal`\n\t *\n\t * @param defaultVal Value to be returned when `Err`\n\t * @param fn Mapping function to map in case of `Ok`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.mapOr(1, (val) => val.length);\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"foo\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapOr(1, (val) => val.length);\n\t *\n\t * console.log(length); // 3\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapOr(1, (val) => val.length);\n\t *\n\t * console.log(length); // 1\n\t * ```\n\t */\n\tmapOr<A>(defaultVal: A, fn: (val: T) => A): A {\n\t\treturn this.match(\n\t\t\t(val) => fn(val),\n\t\t\t(_) => defaultVal\n\t\t);\n\t}\n\n\t/** In the `Ok` case returns the mapped value using `fn` else returns value of `def`\n\t *\n\t * @param def Mapping function called when `Err`\n\t * @param fn Mapping function called when `Ok`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.mapOrElse(() => 1, (val) => val.length);\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"foo\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapOrElse(() => 1, (val) => val.length);\n\t *\n\t * console.log(length); // 3\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapOr(() => 1, (val) => val.length);\n\t *\n\t * console.log(length); // 1\n\t * ```\n\t */\n\tmapOrElse<A>(def: (err: E) => A, fn: (val: T) => A): A {\n\t\treturn this.match(\n\t\t\t(val) => fn(val),\n\t\t\t(err) => def(err)\n\t\t);\n\t}\n\n\t/** Maps `Result<T, E>` to `Result<T, A>` using the passed mapping function\n\t *\n\t * @param fn Mapping function\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.mapErr((err) => getCodeMsg(err));\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(10);\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const message = result.mapErr(() => \"Error\");\n\t *\n\t * console.log(message); // \"Error\"\n\t * ```\n\t */\n\tmapErr<A>(fn: (err: E) => A): Result<T, A> {\n\t\treturn this.match(\n\t\t\t(val) => Ok(val),\n\t\t\t(err) => Err(fn(err))\n\t\t);\n\t}\n\n\t/** In the `Err` case returns the mapped value using the function else returns `defaultVal`\n\t *\n\t * @param defaultVal Value to be returned when `Ok`\n\t * @param fn Mapping function to map in case of `Err`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.mapErrOr(\"Should've been error\", (err) => getCodeMsg(err));\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"foo\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const message = result.mapErrOr(\"Should've been error\", () => \"Error\");\n\t *\n\t * console.log(message); // \"Should've been error\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(10);\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const message = result.mapErrOr(\"Should've been error\", () => \"Error\");\n\t *\n\t * console.log(message); // \"Error\"\n\t * ```\n\t */\n\tmapErrOr<A>(defaultVal: A, fn: (err: E) => A): A {\n\t\treturn this.match(\n\t\t\t(_) => defaultVal,\n\t\t\t(err) => fn(err)\n\t\t);\n\t}\n\n\t/** In the `Err` case returns the mapped value using the function else returns value of `def`\n\t *\n\t * @param def Mapping function called when `Ok`\n\t * @param fn Mapping function called when `Err`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.mapErrOrElse(() => \"Value\", (_) => \"Error!\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"foo\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapErrOrElse(() => 1, (val) => val.length);\n\t *\n\t * console.log(length); // 1\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * const length = result.mapOr(() => 1, (val) => val.length);\n\t *\n\t * console.log(length); // 4\n\t * ```\n\t */\n\tmapErrOrElse<A>(def: (val: T) => A, fn: (err: E) => A): A {\n\t\treturn this.match(\n\t\t\t(val) => def(val),\n\t\t\t(err) => fn(err)\n\t\t);\n\t}\n\n\t/** Returns true if result is `Ok`\n\t *\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.isOk();\n\t * ```\n\t */\n\tisOk(): boolean {\n\t\treturn this.match(\n\t\t\t() => true,\n\t\t\t() => false\n\t\t);\n\t}\n\n\t/** Returns true if result is `Err`\n\t *\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.isErr();\n\t * ```\n\t */\n\tisErr(): boolean {\n\t\treturn this.match(\n\t\t\t() => false,\n\t\t\t() => true\n\t\t);\n\t}\n\n\t/** Tries to return value if value is `Err` throws generic error message.\n\t *\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrap();\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrap()); // \"Hello!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * result.unwrap(); // Error: Attempted to call `.unwrap()` on a non `Ok` value.\n\t * ```\n\t */\n\tunwrap(): T {\n\t\treturn this.match(\n\t\t\t(val) => val,\n\t\t\t() => {\n\t\t\t\tthrow new Error('Attempted to call `.unwrap()` on a non `Ok` value.');\n\t\t\t}\n\t\t);\n\t}\n\n\t/** Tries to return err if value is `Ok` throws generic error message.\n\t *\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrapErr();\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * result.unwrapErr(); // Error: Attempted to call `.unwrapErr()` on a non `Err` value.\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapErr()); // \"oops!\"\n\t * ```\n\t */\n\tunwrapErr(): E {\n\t\treturn this.match(\n\t\t\t() => {\n\t\t\t\tthrow new Error('Attempted to call `.unwrapErr()` on a non `Err` value.');\n\t\t\t},\n\t\t\t(err) => err\n\t\t);\n\t}\n\n\t/** Tries to unwrap the value if value is `Err` returns `defaultVal`\n\t *\n\t * @param defaultVal Value to be returned if `Err`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrapOr(7);\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapOr(\"Yellow!\")); // \"Hello!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapOr(\"Yellow!\")); // \"Yellow!\"\n\t * ```\n\t */\n\tunwrapOr(defaultVal: T): T {\n\t\treturn this.match(\n\t\t\t(val) => val,\n\t\t\t(_) => defaultVal\n\t\t);\n\t}\n\n\t/** Tries to unwrap the error if vale is `Ok` returns `defaultVal`\n\t *\n\t * @param defaultVal\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrapErrOr(\"Error\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapErrOr(\"Yellow!\")); // \"Yellow!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapErrOr(\"Yellow!\")); // \"oops!\"\n\t * ```\n\t */\n\tunwrapErrOr(defaultVal: E): E {\n\t\treturn this.match(\n\t\t\t() => defaultVal,\n\t\t\t(err) => err\n\t\t);\n\t}\n\n\t/** Tries to return the value if value is `Err` calls `fn`\n\t *\n\t * @param fn Function called if `Err`\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrapOrElse(() => \"Hello!\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapOrElse(() => \"oops!\")); // \"Hello!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapOrElse(() => \"Hello!\")); // \"Hello!\"\n\t * ```\n\t *\n\t */\n\tunwrapOrElse(fn: (err: E) => T): T {\n\t\treturn this.match(\n\t\t\t(val) => val,\n\t\t\t(err) => fn(err)\n\t\t);\n\t}\n\n\t/** Tries to return the error if value is `Ok` calls `fn`\n\t *\n\t * @param fn Function called if `Ok`\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.unwrapErrOrElse(() => \"Error!\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapErrOrElse(() => \"oops!\")); // \"oops!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.unwrapErrOrElse(() => \"Hello!\")); // \"oops!\"\n\t * ```\n\t *\n\t */\n\tunwrapErrOrElse(fn: (val: T) => E): E {\n\t\treturn this.match(\n\t\t\t(val) => fn(val),\n\t\t\t(err) => err\n\t\t);\n\t}\n\n\t/** Tries to return value if value is `Err` throws custom error message.\n\t *\n\t * @param message Message to show when value is `Err`\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.expect(\"Custom message\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.expect(\"I failed!\")); // \"Hello!\"\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * result.expect(\"I failed!\"); // Error: I failed!\n\t * ```\n\t */\n\texpect(message: string): T {\n\t\treturn this.match(\n\t\t\t(val) => val,\n\t\t\t() => {\n\t\t\t\tthrow new Error(message);\n\t\t\t}\n\t\t);\n\t}\n\n\t/** Tries to return error value if value is `Ok` throws custom error message\n\t *\n\t * @param message\n\t * @returns\n\t *\n\t * ## Usage\n\t *\n\t * ```ts\n\t * result.expectErr(\"Custom message\");\n\t * ```\n\t *\n\t * ## Examples\n\t *\n\t * ### When `Ok`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Ok(\"Hello!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.expectErr(\"I failed!\")); // Error: I failed!\n\t * ```\n\t *\n\t * ### When `Err`\n\t *\n\t * ```ts\n\t * const functionThatMightFail = (): Result<string, string> => Err(\"oops!\");\n\t *\n\t * const result = functionThatMightFail();\n\t *\n\t * console.log(result.expectErr(\"I failed!\")); // \"oops!\"\n\t * ```\n\t */\n\texpectErr(message: string): E {\n\t\treturn this.match(\n\t\t\t() => {\n\t\t\t\tthrow new Error(message);\n\t\t\t},\n\t\t\t(err) => err\n\t\t);\n\t}\n}\n\n/** Returns a new `Ok` result type with the provided value\n *\n * @param val Value of the result\n * @returns\n *\n * ## Usage\n *\n * ```ts\n * Ok(true);\n * ```\n *\n * ## Examples\n *\n * ```ts\n * const functionThatCanFail = (condition) => {\n * \tif (condition) {\n * \t\tOk(\"Success\")\n * \t}\n *\n * \treturn Err(\"Failure\");\n * }\n * ```\n */\nconst Ok = <T>(val: T): Result<T, never> => {\n\treturn new Result<T, never>({ ok: true, val });\n};\n\n/** Returns a new `Err` result type with the provided error\n *\n * @param err Error of the result\n * @returns\n *\n * ## Usage\n *\n * ```ts\n * Err(\"I failed!\");\n * ```\n *\n * ## Examples\n *\n * ```ts\n * const functionThatCanFail = (condition) => {\n * \tif (condition) {\n * \t\tOk(\"Success\")\n * \t}\n *\n * \treturn Err(\"Failure\");\n * }\n * ```\n */\nconst Err = <E>(err: E): Result<never, E> => {\n\treturn new Result<never, E>({ ok: false, err });\n};\n\nexport { type Result, Ok, Err };\n","import * as v from 'valibot';\nimport { type Manifest, categorySchema, manifestSchema } from '../types';\nimport { Err, Ok, type Result } from './blocks/ts/result';\n\n/** Parses the json string (if it can be) into a manifest.\n *\n * @param json\n */\nexport const parseManifest = (json: string): Result<Manifest, string> => {\n\tlet parsed: unknown;\n\n\ttry {\n\t\tparsed = JSON.parse(json);\n\t} catch (err) {\n\t\treturn Err(`Error parsing manifest json ${err}`);\n\t}\n\n\t// first gen array-based config\n\tif (Array.isArray(parsed)) {\n\t\tconst validated = v.safeParse(v.array(categorySchema), parsed);\n\n\t\tif (!validated.success) {\n\t\t\treturn Err(\n\t\t\t\t`Error parsing categories (array-based config) ${validated.issues.join(' ')}`\n\t\t\t);\n\t\t}\n\n\t\treturn Ok({\n\t\t\tcategories: validated.output,\n\t\t});\n\t}\n\n\tconst validated = v.safeParse(manifestSchema, parsed);\n\n\tif (!validated.success) {\n\t\treturn Err(`Error parsing manifest ${validated.issues.join(' ')}`);\n\t}\n\n\treturn Ok(validated.output);\n};\n","import { MANIFEST_FILE } from '../../constants';\nimport type { Manifest } from '../../types';\nimport { Err, Ok, type Result } from '../blocks/ts/result';\nimport { parseManifest } from '../manifest';\nimport { type AzureProviderState, azure } from './azure';\nimport { type BitBucketProviderState, bitbucket } from './bitbucket';\nimport { type GitHubProviderState, github } from './github';\nimport { type GitLabProviderState, gitlab } from './gitlab';\nimport { http } from './http';\nimport type { RegistryProvider, RegistryProviderState } from './types';\n\nexport const providers = [github, gitlab, bitbucket, azure, http];\n\nexport const selectProvider = (url: string): RegistryProvider | undefined => {\n\tconst provider = providers.find((p) => p.matches(url));\n\n\treturn provider;\n};\n\nexport type FetchOptions = {\n\ttoken: string;\n\t/** Override the fetch method. If you are using this in a node environment you will want to pass `node-fetch` */\n\tfetch?: typeof fetch;\n\tverbose: (str: string) => void;\n};\n\nexport const fetchRaw = async (\n\tstate: RegistryProviderState,\n\tresourcePath: string,\n\t{ verbose, fetch: f = fetch, token }: Partial<FetchOptions> = {}\n): Promise<Result<string, string>> => {\n\tconst url = await state.provider.resolveRaw(state, resourcePath);\n\n\tverbose?.(`Trying to fetch from ${url}`);\n\n\ttry {\n\t\tconst headers = new Headers();\n\n\t\tif (token !== undefined && state.provider.authHeader) {\n\t\t\tconst [key, value] = state.provider.authHeader(token);\n\n\t\t\theaders.append(key, value);\n\t\t}\n\n\t\tconst response = await f(url, { headers });\n\n\t\tverbose?.(`Got a response from ${url} ${response.status} ${response.statusText}`);\n\n\t\tif (!response.ok) {\n\t\t\treturn Err(\n\t\t\t\tstate.provider.formatFetchError(\n\t\t\t\t\tstate,\n\t\t\t\t\tresourcePath,\n\t\t\t\t\t`${response.status} ${response.statusText}`\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\treturn Ok(await response.text());\n\t} catch (err) {\n\t\treturn Err(state.provider.formatFetchError(state, resourcePath, err));\n\t}\n};\n\nexport const fetchManifest = async (\n\tstate: RegistryProviderState,\n\t{ fetch: f = fetch, ...rest }: Partial<FetchOptions> = {}\n): Promise<Result<Manifest, string>> => {\n\tconst manifest = await fetchRaw(state, MANIFEST_FILE, { fetch: f, ...rest });\n\n\tif (manifest.isErr()) return Err(manifest.unwrapErr());\n\n\treturn parseManifest(manifest.unwrap());\n};\n\nexport * from './types';\n\nexport {\n\tgithub,\n\tgitlab,\n\tbitbucket,\n\tazure,\n\thttp,\n\ttype AzureProviderState,\n\ttype GitHubProviderState,\n\ttype GitLabProviderState,\n\ttype BitBucketProviderState,\n};\n"]}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {h,g,f,u,c,s,l,n,t,a,b as b$1,w,v,k}from'./chunk-
|
|
2
|
+
import {h,g,f,u,c,s,l,n,t,a,b as b$1,w,v,k}from'./chunk-6BJA5YI6.js';import {Command,Option,program,Argument,InvalidArgumentError}from'commander';import ie from'node:fs';import {outro,confirm,isCancel,cancel,multiselect,text,select,log,password,spinner,intro}from'@clack/prompts';import D from'chalk';import {resolveCommand}from'package-manager-detector/commands';import {detect}from'package-manager-detector/detect';import Y from'pathe';import*as b from'valibot';import Tn from'is-unicode-supported';import {builtinModules}from'node:module';import {createPathsMatcher,getTsconfig}from'get-tsconfig';import Ko from'validate-npm-package-name';import An from'node:os';import {stripVTControlCharacters}from'node:util';import vs from'escape-string-regexp';import {execa}from'execa';import {detect as detect$1,resolveCommand as resolveCommand$1}from'package-manager-detector';import mo from'boxen';import {diffLines,diffChars}from'diff';import ao from'semver';import {cursor,erase}from'sisteransi';import Wn from'@anthropic-ai/sdk';import zn from'ollama';import Gn from'openai';import Mn from'conf';import xr from'node-fetch';import {Biome,Distribution}from'@biomejs/js-api';import*as $o from'css-dependency';import*as xo from'prettier';import*as Ro from'parse5';import Ss from'oxc-parser';import {walk}from'estree-walker';import Os from'prettier-plugin-svelte';import*as Bo from'svelte/compiler';import*as Vo from'vue/compiler-sfc';import wi from'ignore';var gt={name:"jsrepo",description:"A CLI to add shared code from remote repositories.",version:"1.46.2"};var Nn=Tn(),se=(e,t)=>Nn?e:t,Ur=se("\u25C6","*"),zr=se("\u25C6","*"),Gr=se("\u25A0","x"),T=D.gray(se("\u2502","|")),Pt=D.gray(se("\u2500","-")),Kr=D.gray(se("\u2510","+")),Hr=D.gray(se("\u2518","+")),It=D.gray(se("\u251C","+")),qr=D.gray(se("\u252C","+"));D.gray(se("\u250C","T"));var Yr=D.gray(se("\u2514","-")),fe=D.bgRgb(245,149,66).black(" WARN "),Ie=D.bgBlueBright.white(" INFO "),Et=D.bgRedBright.white(" ERROR "),Ee=D.hex("#f7df1e")("jsrepo");var Qr=(e,t)=>{let r=[];for(let[o,n]of e)r.push(t(o,n));return r},Xr=(e,t)=>{let r=0;for(let o of e)r=r+t(o);return r};var Ot=(e,t,r=" ")=>{if(stripVTControlCharacters(e).length>t)throw new Error("String length is greater than the length provided.");return r.repeat(t-stripVTControlCharacters(e).length)+e};var Fn=/\n|\r\n/g,M=e=>e.split(Fn),V=(e,{lineNumbers:t=false,prefix:r}={})=>{let o=e;if(t){let n=e.length.toString().length+1;o=o.map((s,i)=>`${Ot(`${i+1}`,n)} ${s}`);}return r!==void 0&&(o=o.map((n,s)=>`${r(s,e.length)}${n}`)),o.join(An.EOL)};var Ln={"no-workspace":"--no-workspace","install-as-dev-dependency":"-D"},Bn={"install-as-dev-dependency":"-D"},_n={"no-workspace":"--workspaces=false","install-as-dev-dependency":"-D"},to={"no-workspace":"--ignore-workspace","install-as-dev-dependency":"-D"},ro={"no-workspace":"--focus","install-as-dev-dependency":"-D"},pr={bun:Ln,npm:_n,pnpm:to,deno:Bn,yarn:ro,"yarn@berry":ro,"pnpm@6":to};var Oe=()=>new Mn({projectName:"jsrepo"});var dr="http-registries-w-tokens",De=class{#e;constructor(t){this.#e=t??Oe();}getKey(t){return `${t}-token`.toLowerCase()}get(t){let r=this.getKey(t);return this.#e.get(r,void 0)}set(t,r){if(t.startsWith("http")){let n=this.getHttpRegistriesWithTokens(),s=t.slice(5);n||(n=[]),n.includes(s)||n.push(s),this.#e.set(dr,n);}let o=this.getKey(t);this.#e.set(o,r);}delete(t){if(t.startsWith("http")){let o=this.getHttpRegistriesWithTokens(),n=t.slice(5),s=o.indexOf(n);s!==-1&&(o=[...o.slice(0,s),...o.slice(s+1)]),this.#e.set(dr,o);}let r=this.getKey(t);this.#e.delete(r);}getHttpRegistriesWithTokens(){let t=this.#e.get(dr);return t||[]}};var ur={"Claude 3.7 Sonnet":{updateFile:async({originalFile:e,newFile:t,loading:r,verbose:o,additionalInstructions:n,messages:s})=>{let i=await oo("Anthropic");o||r.start("Asking Claude 3.7 Sonnet");let a=fr({originalFile:e,newFile:t,additionalInstructions:n,rePrompt:s!==void 0&&s.length>0});o?.(`Prompting Claude 3.7 Sonnet with:
|
|
3
3
|
${JSON.stringify(a,null," ")}`);let c=await Hn({model:"claude-3-7-sonnet-latest",prompt:a,apiKey:i,messages:s,maxTokens:(e.content.length+t.content.length)*2});return o||r.stop("Claude 3.7 Sonnet updated the file"),c?{content:mr(c),prompt:a.message}:{content:t.content,prompt:a.message}}},"OpenAI o3-mini":{updateFile:async({originalFile:e,newFile:t,loading:r,verbose:o,additionalInstructions:n,messages:s})=>{let i=await oo("OpenAI");o||r.start("Asking OpenAI o3-mini");let a=fr({originalFile:e,newFile:t,additionalInstructions:n,rePrompt:s!==void 0&&s.length>0});o?.(`Prompting OpenAI o3-mini with:
|
|
4
4
|
${JSON.stringify(a,null," ")}`);let c=await Kn({model:"o3-mini",prompt:a,apiKey:i,messages:s,maxTokens:(e.content.length+t.content.length)*2});return o||r.stop("OpenAI o3-mini updated the file"),c?{content:mr(c),prompt:a.message}:{content:t.content,prompt:a.message}}},Phi4:{updateFile:async({originalFile:e,newFile:t,loading:r,verbose:o,additionalInstructions:n,messages:s})=>{o||r.start("Asking Phi4");let i=fr({originalFile:e,newFile:t,additionalInstructions:n,rePrompt:s!==void 0&&s.length>0});o?.(`Prompting Phi4 with:
|
|
5
5
|
${JSON.stringify(i,null," ")}`);let a=await qn({model:"phi4",prompt:i,messages:s});return o||r.stop("Phi4 updated the file"),a?{content:mr(a),prompt:i.message}:{content:t.content,prompt:i.message}}}},Kn=async({prompt:e,maxTokens:t,model:r,apiKey:o,messages:n})=>{let a=(await new Gn({apiKey:o}).chat.completions.create({model:r,max_completion_tokens:t,messages:[{role:"system",content:e.system},...n??[],{role:"user",content:e.message}]})).choices[0];return a.message.content===null?null:a.message.content},Hn=async({prompt:e,messages:t,maxTokens:r,model:o,apiKey:n})=>{let s=new Wn({apiKey:n}),i=[];if(t)for(let l of t)i.push({role:l.role,content:[{type:"text",text:l.content}]});i.push({role:"user",content:[{type:"text",text:e.message}]});let c=(await s.messages.create({model:o,max_tokens:Math.min(r,8192),temperature:.5,system:e.system,messages:i})).content[0];return c.type!=="text"?null:c.text},qn=async({prompt:e,messages:t,model:r})=>(await zn.chat({model:r,messages:[{role:"system",content:e.system},...t??[],{role:"user",content:e.message}]})).message.content,fr=({originalFile:e,newFile:t,additionalInstructions:r,rePrompt:o})=>({system:"You will merge two files provided by the user. You will respond only with the resulting code. DO NOT format the code with markdown, DO NOT put the code inside of triple quotes, only return the code as a raw string. DO NOT make unnecessary changes.",message:o?r??"":`
|
|
@@ -66,7 +66,7 @@ ${V(M(e),{prefix:()=>" "})}
|
|
|
66
66
|
`)):a(l.unwrap())},comment:e=>`<!--
|
|
67
67
|
${V(M(e),{prefix:()=>" "})}
|
|
68
68
|
-->`,format:async(e,{formatter:t,prettierOptions:r})=>t&&t==="prettier"?await xo.format(e,{parser:"vue",...r}):e};var zo={matches:e=>e.endsWith(".yml")||e.endsWith(".yaml"),resolveDependencies:()=>a({dependencies:[],local:[],devDependencies:[],imports:{}}),comment:e=>V(M(e),{prefix:()=>"# "}),format:async(e,{formatter:t,prettierOptions:r})=>t&&t==="prettier"?await xo.format(e,{parser:"yaml",...r}):e};var be=e=>`${V(M(e),{prefix:t=>t===0?`${T} ${Et} `:`${T} `})}`,$e=({moduleSpecifiers:e,isSubDir:t,filePath:r,containingDir:o,doNotInstall:n,dirs:s,cwd:i})=>{let a$1=[],c=new Set,l=new Set,p={};for(let k of e){if(builtinModules.includes(k)||k.startsWith("node:"))continue;if(k.startsWith(".")){let d=Ho(k,t,{filePath:r,containingDir:o,dirs:s,cwd:i});if(d.isErr()){a$1.push(d.unwrapErr());continue}let S=d.unwrap();S&&(l.add(S.dependency),p[k]=S.template);continue}let m=We(k);if(!m.isErr()){let d=m.unwrap();if(Ko(d.name).validForNewPackages){c.add(k);continue}}let h=As(k,t,{filePath:r,containingDir:o,dirs:s,cwd:i});if(h.isErr()){a$1.push(h.unwrapErr());continue}let f=h.unwrap();f?(l.add(f.dependency),p[k]=f.template):console.warn(`${T} ${fe} Skipped adding import \`${D.cyan(k)}\` from ${r}. Reason: Not a valid package name or path alias.`);}if(a$1.length>0)return b$1(a$1);let{devDependencies:u,dependencies:v}=Bs(Array.from(c),r,{doNotInstall:n||[]});return a({dependencies:v,devDependencies:u,local:Array.from(l),imports:p})},Ho=(e,t,{filePath:r,containingDir:o,dropExtension:n=true,alias:s,dirs:i,cwd:a$1})=>{if(t&&(e.startsWith("./")||e==="."))return a(void 0);let c=t?Y.join(o,"../"):Y.join(r,"../"),l=Y.join(Y.join(r,"../"),e),p=Y.join(c,"../");if(o&&l.startsWith(o))return a(void 0);if(l.startsWith(p))return a(Go(l.slice(p.length),n));for(let u of i){let v=Y.resolve(Y.join(a$1,u)),k=Y.resolve(l);if(k.startsWith(v))return a(Go(k.slice(v.length+1),n))}return b$1(`${r}:
|
|
69
|
-
${s||e} references code not contained in ${D.bold(i.join(", "))} and cannot be resolved.`)},Go=(e,t=true)=>{let[r,o,...n]=e.split("/");o===void 0&&(o="index");let s=o;t&&s.includes(".")&&(s=s.slice(0,s.length-Y.parse(s).ext.length));let i=`${r}/${s}`,a=`{{${i}}}`;return n.length===0?s.length!==o.length&&(a+=Y.parse(o).ext):a+=`/${n.join("/")}`,{dependency:i,template:a}},As=(e,t,{filePath:r,dirs:o,cwd:n,containingDir:s})=>{let i=vt(r);if(i.isErr())return b$1(i.unwrapErr());let a$1=i.unwrap();if(a$1===null)return a(void 0);let c=createPathsMatcher(a$1);if(c){let l=c(e);for(let p of l){let u=Ls(p);if(!u)continue;let v=Y.relative(Y.resolve(Y.join(r,"../")),u.prettyPath),k=Fs(u.prettyPath,u.path,[".js",".ts"]),m=Ho(v,t,{filePath:r,containingDir:s,alias:e,dropExtension:k,dirs:o,cwd:n,modIsFile:u.type==="file"});if(m.isErr())return b$1(m.unwrapErr());if(m.unwrap())return a(m.unwrap());break}}return a(void 0)},Fs=(e,t,r=[".ts",".js",""])=>{if(e===t)return true;let o=Y.parse(e),n=Y.parse(t),s=Y.join(o.dir,o.name),i=Y.join(n.dir,n.name);return s!==i?false:!!(r.includes(o.ext)&&r.includes(n.ext))},Ls=e=>{if(ie.existsSync(e))return {path:e,prettyPath:e,type:ie.statSync(e).isDirectory()?"directory":"file"};let t=Y.join(e,"../");if(!ie.existsSync(t))return;let r=Y.parse(e);if(r.ext===".js"){let n=`${e.slice(0,e.length-3)}.ts`;if(ie.existsSync(n))return {path:n,prettyPath:e,type:"file"}}let o=ie.readdirSync(t);for(let n of o){let s=Y.parse(n);if(s.name===r.base){let i=Y.join(t,n),a=i.slice(0,i.length-s.ext.length);return {path:i,prettyPath:a,type:ie.statSync(i).isDirectory()?"directory":"file"}}}},Bs=(e,t,{doNotInstall:r}={doNotInstall:[]})=>{let o=new Set(r),n=yr(Y.dirname(t),""),s=new Set,i=new Set;if(n){let{devDependencies:a,dependencies:c}=JSON.parse(ie.readFileSync(n,"utf-8"));for(let l of e){let p=We(l);if(p.isErr()){console.warn(`${T} ${fe} Skipped adding import \`${D.cyan(l)}\`. Reason: Couldn't parse package name`);continue}let u=p.unwrap();if(!Ko(u.name).validForNewPackages){console.warn(`${T} ${fe} Skipped adding import \`${D.cyan(l)}\`. Reason: Not a valid package name`);continue}if(o.has(u.name))continue;let v;if(c!==void 0&&(v=c[u.name]),v!==void 0){s.add(`${u.name}@${v}`);continue}if(a!==void 0&&(v=a[u.name]),v!==void 0){i.add(`${u.name}@${v}`);continue}s.add(u.name);}}return {dependencies:Array.from(s),devDependencies:Array.from(i)}},st=[Co,jo,Qt,Do,Ao,_o,Mo,Io,Jo,zo];var Yo=new Set(["svelte","@sveltejs/kit","vue","nuxt","react","react-dom","next","@remix-run/react","@angular/core","@angular/common","@angular/forms","@angular/platform-browser","@angular/platform-browser-dynamic","@angular/router","@builder.io/qwik","astro","solid-js"]),Qo=b.union([b.literal("off"),b.literal("warn"),b.literal("error")]),Ms=b.union([b.literal("no-category-index-file-dependency"),b.literal("no-unpinned-dependency"),b.literal("require-local-dependency-exists"),b.literal("max-local-dependencies"),b.literal("no-circular-dependency"),b.literal("no-unused-block"),b.literal("no-framework-dependency"),b.literal("require-config-file-exists"),b.literal("no-config-file-framework-dependency"),b.literal("no-config-file-unpinned-dependency")]),Xo={"no-unpinned-dependency":{description:"Require all dependencies to have a pinned version.",scope:"block",check:e=>{let t=[];for(let r of [...e.dependencies,...e.devDependencies])r.includes("@")||t.push(`Couldn't find a version to use for ${D.bold(r)}`);return t.length>0?t:void 0}},"require-local-dependency-exists":{description:"Require all local dependencies to exist.",scope:"block",check:(e,{manifest:t})=>{let r=[];for(let o of e.localDependencies){let[n,s]=o.split("/"),i=t.categories.find(c=>c.name.trim()===n.trim()),a=`${D.bold(`${e.category}/${e.name}`)} depends on local dependency ${D.bold(o)} which doesn't exist`;if(!i){r.push(a);continue}i.blocks.find(c=>c.name===s)===void 0&&r.push(a);}return r.length>0?r:void 0}},"no-category-index-file-dependency":{description:"Disallow depending on the index file of a category.",scope:"block",check:(e,{manifest:t})=>{let r=[];for(let o of e.localDependencies){let[n,s]=o.split("/");if(s!=="index")continue;let i=t.categories.find(c=>c.name===n);!i||!i.blocks.find(c=>c.name===s)||r.push(`${D.bold(`${e.category}/${e.name}`)} depends on ${D.bold(`${n}/${s}`)}`);}return r.length>0?r:void 0}},"max-local-dependencies":{description:"Enforces a limit on the amount of local dependencies a block can have.",scope:"block",check:(e,{options:t})=>{let r=[],o;return typeof t[0]!="number"?o=5:o=t[0],e.localDependencies.length>o&&r.push(`${D.bold(`${e.category}/${e.name}`)} has too many local dependencies (${D.bold(e.localDependencies.length)}) limit (${D.bold(o)})`),r.length>0?r:void 0}},"no-circular-dependency":{description:"Disallow circular dependencies.",scope:"block",check:(e,{manifest:t})=>{let r=[],o=`${e.category}/${e.name}`,n=Zt(o,e,t.categories);return n&&r.push(`There is a circular dependency in ${D.bold(o)}: ${D.bold(n.join(" -> "))}`),r.length>0?r:void 0}},"no-unused-block":{description:"Disallow unused blocks. (Not listed and not a dependency of another block)",scope:"block",check:(e,{manifest:t})=>{if(e.list)return;let r=`${e.category}/${e.name}`,o=t.categories.flatMap(n=>n.blocks).filter(n=>n.list);for(let n of o)if(Zt(r,n,t.categories))return;return [`${D.bold(r)} is unused and will be ${D.bold.red("removed")}`]}},"no-framework-dependency":{description:"Disallow frameworks (Svelte, Vue, React) as dependencies.",scope:"block",check:e=>{let t=[],r=[...e.devDependencies,...e.dependencies].map(o=>We(o).unwrap().name).filter(o=>Yo.has(o));if(r.length>0)for(let o of r)t.push(`${D.bold(`${e.category}/${e.name}`)} depends on ${D.bold(o)} causing it to be installed when added`);return t.length>0?t:void 0}},"require-config-file-exists":{description:"Require all of the paths listed in `configFiles` to exist.",scope:"global",check:({manifest:e,cwd:t})=>{let r=[];if(e.configFiles!==void 0){for(let o of e.configFiles)ie.existsSync(Y.join(t,o.path))||r.push(`The ${D.bold(o.name)} config file doesn't exist at ${D.bold(Y.join(t,o.path))}`);return r.length>0?r:void 0}}},"no-config-file-framework-dependency":{description:"Disallow frameworks (Svelte, Vue, React) as dependencies of config files.",scope:"global",check:({manifest:e})=>{let t=[];if(e.configFiles!==void 0){for(let r of e.configFiles){let o=[...r.devDependencies??[],...r.dependencies??[]].map(n=>We(n).unwrap().name).filter(n=>Yo.has(n));if(o.length>0)for(let n of o)t.push(`${D.bold(r.name)} depends on ${D.bold(n)} causing it to be installed when added`);}return t.length>0?t:void 0}}},"no-config-file-unpinned-dependency":{description:"Require all dependencies of config files to have a pinned version.",scope:"global",check:({manifest:e})=>{let t=[];if(e.configFiles){for(let r of e.configFiles)for(let o of [...r.dependencies??[],...r.devDependencies??[]])o.includes("@")||t.push(`Couldn't find a version to use for ${D.bold(o)}`);return t.length>0?t:void 0}}}},Zo=b.record(Ms,b.union([Qo,b.tupleWithRest([Qo,b.union([b.string(),b.number()])],b.union([b.string(),b.number()]))])),br={"no-category-index-file-dependency":"warn","no-unpinned-dependency":"warn","require-local-dependency-exists":"error","max-local-dependencies":["warn",10],"no-circular-dependency":"error","no-unused-block":"warn","no-framework-dependency":"warn","require-config-file-exists":"error","no-config-file-framework-dependency":"warn","no-config-file-unpinned-dependency":"warn"},en=(e,t,r,o=br)=>{let n=[],s=[];for(let[i,a]of Object.entries(Xo)){if(a.scope==="block")continue;let c=o[i],l,p=[];if(Array.isArray(c)?(l=c[0],p.push(...c.slice(1))):l=c,l==="off")continue;let u=a.check({manifest:e,options:p,cwd:r,config:t});if(u){if(l==="error"){s.push(...u.map(v=>`${T} ${Et} ${D.red(v)} ${D.gray(i)}`));continue}n.push(...u.map(v=>`${T} ${fe} ${v} ${D.gray(i)}`));}}for(let i of e.categories)for(let a of i.blocks)for(let[c,l]of Object.entries(Xo)){if(l.scope==="global")continue;let p=o[c],u,v=[];if(Array.isArray(p)?(u=p[0],v.push(...p.slice(1))):u=p,u==="off")continue;let k=l.check(a,{manifest:e,options:v,cwd:r,config:t});if(k){if(u==="error"){s.push(...k.map(m=>`${T} ${Et} ${D.red(m)} ${D.gray(c)}`));continue}n.push(...k.map(m=>`${T} ${fe} ${m} ${D.gray(c)}`));}}return {warnings:n,errors:s}},Zt=(e,t,r,o=[])=>{let n=[...o,`${t.category}/${t.name}`];for(let s of t.localDependencies){if(s===e)return n;if(o.includes(s))return;let[i,a]=s.split("/"),c=r.find(p=>p.name===i)?.blocks.find(p=>p.name===a);if(!c)continue;let l=Zt(e,c,r,n);if(l)return [...l,e]}},tn=(e,t)=>{for(let r of t)for(let o of r.blocks){if(!o.list)continue;if(Zt(e,o,t))return true}return false};var sn=[".test.ts","_test.ts",".test.js","_test.js",".spec.ts","_spec.ts",".spec.js","_spec.js",".stories.jsx","_stories.jsx",".stories.tsx","_stories.tsx"],Ye=e=>sn.find(t=>e.endsWith(t))!==void 0,an=(e,{cwd:t,ignore:r,config:o})=>{let n;try{n=ie.readdirSync(e);}catch{program.error(D.red(`Couldn't read the ${D.bold(e)} directory.`));}let s=[];for(let i of n){let a=Y.join(e,i);if(ie.statSync(a).isFile())continue;let c=`${Y.relative(t,a)}/`;if(r.ignores(c))continue;let l=Y.basename(i);if(!Vs(l,o))continue;let p=Ws(l,o),u={name:l,blocks:[]},v=ie.readdirSync(a);for(let k of v){let m=Y.join(a,k);if(ie.statSync(m).isFile()){if(Ye(k))continue;let h=Js(k),f=rn(h,o);if(!on(h,o))continue;let d=st.find(I=>I.matches(k));if(!d){console.warn(`${T} ${fe} Skipped \`${D.bold(m)}\` \`*${D.bold(Y.parse(k).ext)}\` files are not currently supported!`);continue}let S=v.find(I=>sn.find(ee=>I===`${h}${ee}`)),{dependencies:C,devDependencies:g,local:x,imports:$}=d.resolveDependencies({filePath:m,isSubDir:false,excludeDeps:o.excludeDeps,dirs:o.dirs,cwd:t}).match(I=>I,I=>{program.error(D.red(I));}),R={name:h,directory:Y.relative(t,a),category:l,tests:S!==void 0,subdirectory:false,list:p?f:false,files:[k],localDependencies:x,_imports_:$,dependencies:C,devDependencies:g};S!==void 0&&R.files.push(S),u.blocks.push(R);}else {let h=k,f=rn(h,o);if(!on(h,o))continue;let d=new Set,S=new Set,C=new Set,g={},x=false,$=[],R=(ee,te)=>{for(let K of te){let w=Y.join(ee,K),N=w.slice(m.length+1);if(Ye(K)){x=true,$.push(N);continue}if(ie.statSync(w).isDirectory()){if(!o.allowSubdirectories){console.warn(`${T} ${fe} Skipped \`${D.bold(Y.join(m,K))}\` subdirectories are not allowed! Allow them with ${D.bold("--allow-subdirectories")}!`);continue}let _=ie.readdirSync(w);R(w,_);continue}let y=st.find(_=>_.matches(K));if(!y){console.warn(`${T} ${fe} Skipped \`${w}\` \`*${D.bold(Y.parse(K).ext)}\` files are not currently supported!`);continue}let{local:U,dependencies:j,devDependencies:B,imports:X}=y.resolveDependencies({isSubDir:true,excludeDeps:o.excludeDeps,dirs:o.dirs,containingDir:m,filePath:w,cwd:t}).match(_=>_,_=>{program.error(D.red(_));});for(let _ of U)_!==`${l}/${h}`&&d.add(_);for(let _ of j)S.add(_);for(let _ of B)C.add(_);for(let[_,Ge]of Object.entries(X))g[_]=Ge;$.push(N);}};R(m,ie.readdirSync(m));let I={name:h,directory:Y.relative(t,m),category:l,tests:x,subdirectory:true,list:p?f:false,files:$,localDependencies:Array.from(d.keys()),dependencies:Array.from(S.keys()),devDependencies:Array.from(C.keys()),_imports_:g};u.blocks.push(I);}}s.push(u);}return s},cn=(e,{cwd:t})=>{if(!e.configFiles)return;let r=[];for(let o of e.configFiles){let n=st.find(c=>c.matches(o.path));if(!n){r.push(o);continue}let{dependencies:s,devDependencies:i,local:a}=n.resolveDependencies({filePath:Y.join(t,o.path),isSubDir:false,excludeDeps:e.excludeDeps,dirs:e.dirs,cwd:t}).match(c=>c,c=>{program.error(D.red(c));});a.length>0&&program.error(D.red(`${D.bold(o.name)} ${D.bold(o.path)} Config files cannot have local dependencies!`)),r.push({...o,dependencies:s,devDependencies:i});}return r},rn=(e,t)=>t.doNotListBlocks.length>0&&t.doNotListBlocks.includes(e)?false:t.listBlocks.length>0?t.listBlocks.includes(e):true,on=(e,t)=>t.excludeBlocks.length>0&&t.excludeBlocks.includes(e)?false:t.includeBlocks.length>0?t.includeBlocks.includes(e):true,Ws=(e,t)=>t.doNotListCategories.length>0&&t.doNotListCategories.includes(e)?false:t.listCategories.length>0?t.listCategories.includes(e):true,Vs=(e,t)=>t.excludeCategories.length>0&&t.excludeCategories.includes(e)?false:t.includeCategories.length>0?t.includeCategories.includes(e):true,Js=e=>Y.parse(Y.basename(e)).name,ln=e=>{let t=[];for(let o of e){let n=[];for(let s of o.blocks){let i=`${s.category}/${s.name}`;!s.list&&!tn(i,e)||n.push(s);}n.length>0&&t.push({name:o.name,blocks:n});}return [t,0]};var ct="jsrepo.json",Qe="jsrepo-build-config.json",At=b.union([b.literal("prettier"),b.literal("biome")]),zs=b.objectWithRest({"*":b.string()},b.string()),$r=b.object({$schema:b.string(),repos:b.optional(b.array(b.string()),[]),includeTests:b.boolean(),paths:zs,configFiles:b.optional(b.record(b.string(),b.string())),watermark:b.optional(b.boolean(),true),formatter:b.optional(At)}),xe=e=>{if(!ie.existsSync(Y.join(e,ct)))return b$1("Could not find your configuration file! Please run `init`.");let t=b.safeParse($r,JSON.parse(ie.readFileSync(Y.join(e,ct)).toString()));return t.success?a(t.output):b$1(`There was an error reading your \`${ct}\` file!`)},Gs=b.object({$schema:b.string(),meta:b.optional(f),peerDependencies:b.optional(g),configFiles:b.optional(b.array(h)),dirs:b.array(b.string()),outputDir:b.optional(b.string()),includeBlocks:b.optional(b.array(b.string()),[]),includeCategories:b.optional(b.array(b.string()),[]),excludeBlocks:b.optional(b.array(b.string()),[]),excludeCategories:b.optional(b.array(b.string()),[]),doNotListBlocks:b.optional(b.array(b.string()),[]),doNotListCategories:b.optional(b.array(b.string()),[]),listBlocks:b.optional(b.array(b.string()),[]),listCategories:b.optional(b.array(b.string()),[]),excludeDeps:b.optional(b.array(b.string()),[]),allowSubdirectories:b.optional(b.boolean()),preview:b.optional(b.boolean()),rules:b.optional(Zo)}),rr=e=>{if(!ie.existsSync(Y.join(e,Qe)))return a(null);let t=b.safeParse(Gs,JSON.parse(ie.readFileSync(Y.join(e,Qe)).toString()));return t.success?a(t.output):b$1(`There was an error reading your \`${Qe}\` file!`)},Ae=(e,t)=>{let r=vt(t).unwrapOr(null),o=r?createPathsMatcher(r):null,n={"*":""};for(let[s,i]of Object.entries(e)){if(i.startsWith("./")){n[s]=Y.relative(t,Y.join(Y.resolve(t),i));continue}if(o===null)return b$1(`Cannot resolve ${D.bold(`\`"${s}": "${i}"\``)} from paths because we couldn't find a tsconfig! If you intended to use a relative path ensure that your path starts with ${D.bold("`./`")}.`);let a=Ks(i,o,t);if(!a)return b$1(`Cannot resolve ${D.bold(`\`"${s}": "${i}"\``)} from paths because we couldn't find a matching alias in the tsconfig. If you intended to use a relative path ensure that your path starts with ${D.bold("`./`")}.`);n[s]=a;}return a(n)},Ks=(e,t,r)=>{let o=t(e);return o.length>0?Y.relative(r,o[0]):void 0},Ft=(e,t,r)=>{let o;return t[e.category]!==void 0?o=Y.join(r,t[e.category]):o=Y.join(r,t["*"],e.category),o};var Xe=async(e,t,{verbose:r}={})=>await v(e,t,{verbose:r,fetch:xr,token:Cr(e.provider,e.url)}),or=async(e,{verbose:t}={})=>await w(e,{verbose:t,fetch:xr,token:Cr(e.provider,e.url)}),Cr=(e,t)=>{let r=new De;return e.name==="http"?r.get(`http-${new URL(t).origin}`):r.get(e.name)},Lt=async(e,{noCache:t$1=false}={})=>{let r=u(e);if(r){let o=Oe();if(r.name!==s.name&&!t$1){let i=o.get(`${e}-state`);if(i)return a({...i,provider:r})}let n=r.parse(e,{fullyQualified:false}),s$1=await r.state(e,{token:Cr(r,n.url),fetch:xr});return r.name!==s.name&&!t$1&&o.set(`${e}-state`,s$1),a(s$1)}return b$1(`Only ${t.map((o,n)=>`${n===t.length-1?"and ":""}${D.bold(o.name)}`).join(", ")} registries are supported at this time!`)},Ze=async(e,{noCache:t=false}={})=>{let r=[],n=(await Promise.all(e.map(async s=>{let i=await Lt(s,{noCache:t});if(i.isErr())return b$1({message:i.unwrapErr(),repo:s});let a=i.unwrap();r.push(a);}))).find(s=>s!==void 0);return n||a(r)},Bt=async(...e)=>{let t=new Map,o=(await Promise.all(e.map(async n=>{let s=await or(n);if(s.isErr())return b$1({message:s.unwrapErr(),repo:n.url});let i=s.unwrap();for(let a of i.categories)for(let c$1 of a.blocks)t.set(c(n.url,`${c$1.category}/${c$1.name}`),{...c$1,sourceRepo:n});}))).find(n=>n!==void 0);return o||a(t)},nr=e=>{let t=new Map;for(let r of e)for(let o of r.manifest.categories)for(let n of o.blocks)t.set(c(r.state.url,`${n.category}/${n.name}`),{...n,sourceRepo:r.state});return t},sr=async(...e)=>{let t=[],o=(await Promise.all(e.map(async n=>{let s=await or(n);if(s.isErr())return b$1({message:s.unwrapErr(),repo:n.url});let i=s.unwrap();t.push({state:n,manifest:i});}))).find(n=>n!==void 0);return o||a(t)};var lt=async(e,t,r,o=new Map)=>{let n=new Map;for(let s of e){let i,a=u(s);if(a){let{url:l,specifier:p}=a.parse(s,{fullyQualified:true});i=t.get(c(l,p));}else {if(r.length===0)return b$1(D.red(`If your config doesn't contain repos then you must provide the repo in the block specifier ex: \`${D.bold(`github/ieedan/std/${s}`)}\`!`));for(let l of r){let{url:p,specifier:u}=l.provider.parse(c(l.url,s),{fullyQualified:true}),v=t.get(c(p,u));if(v!==void 0){i=v;break}}}if(!i)return b$1(`Invalid block! ${D.bold(s)} does not exist!`);let c$1=`${i.category}/${i.name}`;if(n.set(c$1,i),i.localDependencies&&i.localDependencies.length>0){let l=await lt(i.localDependencies.filter(p=>!n.has(p)&&!o.has(p)),t,r,n);if(l.isErr())return b$1(l.unwrapErr());for(let p of l.unwrap())n.set(`${p.category}/${p.name}`,p);}}return a(Qr(n,(s,i)=>i))},pt=(e,t,r)=>{let o=[],n=Ae(t.paths,r).match(s=>s,s=>program.error(D.red(s)));for(let[s,i]of e){let a=Ft(i,n,r),c=Y.join(a,i.files[0]);i.subdirectory&&(c=Y.join(a,i.name)),ie.existsSync(c)&&o.push({specifier:`${i.category}/${i.name}`,path:c,block:i});}return o},ar=(e,t)=>{let r=[];for(let o of e){let n=o.files.filter(i=>Ye(i)?t.includeTests:true),s=Promise.all(n.map(async i=>{let a=await Xe(o.sourceRepo,Y.join(o.directory,i));return {name:i,content:a}}));r.push({block:o,files:s});}return r},Mt=(e,t,r,o)=>{let n=Ft(t,r,o);return t.subdirectory?Y.join(n,t.name,e):Y.join(n,e)};function pn(e){if(e===void 0)return;let t={};for(let r of e.split(",")){let[o,n]=r.split("=");if(o===void 0||n===void 0)throw new InvalidArgumentError("Expected map to be provided in the following format: `--option key=value,key=value`");t[o]=n;}return t}function dn(e){return new Promise(t=>t(e))}var dt=async({formatter:e,cwd:t})=>{let r=null;e==="prettier"&&(r=await xo.resolveConfig(Y.join(t,".prettierrc")));let o=null;if(e==="biome"){let n=Y.join(t,"biome.json");ie.existsSync(n)&&(o=JSON.parse(ie.readFileSync(n).toString()));}return {biomeOptions:o,prettierOptions:r}};var Wt=e=>`Installed from ${e}`;var bt=(e,t,r)=>{if(!t.peerDependencies)return;let o=vr(Y.join(r,"package.json")).match(i=>i,i=>{i.endsWith("doesn't exist")&&program.error(`Couldn't find your ${D.bold("package.json")}. Please create one.`),program.error(D.red(i));}),n={...o.dependencies,...o.devDependencies},s=[];for(let[i,a]of Object.entries(t.peerDependencies)){let c,l;typeof a=="string"?c=a:(c=a.version,l=a.message);let p=n[i];if(!p){s.push({name:i,expected:c,message:l,version:p,exists:false});continue}ao.satisfies(zt(p),c)||s.push({name:i,expected:c,message:l,version:p,exists:true});}if(s.length>0){process.stdout.write(`${T}
|
|
69
|
+
${s||e} references code not contained in ${D.bold(i.join(", "))} and cannot be resolved.`)},Go=(e,t=true)=>{let[r,o,...n]=e.split("/");o===void 0&&(o="index");let s=o;t&&s.includes(".")&&(s=s.slice(0,s.length-Y.parse(s).ext.length));let i=`${r}/${s}`,a=`{{${i}}}`;return n.length===0?s.length!==o.length&&(a+=Y.parse(o).ext):a+=`/${n.join("/")}`,{dependency:i,template:a}},As=(e,t,{filePath:r,dirs:o,cwd:n,containingDir:s})=>{let i=vt(r);if(i.isErr())return b$1(i.unwrapErr());let a$1=i.unwrap();if(a$1===null)return a(void 0);let c=createPathsMatcher(a$1);if(c){let l=c(e);for(let p of l){let u=Ls(p);if(!u)continue;let v=Y.relative(Y.resolve(Y.join(r,"../")),u.prettyPath),k=Fs(u.prettyPath,u.path,[".js",".ts"]),m=Ho(v,t,{filePath:r,containingDir:s,alias:e,dropExtension:k,dirs:o,cwd:n,modIsFile:u.type==="file"});if(m.isErr())return b$1(m.unwrapErr());if(m.unwrap())return a(m.unwrap());break}}return a(void 0)},Fs=(e,t,r=[".ts",".js",""])=>{if(e===t)return true;let o=Y.parse(e),n=Y.parse(t),s=Y.join(o.dir,o.name),i=Y.join(n.dir,n.name);return s!==i?false:!!(r.includes(o.ext)&&r.includes(n.ext))},Ls=e=>{if(ie.existsSync(e))return {path:e,prettyPath:e,type:ie.statSync(e).isDirectory()?"directory":"file"};let t=Y.join(e,"../");if(!ie.existsSync(t))return;let r=Y.parse(e);if(r.ext===".js"){let n=`${e.slice(0,e.length-3)}.ts`;if(ie.existsSync(n))return {path:n,prettyPath:e,type:"file"}}let o=ie.readdirSync(t);for(let n of o){let s=Y.parse(n);if(s.name===r.base){let i=Y.join(t,n),a=i.slice(0,i.length-s.ext.length);return {path:i,prettyPath:a,type:ie.statSync(i).isDirectory()?"directory":"file"}}}},Bs=(e,t,{doNotInstall:r}={doNotInstall:[]})=>{let o=new Set(r),n=yr(Y.dirname(t),""),s=new Set,i=new Set;if(n){let{devDependencies:a,dependencies:c}=JSON.parse(ie.readFileSync(n,"utf-8"));for(let l of e){let p=We(l);if(p.isErr()){console.warn(`${T} ${fe} Skipped adding import \`${D.cyan(l)}\`. Reason: Couldn't parse package name`);continue}let u=p.unwrap();if(!Ko(u.name).validForNewPackages){console.warn(`${T} ${fe} Skipped adding import \`${D.cyan(l)}\`. Reason: Not a valid package name`);continue}if(o.has(u.name))continue;let v;if(c!==void 0&&(v=c[u.name]),v!==void 0){s.add(`${u.name}@${v}`);continue}if(a!==void 0&&(v=a[u.name]),v!==void 0){i.add(`${u.name}@${v}`);continue}s.add(u.name);}}return {dependencies:Array.from(s),devDependencies:Array.from(i)}},st=[Co,jo,Qt,Do,Ao,_o,Mo,Io,Jo,zo];var Yo=new Set(["svelte","@sveltejs/kit","vue","nuxt","react","react-dom","next","@remix-run/react","@angular/core","@angular/common","@angular/forms","@angular/platform-browser","@angular/platform-browser-dynamic","@angular/router","@builder.io/qwik","astro","solid-js"]),Qo=b.union([b.literal("off"),b.literal("warn"),b.literal("error")]),Ms=b.union([b.literal("no-category-index-file-dependency"),b.literal("no-unpinned-dependency"),b.literal("require-local-dependency-exists"),b.literal("max-local-dependencies"),b.literal("no-circular-dependency"),b.literal("no-unused-block"),b.literal("no-framework-dependency"),b.literal("require-config-file-exists"),b.literal("no-config-file-framework-dependency"),b.literal("no-config-file-unpinned-dependency")]),Xo={"no-unpinned-dependency":{description:"Require all dependencies to have a pinned version.",scope:"block",check:e=>{let t=[];for(let r of [...e.dependencies,...e.devDependencies])r.includes("@")||t.push(`Couldn't find a version to use for ${D.bold(r)}`);return t.length>0?t:void 0}},"require-local-dependency-exists":{description:"Require all local dependencies to exist.",scope:"block",check:(e,{manifest:t})=>{let r=[];for(let o of e.localDependencies){let[n,s]=o.split("/"),i=t.categories.find(c=>c.name.trim()===n.trim()),a=`${D.bold(`${e.category}/${e.name}`)} depends on local dependency ${D.bold(o)} which doesn't exist`;if(!i){r.push(a);continue}i.blocks.find(c=>c.name===s)===void 0&&r.push(a);}return r.length>0?r:void 0}},"no-category-index-file-dependency":{description:"Disallow depending on the index file of a category.",scope:"block",check:(e,{manifest:t})=>{let r=[];for(let o of e.localDependencies){let[n,s]=o.split("/");if(s!=="index")continue;let i=t.categories.find(c=>c.name===n);!i||!i.blocks.find(c=>c.name===s)||r.push(`${D.bold(`${e.category}/${e.name}`)} depends on ${D.bold(`${n}/${s}`)}`);}return r.length>0?r:void 0}},"max-local-dependencies":{description:"Enforces a limit on the amount of local dependencies a block can have.",scope:"block",check:(e,{options:t})=>{let r=[],o;return typeof t[0]!="number"?o=5:o=t[0],e.localDependencies.length>o&&r.push(`${D.bold(`${e.category}/${e.name}`)} has too many local dependencies (${D.bold(e.localDependencies.length)}) limit (${D.bold(o)})`),r.length>0?r:void 0}},"no-circular-dependency":{description:"Disallow circular dependencies.",scope:"block",check:(e,{manifest:t})=>{let r=[],o=`${e.category}/${e.name}`,n=Zt(o,e,t.categories);return n&&r.push(`There is a circular dependency in ${D.bold(o)}: ${D.bold(n.join(" -> "))}`),r.length>0?r:void 0}},"no-unused-block":{description:"Disallow unused blocks. (Not listed and not a dependency of another block)",scope:"block",check:(e,{manifest:t})=>{if(e.list)return;let r=`${e.category}/${e.name}`,o=t.categories.flatMap(n=>n.blocks).filter(n=>n.list);for(let n of o)if(Zt(r,n,t.categories))return;return [`${D.bold(r)} is unused and will be ${D.bold.red("removed")}`]}},"no-framework-dependency":{description:"Disallow frameworks (Svelte, Vue, React) as dependencies.",scope:"block",check:e=>{let t=[],r=[...e.devDependencies,...e.dependencies].map(o=>We(o).unwrap().name).filter(o=>Yo.has(o));if(r.length>0)for(let o of r)t.push(`${D.bold(`${e.category}/${e.name}`)} depends on ${D.bold(o)} causing it to be installed when added`);return t.length>0?t:void 0}},"require-config-file-exists":{description:"Require all of the paths listed in `configFiles` to exist.",scope:"global",check:({manifest:e,cwd:t})=>{let r=[];if(e.configFiles!==void 0){for(let o of e.configFiles)ie.existsSync(Y.join(t,o.path))||r.push(`The ${D.bold(o.name)} config file doesn't exist at ${D.bold(Y.join(t,o.path))}`);return r.length>0?r:void 0}}},"no-config-file-framework-dependency":{description:"Disallow frameworks (Svelte, Vue, React) as dependencies of config files.",scope:"global",check:({manifest:e})=>{let t=[];if(e.configFiles!==void 0){for(let r of e.configFiles){let o=[...r.devDependencies??[],...r.dependencies??[]].map(n=>We(n).unwrap().name).filter(n=>Yo.has(n));if(o.length>0)for(let n of o)t.push(`${D.bold(r.name)} depends on ${D.bold(n)} causing it to be installed when added`);}return t.length>0?t:void 0}}},"no-config-file-unpinned-dependency":{description:"Require all dependencies of config files to have a pinned version.",scope:"global",check:({manifest:e})=>{let t=[];if(e.configFiles){for(let r of e.configFiles)for(let o of [...r.dependencies??[],...r.devDependencies??[]])o.includes("@")||t.push(`Couldn't find a version to use for ${D.bold(o)}`);return t.length>0?t:void 0}}}},Zo=b.record(Ms,b.union([Qo,b.tupleWithRest([Qo,b.union([b.string(),b.number()])],b.union([b.string(),b.number()]))])),br={"no-category-index-file-dependency":"warn","no-unpinned-dependency":"warn","require-local-dependency-exists":"error","max-local-dependencies":["warn",10],"no-circular-dependency":"error","no-unused-block":"warn","no-framework-dependency":"warn","require-config-file-exists":"error","no-config-file-framework-dependency":"warn","no-config-file-unpinned-dependency":"warn"},en=(e,t,r,o=br)=>{let n=[],s=[];for(let[i,a]of Object.entries(Xo)){if(a.scope==="block")continue;let c=o[i],l,p=[];if(Array.isArray(c)?(l=c[0],p.push(...c.slice(1))):l=c,l==="off")continue;let u=a.check({manifest:e,options:p,cwd:r,config:t});if(u){if(l==="error"){s.push(...u.map(v=>`${T} ${Et} ${D.red(v)} ${D.gray(i)}`));continue}n.push(...u.map(v=>`${T} ${fe} ${v} ${D.gray(i)}`));}}for(let i of e.categories)for(let a of i.blocks)for(let[c,l]of Object.entries(Xo)){if(l.scope==="global")continue;let p=o[c],u,v=[];if(Array.isArray(p)?(u=p[0],v.push(...p.slice(1))):u=p,u==="off")continue;let k=l.check(a,{manifest:e,options:v,cwd:r,config:t});if(k){if(u==="error"){s.push(...k.map(m=>`${T} ${Et} ${D.red(m)} ${D.gray(c)}`));continue}n.push(...k.map(m=>`${T} ${fe} ${m} ${D.gray(c)}`));}}return {warnings:n,errors:s}},Zt=(e,t,r,o=[])=>{let n=[...o,`${t.category}/${t.name}`];for(let s of t.localDependencies){if(s===e)return n;if(o.includes(s))return;let[i,a]=s.split("/"),c=r.find(p=>p.name===i)?.blocks.find(p=>p.name===a);if(!c)continue;let l=Zt(e,c,r,n);if(l)return [...l,e]}},tn=(e,t)=>{for(let r of t)for(let o of r.blocks){if(!o.list)continue;if(Zt(e,o,t))return true}return false};var sn=[".test.ts","_test.ts",".test.js","_test.js",".spec.ts","_spec.ts",".spec.js","_spec.js",".stories.jsx","_stories.jsx",".stories.tsx","_stories.tsx"],Ye=e=>sn.find(t=>e.endsWith(t))!==void 0,an=(e,{cwd:t,ignore:r,config:o})=>{let n;try{n=ie.readdirSync(e);}catch{program.error(D.red(`Couldn't read the ${D.bold(e)} directory.`));}let s=[];for(let i of n){let a=Y.join(e,i);if(ie.statSync(a).isFile())continue;let c=`${Y.relative(t,a)}/`;if(r.ignores(c))continue;let l=Y.basename(i);if(!Vs(l,o))continue;let p=Ws(l,o),u={name:l,blocks:[]},v=ie.readdirSync(a);for(let k of v){let m=Y.join(a,k);if(ie.statSync(m).isFile()){if(Ye(k))continue;let h=Js(k),f=rn(h,o);if(!on(h,o))continue;let d=st.find(I=>I.matches(k));if(!d){console.warn(`${T} ${fe} Skipped \`${D.bold(m)}\` \`*${D.bold(Y.parse(k).ext)}\` files are not currently supported!`);continue}let S=v.find(I=>sn.find(ee=>I===`${h}${ee}`)),{dependencies:C,devDependencies:g,local:x,imports:$}=d.resolveDependencies({filePath:m,isSubDir:false,excludeDeps:o.excludeDeps,dirs:o.dirs,cwd:t}).match(I=>I,I=>{program.error(D.red(I));}),R={name:h,directory:Y.relative(t,a),category:l,tests:S!==void 0,subdirectory:false,list:p?f:false,files:[k],localDependencies:x,_imports_:$,dependencies:C,devDependencies:g};S!==void 0&&R.files.push(S),u.blocks.push(R);}else {let h=k,f=rn(h,o);if(!on(h,o))continue;let d=new Set,S=new Set,C=new Set,g={},x=false,$=[],R=(ee,te)=>{for(let K of te){let w=Y.join(ee,K),N=w.slice(m.length+1);if(Ye(K)){x=true,$.push(N);continue}if(ie.statSync(w).isDirectory()){if(!o.allowSubdirectories){console.warn(`${T} ${fe} Skipped \`${D.bold(Y.join(m,K))}\` subdirectories are not allowed! Allow them with ${D.bold("--allow-subdirectories")}!`);continue}let _=ie.readdirSync(w);R(w,_);continue}let y=st.find(_=>_.matches(K));if(!y){console.warn(`${T} ${fe} Skipped \`${w}\` \`*${D.bold(Y.parse(K).ext)}\` files are not currently supported!`);continue}let{local:U,dependencies:j,devDependencies:B,imports:X}=y.resolveDependencies({isSubDir:true,excludeDeps:o.excludeDeps,dirs:o.dirs,containingDir:m,filePath:w,cwd:t}).match(_=>_,_=>{program.error(D.red(_));});for(let _ of U)_!==`${l}/${h}`&&d.add(_);for(let _ of j)S.add(_);for(let _ of B)C.add(_);for(let[_,Ge]of Object.entries(X))g[_]=Ge;$.push(N);}};R(m,ie.readdirSync(m));let I={name:h,directory:Y.relative(t,m),category:l,tests:x,subdirectory:true,list:p?f:false,files:$,localDependencies:Array.from(d.keys()),dependencies:Array.from(S.keys()),devDependencies:Array.from(C.keys()),_imports_:g};u.blocks.push(I);}}s.push(u);}return s},cn=(e,{cwd:t})=>{if(!e.configFiles)return;let r=[];for(let o of e.configFiles){let n=st.find(c=>c.matches(o.path));if(!n){r.push(o);continue}let{dependencies:s,devDependencies:i,local:a}=n.resolveDependencies({filePath:Y.join(t,o.path),isSubDir:false,excludeDeps:e.excludeDeps,dirs:e.dirs,cwd:t}).match(c=>c,c=>{program.error(D.red(c));});a.length>0&&program.error(D.red(`${D.bold(o.name)} ${D.bold(o.path)} Config files cannot have local dependencies!`)),r.push({...o,dependencies:s,devDependencies:i});}return r},rn=(e,t)=>t.doNotListBlocks.length>0&&t.doNotListBlocks.includes(e)?false:t.listBlocks.length>0?t.listBlocks.includes(e):true,on=(e,t)=>t.excludeBlocks.length>0&&t.excludeBlocks.includes(e)?false:t.includeBlocks.length>0?t.includeBlocks.includes(e):true,Ws=(e,t)=>t.doNotListCategories.length>0&&t.doNotListCategories.includes(e)?false:t.listCategories.length>0?t.listCategories.includes(e):true,Vs=(e,t)=>t.excludeCategories.length>0&&t.excludeCategories.includes(e)?false:t.includeCategories.length>0?t.includeCategories.includes(e):true,Js=e=>Y.parse(Y.basename(e)).name,ln=e=>{let t=[];for(let o of e){let n=[];for(let s of o.blocks){let i=`${s.category}/${s.name}`;!s.list&&!tn(i,e)||n.push(s);}n.length>0&&t.push({name:o.name,blocks:n});}return [t,0]};var ct="jsrepo.json",Qe="jsrepo-build-config.json",At=b.union([b.literal("prettier"),b.literal("biome")]),zs=b.objectWithRest({"*":b.string()},b.string()),$r=b.object({$schema:b.string(),repos:b.optional(b.array(b.string()),[]),includeTests:b.boolean(),paths:zs,configFiles:b.optional(b.record(b.string(),b.string())),watermark:b.optional(b.boolean(),true),formatter:b.optional(At)}),xe=e=>{if(!ie.existsSync(Y.join(e,ct)))return b$1("Could not find your configuration file! Please run `init`.");let t=b.safeParse($r,JSON.parse(ie.readFileSync(Y.join(e,ct)).toString()));return t.success?a(t.output):b$1(`There was an error reading your \`${ct}\` file!`)},Gs=b.object({$schema:b.string(),meta:b.optional(f),peerDependencies:b.optional(g),configFiles:b.optional(b.array(h)),dirs:b.array(b.string()),outputDir:b.optional(b.string()),includeBlocks:b.optional(b.array(b.string()),[]),includeCategories:b.optional(b.array(b.string()),[]),excludeBlocks:b.optional(b.array(b.string()),[]),excludeCategories:b.optional(b.array(b.string()),[]),doNotListBlocks:b.optional(b.array(b.string()),[]),doNotListCategories:b.optional(b.array(b.string()),[]),listBlocks:b.optional(b.array(b.string()),[]),listCategories:b.optional(b.array(b.string()),[]),excludeDeps:b.optional(b.array(b.string()),[]),allowSubdirectories:b.optional(b.boolean()),preview:b.optional(b.boolean()),rules:b.optional(Zo)}),rr=e=>{if(!ie.existsSync(Y.join(e,Qe)))return a(null);let t=b.safeParse(Gs,JSON.parse(ie.readFileSync(Y.join(e,Qe)).toString()));return t.success?a(t.output):b$1(`There was an error reading your \`${Qe}\` file!`)},Ae=(e,t)=>{let r=vt(t).unwrapOr(null),o=r?createPathsMatcher(r):null,n={"*":""};for(let[s,i]of Object.entries(e)){if(i.startsWith("./")){n[s]=Y.relative(t,Y.join(Y.resolve(t),i));continue}if(o===null)return b$1(`Cannot resolve ${D.bold(`\`"${s}": "${i}"\``)} from paths because we couldn't find a tsconfig! If you intended to use a relative path ensure that your path starts with ${D.bold("`./`")}.`);let a=Ks(i,o,t);if(!a)return b$1(`Cannot resolve ${D.bold(`\`"${s}": "${i}"\``)} from paths because we couldn't find a matching alias in the tsconfig. If you intended to use a relative path ensure that your path starts with ${D.bold("`./`")}.`);n[s]=a;}return a(n)},Ks=(e,t,r)=>{let o=t(e);return o.length>0?Y.relative(r,o[0]):void 0},Ft=(e,t,r)=>{let o;return t[e.category]!==void 0?o=Y.join(r,t[e.category]):o=Y.join(r,t["*"],e.category),o};var Xe=async(e,t,{verbose:r}={})=>await v(e,t,{verbose:r,fetch:xr,token:Cr(e.provider,e.url)}),or=async(e,{verbose:t}={})=>await w(e,{verbose:t,fetch:xr,token:Cr(e.provider,e.url)}),Cr=(e,t)=>{let r=new De;return e.name==="http"?r.get(`http-${new URL(t).origin}`):r.get(e.name)},Lt=async(e,{noCache:t$1=false}={})=>{let r=u(e);if(r){let o=Oe();if(r.name!==s.name&&!t$1)if(t$1)o.delete(`${e}-state`);else {let i=o.get(`${e}-state`);if(i)return a({...i,provider:r})}let n=r.parse(e,{fullyQualified:false}),s$1=await r.state(e,{token:Cr(r,n.url),fetch:xr});return r.name!==s.name&&!t$1&&o.set(`${e}-state`,s$1),a(s$1)}return b$1(`Only ${t.map((o,n)=>`${n===t.length-1?"and ":""}${D.bold(o.name)}`).join(", ")} registries are supported at this time!`)},Ze=async(e,{noCache:t=false}={})=>{let r=[],n=(await Promise.all(e.map(async s=>{let i=await Lt(s,{noCache:t});if(i.isErr())return b$1({message:i.unwrapErr(),repo:s});let a=i.unwrap();r.push(a);}))).find(s=>s!==void 0);return n||a(r)},Bt=async(...e)=>{let t=new Map,o=(await Promise.all(e.map(async n=>{let s=await or(n);if(s.isErr())return b$1({message:s.unwrapErr(),repo:n.url});let i=s.unwrap();for(let a of i.categories)for(let c$1 of a.blocks)t.set(c(n.url,`${c$1.category}/${c$1.name}`),{...c$1,sourceRepo:n});}))).find(n=>n!==void 0);return o||a(t)},nr=e=>{let t=new Map;for(let r of e)for(let o of r.manifest.categories)for(let n of o.blocks)t.set(c(r.state.url,`${n.category}/${n.name}`),{...n,sourceRepo:r.state});return t},sr=async(...e)=>{let t=[],o=(await Promise.all(e.map(async n=>{let s=await or(n);if(s.isErr())return b$1({message:s.unwrapErr(),repo:n.url});let i=s.unwrap();t.push({state:n,manifest:i});}))).find(n=>n!==void 0);return o||a(t)};var lt=async(e,t,r,o=new Map)=>{let n=new Map;for(let s of e){let i,a=u(s);if(a){let{url:l,specifier:p}=a.parse(s,{fullyQualified:true});i=t.get(c(l,p));}else {if(r.length===0)return b$1(D.red(`If your config doesn't contain repos then you must provide the repo in the block specifier ex: \`${D.bold(`github/ieedan/std/${s}`)}\`!`));for(let l of r){let{url:p,specifier:u}=l.provider.parse(c(l.url,s),{fullyQualified:true}),v=t.get(c(p,u));if(v!==void 0){i=v;break}}}if(!i)return b$1(`Invalid block! ${D.bold(s)} does not exist!`);let c$1=`${i.category}/${i.name}`;if(n.set(c$1,i),i.localDependencies&&i.localDependencies.length>0){let l=await lt(i.localDependencies.filter(p=>!n.has(p)&&!o.has(p)),t,r,n);if(l.isErr())return b$1(l.unwrapErr());for(let p of l.unwrap())n.set(`${p.category}/${p.name}`,p);}}return a(Qr(n,(s,i)=>i))},pt=(e,t,r)=>{let o=[],n=Ae(t.paths,r).match(s=>s,s=>program.error(D.red(s)));for(let[s,i]of e){let a=Ft(i,n,r),c=Y.join(a,i.files[0]);i.subdirectory&&(c=Y.join(a,i.name)),ie.existsSync(c)&&o.push({specifier:`${i.category}/${i.name}`,path:c,block:i});}return o},ar=(e,t)=>{let r=[];for(let o of e){let n=o.files.filter(i=>Ye(i)?t.includeTests:true),s=Promise.all(n.map(async i=>{let a=await Xe(o.sourceRepo,Y.join(o.directory,i));return {name:i,content:a}}));r.push({block:o,files:s});}return r},Mt=(e,t,r,o)=>{let n=Ft(t,r,o);return t.subdirectory?Y.join(n,t.name,e):Y.join(n,e)};function pn(e){if(e===void 0)return;let t={};for(let r of e.split(",")){let[o,n]=r.split("=");if(o===void 0||n===void 0)throw new InvalidArgumentError("Expected map to be provided in the following format: `--option key=value,key=value`");t[o]=n;}return t}function dn(e){return new Promise(t=>t(e))}var dt=async({formatter:e,cwd:t})=>{let r=null;e==="prettier"&&(r=await xo.resolveConfig(Y.join(t,".prettierrc")));let o=null;if(e==="biome"){let n=Y.join(t,"biome.json");ie.existsSync(n)&&(o=JSON.parse(ie.readFileSync(n).toString()));}return {biomeOptions:o,prettierOptions:r}};var Wt=e=>`Installed from ${e}`;var bt=(e,t,r)=>{if(!t.peerDependencies)return;let o=vr(Y.join(r,"package.json")).match(i=>i,i=>{i.endsWith("doesn't exist")&&program.error(`Couldn't find your ${D.bold("package.json")}. Please create one.`),program.error(D.red(i));}),n={...o.dependencies,...o.devDependencies},s=[];for(let[i,a]of Object.entries(t.peerDependencies)){let c,l;typeof a=="string"?c=a:(c=a.version,l=a.message);let p=n[i];if(!p){s.push({name:i,expected:c,message:l,version:p,exists:false});continue}ao.satisfies(zt(p),c)||s.push({name:i,expected:c,message:l,version:p,exists:true});}if(s.length>0){process.stdout.write(`${T}
|
|
70
70
|
${D.yellow("\u25B2")} ${qr} Issues with ${D.bold(e.url)} peer dependencies
|
|
71
71
|
`);let i=s.map((a,c)=>{let l=s.length-1===c,p;a.exists?p=`${D.yellowBright("x unmet peer")} need ${D.bold(`${a.name}@`)}${D.greenBright.bold(a.expected)} >> found ${D.yellowBright.bold(a.version)}`:p=`${D.red("x missing peer")} need ${D.bold(`${a.name}@`)}${D.greenBright.bold(a.expected)}`;let u=`${T} ${l?Yr:It}${Pt} ${p}`;return a.message?`${u}
|
|
72
72
|
${T} ${l?"":T} ${D.gray(a.message)}`:u}).join(`
|