jsrepo
Version:
A CLI to add shared code from remote repositories.
30 lines • 111 kB
JavaScript
#!/usr/bin/env node
import{i as e,n as t,r as n,t as r}from"./picocolors-DQPB0Sb5.mjs";import{$ as i,A as a,C as o,Ct as s,D as c,E as l,J as u,M as d,N as f,O as p,Q as m,S as h,St as g,Tt as _,V as v,X as y,Y as b,Z as x,_ as S,_t as C,at as w,b as T,bt as E,ct as D,dt as O,et as k,ft as A,g as j,gt as M,h as ee,ht as N,it as te,j as ne,k as re,lt as ie,m as ae,mt as oe,nt as se,ot as P,pt as ce,q as le,r as ue,rt as de,st as F,t as fe,tt as pe,ut as me,v as he,vt as ge,w as _e,wt as ve,xt as I,y as ye,yt as L}from"./providers-lyYy80j9.mjs";import{_ as be,b as R,c as xe,d as Se,g as Ce,h as we,l as z,m as Te,p as B,s as Ee,u as V,v as De,y as Oe}from"./warnings-DFbHh8ba.mjs";import{A as ke,N as Ae,O as je,P as Me,S as H,_ as Ne,a as Pe,b as Fe,g as Ie,h as Le,i as Re,j as ze,r as Be,t as Ve,x as He,y as Ue,z as We}from"./errors-ZO96VU6k.mjs";import{Command as U,Option as W,program as Ge}from"commander";import{watch as Ke}from"node:fs";import{Visitor as qe,parse as Je}from"oxc-parser";import Ye from"node:os";import{buffer as Xe}from"node:stream/consumers";import{createGzip as Ze}from"node:zlib";var G=g(),K=e(r(),1);const q=C({cwd:L().transform(e=>e)}),J={yes:new W(`--yes`,`Skip the confirmation prompt.`).default(!1),noCache:new W(`--no-cache`,`Disable caching of resolved git urls.`).default(!1),verbose:new W(`--verbose`,`Include debug logs.`).default(!1),overwrite:new W(`--overwrite`,`Overwrite files without prompting.`).default(!1),expand:new W(`-E, --expand`,`Expands the diff so you see the entire file.`).default(!1),maxUnchanged:new W(`--max-unchanged <lines>`,`Maximum unchanged lines that will show without being collapsed.`).argParser(e=>Number.parseInt(e,10)).default(5),cwd:new W(`--cwd <path>`,`The current working directory.`).default(process.cwd())};function Y(e,t){return ie(e,t).match(e=>e,e=>Z(new Ie(e.zodError)))}async function X(e){try{let t=await e;return t.isErr()?Z(t.error):t.value}catch(e){e instanceof H&&Z(e),Z(new H(e instanceof Error?e.message:String(e),{suggestion:`Please try again.`}))}}function Z(e){return Qe(e)}function Qe(e){B.message(),process.env.JSREPO_TRACE===`1`?(console.trace(e),process.exit(1)):(V(K.default.red(e.toString())),process.exit(1))}async function $e(e,t,n){if(Array.isArray(e.registry)){let r=[];for(let i of e.registry)r.push(await t(await O(i,n)));return r}else return[await t(await O(e.registry,n))]}function et(e){return Array.isArray(e.registry)?e.registry.length>0:!0}var tt=44,nt=59,rt=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,it=new Uint8Array(64),at=new Uint8Array(128);for(let e=0;e<rt.length;e++){let t=rt.charCodeAt(e);it[e]=t,at[t]=e}function ot(e,t,n){let r=t-n;r=r<0?-r<<1|1:r<<1;do{let t=r&31;r>>>=5,r>0&&(t|=32),e.write(it[t])}while(r>0);return t}var st=1024*16,ct=typeof TextDecoder<`u`?new TextDecoder:typeof Buffer<`u`?{decode(e){return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString()}}:{decode(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}},lt=class{constructor(){this.pos=0,this.out=``,this.buffer=new Uint8Array(st)}write(e){let{buffer:t}=this;t[this.pos++]=e,this.pos===st&&(this.out+=ct.decode(t),this.pos=0)}flush(){let{buffer:e,out:t,pos:n}=this;return n>0?t+ct.decode(e.subarray(0,n)):t}};function ut(e){let t=new lt,n=0,r=0,i=0,a=0;for(let o=0;o<e.length;o++){let s=e[o];if(o>0&&t.write(nt),s.length===0)continue;let c=0;for(let e=0;e<s.length;e++){let o=s[e];e>0&&t.write(tt),c=ot(t,o[0],c),o.length!==1&&(n=ot(t,o[1],n),r=ot(t,o[2],r),i=ot(t,o[3],i),o.length!==4&&(a=ot(t,o[4],a)))}}return t.flush()}var dt=class e{constructor(t){this.bits=t instanceof e?t.bits.slice():[]}add(e){this.bits[e>>5]|=1<<(e&31)}has(e){return!!(this.bits[e>>5]&1<<(e&31))}},ft=class e{constructor(e,t,n){this.start=e,this.end=t,this.original=n,this.intro=``,this.outro=``,this.content=n,this.storeName=!1,this.edited=!1,this.previous=null,this.next=null}appendLeft(e){this.outro+=e}appendRight(e){this.intro+=e}clone(){let t=new e(this.start,this.end,this.original);return t.intro=this.intro,t.outro=this.outro,t.content=this.content,t.storeName=this.storeName,t.edited=this.edited,t}contains(e){return this.start<e&&e<this.end}eachNext(e){let t=this;for(;t;)e(t),t=t.next}eachPrevious(e){let t=this;for(;t;)e(t),t=t.previous}edit(e,t,n){return this.content=e,n||(this.intro=``,this.outro=``),this.storeName=t,this.edited=!0,this}prependLeft(e){this.outro=e+this.outro}prependRight(e){this.intro=e+this.intro}reset(){this.intro=``,this.outro=``,this.edited&&=(this.content=this.original,this.storeName=!1,!1)}split(t){let n=t-this.start,r=this.original.slice(0,n),i=this.original.slice(n);this.original=r;let a=new e(t,this.end,i);return a.outro=this.outro,this.outro=``,this.end=t,this.edited?(a.edit(``,!1),this.content=``):this.content=r,a.next=this.next,a.next&&(a.next.previous=a),a.previous=this,this.next=a,a}toString(){return this.intro+this.content+this.outro}trimEnd(e){if(this.outro=this.outro.replace(e,``),this.outro.length)return!0;let t=this.content.replace(e,``);if(t.length)return t!==this.content&&(this.split(this.start+t.length).edit(``,void 0,!0),this.edited&&this.edit(t,this.storeName,!0)),!0;if(this.edit(``,void 0,!0),this.intro=this.intro.replace(e,``),this.intro.length)return!0}trimStart(e){if(this.intro=this.intro.replace(e,``),this.intro.length)return!0;let t=this.content.replace(e,``);if(t.length){if(t!==this.content){let e=this.split(this.end-t.length);this.edited&&e.edit(t,this.storeName,!0),this.edit(``,void 0,!0)}return!0}else if(this.edit(``,void 0,!0),this.outro=this.outro.replace(e,``),this.outro.length)return!0}};function pt(){return typeof globalThis<`u`&&typeof globalThis.btoa==`function`?e=>globalThis.btoa(unescape(encodeURIComponent(e))):typeof Buffer==`function`?e=>Buffer.from(e,`utf-8`).toString(`base64`):()=>{throw Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.")}}const mt=pt();var ht=class{constructor(e){this.version=3,this.file=e.file,this.sources=e.sources,this.sourcesContent=e.sourcesContent,this.names=e.names,this.mappings=ut(e.mappings),e.x_google_ignoreList!==void 0&&(this.x_google_ignoreList=e.x_google_ignoreList),e.debugId!==void 0&&(this.debugId=e.debugId)}toString(){return JSON.stringify(this)}toUrl(){return`data:application/json;charset=utf-8;base64,`+mt(this.toString())}};function gt(e){let t=e.split(`
`),n=t.filter(e=>/^\t+/.test(e)),r=t.filter(e=>/^ {2,}/.test(e));if(n.length===0&&r.length===0)return null;if(n.length>=r.length)return` `;let i=r.reduce((e,t)=>{let n=/^ +/.exec(t)[0].length;return Math.min(n,e)},1/0);return Array(i+1).join(` `)}function _t(e,t){let n=e.split(/[/\\]/),r=t.split(/[/\\]/);for(n.pop();n[0]===r[0];)n.shift(),r.shift();if(n.length){let e=n.length;for(;e--;)n[e]=`..`}return n.concat(r).join(`/`)}const vt=Object.prototype.toString;function yt(e){return vt.call(e)===`[object Object]`}function bt(e){let t=e.split(`
`),n=[];for(let e=0,r=0;e<t.length;e++)n.push(r),r+=t[e].length+1;return function(e){let t=0,r=n.length;for(;t<r;){let i=t+r>>1;e<n[i]?r=i:t=i+1}let i=t-1;return{line:i,column:e-n[i]}}}const xt=/\w/;var St=class{constructor(e){this.hires=e,this.generatedCodeLine=0,this.generatedCodeColumn=0,this.raw=[],this.rawSegments=this.raw[this.generatedCodeLine]=[],this.pending=null}addEdit(e,t,n,r){if(t.length){let i=t.length-1,a=t.indexOf(`
`,0),o=-1;for(;a>=0&&i>a;){let i=[this.generatedCodeColumn,e,n.line,n.column];r>=0&&i.push(r),this.rawSegments.push(i),this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,o=a,a=t.indexOf(`
`,a+1)}let s=[this.generatedCodeColumn,e,n.line,n.column];r>=0&&s.push(r),this.rawSegments.push(s),this.advance(t.slice(o+1))}else this.pending&&(this.rawSegments.push(this.pending),this.advance(t));this.pending=null}addUneditedChunk(e,t,n,r,i){let a=t.start,o=!0,s=!1;for(;a<t.end;){if(n[a]===`
`)r.line+=1,r.column=0,this.generatedCodeLine+=1,this.raw[this.generatedCodeLine]=this.rawSegments=[],this.generatedCodeColumn=0,o=!0,s=!1;else{if(this.hires||o||i.has(a)){let t=[this.generatedCodeColumn,e,r.line,r.column];this.hires===`boundary`?xt.test(n[a])?s||=(this.rawSegments.push(t),!0):(this.rawSegments.push(t),s=!1):this.rawSegments.push(t)}r.column+=1,this.generatedCodeColumn+=1,o=!1}a+=1}this.pending=null}advance(e){if(!e)return;let t=e.split(`
`);if(t.length>1){for(let e=0;e<t.length-1;e++)this.generatedCodeLine++,this.raw[this.generatedCodeLine]=this.rawSegments=[];this.generatedCodeColumn=0}this.generatedCodeColumn+=t[t.length-1].length}};const Ct={insertLeft:!1,insertRight:!1,storeName:!1};var wt=class e{constructor(e,t={}){let n=new ft(0,e.length,e);Object.defineProperties(this,{original:{writable:!0,value:e},outro:{writable:!0,value:``},intro:{writable:!0,value:``},firstChunk:{writable:!0,value:n},lastChunk:{writable:!0,value:n},lastSearchedChunk:{writable:!0,value:n},byStart:{writable:!0,value:{}},byEnd:{writable:!0,value:{}},filename:{writable:!0,value:t.filename},indentExclusionRanges:{writable:!0,value:t.indentExclusionRanges},sourcemapLocations:{writable:!0,value:new dt},storedNames:{writable:!0,value:{}},indentStr:{writable:!0,value:void 0},ignoreList:{writable:!0,value:t.ignoreList},offset:{writable:!0,value:t.offset||0}}),this.byStart[0]=n,this.byEnd[e.length]=n}addSourcemapLocation(e){this.sourcemapLocations.add(e)}append(e){if(typeof e!=`string`)throw TypeError(`outro content must be a string`);return this.outro+=e,this}appendLeft(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byEnd[e];return n?n.appendLeft(t):this.intro+=t,this}appendRight(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byStart[e];return n?n.appendRight(t):this.outro+=t,this}clone(){let t=new e(this.original,{filename:this.filename,offset:this.offset}),n=this.firstChunk,r=t.firstChunk=t.lastSearchedChunk=n.clone();for(;n;){t.byStart[r.start]=r,t.byEnd[r.end]=r;let e=n.next,i=e&&e.clone();i&&(r.next=i,i.previous=r,r=i),n=e}return t.lastChunk=r,this.indentExclusionRanges&&(t.indentExclusionRanges=this.indentExclusionRanges.slice()),t.sourcemapLocations=new dt(this.sourcemapLocations),t.intro=this.intro,t.outro=this.outro,t}generateDecodedMap(e){e||={};let t=Object.keys(this.storedNames),n=new St(e.hires),r=bt(this.original);return this.intro&&n.advance(this.intro),this.firstChunk.eachNext(e=>{let i=r(e.start);e.intro.length&&n.advance(e.intro),e.edited?n.addEdit(0,e.content,i,e.storeName?t.indexOf(e.original):-1):n.addUneditedChunk(0,e,this.original,i,this.sourcemapLocations),e.outro.length&&n.advance(e.outro)}),this.outro&&n.advance(this.outro),{file:e.file?e.file.split(/[/\\]/).pop():void 0,sources:[e.source?_t(e.file||``,e.source):e.file||``],sourcesContent:e.includeContent?[this.original]:void 0,names:t,mappings:n.raw,x_google_ignoreList:this.ignoreList?[0]:void 0}}generateMap(e){return new ht(this.generateDecodedMap(e))}_ensureindentStr(){this.indentStr===void 0&&(this.indentStr=gt(this.original))}_getRawIndentString(){return this._ensureindentStr(),this.indentStr}getIndentString(){return this._ensureindentStr(),this.indentStr===null?` `:this.indentStr}indent(e,t){let n=/^[^\r\n]/gm;if(yt(e)&&(t=e,e=void 0),e===void 0&&(this._ensureindentStr(),e=this.indentStr||` `),e===``)return this;t||={};let r={};t.exclude&&(typeof t.exclude[0]==`number`?[t.exclude]:t.exclude).forEach(e=>{for(let t=e[0];t<e[1];t+=1)r[t]=!0});let i=t.indentStart!==!1,a=t=>i?`${e}${t}`:(i=!0,t);this.intro=this.intro.replace(n,a);let o=0,s=this.firstChunk;for(;s;){let t=s.end;if(s.edited)r[o]||(s.content=s.content.replace(n,a),s.content.length&&(i=s.content[s.content.length-1]===`
`));else for(o=s.start;o<t;){if(!r[o]){let t=this.original[o];t===`
`?i=!0:t!==`\r`&&i&&(i=!1,o===s.start?s.prependRight(e):(this._splitChunk(s,o),s=s.next,s.prependRight(e)))}o+=1}o=s.end,s=s.next}return this.outro=this.outro.replace(n,a),this}insert(){throw Error(`magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)`)}insertLeft(e,t){return Ct.insertLeft||=(console.warn(`magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead`),!0),this.appendLeft(e,t)}insertRight(e,t){return Ct.insertRight||=(console.warn(`magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead`),!0),this.prependRight(e,t)}move(e,t,n){if(e+=this.offset,t+=this.offset,n+=this.offset,n>=e&&n<=t)throw Error(`Cannot move a selection inside itself`);this._split(e),this._split(t),this._split(n);let r=this.byStart[e],i=this.byEnd[t],a=r.previous,o=i.next,s=this.byStart[n];if(!s&&i===this.lastChunk)return this;let c=s?s.previous:this.lastChunk;return a&&(a.next=o),o&&(o.previous=a),c&&(c.next=r),s&&(s.previous=i),r.previous||(this.firstChunk=i.next),i.next||(this.lastChunk=r.previous,this.lastChunk.next=null),r.previous=c,i.next=s||null,c||(this.firstChunk=r),s||(this.lastChunk=i),this}overwrite(e,t,n,r){return r||={},this.update(e,t,n,{...r,overwrite:!r.contentOnly})}update(e,t,n,r){if(e+=this.offset,t+=this.offset,typeof n!=`string`)throw TypeError(`replacement content must be a string`);if(this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(t>this.original.length)throw Error(`end is out of bounds`);if(e===t)throw Error(`Cannot overwrite a zero-length range – use appendLeft or prependRight instead`);this._split(e),this._split(t),r===!0&&(Ct.storeName||=(console.warn(`The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string`),!0),r={storeName:!0});let i=r===void 0?!1:r.storeName,a=r===void 0?!1:r.overwrite;if(i){let n=this.original.slice(e,t);Object.defineProperty(this.storedNames,n,{writable:!0,value:!0,enumerable:!0})}let o=this.byStart[e],s=this.byEnd[t];if(o){let e=o;for(;e!==s;){if(e.next!==this.byStart[e.end])throw Error(`Cannot overwrite across a split point`);e=e.next,e.edit(``,!1)}o.edit(n,i,!a)}else{let r=new ft(e,t,``).edit(n,i);s.next=r,r.previous=s}return this}prepend(e){if(typeof e!=`string`)throw TypeError(`outro content must be a string`);return this.intro=e+this.intro,this}prependLeft(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byEnd[e];return n?n.prependLeft(t):this.intro=t+this.intro,this}prependRight(e,t){if(e+=this.offset,typeof t!=`string`)throw TypeError(`inserted content must be a string`);this._split(e);let n=this.byStart[e];return n?n.prependRight(t):this.outro=t+this.outro,this}remove(e,t){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw Error(`Character is out of bounds`);if(e>t)throw Error(`end must be greater than start`);this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.intro=``,n.outro=``,n.edit(``),n=t>n.end?this.byStart[n.end]:null;return this}reset(e,t){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}if(e===t)return this;if(e<0||t>this.original.length)throw Error(`Character is out of bounds`);if(e>t)throw Error(`end must be greater than start`);this._split(e),this._split(t);let n=this.byStart[e];for(;n;)n.reset(),n=t>n.end?this.byStart[n.end]:null;return this}lastChar(){if(this.outro.length)return this.outro[this.outro.length-1];let e=this.lastChunk;do{if(e.outro.length)return e.outro[e.outro.length-1];if(e.content.length)return e.content[e.content.length-1];if(e.intro.length)return e.intro[e.intro.length-1]}while(e=e.previous);return this.intro.length?this.intro[this.intro.length-1]:``}lastLine(){let e=this.outro.lastIndexOf(`
`);if(e!==-1)return this.outro.substr(e+1);let t=this.outro,n=this.lastChunk;do{if(n.outro.length>0){if(e=n.outro.lastIndexOf(`
`),e!==-1)return n.outro.substr(e+1)+t;t=n.outro+t}if(n.content.length>0){if(e=n.content.lastIndexOf(`
`),e!==-1)return n.content.substr(e+1)+t;t=n.content+t}if(n.intro.length>0){if(e=n.intro.lastIndexOf(`
`),e!==-1)return n.intro.substr(e+1)+t;t=n.intro+t}}while(n=n.previous);return e=this.intro.lastIndexOf(`
`),e===-1?this.intro+t:this.intro.substr(e+1)+t}slice(e=0,t=this.original.length-this.offset){if(e+=this.offset,t+=this.offset,this.original.length!==0){for(;e<0;)e+=this.original.length;for(;t<0;)t+=this.original.length}let n=``,r=this.firstChunk;for(;r&&(r.start>e||r.end<=e);){if(r.start<t&&r.end>=t)return n;r=r.next}if(r&&r.edited&&r.start!==e)throw Error(`Cannot use replaced character ${e} as slice start anchor.`);let i=r;for(;r;){r.intro&&(i!==r||r.start===e)&&(n+=r.intro);let a=r.start<t&&r.end>=t;if(a&&r.edited&&r.end!==t)throw Error(`Cannot use replaced character ${t} as slice end anchor.`);let o=i===r?e-r.start:0,s=a?r.content.length+t-r.end:r.content.length;if(n+=r.content.slice(o,s),r.outro&&(!a||r.end===t)&&(n+=r.outro),a)break;r=r.next}return n}snip(e,t){let n=this.clone();return n.remove(0,e),n.remove(t,n.original.length),n}_split(e){if(this.byStart[e]||this.byEnd[e])return;let t=this.lastSearchedChunk,n=t,r=e>t.end;for(;t;){if(t.contains(e))return this._splitChunk(t,e);if(t=r?this.byStart[t.end]:this.byEnd[t.start],t===n)return;n=t}}_splitChunk(e,t){if(e.edited&&e.content.length){let n=bt(this.original)(t);throw Error(`Cannot split a chunk that has already been edited (${n.line}:${n.column} – "${e.original}")`)}let n=e.split(t);return this.byEnd[t]=e,this.byStart[t]=n,this.byEnd[n.end]=n,e===this.lastChunk&&(this.lastChunk=n),this.lastSearchedChunk=e,!0}toString(){let e=this.intro,t=this.firstChunk;for(;t;)e+=t.toString(),t=t.next;return e+this.outro}isEmpty(){let e=this.firstChunk;do if(e.intro.length&&e.intro.trim()||e.content.length&&e.content.trim()||e.outro.length&&e.outro.trim())return!1;while(e=e.next);return!0}length(){let e=this.firstChunk,t=0;do t+=e.intro.length+e.content.length+e.outro.length;while(e=e.next);return t}trimLines(){return this.trim(`[\\r\\n]`)}trim(e){return this.trimStart(e).trimEnd(e)}trimEndAborted(e){let t=RegExp((e||`\\s`)+`+$`);if(this.outro=this.outro.replace(t,``),this.outro.length)return!0;let n=this.lastChunk;do{let e=n.end,r=n.trimEnd(t);if(n.end!==e&&(this.lastChunk===n&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.previous}while(n);return!1}trimEnd(e){return this.trimEndAborted(e),this}trimStartAborted(e){let t=RegExp(`^`+(e||`\\s`)+`+`);if(this.intro=this.intro.replace(t,``),this.intro.length)return!0;let n=this.firstChunk;do{let e=n.end,r=n.trimStart(t);if(n.end!==e&&(n===this.lastChunk&&(this.lastChunk=n.next),this.byEnd[n.end]=n,this.byStart[n.next.start]=n.next,this.byEnd[n.next.end]=n.next),r)return!0;n=n.next}while(n);return!1}trimStart(e){return this.trimStartAborted(e),this}hasChanged(){return this.original!==this.toString()}_replaceRegexp(e,t){function n(e,n){return typeof t==`string`?t.replace(/\$(\$|&|\d+)/g,(t,n)=>n===`$`?`$`:n===`&`?e[0]:+n<e.length?e[+n]:`$${n}`):t(...e,e.index,n,e.groups)}function r(e,t){let n,r=[];for(;n=e.exec(t);)r.push(n);return r}if(e.global)r(e,this.original).forEach(e=>{if(e.index!=null){let t=n(e,this.original);t!==e[0]&&this.overwrite(e.index,e.index+e[0].length,t)}});else{let t=this.original.match(e);if(t&&t.index!=null){let e=n(t,this.original);e!==t[0]&&this.overwrite(t.index,t.index+t[0].length,e)}}return this}_replaceString(e,t){let{original:n}=this,r=n.indexOf(e);return r!==-1&&(typeof t==`function`&&(t=t(e,r,n)),e!==t&&this.overwrite(r,r+e.length,t)),this}replace(e,t){return typeof e==`string`?this._replaceString(e,t):this._replaceRegexp(e,t)}_replaceAllString(e,t){let{original:n}=this,r=e.length;for(let i=n.indexOf(e);i!==-1;i=n.indexOf(e,i+r)){let e=n.slice(i,i+r),a=t;typeof t==`function`&&(a=t(e,i,n)),e!==a&&this.overwrite(i,i+r,a)}return this}replaceAll(e,t){if(typeof e==`string`)return this._replaceAllString(e,t);if(!e.global)throw TypeError(`MagicString.prototype.replaceAll called with a non-global RegExp argument`);return this._replaceRegexp(e,t)}},Tt=class{withinExportDefaultDeclaration=!1;withinDefineConfig=!1;withinMainObjectExpression=!1;withinIgnoredProperty=!1;configKeyPropertyDeclaration=null;mainObjectExpression=null};async function Et(e,{config:t}){if(Object.keys(e).length===0)return(0,G.ok)(t.code);let n=await Je(t.path,t.code),r=new wt(t.code),i=new Tt;if(i.withinDefineConfig=!0,new qe({ExportDefaultDeclaration(){i.withinExportDefaultDeclaration=!0},"ExportDefaultDeclaration:exit"(){i.withinExportDefaultDeclaration=!1},ObjectExpression(e){i.withinExportDefaultDeclaration&&i.withinDefineConfig&&(i.withinIgnoredProperty||(i.withinMainObjectExpression||=(i.mainObjectExpression=e,!0)))},CallExpression(e){i.withinExportDefaultDeclaration&&e.callee.type===`Identifier`&&e.callee.name===`defineConfig`&&(i.withinDefineConfig=!0)},"CallExpression:exit"(e){i.withinDefineConfig&&e.callee.type===`Identifier`&&e.callee.name===`defineConfig`&&(i.withinDefineConfig=!1,i.withinMainObjectExpression=!1)},Property(e){if(i.withinDefineConfig&&i.withinMainObjectExpression&&!i.withinIgnoredProperty){if(e.key.type===`Identifier`&&e.key.name!==`paths`){i.withinIgnoredProperty=!0;return}if(e.key.type===`Identifier`&&(e.kind===`init`||e.kind===`get`)&&e.key.name===`paths`){if(e.value.type!==`ObjectExpression`)return(0,G.err)(new Le({key:`paths`,type:`object`}));i.configKeyPropertyDeclaration=e}}},"Property:exit"(e){if(i.withinDefineConfig&&e.key.type===`Identifier`&&e.key.name!==`paths`){i.withinIgnoredProperty=!1;return}}}).visit(n.program),i.configKeyPropertyDeclaration!==null){if(i.configKeyPropertyDeclaration.value.type!==`ObjectExpression`)return(0,G.err)(new Le({key:`paths`,type:`object`}));let t=new Map;for(let n of i.configKeyPropertyDeclaration.value.properties)if(n.type===`Property`&&(n.key.type===`Literal`||n.key.type===`Identifier`)){let i=r.slice(n.key.start,n.key.end).replaceAll(/['"]/g,``);e[i]!==void 0&&t.set(i,n)}let n=r.slice(i.configKeyPropertyDeclaration.value.start,i.configKeyPropertyDeclaration.value.end);if(i.configKeyPropertyDeclaration.value.properties.length===0)r.overwrite(i.configKeyPropertyDeclaration.value.start,i.configKeyPropertyDeclaration.value.end,`{\n${Object.entries(e).map(([e,t])=>`\t\t${ne.test(e)?e:`'${e}'`}: '${t}'`).join(`,
`)}\n\t}`);else{let a=i.configKeyPropertyDeclaration.value.properties[i.configKeyPropertyDeclaration.value.properties.length-1],o=n.lastIndexOf(`,`),s=o===-1?-1:o+i.configKeyPropertyDeclaration.value.start+1,c=!1;c=!(s!==-1&&s>a.end);for(let[n,i]of Object.entries(e)){let a=t.get(n);a!==void 0&&(r.overwrite(a.value.start,a.value.end,`'${i}'`),delete e[n])}Object.keys(e).length>0&&r.appendRight(c?a.end:s,`${c?`,`:``}\n${Object.entries(e).map(([e,t])=>`\t\t${ne.test(e)?e:`'${e}'`}: '${t}'`).join(`,
`)}`)}}else{if(i.mainObjectExpression===null)return(0,G.err)(new Re);let t=r.slice(i.mainObjectExpression.start,i.mainObjectExpression.end).lastIndexOf(`,`),n=t===-1?-1:t+i.mainObjectExpression.start+1;if(i.mainObjectExpression.properties.length===0)r.appendRight(i.mainObjectExpression.start+1,`\n\tpaths: {\n${Object.entries(e).map(([e,t])=>`\t\t${ne.test(e)?e:`'${e}'`}: '${t}'`).join(`,
`)}\n\t}`);else{let t=i.mainObjectExpression.properties[i.mainObjectExpression.properties.length-1],a=!1;a=!(n!==-1&&n>t.end),r.appendRight(a?t.end:n,`${a?`,`:``}\n\tpaths: {\n${Object.entries(e).map(([e,t])=>`\t\t${ne.test(e)?e:`'${e}'`}: '${t}'`).join(`,
`)}\n\t}`)}}return(0,G.ok)(r.toString())}async function Dt(e,t=process.cwd()){try{let[n,r]=process.platform===`win32`?[`cmd`,[`/c`,e]]:[`sh`,[`-c`,e]],a=i(n,[...r],{nodeOptions:{stdio:`inherit`,cwd:t}});return await a,a.exitCode===0?(0,G.ok)(void 0):(0,G.err)(Error(`Command "${e}" failed with exit code ${a.exitCode}`))}catch(e){return(0,G.err)(e instanceof Error?e:Error(String(e)))}}async function Ot(e,t,n,r){let i=e.hooks?.[t]??[],a=Array.isArray(i)?i:[i],o=r??process.cwd();for(let e of a)if(typeof e==`function`)try{await e(n)}catch(e){return(0,G.err)(e instanceof Error?e:Error(String(e)))}else if(typeof e==`string`){let t=await Dt(e,o);if(t.isErr())return t}return(0,G.ok)(void 0)}async function Q(e,t,n){let r=e.hooks?.before??[];if((Array.isArray(r)?r:[r]).length!==0){if(console.clear(),we(`Running before hooks`),(await Ot(e,`before`,t,n.cwd)).isErr()){if(n.yes){z(``);return}let e=await Te({message:`Before hooks failed. Would you like to continue?`,initialValue:!1});(R(e)||!e)&&process.exit(1)}z(``)}}async function $(e,t,n){let r=e.hooks?.after??[];if((Array.isArray(r)?r:[r]).length===0)return;we(`Running after hooks`);let i=await Ot(e,`after`,t,n?.cwd);i.isErr()&&B.warn(`After hooks failed: ${i.error.message}`),z(``)}const kt=q.extend({yes:N(),all:N(),overwrite:N(),verbose:N(),registry:L().optional(),with:oe(L()).default([]),withExamples:N(),withDocs:N(),withTests:N(),expand:N(),maxUnchanged:M()}),At=new U(`add`).description(`Add items to your project.`).argument(`[items...]`,`Names of the items you want to add to your project. ex: (utils/math, github/ieedan/std/utils/math)`).option(`--registry <registry>`,`The registry to add items from.`,void 0).option(`--all`,`Add all items from every registry.`,!1).option(`--with <roles...>`,`Include files with the given roles.`).option(`--with-examples`,"Deprecated. Use `--with example`.",!1).option(`--with-docs`,"Deprecated. Use `--with doc`.",!1).option(`--with-tests`,"Deprecated. Use `--with test`.",!1).addOption(J.cwd).addOption(J.yes).addOption(J.verbose).addOption(J.overwrite).addOption(J.expand).addOption(J.maxUnchanged).action(async(e,t)=>{let n=Y(kt,t),r=await f({cwd:n.cwd,promptForContinueIfNull:!n.yes}),i=r?.config??{},a=r?I.dirname(r.path):n.cwd;await Q(i,{command:`add`,options:{...n,cwd:a}},{cwd:a,yes:n.yes}),u();let o=await X(jt(e,{...n,cwd:a},r));z(Mt(o)),await $(i,{command:`add`,options:{...n,cwd:a},result:o},{cwd:a})});async function jt(e,t,n){let{verbose:r,spinner:i}=le({options:t}),s=n?.config,c=s?.providers??fe,l=t.registry?[t.registry]:s?.registries??[],u;if(e.length===0||t.all){if(t.all&&e.length>0)for(let t of e)c.some(e=>e.matches(t))||Z(new Ue(t));let n=e.length>0?e:l;if(n.length===0)return(0,G.err)(new We);i.start(`Retrieving manifest${l.length>1?`s`:``} from ${K.default.cyan(l.join(`, `))}`);let r=await T(n,{cwd:t.cwd,providers:c});if(r.isErr())return i.stop(`Failed to retrieve manifests`),(0,G.err)(r.error);i.stop(`Retrieved manifest${l.length>1?`s`:``} from ${K.default.cyan(l.join(`, `))}`);let a=r.value,o=Array.from(a.entries()).flatMap(([e,t])=>t.manifest.items.map(e=>({item:e,registry:t})));if(t.all)u=o;else{let e=await Oe({message:`Which items would you like to add?`,options:o.filter(e=>(e.item.add??`when-added`)===`when-added`&&e.item.name!==`index`).map(e=>{let t=`${e.registry.url}/${e.item.name}`,n=a.size>1?`${K.default.cyan(e.registry.url)}/${e.item.name}`:e.item.name;return{label:n,value:t,hint:e.item.description?.length??0>=process.stdout.columns-n.length-12?`${e.item.description?.slice(0,process.stdout.columns-n.length-12).trim()}...`:e.item.description}}),maxItems:process.stdout.rows-10,required:!0});R(e)&&(V(`Canceled!`),process.exit(0)),u=o.filter(t=>e.includes(`${t.registry.url}/${t.item.name}`)).map(e=>({registry:e.registry,item:e.item}))}}else{let n=S(e,{providers:c,registries:l});if(n.isErr())return(0,G.err)(n.error);let{wantedItems:r,neededRegistries:a}=n.value;i.start(`Retrieving manifest${a.length>1?`s`:``} from ${K.default.cyan(a.join(`, `))}`);let o=await T(a,{cwd:t.cwd,providers:c});if(o.isErr())return i.stop(`Failed to retrieve manifests`),(0,G.err)(o.error);i.stop(`Retrieved manifest${a.length>1?`s`:``} from ${K.default.cyan(a.join(`, `))}`);let s=o.value,d=await h(r,{resolvedRegistries:s,nonInteractive:t.yes});if(d.isErr())return(0,G.err)(d.error);u=d.value}i.start(`Fetching ${K.default.cyan(u.map(e=>e.item.name).join(`, `))}...`);let d=a(t),f=await ye(u,{withRoles:d});if(f.isErr())return i.stop(`Failed to fetch items`),(0,G.err)(f.error);i.stop(`Fetched ${K.default.cyan(u.map(e=>e.item.name).join(`, `))}`);let p=f.value,g=await ae({items:p,config:s,options:t});if(g.isErr())return(0,G.err)(g.error);let{itemPaths:_,updatedPaths:v}=g.value,b=await he({configResult:n,options:{cwd:t.cwd,yes:t.yes,withRoles:d},itemPaths:_,items:p});if(b.isErr())return(0,G.err)(b.error);let{neededDependencies:x,neededEnvVars:C,neededFiles:E}=b.value,D=await o({files:E,options:t});if(D.isErr())return(0,G.err)(D.error);let O=D.value;if(n&&v){let e=w(n.path);if(e.isErr())return(0,G.err)(e.error);let t=e.value,r=await Et(s?.paths??v,{config:{path:n.path,code:t}});if(r.isErr())return(0,G.err)(r.error);let i=P(n.path,r.value);if(i.isErr())return(0,G.err)(i.error)}let k;if(C){let e=await y(C,{options:t});if(e.isErr())return(0,G.err)(e.error);k=e.value}return(0,G.ok)({items:p,updatedDependencies:await m(x,{options:t,config:s}),updatedEnvVars:k,updatedFiles:O,updatedPaths:v})}function Mt(e){let t=[`Added ${K.default.cyan(e.items.map(e=>e.name).join(`, `))} to your project.`];return e.updatedFiles.length>0&&t.push(` Updated ${K.default.green(e.updatedFiles.length)} ${e.updatedFiles.length===1?`file`:`files`}.`),e.updatedPaths&&Object.keys(e.updatedPaths).length>0&&t.push(` Updated ${K.default.green(Object.keys(e.updatedPaths).length)} ${Object.keys(e.updatedPaths).length===1?`path`:`paths`}.`),e.updatedDependencies.dependencies.length>0&&(e.updatedDependencies.installed?t.push(` Installed ${K.default.green(e.updatedDependencies.dependencies.length)} ${e.updatedDependencies.dependencies.length===1?`dependency`:`dependencies`}.`):t.push(` Skipped installation of ${K.default.cyan(e.updatedDependencies.dependencies.map(e=>`${e.name}${e.version?`@${e.version}`:``}`).join(`, `))}.`)),e.updatedEnvVars&&Object.keys(e.updatedEnvVars).length>0&&t.push(` Updated ${K.default.green(Object.keys(e.updatedEnvVars).length)} ${Object.keys(e.updatedEnvVars).length===1?`environment variable`:`environment variables`}.`),t.join(`
`)}const Nt=q.extend({registry:L().optional(),token:L().optional(),logout:N(),verbose:N()}),Pt=new U(`auth`).description(`Authenticate to a provider or registry.`).argument(`[provider]`,`The provider to authenticate to.`).option(`--logout`,`Execute the logout flow.`,!1).option(`--registry <registry>`,`The registry to authenticate to.`).option(`--token <token>`,`The token to use for authenticating to this provider.`).addOption(J.cwd).addOption(J.verbose).action(async(e,t)=>{let n=Y(Nt,t),r=await f({cwd:n.cwd,promptForContinueIfNull:!1}),i=r?.config??{},a=r?I.dirname(r.path):n.cwd;await Q(i,{command:`auth`,options:{...n,cwd:a}},{cwd:a,yes:!1}),u();let o=await X(Ft(e,n,r?.config));z(Rt(o)),await $(i,{command:`auth`,options:{...n,cwd:a},result:o},{cwd:a})});async function Ft(e,t,n){let{verbose:r,spinner:i}=le({options:t}),a=(n?.providers??fe).filter(e=>e.auth!==void 0),o;if(e){if(o=a.find(t=>t.name===e),!o)return(0,G.err)(new Ae(e))}else if(t.registry){if(o=a.find(e=>e.matches(t.registry)),!o)return(0,G.err)(new Ae(t.registry))}else{let e=await xe({message:`Select a provider to authenticate to.`,options:a.map(e=>({label:e.name,value:e.name}))});R(e)&&(V(`Canceled!`),process.exit(0)),o=a.find(t=>t.name===e)}return t.registry&&!o.matches(t.registry)?(0,G.err)(new H(`Registry ${K.default.bold(t.registry)} cannot be parsed by provider ${K.default.bold(o.name)}.`,{suggestion:`Pass a registry that matches ${K.default.bold(o.name)} or omit the provider argument.`})):t.logout?await It(o,t):await Lt(o,{config:n,options:t})}async function It(e,t){let n=new _e;if(e.auth.tokenStoredFor===`registry`){if(t.registry)return n.delete(e,t.registry),(0,G.ok)({type:`logout`,provider:e.name,registry:t.registry});let r=n.getProviderRegistryTokens(e);if(Object.keys(r).length===0)return(0,G.ok)({type:`logout`,provider:e.name,registry:void 0});let i=await xe({message:`Select a registry to logout of.`,options:Object.keys(r).map(e=>({label:e,value:e}))});return R(i)&&(V(`Canceled!`),process.exit(0)),n.delete(e,i),(0,G.ok)({type:`logout`,provider:e.name,registry:i})}else return n.delete(e,void 0),(0,G.ok)({type:`logout`,provider:e.name,registry:void 0})}async function Lt(e,{config:t,options:n}){let r=new _e;if(e.auth.tokenStoredFor===`registry`){let i=t?.registries??[],a=n.registry;if(!a)if(i.length===0){let t=await Ce({message:`Enter the name of the registry to authenticate to.`,validate(t){if(!t||t.trim()===``)return`Please provide a value`;if(!e.matches(t))return`Registry cannot be parsed by this provider`}});R(t)&&(V(`Canceled!`),process.exit(0)),a=t}else{let t=await xe({message:`Select a registry to authenticate to.`,options:[...i.map(e=>({label:e,value:e})),{label:`Other`,value:`other`}]});if(R(t)&&(V(`Canceled!`),process.exit(0)),t===`other`){let t=await Ce({message:`Enter the name of the registry to authenticate to.`,validate(t){if(!t||t.trim()===``)return`Please provide a value`;if(!e.matches(t))return`Registry cannot be parsed by this provider`}});R(t)&&(V(`Canceled!`),process.exit(0)),a=t}else a=t}let o=n.token;if(!o)if(e.auth.getToken)o=await e.auth.getToken({registry:a,p:{confirm:Te,multiselect:De,select:xe,text:Ce,log:B,spinner:be,groupMultiselect:Se,password:Ee,isCancel:R,cancel:V,color:K.default}});else{let e=await Ee({message:`Enter your token for ${K.default.cyan(a)}`,validate(e){if(!e||e.trim()===``)return`Please provide a value`}});R(e)&&(V(`Canceled!`),process.exit(0)),o=e}return r.set(e,a,o),(0,G.ok)({type:`login`,provider:e.name,registry:a})}else{let t=n.token;if(!t)if(e.auth.getToken)t=await e.auth.getToken({p:{confirm:Te,multiselect:De,select:xe,text:Ce,log:B,spinner:be,groupMultiselect:Se,password:Ee,isCancel:R,cancel:V,color:K.default}});else{let n=await Ee({message:`Enter your token for ${K.default.cyan(e.name)}`,validate(e){if(!e||e.trim()===``)return`Please provide a value`}});R(n)&&(V(`Canceled!`),process.exit(0)),t=n}return r.set(e,void 0,t),(0,G.ok)({type:`login`,provider:e.name})}}function Rt({type:e,provider:t,registry:n}){let r=n?`${K.default.cyan(n)}`:`${K.default.cyan(t)}`;return e===`login`?`Logged in to ${r}.`:`Logged out of ${r}.`}const zt=q.extend({watch:N(),debounce:M()}),Bt=new U(`build`).description(`Build your registry.`).addOption(J.cwd).option(`-w, --watch`,`Watch for changes and rebuild automatically`,!1).option(`-d, --debounce <ms>`,`How long to wait before building again after a change is detected (watch mode only)`,e=>Number.parseInt(e,10),100).action(async e=>{let t=Y(zt,e),n=await f({cwd:t.cwd,promptForContinueIfNull:!1});if(n||Z(new Be(t.cwd)),t.watch)await Ht(t,n);else{let e=n.config,r=I.dirname(n.path),i={...t,cwd:r};await Q(e,{command:`build`,options:i},{cwd:r,yes:!1}),u();let a=await X(Vt(i,e));z(Wt(a,{type:`build`})),await $(e,{command:`build`,options:i,result:a},{cwd:r}),a.results.some(e=>e.isErr())&&process.exit(1)}});async function Vt(e,t){if(!et(t))return(0,G.err)(new Me);let n=performance.now();return(0,G.ok)({results:await $e(t,async n=>{n.outputs=n.outputs??[];let r=performance.now(),i=await re(n);if(i.isErr())return(0,G.err)(i.error);n.outputs.length>0&&await Promise.all(n.outputs.map(t=>t.clean({cwd:e.cwd})));let a=await p(n,{options:e,config:t});if(a.isErr())return(0,G.err)(a.error);let o=a.value;if(n.outputs.length===0)return(0,G.err)(new ke({registryName:n.name}));await Promise.all(n.outputs.map(t=>t.output(o,{cwd:e.cwd})));let s=performance.now()-r;return(0,G.ok)({name:n.name,time:s,items:o.items.length,files:o.items.flatMap(e=>e.files.length).length,outputs:n.outputs.length})},{cwd:e.cwd}),duration:performance.now()-n})}async function Ht(e,t){let n=t.config,r=new AbortController,i=new Map,a=!0,o=()=>{b&&(process.stdout.clearLine(0),process.stdout.cursorTo(0))},s=(e,t=!1)=>{b?(o(),process.stdout.write(e)):t&&process.stdout.write(`${e}\n`)},c=me(async({options:e,config:t})=>{if(a)return;a=!0,s(K.default.dim(`Building...`));let n=await Vt(e,t);o(),n.isErr()?process.stdout.write(`Error building registry: ${K.default.red(n.error.message)}\n`):process.stdout.write(`${Wt(n.value,{type:`build`})}\n`),s(K.default.dim(`${b?`
`:``}Watching for changes...`)),a=!1},e.debounce);i.set(t.path,Ut(t.path,{signal:r.signal,onChange:async()=>{let r=await d({cwd:I.dirname(t.path)});r.isErr()||(n=r.value,await l(),c({options:e,config:n}))}}));async function l(){await $e(t.config,async t=>{let a=t.items.flatMap(t=>t.files.map(t=>F(e.cwd,t.path)));for(let t of a)i.has(t)||te(t)&&i.set(t,Ut(t,{signal:r.signal,onChange:()=>c({options:e,config:n})}))},{cwd:e.cwd})}l(),s(`Building...`,!0);let u=await Vt(e,t.config);o(),u.isErr()?process.stdout.write(`Error building registry: ${K.default.red(u.error.message)}\n`):process.stdout.write(`${Wt(u.value,{type:`build`})}\n`),s(K.default.dim(`${b?`
`:``}Watching for changes...`)),a=!1,process.on(`SIGINT`,()=>{r.abort()}),process.on(`SIGTERM`,()=>{r.abort()})}function Ut(e,{onChange:t,signal:n}){return Ke(e,{recursive:!0,signal:n},e=>{e===`change`&&t?.()})}function Wt({results:e,duration:t},{type:n}){return`${n===`build`?`Finished`:`Rebuilt`} in ${K.default.green(`${t.toFixed(2)}ms`)}
${e.map(e=>` ${Gt(e)}`).join(`
`)}`}function Gt(e){if(e.isErr())return`${K.default.cyan(e.error.registryName)}: ${K.default.red(e.error.toString())}`;let{name:t,outputs:n,time:r,items:i,files:a}=e.value;return`${K.default.cyan(t)}: Created ${K.default.green(n.toString())} ${n>1?`outputs`:`output`} in ${K.default.green(`${r.toFixed(2)}ms`)} with ${K.default.green(i.toString())} ${i>1?`items`:`item`} and ${K.default.green(a.toString())} ${a>1?`files`:`file`}.`}function Kt(e){let t=``;for(let n=0;n<e.length;n++){if(e[n]===`-`){n++,n<=e.length-1&&(t+=e[n].toUpperCase());continue}t+=e[n].toLocaleLowerCase()}return t}var qt=class{IGNORED_PROPERTIES=[`registry`,`registries`,`paths`];importDeclarations=[];withinExportDefaultDeclaration=!1;withinDefineConfig=!1;withinMainObjectExpression=!1;withinIgnoredProperty=!1;lastImportDeclaration=null;configKeyPropertyDeclaration=null;mainObjectExpression=null};async function Jt({plugins:e,key:t,config:n}){if(e.length===0)return(0,G.ok)(n.code);let r=await Je(n.path,n.code),i=new wt(n.code),a=new qt;if(a.withinDefineConfig=!0,new qe({ImportDeclaration(e){a.withinDefineConfig&&(a.lastImportDeclaration=e,a.importDeclarations.push(e))},ExportDefaultDeclaration(){a.withinExportDefaultDeclaration=!0},"ExportDefaultDeclaration:exit"(){a.withinExportDefaultDeclaration=!1},ObjectExpression(e){a.withinExportDefaultDeclaration&&a.withinDefineConfig&&(a.withinIgnoredProperty||(a.withinMainObjectExpression||=(a.mainObjectExpression=e,!0)))},CallExpression(e){a.withinExportDefaultDeclaration&&e.callee.type===`Identifier`&&e.callee.name===`defineConfig`&&(a.withinDefineConfig=!0)},"CallExpression:exit"(e){a.withinDefineConfig&&e.callee.type===`Identifier`&&e.callee.name===`defineConfig`&&(a.withinDefineConfig=!1,a.withinMainObjectExpression=!1)},Property(e){if(a.withinDefineConfig&&a.withinMainObjectExpression&&!a.withinIgnoredProperty){if(a.IGNORED_PROPERTIES.includes(e.key.type===`Identifier`?e.key.name:``)){a.withinIgnoredProperty=!0;return}if(e.key.type===`Identifier`&&(e.kind===`init`||e.kind===`get`)&&e.key.name===t){if(e.value.type!==`ArrayExpression`)return(0,G.err)(new Le({key:t,type:`array`}));a.configKeyPropertyDeclaration=e}}},"Property:exit"(e){if(a.withinDefineConfig&&a.IGNORED_PROPERTIES.includes(e.key.type===`Identifier`?e.key.name:``)){a.withinIgnoredProperty=!1;return}}}).visit(r.program),e=e.filter(e=>!a.importDeclarations.some(t=>t.source.value===e.packageName)),e.length===0)return(0,G.ok)(n.code);a.lastImportDeclaration!==null&&i.appendRight(a.lastImportDeclaration.end,e.map(e=>`\nimport ${e.name} from '${e.packageName}';`).join(``));let o=null;t===`providers`?o=`DEFAULT_PROVIDERS`:t===`languages`&&(o=`DEFAULT_LANGS`);let s=a.importDeclarations.find(e=>e.source.value===`jsrepo`);if(s===void 0)return(0,G.err)(new Pe);let c=o?{added:!1,name:o}:null;if(c!==null){for(let e of s.specifiers)if(e.type===`ImportSpecifier`&&e.imported.type===`Identifier`&&e.imported.name===o){c.added=!0,e.local.name!==o&&(c.name=e.local.name);break}}if(a.configKeyPropertyDeclaration!==null){if(a.configKeyPropertyDeclaration.value.type!==`ArrayExpression`)return(0,G.err)(new Le({key:t,type:`array`}));let n=i.slice(a.configKeyPropertyDeclaration.value.start,a.configKeyPropertyDeclaration.value.end).lastIndexOf(`,`),r=n===-1?-1:n+a.configKeyPropertyDeclaration.value.start+1;if(a.configKeyPropertyDeclaration.value.elements.length===0)c=null,i.appendRight(a.configKeyPropertyDeclaration.value.start+1,`${e.map(e=>`${e.name}()`).join(`, `)}`);else{let t=a.configKeyPropertyDeclaration.value.elements[a.configKeyPropertyDeclaration.value.elements.length-1],n=!1;n=!(r!==-1&&r>t.end),c=null,i.appendRight(n?t.end:r,`${n?`,`:``} ${e.map(e=>`${e.name}()`).join(`, `)}`)}}else{if(a.mainObjectExpression===null)return(0,G.err)(new Re);let n=i.slice(a.mainObjectExpression.start,a.mainObjectExpression.end).lastIndexOf(`,`),r=n===-1?-1:n+a.mainObjectExpression.start+1;if(a.mainObjectExpression.properties.length===0)i.appendRight(a.mainObjectExpression.start+1,`\n\t${t}: [${c?`...${c.name}, `:``}${e.map(e=>`${e.name}()`).join(`, `)}]`);else{let n=a.mainObjectExpression.properties[a.mainObjectExpression.properties.length-1],o=!1;o=!(r!==-1&&r>n.end),i.appendRight(o?n.end:r,`${o?`,`:``}\n\t${t}: [${c?`...${c.name}, `:``}${e.map(e=>`${e.name}()`).join(`, `)}]`)}if(c&&!c.added){let e=i.slice(s.start,s.end).lastIndexOf(`,`),t=e===-1?-1:e+s.start+1,n=s.specifiers[s.specifiers.length-1],r=!1;r=!(t!==-1&&t>n.end),i.appendRight(r?n.end:t,`${r?`,`:``} ${c.name}`)}}return(0,G.ok)(i.toString())}async function Yt({plugins:e,config:t}){let n=await v(t.code,{fileName:t.path,warn:A});return e.filter(e=>!n.includes(e.package))}const Xt=[{shorthand:`prettier`,name:`@jsrepo/transform-prettier`},{shorthand:`biome`,name:`@jsrepo/transform-biome`},{shorthand:`javascript`,name:`@jsrepo/transform-javascript`},{shorthand:`oxfmt`,name:`@jsrepo/transform-oxfmt`},{shorthand:`filecasing`,name:`@jsrepo/transform-filecasing`}];function Zt(e,t){let n=e.map(e=>Qt(e,t)),r=[];for(let e of n){if(e.isErr())return(0,G.err)(e.error);r.push(e.value)}return(0,G.ok)(r)}function Qt(e,t){let n=Xt.find(t=>t.shorthand===e);if(n){let e=Qt(n.name,t);return e.isErr()?(0,G.err)(e.error):(0,G.ok)({name:e.value.name,packageName:n.name,version:void 0})}let r=k(e);if(r.isErr())return(0,G.err)(new Ne(e));let i=r.value.name;return r.value.name.startsWith(`@`)&&(i=r.value.name.startsWith(`@jsrepo/`)?r.value.name.split(`/`)[1]?.includes(t)?`jsrepo-${r.value.name.split(`/`)[1]}`:`jsrepo-${t}-${r.value.name.split(`/`)[1]}`:r.value.name.split(`/`)[1]),(0,G.ok)({name:Kt(i.replace(`jsrepo-${t}-`,``)),packageName:r.value.name,version:r.value.version})}const $t=q.extend({yes:N()}),en=new U(`language`).description(`Add a language to your config.`).argument(`[languages...]`,`Names of the languages you want to add to your config. ex: (jsrepo-language-go, jsrepo-language-rust)`).addOption(J.cwd).addOption(J.yes).action(async(e,t)=>{let n=Y($t,t),r=await f({cwd:n.cwd,promptForContinueIfNull:!n.yes});r||Z(new Be(n.cwd));let i=r.config,a=I.dirname(r.path),o={...n,cwd:a};await Q(i,{command:`config.language`,options:o},{cwd:a,yes:n.yes}),u();let s=await X(tn(e,o,r));z(nn(s)),await $(i,{command:`config.language`,options:o,result:s},{cwd:a})});async function tn(e,t,n){let r=performance.now(),i=Zt(e,`language`);if(i.isErr())return(0,G.err)(i.error);let a=i.value,o=w(n.path);if(o.isErr())return(0,G.err)(o.error);let s=o.value,c=await Jt({plugins:a,key:`languages`,config:{path:n.path,code:s}});if(c.isErr())return(0,G.err)(c.error);let l=c.value,u=P(n.path,l);return u.isErr()?(0,G.err)(u.error):(await x({devDependencies:a.map(e=>({name:e.packageName,version:e.version})),dependencies:[]},{options:t,configPath:n.path}),(0,G.ok)({duration:performance.now()-r,languages:e.length}))}function nn({duration:e,languages:t}){return`Added ${K.default.green(t.toString())} ${t>1?`languages`:`language`} in ${K.default.green(`${e.toFixed(2)}ms`)}.`}const rn=[`cursor`,`claude`,`vscode`,`codex`,`antigravity`],an=q.extend({client:oe(ce(rn)).optional(),all:N().optional()}),on=new U(`mcp`).description(`Configure the jsrepo MCP server for your environment.`).addOption(new W(`--client <clients...>`,`The MCP client(s) to configure`).choices(rn)).option(`--all`,`Configure all supported MCP clients`,!1).addOption(J.cwd).action(async e=>{let t=Y(an,e),n=(await f({cwd:t.cwd,promptForContinueIfNull:!1}))?.config??{},r=t.cwd;await Q(n,{command:`config.mcp`,options:t},{cwd:r,yes:!1}),u();let i=await X(sn(t));z(cn({...i,cwd:t.cwd})),await $(n,{command:`config.mcp`,options:t,result:i},{cwd:r})});async function sn(e){let t;if(e.all)t=Object.keys(bn);else if(e.client&&e.client.length>0)t=e.client;else{let e=await De({message:`Which clients would you like to configure?`,options:Object.entries(bn).map(([e,t])=>({value:e,label:t.name}))});R(e)&&(V(`Canceled!`),process.exit(0)),t=e}let n=performance.now(),r=[];for(let n of t){let t=bn[n],i=t.filePath(e.cwd),a=t.writeConfig(i);r.push({name:t.name,result:a.isErr()?(0,G.err)(a.error):(0,G.ok)({filePath:i})})}return(0,G.ok)({duration:performance.now()-n,results:r})}function cn({duration:e,results:t,cwd:n}){return`Configured ${t.length} ${t.length>1?`clients`:`client`} in ${K.default.green(`${e.toFixed(2)}ms`)}:\n${t.map(e=>ln(e,n)).join(`
`)}`}function ln({name:e,result:t},n){if(t.isErr())return` ${K.default.cyan(e)}: ${K.default.red(t.error.message)}`;let{filePath:r}=t.value;return` ${K.default.cyan(e)} → ${K.default.dim(I.relative(n,r))}`}function un(e,t){try{return P(e,t),(0,G.ok)(void 0)}catch(t){return(0,G.err)(new H(`Failed to write config to ${e}: ${t instanceof Error?t.message:String(t)}`,{suggestion:`Please try again.`}))}}const dn={command:`npx`,args:[`@jsrepo/mcp`]},fn=`[mcp_servers.jsrepo]
command = "npx"
args = ["@jsrepo/mcp"]
`;function pn(e){return e?e.includes(`[mcp_servers.jsrepo]`)?e:(e.endsWith(`
`)||(e+=`
`),`${e}${fn}`):fn}const mn=C({command:L().optional(),args:oe(L()).optional(),env:ge(L(),L()).optional(),type:L().optional(),url:L().optional(),headers:ge(L(),L()).optional()}).catchall(E()),hn=C({mcpServers:ge(L(),mn)}),gn=C({servers:ge(L(),mn)});function _n({existingContent:e,serverName:t,serverConfig:n}){if(e.trim().length===0)return(0,G.ok)(l({mcpServers:{[t]:n}},{format:!0}));let r=D(hn,e);return r.isErr()?(0,G.err)(new H(`Failed to parse MCP server config: ${r.error.message}`,{suggestion:`Please try again.`})):(0,G.ok)(l({mcpServers:{...r.value.mcpServers,[t]:n}},{format:!0}))}function vn({existingContent:e,serverName:t,serverConfig:n}){if(e.trim().length===0)return(0,G.ok)(l({servers:{[t]:n}},{format:!0}));let r=D(gn,e);return r.isErr()?(0,G.err)(new H(`Failed to parse MCP server config: ${r.error.message}`,{suggestion:`Please try again.`})):(0,G.ok)(l({servers:{...r.value.servers,[t]:n}},{format:!0}))}function yn(e,t,n=`generic`){let r=te(e)?w(e)._unsafeUnwrap():``,i=n===`vscode`?vn({existingContent:r,serverName:`jsrepo`,serverConfig:t}):_n({existingContent:r,serverName:`jsrepo`,serverConfig:t});return i.isErr()?(0,G.err)(i.error):un(e,i.value)}const bn={cursor:{name:`Cursor`,filePath:e=>F(e,`.cursor/mcp.json`),writeConfig:e=>yn(e,dn)},claude:{name:`Claude Code`,filePath:e=>F(e,`.mcp.json`),writeConfig:e=>yn(e,dn)},vscode:{name:`VS Code`,filePath:e=>F(e,`.vscode/mcp.json`),writeConfig:e=>yn(e,dn,`vscode`)},codex:{name:`Codex`,filePath:()=>F(Ye.homedir(),`.codex/config.toml`),writeConfig:e=>un(e,pn(te(e)?w(e)._unsafeUnwrap():``))},antigravity:{name:`Antigravity`,filePath:()=>F(Ye.homedir(),`.gemini/antigravity/mcp_config.json`),writeConfig:e=>yn(e,dn)}},xn=q.extend({yes:N()}),Sn=new U(`provider`).description(`Add a provider to your config.`).argument(`[providers...]`,`Names of the providers you want to add to your config. ex: (jsrepo-provider-jsr, jsrepo-provider-npm)`).addOption(J.cwd).addOption(J.yes).action(async(e,t)=>{let n=Y(xn,t),r=await f({cwd:n.cwd,promptForContinueIfNull:!n.yes});r||Z(new Be(n.cwd));let i=r.config,a=I.dirname(r.path),o={...n,cwd:a};await Q(i,{command:`config.provider`,options:o},{cwd:a,yes:n.yes}),u();let s=await X(Cn(e,o,r));z(wn(s)),await $(i,{command:`config.provider`,options:o,result:s},{cwd:a})});async function Cn(e,t,n){let r=performance.now(),i=Zt(e,`provider`);if(i.isErr())return(0,G.err)(i.error);let a=i.value,o=w(n.path);if(o.isErr())return(0,G.err)(o.error);let s=o.value,c=await Jt({plugins:a,key:`providers`,config:{path:n.path,code:s}});if(c.isErr())return(0,G.err)(c.error);let l=c.value,u=P(n.path,l);return u.isErr()?(0,G.err)(u.error):(await x({devDependencies:a.map(e=>({name:e.packageName,version:e.version})),dependencies:[]},{options:t,configPath:n.path}),(0,G.ok)({duration:performance.now()-r,providers:e.length}))}function wn({duration:e,providers:t}){return`Added ${K.default.green(t.toString())} ${t>1?`providers`:`provider`} in ${K.default.green(`${e.toFixed(2)}ms`)}.`}const Tn=q.extend({yes:N()}),En=new U(`transform`).description(`Add a transform to your config.`).argument(`[transforms...]`,`Names of the transforms you want to add to your config. ex: (@jsrepo/transform-prettier, @jsrepo/transform-biome)`).addOption(J.cwd).addOption(J.yes).action(async(e,t)=>{let n=Y(Tn,t),r=await f({cwd:n.cwd,promptForContinueIfNull:!n.yes});r||Z(new Be(n.cwd));let i=r.config,a=I.dirname(r.path),o={...n,cwd:a};await Q(i,{command:`config.transform`,options:o},{cwd:a,yes:n.yes}),u();let s=await X(Dn(e,o,r));z(On(s)),await $(i,{command:`config.transform`,options:o,result:s},{cwd:a})});async function Dn(e,t,n){let r=performance.now(),i=Zt(e,`transform`);if(i.isErr())return(0,G.err)(i.error);let a=i.value,o=w(n.path);if(o.isErr())return(0,G.err)(o.error);let s=o.value,c=await Jt({plugins:a,key:`transforms`,config:{path:n.path,code:s}});if(c.isErr())return(0,G.err)(c.error);let l=c.value,u=P(n.path,l);return