UNPKG

@stacksjs/launchpad

Version:
42 lines (37 loc) 78.9 kB
#!/usr/bin/env bun // @bun import{a as f0,b as g0,c as W0}from"../chunk-w67rbjbs.js";import{d as Y0,e as u0,f as b0,g as y0,h as m0,i as S0,j as q0,k as P0,l as k0,m as j0,n as d0,o as v0}from"../src/index.js";import{p as h0}from"../chunk-x48ph7z5.js";import"../chunk-7ne7xtmq.js";import"../chunk-xcf3khvr.js";import{z as D0}from"../chunk-wnwbsmkf.js";import{A as Z0}from"../chunk-sj98d84b.js";import"../chunk-sjvnrpb6.js";import{F as B0,G as g,J as N0,N as X0}from"../chunk-83b6axd0.js";import"../chunk-kd525svk.js";import"../chunk-2q79gpta.js";import"../chunk-6qxbw28k.js";import{Ka as w0,La as v,Qa as p,Ra as A0,za as T0}from"../chunk-wkk6vc0r.js";import{Ya as I0}from"../chunk-f8dcmgkp.js";import"../chunk-fhet42vs.js";import{ab as L}from"../chunk-b9hx8gsj.js";import{bb as F,cb as B}from"../chunk-8pxdwzvm.js";import U from"fs";import{homedir as N}from"os";import X from"path";import Y from"process";import{EventEmitter as c0}from"events";function r(O){return O==null?[]:Array.isArray(O)?O:[O]}function n0(O,$,w,A){var q,j=O[$],Q=~A.string.indexOf($)?w==null||w===!0?"":String(w):typeof w==="boolean"?w:~A.boolean.indexOf($)?w==="false"?!1:w==="true"||(O._.push((q=+w,q*0===0)?q:w),!!w):(q=+w,q*0===0)?q:w;O[$]=j==null?Q:Array.isArray(j)?j.concat(Q):[j,Q]}function p0(O,$){O=O||[],$=$||{};var w,A,q,j,Q,W={_:[]},K=0,_=0,M=0,J=O.length;let Z=$.alias!==void 0,E=$.unknown!==void 0,x=$.default!==void 0;if($.alias=$.alias||{},$.string=r($.string),$.boolean=r($.boolean),Z)for(w in $.alias){A=$.alias[w]=r($.alias[w]);for(K=0;K<A.length;K++)($.alias[A[K]]=A.concat(w)).splice(K,1)}for(K=$.boolean.length;K-- >0;){A=$.alias[$.boolean[K]]||[];for(_=A.length;_-- >0;)$.boolean.push(A[_])}for(K=$.string.length;K-- >0;){A=$.alias[$.string[K]]||[];for(_=A.length;_-- >0;)$.string.push(A[_])}if(x){for(w in $.default)if(j=typeof $.default[w],A=$.alias[w]=$.alias[w]||[],$[j]!==void 0){$[j].push(w);for(K=0;K<A.length;K++)$[j].push(A[K])}}let R=E?Object.keys($.alias):[];for(K=0;K<J;K++){if(q=O[K],q==="--"){W._=W._.concat(O.slice(++K));break}for(_=0;_<q.length;_++)if(q.charCodeAt(_)!==45)break;if(_===0)W._.push(q);else if(q.substring(_,_+3)==="no-"){if(j=q.substring(_+3),E&&!~R.indexOf(j))return $.unknown(q);W[j]=!1}else{for(M=_+1;M<q.length;M++)if(q.charCodeAt(M)===61)break;j=q.substring(_,M),Q=q.substring(++M)||(K+1===J||(""+O[K+1]).charCodeAt(0)===45||O[++K]),A=_===2?[j]:j;for(M=0;M<A.length;M++){if(j=A[M],E&&!~R.indexOf(j))return $.unknown("-".repeat(_)+j);n0(W,j,M+1<A.length||Q,$)}}}if(x){for(w in $.default)if(W[w]===void 0)W[w]=$.default[w]}if(Z)for(w in W){A=$.alias[w]||[];while(A.length>0)W[A.shift()]=W[w]}return W}var H0=(O)=>O.replace(/[<[].+/,"").trim(),a0=(O)=>{let $=/<([^>]+)>/g,w=/\[([^\]]+)\]/g,A=[],q=(W)=>{let K=!1,_=W[1];if(_.startsWith("..."))_=_.slice(3),K=!0;return{required:W[0].startsWith("<"),value:_,variadic:K}},j;while(j=$.exec(O))A.push(q(j));let Q;while(Q=w.exec(O))A.push(q(Q));return A},t0=(O)=>{let $={alias:{},boolean:[]};for(let[w,A]of O.entries()){if(A.names.length>1)$.alias[A.names[0]]=A.names.slice(1);if(A.isBoolean)if(A.negated){if(!O.some((j,Q)=>{return Q!==w&&j.names.some((W)=>A.names.includes(W))&&typeof j.required==="boolean"}))$.boolean.push(A.names[0])}else $.boolean.push(A.names[0])}return $},J0=(O)=>{return O.sort(($,w)=>{return $.length>w.length?-1:1})[0]},C0=(O,$)=>{return O.length>=$?O:`${O}${" ".repeat($-O.length)}`},i0=(O)=>{return O.replace(/([a-z])-([a-z])/g,($,w,A)=>{return w+A.toUpperCase()})},s0=(O,$,w)=>{let A=0,q=$.length,j=O,Q;for(;A<q;++A)Q=j[$[A]],j=j[$[A]]=A===q-1?w:Q!=null?Q:!!~$[A+1].indexOf(".")||!(+$[A+1]>-1)?{}:[]},o0=(O,$)=>{for(let w of Object.keys($)){let A=$[w];if(A.shouldTransform){if(O[w]=Array.prototype.concat.call([],O[w]),typeof A.transformFunction==="function")O[w]=O[w].map(A.transformFunction)}}},r0=(O)=>{let $=/([^\\\/]+)$/.exec(O);return $?$[1]:""},E0=(O)=>{return O.split(".").map(($,w)=>{return w===0?i0($):$}).join(".")};class n extends Error{constructor(O){super(O);if(this.name=this.constructor.name,typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=new Error(O).stack}}class V0{constructor(O,$,w){if(this.rawName=O,this.description=$,this.config=Object.assign({},w),O=O.replace(/\.\*/g,""),this.negated=!1,this.names=H0(O).split(",").map((A)=>{let q=A.trim().replace(/^-{1,2}/,"");if(q.startsWith("no-"))this.negated=!0,q=q.replace(/^no-/,"");return E0(q)}).sort((A,q)=>A.length>q.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(O.includes("<"))this.required=!0;else if(O.includes("["))this.required=!1;else this.isBoolean=!0}}var e0=process.argv,OO=`${process.platform}-${process.arch} node-${process.version}`;class e{constructor(O,$,w={},A){this.rawName=O,this.description=$,this.config=w,this.cli=A,this.options=[],this.aliasNames=[],this.name=H0(O),this.args=a0(O),this.examples=[]}usage(O){return this.usageText=O,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(O,$="-v, --version"){return this.versionNumber=O,this.option($,"Display version number"),this}example(O){return this.examples.push(O),this}option(O,$,w){let A=new V0(O,$,w);return this.options.push(A),this}alias(O){return this.aliasNames.push(O),this}action(O){return this.commandAction=O,this}isMatched(O){return this.name===O||this.aliasNames.includes(O)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof O0}hasOption(O){return O=O.split(".")[0],this.options.find(($)=>{return $.names.includes(O)})}outputHelp(){let{name:O,commands:$}=this.cli,{versionNumber:w,options:A,helpCallback:q}=this.cli.globalCommand,j=[{body:`${O}${w?`/${w}`:""}`}];if(j.push({title:"Usage",body:` $ ${O} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&$.length>0){let K=J0($.map((_)=>_.rawName));j.push({title:"Commands",body:$.map((_)=>{return` ${C0(_.rawName,K.length)} ${_.description}`}).join(` `)}),j.push({title:"For more info, run any command with the `--help` flag",body:$.map((_)=>` $ ${O}${_.name===""?"":` ${_.name}`} --help`).join(` `)})}let W=this.isGlobalCommand?A:[...this.options,...A||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand)W=W.filter((K)=>K.name!=="version");if(W.length>0){let K=J0(W.map((_)=>_.rawName));j.push({title:"Options",body:W.map((_)=>{return` ${C0(_.rawName,K.length)} ${_.description} ${_.config.default===void 0?"":`(default: ${_.config.default})`}`}).join(` `)})}if(this.examples.length>0)j.push({title:"Examples",body:this.examples.map((K)=>{if(typeof K==="function")return K(O);return K}).join(` `)});if(q)j=q(j)||j;console.log(j.map((K)=>{return K.title?`${K.title}: ${K.body}`:K.body}).join(` `))}outputVersion(){let{name:O}=this.cli,{versionNumber:$}=this.cli.globalCommand;if($)console.log(`${O}/${$} ${OO}`)}checkRequiredArgs(){let O=this.args.filter(($)=>$.required).length;if(this.cli.args.length<O)throw new n(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:O,globalCommand:$}=this.cli;if(!this.config.allowUnknownOptions){for(let w of Object.keys(O))if(w!=="--"&&!this.hasOption(w)&&!$.hasOption(w))throw new n(`Unknown option \`${w.length>1?`--${w}`:`-${w}`}\``)}}checkOptionValue(){let{options:O,globalCommand:$}=this.cli,w=[...$.options,...this.options];for(let A of w){let q=O[A.name.split(".")[0]];if(A.required){let j=w.some((Q)=>Q.negated&&Q.names.includes(A.name));if(q===!0||q===!1&&!j)throw new n(`option \`${A.rawName}\` value is missing`)}}}}class O0 extends e{constructor(O){super("@@global@@","",{},O)}}var c=Object.assign;class $0 extends c0{constructor(O=""){super();this.name=O,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new O0(this),this.globalCommand.usage("<command> [options]")}usage(O){return this.globalCommand.usage(O),this}command(O,$,w){let A=new e(O,$||"",w,this);return A.globalCommand=this.globalCommand,this.commands.push(A),A}option(O,$,w){return this.globalCommand.option(O,$,w),this}help(O){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=O,this.showHelpOnExit=!0,this}version(O,$="-v, --version"){return this.globalCommand.version(O,$),this.showVersionOnExit=!0,this}example(O){return this.globalCommand.example(O),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:O,options:$},w,A){if(this.args=O,this.options=$,w)this.matchedCommand=w;if(A)this.matchedCommandName=A;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(O=e0,{run:$=!0}={}){if(this.rawArgs=O,!this.name)this.name=O[1]?r0(O[1]):"cli";let w=!0;for(let q of this.commands){let j=this.mri(O.slice(2),q),Q=j.args[0];if(q.isMatched(Q)){w=!1;let W=c(c({},j),{args:j.args.slice(1)});this.setParsedInfo(W,q,Q),this.emit(`command:${Q}`,q)}}if(w){for(let q of this.commands)if(q.name===""){w=!1;let j=this.mri(O.slice(2),q);this.setParsedInfo(j,q),this.emit("command:!",q)}}if(w){let q=this.mri(O.slice(2));this.setParsedInfo(q)}if(this.options.help&&this.showHelpOnExit)this.outputHelp(),$=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),$=!1,this.unsetMatchedCommand();let A={args:this.args,options:this.options};if($)this.runMatchedCommand();if(!this.matchedCommand&&this.args[0])this.emit("command:*");return A}mri(O,$){let w=[...this.globalCommand.options,...$?$.options:[]],A=t0(w),q=[],j=O.indexOf("--");if(j>-1)q=O.slice(j+1),O=O.slice(0,j);let Q=p0(O,A);Q=Object.keys(Q).reduce((J,Z)=>{return c(c({},J),{[E0(Z)]:Q[Z]})},{_:[]});let W=Q._,K={"--":q},_=$&&$.config.ignoreOptionDefaultValue?$.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,M=Object.create(null);for(let J of w){if(!_&&J.config.default!==void 0)for(let Z of J.names)K[Z]=J.config.default;if(Array.isArray(J.config.type)){if(M[J.name]===void 0)M[J.name]=Object.create(null),M[J.name].shouldTransform=!0,M[J.name].transformFunction=J.config.type[0]}}for(let J of Object.keys(Q))if(J!=="_"){let Z=J.split(".");s0(K,Z,Q[J]),o0(K,M)}return{args:W,options:K}}runMatchedCommand(){let{args:O,options:$,matchedCommand:w}=this;if(!w||!w.commandAction)return;w.checkUnknownOptions(),w.checkOptionValue(),w.checkRequiredArgs();let A=[];return w.args.forEach((q,j)=>{if(q.variadic)A.push(O.slice(j));else A.push(O[j])}),A.push($),w.commandAction.apply(this,A)}}function x0(O,$={}){let{includeVersions:w=!1,maxVersions:A=10}=$,q=w0(O);if(!q)return null;let j={name:q.name,domain:q.domain,description:q.description,latestVersion:q.latestVersion,totalVersions:q.totalVersions,programs:q.programs,dependencies:q.dependencies,companions:q.companions};if(w){let Q=T0(O);j.versions=Q.slice(0,A)}return j}function G0(O,$={}){let{showVersions:w=!0,showPrograms:A=!0,showDependencies:q=!0,showCompanions:j=!0,compact:Q=!1}=$,W=[];if(Q){let K=O.description?` - ${O.description}`:"";if(W.push(`\uD83D\uDCE6 ${O.name} (${O.domain})${K}`),O.latestVersion)W.push(` Latest: ${O.latestVersion}`)}else{if(W.push("\uD83D\uDCE6 Package Information"),W.push(`${"=".repeat(50)}`),W.push(""),W.push(`Name: ${O.name}`),W.push(`Domain: ${O.domain}`),O.description)W.push(`Description: ${O.description}`);if(W.push(""),O.latestVersion)W.push(`Latest Version: ${O.latestVersion}`);if(O.totalVersions>0)W.push(`Total Versions: ${O.totalVersions}`);if(w&&O.versions&&O.versions.length>0){if(W.push(""),W.push("Available Versions:"),O.versions.slice(0,10).forEach((_,M)=>{let J=M===0?" (latest)":"";W.push(` \u2022 ${_}${J}`)}),O.versions.length>10)W.push(` ... and ${O.versions.length-10} more`)}if(A&&O.programs&&O.programs.length>0)W.push(""),W.push("Programs:"),O.programs.forEach((K)=>{W.push(` \u2022 ${K}`)});if(q&&O.dependencies&&O.dependencies.length>0)W.push(""),W.push("Dependencies:"),O.dependencies.forEach((K)=>{W.push(` \u2022 ${K}`)});if(j&&O.companions&&O.companions.length>0)W.push(""),W.push("Companion Packages:"),O.companions.forEach((K)=>{W.push(` \u2022 ${K}`)});if(W.push(""),W.push("Installation:"),W.push(` launchpad install ${O.name}`),O.latestVersion)W.push(` launchpad install ${O.name}@${O.latestVersion}`)}return W.join(` `)}function R0(O){return w0(O)!==null}async function $O(O,$=5){try{let{searchPackages:w}=await import("../chunk-w67rbjbs.js");return w(O,{limit:$}).map((q)=>q.name)}catch{return[]}}async function z0(O){let $=await $O(O),w=[`\u274C Package '${O}' not found.`,""];if($.length>0)w.push("Did you mean one of these?"),$.forEach((A)=>{w.push(` \u2022 ${A}`)}),w.push(""),w.push('Use "launchpad search <term>" to find packages.');else w.push('Use "launchpad search <term>" to find available packages.');return w.join(` `)}Y.env.LAUNCHPAD_CLI_MODE="1";var L0=await import("../chunk-vcjmz9d7.js"),d=L0.default?.version||L0.version||"0.0.0",F0=`v${d}`;function K0(){try{let O=X.join(N(),".cache","launchpad","shell_cache");U.mkdirSync(O,{recursive:!0});let $=X.join(O,"global_refresh_needed");U.writeFileSync($,"")}catch{}}function _0(){try{let O=N(),$=X.join(O,".config","launchpad","hooks","init.d"),w=X.join(O,".config","launchpad","hooks","post-refresh.d");if(U.mkdirSync($,{recursive:!0}),U.mkdirSync(w,{recursive:!0}),[X.join(O,".local","bin","starship"),"/usr/local/bin/starship","/usr/bin/starship"].some((j)=>U.existsSync(j))){let j=["# Launchpad hook: initialize starship prompt if available","if command -v starship >/dev/null 2>&1; then",' if [[ -n "$ZSH_VERSION" ]]; then',' eval "$(starship init zsh)" >/dev/null 2>&1 || true',' elif [[ -n "$BASH_VERSION" ]]; then',' eval "$(starship init bash)" >/dev/null 2>&1 || true'," fi","fi",""].join(` `),Q=X.join($,"99-starship.sh"),W=X.join(w,"99-starship.sh");try{if((U.existsSync(Q)?U.readFileSync(Q,"utf8"):"")!==j)U.writeFileSync(Q,j,{mode:420})}catch{}try{if((U.existsSync(W)?U.readFileSync(W,"utf8"):"")!==j)U.writeFileSync(W,j,{mode:420})}catch{}}}catch{}}function wO(){try{let O=N(),$=X.join(Y.env.ZDOTDIR||O,".zshrc"),w=X.join(O,".bashrc"),A=X.join(O,".bash_profile"),q="launchpad dev:shellcode",j="LAUNCHPAD_SHELL_INTEGRATION=1",Q=[$,w,A].filter((W)=>U.existsSync(W));for(let W of Q){let K=U.readFileSync(W,"utf8");if(K.includes("launchpad dev:shellcode")||K.includes("LAUNCHPAD_SHELL_INTEGRATION=1"))return!0}}catch{}return!1}async function Q0(){try{if(!wO()){let{default:O}=await import("../chunk-sj98d84b.js");await O("install",{dryrun:!1})}}catch{}}async function l0(O){let{targetVersion:$,targetPath:w,force:A,verbose:q}=O;if($&&!$.match(/^v?\d+\.\d+\.\d+$/))throw new Error(`Invalid version format: ${$}. Expected format: v0.3.6 or 0.3.6`);if(U.existsSync(w)&&!A)try{let Z=U.lstatSync(w),E=`File already exists at ${w}`;if(Z.isSymbolicLink()){let x=U.readlinkSync(w);E=`Symlink already exists at ${w} \u2192 ${x}`}throw new Error(`${E} Options: \u2022 Use --force to overwrite \u2022 Choose a different --target path \u2022 Remove the existing file/symlink manually`)}catch(Z){if(Z instanceof Error&&Z.message.includes("Options:"))throw Z;throw new Error(`Something already exists at ${w}. Use --force to overwrite.`)}let j=await import("os"),Q=j.platform(),W=j.arch(),K;if(Q==="darwin")K=W==="arm64"?"launchpad-darwin-arm64.zip":"launchpad-darwin-x64.zip";else if(Q==="linux")K=W==="arm64"?"launchpad-linux-arm64.zip":"launchpad-linux-x64.zip";else if(Q==="win32")K="launchpad-windows-x64.zip";else throw new Error(`Unsupported platform: ${Q}-${W} Supported platforms: \u2022 macOS (arm64, x64) \u2022 Linux (arm64, x64) \u2022 Windows (x64)`);if(q)console.log(`\uD83D\uDCCB Platform: ${Q}-${W}`),console.log(`\uD83C\uDFAF Target: ${w}`),console.log(`\uD83D\uDCCC Version: ${$}`);let _=`https://github.com/stacksjs/launchpad/releases/download/${$}/${K}`,M=X.join(j.tmpdir(),`launchpad-setup-${Date.now()}`);U.mkdirSync(M,{recursive:!0});let J=X.join(M,K);try{let Z=await globalThis.fetch(_);if(!Z.ok){if(Z.status===404)throw new Error(`Version ${$} not found. Please check available releases at: https://github.com/stacksjs/launchpad/releases`);throw new Error(`Failed to download: ${Z.status} ${Z.statusText}`)}let E=Z.headers.get("content-length"),x=E?Number.parseInt(E,10):0,R=Z.body?.getReader(),b=[],V=0;if(R&&x>0&&!q){while(!0){let{done:G,value:u}=await R.read();if(G)break;if(u){b.push(u),V+=u.length;let k=(V/x*100).toFixed(0);Y.stdout.write(`\r\u2B07\uFE0F ${V}/${x} bytes (${k}%)`)}}Y.stdout.write("\r\x1B[K")}else{if(q)if(x>0)console.log(`\u2B07\uFE0F Downloading ${(x/1024/1024).toFixed(1)} MB...`);else console.log("\u2B07\uFE0F Downloading...");let G=await Z.arrayBuffer();if(b.push(new Uint8Array(G)),q)console.log(`\u2705 Downloaded ${(b[0].length/1024/1024).toFixed(1)} MB`)}let C=b.reduce((G,u)=>G+u.length,0),H=new Uint8Array(C),z=0;for(let G of b)H.set(G,z),z+=G.length;if(U.writeFileSync(J,H),q)console.log("\uD83D\uDCC2 Extracting...");let{execSync:I}=await import("child_process");try{I(`cd "${M}" && unzip -q "${K}"`,{stdio:"pipe"})}catch{throw new Error("Failed to extract zip file. Please ensure unzip is installed on your system.")}let D=U.readdirSync(M).filter((G)=>G!==K),y=D.find((G)=>G==="launchpad"||G.startsWith("launchpad"));if(!y)for(let G of D){let u=X.join(M,G);if(U.statSync(u).isDirectory()){let l=U.readdirSync(u).find((f)=>f==="launchpad"||f.startsWith("launchpad"));if(l){y=X.join(G,l);break}}}if(!y)throw new Error("Could not find launchpad binary in extracted files");let m=X.join(M,y),h=X.dirname(w);if(!U.existsSync(h))U.mkdirSync(h,{recursive:!0});if((w.startsWith("/usr/")||w.startsWith("/opt/")||w.startsWith("/bin/")||w.startsWith("/sbin/"))&&Q!=="win32"){console.log("\uD83D\uDD12 Installing to system directory \x1B[3m(may require sudo)\x1B[0m...");try{I(`sudo cp "${m}" "${w}"`,{stdio:"inherit"}),I(`sudo chmod +x "${w}"`,{stdio:"inherit"}),I(`sudo chown root:${Q==="darwin"?"wheel":"root"} "${w}"`,{stdio:"inherit"})}catch{throw new Error(`Failed to install with sudo. You may need to run this command with elevated privileges. Alternative: Try installing to a user directory: launchpad setup --target ~/bin/launchpad \uD83D\uDCA1 Tip: You can also try copying the binary manually: sudo cp "${m}" "${w}" sudo chmod +x "${w}"`)}}else{if(q)console.log("\uD83D\uDCCB Installing binary...");if(U.copyFileSync(m,w),Q!=="win32")U.chmodSync(w,493)}if(q)console.log(`\u2705 Binary installed to: ${w}`);let S=!1;try{let G=I(`"${w}" --version`,{encoding:"utf8",stdio:"pipe",timeout:1e4});if(q)console.log(`\uD83C\uDF89 Installation verified: ${G.trim()}`);S=!0;try{if(U.accessSync(w,U.constants.X_OK),q)console.log("\u2705 Binary is executable")}catch{if(q)console.log("\u26A0\uFE0F Binary may not be executable")}}catch(G){let u=G instanceof Error?G.message:String(G);if(u.includes("timeout")||u.includes("ETIMEDOUT")){if(q)console.log("\u26A0\uFE0F Verification timed out - the binary may still work correctly");if(U.existsSync(w)){if(U.statSync(w).size>1e6)S=!0}}else if(u.includes("killed")||u.includes("SIGKILL")||u.includes("signal")){console.log("\u26A0\uFE0F Installation completed but verification failed due to code signing issues"),console.log("\u26A0\uFE0F This is a known issue with downloaded pre-built binaries on macOS"),console.log(""),console.log("\uD83D\uDD27 To fix this issue:"),console.log(`1. Remove the quarantine attribute: sudo xattr -d com.apple.quarantine "${w}"`),console.log("2. Or build from source instead:"),console.log(" git clone https://github.com/stacksjs/launchpad.git"),console.log(" cd launchpad/packages/launchpad && bun install && bun run build"),console.log(` sudo cp bin/launchpad "${w}"`),console.log(""),console.log("\uD83D\uDCA1 The binary was installed but may not work due to macOS security restrictions");try{I(`sudo xattr -d com.apple.quarantine "${w}"`,{stdio:"pipe"}),console.log("\u2705 Attempted to remove quarantine attribute");try{I(`"${w}" --version`,{encoding:"utf8",stdio:"pipe",timeout:5000}),console.log("\u2705 Binary verification succeeded after removing quarantine attribute"),S=!0}catch{console.log("\u26A0\uFE0F Binary still fails verification - code signing issues persist")}}catch{console.log("\u26A0\uFE0F Could not automatically remove quarantine attribute (no sudo access)")}}else if(u.includes("Cannot find module")||u.includes("dyld")||u.includes("Library not loaded"))console.log("\u26A0\uFE0F Installation completed but verification failed"),console.log("\u26A0\uFE0F The binary appears to have dependency issues"),console.log("This may be due to an issue with the pre-built binary"),console.log(""),console.log("\uD83D\uDCA1 Alternative solutions:"),console.log("1. Try a different version with --release"),console.log("2. Build from source instead:"),console.log(" git clone https://github.com/stacksjs/launchpad.git"),console.log(" cd launchpad/packages/launchpad && bun install && bun run build"),console.log(` sudo cp bin/launchpad "${w}"`);else{if(q)console.log("\u26A0\uFE0F Installation completed but verification failed"),console.log("The binary may still work correctly");if(U.existsSync(w)){let k=U.statSync(w);if(k.size>1e6)S=!0;if(q)console.log(`\u2139\uFE0F File exists (${(k.size/1024/1024).toFixed(1)} MB)`)}}}if(!w.includes("/usr/local/bin")&&!w.includes("/usr/bin")){let G=X.dirname(w);if(!p(G))console.log(""),console.log("\uD83D\uDCA1 Tip: Add the binary directory to your PATH:"),console.log(` export PATH="${G}:$PATH"`),console.log(""),console.log("Or add this line to your shell configuration (~/.zshrc, ~/.bashrc, etc.)")}return S}finally{try{if(U.rmSync(M,{recursive:!0,force:!0}),q)console.log("\uD83E\uDDF9 Cleaned up temporary files")}catch{if(q)console.log(`\u26A0\uFE0F Could not clean up temporary files: ${M}`)}}}async function AO(O){try{return(await U.promises.stat(O)).isDirectory()}catch{return!1}}async function qO(O,$){let w=$?.shell||!1;if(w)Y.env.LAUNCHPAD_SHELL_INTEGRATION="1";await Y0(O,{dryrun:$?.dryRun||!1,quiet:$?.quiet||w,shellOutput:w,skipGlobal:Y.env.NODE_ENV==="test"||Y.env.LAUNCHPAD_SKIP_GLOBAL_AUTO_SCAN==="true"})}async function U0(O){try{let $=X.join(O,"bin"),w=X.join(N(),".local","bin");if(await U.promises.mkdir(w,{recursive:!0}),!U.existsSync($))return;let A=await U.promises.readdir($);for(let q of A){let j=X.join($,q),Q=X.join(w,q),W=await U.promises.lstat(j);if(!W.isFile()&&!W.isSymbolicLink())continue;if(U.existsSync(Q))await U.promises.unlink(Q);await U.promises.symlink(j,Q)}}catch($){console.warn("\u26A0\uFE0F Warning: Failed to create global binary symlinks:",$)}}async function jO(O){if(!O.quiet)console.log("\uD83D\uDD0D Scanning machine for dependency files...");let $=Date.now(),w=["deps.yaml","deps.yml","dependencies.yaml","dependencies.yml"],A=[N(),X.join(N(),".dotfiles"),X.join(N(),".config"),X.join(N(),"Projects"),X.join(N(),"Code"),X.join(N(),"Development"),X.join(N(),"dev"),X.join(N(),"workspace"),X.join(N(),"src"),X.join(N(),"Desktop"),"/opt","/usr/local"],q=[],j=new Set,Q=w.map((Z)=>`**/${Z}`);for(let Z of A){if(!U.existsSync(Z))continue;try{if(O.verbose)console.log(`\uD83D\uDD0D Scanning ${Z}...`);let E=Date.now(),x=Z===N(),R=Z.includes("/Code")||Z.includes("/Projects")||Z.includes("/Development");for(let V of Q){let C=0,H=Date.now(),z=x?1000:R?5000:2000,I=V.replace("**/","");if(x)try{let D=await U.promises.readdir(Z);for(let y of D)if(y===I)q.push(X.join(Z,y)),C++}catch{}else{async function D(y,m=0){if(Date.now()-H>z||C>=100||m>6)return;try{let h=await U.promises.readdir(y,{withFileTypes:!0});for(let P of h){if(Date.now()-H>z||C>=100)break;let S=X.join(y,P.name);if(P.isFile()&&P.name===I)q.push(S),C++;else if(P.isDirectory()){if(!["node_modules","vendor",".git",".svn",".hg","dist","build","target","out","tmp","temp","cache",".cache",".npm",".yarn",".pnpm",".bun","logs","coverage",".nyc_output",".pytest_cache","__pycache__",".venv","venv","env",".env","virtualenv",".next",".nuxt",".output","public","static","assets","uploads","storage","backups","dumps","migrations","seeds","test-results","playwright-report",".playwright",".vscode",".idea","docs","documentation","examples","demo","demos","samples","test","tests","__tests__","test-envs","test-environments","spec","cypress","e2e",".turbo",".vercel",".netlify",".github",".gitlab",".bitbucket"].includes(P.name))await D(S,m+1)}}}catch{}}await D(Z)}if(O.verbose&&C>0)console.log(` \u2713 Found ${C} files matching ${V} in ${Z} (${Date.now()-H}ms)`)}let b=Date.now()-E;if(O.verbose||b>1000)console.log(`\uD83D\uDCCD Completed ${Z} in ${b}ms`)}catch(E){if(O.verbose)console.warn(`Failed to scan ${Z}: ${E instanceof Error?E.message:String(E)}`);continue}}let W=Date.now()-$;if(!O.quiet)console.log(`\uD83D\uDCC1 Found ${q.length} dependency files in ${W}ms`);let{default:K}=await import("../chunk-xcf3khvr.js");for(let Z of q)try{let E=X.dirname(Z),x=await K({string:E}),R=x.pkgs.filter((b)=>b.global);for(let b of R)j.add(b.project);if(O.verbose){let b=x.pkgs.length-R.length;console.log(` \uD83D\uDCC4 ${Z}: ${R.length} global package(s)${b>0?`, skipped ${b} local`:""}`)}}catch(E){if(O.verbose)console.warn(`Failed to parse ${Z}: ${E instanceof Error?E.message:String(E)}`)}let _=["fake.com","nonexistent.org","test.com","example.com","localhost","invalid.domain","mock.test","dummy.pkg"],M=Array.from(j).filter((Z)=>{let E=Z.split("@")[0].toLowerCase(),x=_.some((R)=>E.includes(R)||E===R);if(x&&O.verbose)console.log(`\uD83D\uDEAB Skipping fake/test package: ${Z}`);return!x});if(!O.quiet){if(console.log(`\uD83D\uDCE6 Found ${M.length} unique global dependencies`),O.dryRun){console.log("\uD83D\uDD0D Packages that would be installed:"),M.forEach((Z)=>console.log(` \u2022 ${Z}`));return}}if(M.length===0){if(!O.quiet)console.log("\u2139\uFE0F No global dependencies found");return}let J=X.join(N(),".local","share","launchpad","global");try{Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY="true";let Z=await X0(M,J);if(delete Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY,await U0(J),await Q0(),_0(),K0(),!O.quiet)if(Z.length>0)console.log(`\uD83C\uDF89 Successfully installed ${M.length} global dependencies (${Z.length} binaries)`);else console.log("\u2705 All global dependencies were already installed")}catch(Z){if(!O.quiet)console.error("\u274C Failed to install global dependencies:",Z instanceof Error?Z.message:String(Z));throw Z}}var T=new $0("launchpad");T.version(d);T.help();T.command("config","Show current Launchpad configuration").option("--json","Output as JSON (default)").example("launchpad config").example("launchpad config --json").action(async(O)=>{try{let $=JSON.stringify(L,null,2);console.log($)}catch($){console.error("Failed to load configuration:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("install [packages...]","Install packages or set up development environment").alias("i").alias("add").option("--verbose","Enable verbose output").option("--path <path>","Custom installation path").option("-g, --global-deps","Install all global dependencies found across the machine").option("--deps-only","Install only the dependencies of packages, not the packages themselves").option("--dry-run","Show packages that would be installed without installing them").option("--quiet","Suppress non-error output").option("--shell","Output shell code for evaluation (use with eval)").example("launchpad install node python").example("launchpad install --path ~/.local node python").example("launchpad install php --deps-only").example("launchpad install").example("launchpad install ./my-project").example("launchpad install --global-deps").example("launchpad add node python").action(async(O,$)=>{if($.verbose)L.verbose=!0;let w=Array.isArray(O)?O:[O].filter(Boolean);try{if($.globalDeps){await jO($);return}if($.depsOnly){if(w.length===0)console.error("Error: --deps-only requires at least one package to be specified"),Y.exit(1);let Q=X.join(N(),".local","share","launchpad","global"),W=$.path||Q;Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY="true";let K=await N0(w,W);if(delete Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY,!$.path)await U0(W);if(await Q0(),_0(),K0(),!$.quiet&&$.verbose&&K.length>0)K.forEach((_)=>{console.log(` ${_}`)});return}if(w.length===0||w.length===1&&await AO(w[0])){let Q=w.length===1?X.resolve(w[0]):Y.cwd();await qO(Q,$);return}let A=X.join(N(),".local","share","launchpad","global"),q=$.path||A;Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY="true";let j=await X0(w,q);if(delete Y.env.LAUNCHPAD_SUPPRESS_INSTALL_SUMMARY,!$.path)await U0(q);if(await Q0(),_0(),K0(),!$.quiet)if(j.length>0)console.log(`\uD83C\uDF89 Successfully installed ${w.join(", ")} (${j.length} ${j.length===1?"binary":"binaries"})`),j.forEach((Q)=>{console.log(` ${Q}`)});else console.log("\u26A0\uFE0F No binaries were installed")}catch(A){if(!$.quiet)console.error("Installation failed:",A instanceof Error?A.message:String(A));Y.exit(1)}});T.command("search [term]","Search for available packages").alias("find").option("--limit <number>","Maximum number of results to show").option("--compact","Show compact output format").option("--no-programs","Exclude program names from search").option("--case-sensitive","Case sensitive search").example("launchpad search node").example('launchpad search "web server" --limit 10').example("launchpad search python --compact").action(async(O,$)=>{try{let w=$?.limit?Number.parseInt($.limit,10):20;if(!O||O.trim().length===0){console.log(`\uD83C\uDF1F Popular Packages: `);let q=g0(w);console.log(W0(q,{compact:$?.compact,showPrograms:$?.programs!==!1}));return}let A=f0(O,{limit:w,includePrograms:$?.programs!==!1,caseSensitive:$?.caseSensitive||!1});if(A.length===0)console.log(`No packages found matching "${O}".`),console.log(` Try:`),console.log(" \u2022 Using different keywords"),console.log(" \u2022 Checking spelling"),console.log(' \u2022 Using "launchpad search" without arguments to see popular packages');else console.log(W0(A,{compact:$?.compact,showPrograms:$?.programs!==!1,searchTerm:O}))}catch(w){console.error("Search failed:",w instanceof Error?w.message:String(w)),Y.exit(1)}});T.command("info <package>","Show detailed information about a package").alias("show").option("--versions","Show available versions").option("--no-programs","Hide program list").option("--no-dependencies","Hide dependencies").option("--no-companions","Hide companion packages").option("--compact","Show compact output format").example("launchpad info node").example("launchpad info python --versions").example("launchpad show rust --compact").action(async(O,$)=>{try{if(!R0(O)){let q=await z0(O);console.error(q),Y.exit(1)}let w=x0(O,{includeVersions:$?.versions||!1,maxVersions:15});if(!w)console.error(`\u274C Failed to get information for package '${O}'`),Y.exit(1);let A=G0(w,{showVersions:$?.versions||!1,showPrograms:$?.programs!==!1,showDependencies:$?.dependencies!==!1,showCompanions:$?.companions!==!1,compact:$?.compact||!1});console.log(A)}catch(w){console.error("Failed to get package info:",w instanceof Error?w.message:String(w)),Y.exit(1)}});T.command("doctor","Run health checks and diagnose installation issues").alias("health").alias("check").option("--verbose","Show detailed diagnostic information").example("launchpad doctor").example("launchpad health").action(async(O)=>{if(O?.verbose)L.verbose=!0;try{console.log(`\uD83D\uDD0D Running health checks... `);let $=await m0(),w=S0($);if(console.log(w),$.overall==="critical")Y.exit(1);else if($.overall==="issues")Y.exit(2)}catch($){console.error("Health check failed:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("tags","Browse packages by category and tags").alias("categories").alias("browse").option("--list","List all available categories").option("--category <name>","Show packages in a specific category").option("--search <term>","Search packages by tag or category").option("--compact","Use compact display format").option("--no-programs","Hide program listings").option("--no-versions","Hide version information").example("launchpad tags --list").example('launchpad tags --category "Programming Languages"').example("launchpad tags --search database").example("launchpad categories").action(async(O)=>{try{if(O?.list){let A=q0(),q=j0(A);console.log(q);return}if(O?.category){let A=P0(O.category),q=d0(O.category,A,{compact:O.compact,showPrograms:O.programs!==!1,showVersions:O.versions!==!1});console.log(q);return}if(O?.search){let A=k0(O.search),q=v0(O.search,A,{compact:O.compact,groupByCategory:!0});console.log(q);return}let $=q0(),w=j0($);console.log(w)}catch($){console.error("Tags command failed:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("list","List installed packages").alias("ls").option("--path <path>","Installation path to list packages from").option("--verbose","Enable verbose output").example("launchpad list").example("launchpad ls").action(async(O)=>{if(O?.verbose)L.verbose=!0;try{let $=O?.path||v().string,w=await D0($);if(w.length===0)console.log("No packages installed");else console.log("Installed packages:"),w.forEach((A)=>{console.log(` ${A.project}@${A.version}`)})}catch($){console.error("Failed to list packages:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("bootstrap","Install essential tools for a complete Launchpad setup").option("--verbose","Enable verbose output").option("--path <path>","Custom installation path (default: auto-detected)").option("--force","Force reinstall even if already installed").option("--no-auto-path","Do not automatically add to PATH").option("--skip-shell-integration","Skip shell integration setup").example("launchpad bootstrap").example("launchpad bootstrap --verbose --force").example("launchpad bootstrap --path ~/.local").action(async(O)=>{if(O?.verbose)L.verbose=!0;if(O?.force)L.forceReinstall=!0;if(O?.autoPath===!1)L.autoAddToPath=!1;console.log("\uD83D\uDE80 Bootstrapping Launchpad - Installing essential tools...");let $=O?.path?new I0(O.path):v();console.log(`\uD83D\uDCCD Installation prefix: ${$.string}`),console.log("");let w=[],A=(_,M,J)=>{w.push({tool:_,status:M,message:J}),console.log(`${M==="success"?"\u2705":M==="failed"?"\u274C":M==="skipped"?"\u23ED\uFE0F":"\uD83D\uDD04"} ${_}: ${J||M}`)};console.log("\uD83D\uDCC1 Setting up directories...");let q=X.join($.string,"bin"),j=X.join($.string,"sbin");try{U.mkdirSync(q,{recursive:!0}),U.mkdirSync(j,{recursive:!0}),A("directories","success","created bin/ and sbin/")}catch(_){A("directories","failed",_ instanceof Error?_.message:String(_))}if(console.log(""),console.log("\uD83D\uDEE4\uFE0F Setting up PATH..."),L.autoAddToPath){let _=!1;if(!p(q))if(A0(q))console.log(`\u2705 Added ${q} to PATH`),_=!0;else console.log(`\u26A0\uFE0F Could not automatically add ${q} to PATH`);else console.log(`\u2705 ${q} already in PATH`);if(!p(j))if(A0(j))console.log(`\u2705 Added ${j} to PATH`),_=!0;else console.log(`\u26A0\uFE0F Could not automatically add ${j} to PATH`);else console.log(`\u2705 ${j} already in PATH`);if(_)A("PATH setup","success","PATH updated successfully");else A("PATH setup","success","PATH already configured")}else A("PATH setup","skipped","auto PATH setup disabled");if(console.log(""),!O?.skipShellIntegration){console.log("\uD83D\uDC1A Setting up shell integration...");try{await Z0("install",{dryrun:!1}),A("shell integration","success","hooks installed")}catch(_){A("shell integration","failed",_ instanceof Error?_.message:String(_))}}else A("shell integration","skipped","skipped by user");console.log(""),console.log("\uD83D\uDCCB Bootstrap Summary:"),console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");let Q=w.filter((_)=>_.status==="success"||_.status==="already-installed"),W=w.filter((_)=>_.status==="failed"),K=w.filter((_)=>_.status==="skipped");if(Q.forEach((_)=>console.log(`\u2705 ${_.tool}: ${_.message||_.status}`)),W.forEach((_)=>console.log(`\u274C ${_.tool}: ${_.message||_.status}`)),K.forEach((_)=>console.log(`\u23ED\uFE0F ${_.tool}: ${_.message||_.status}`)),console.log(""),W.length===0)console.log("\uD83C\uDF89 Bootstrap completed successfully!"),console.log(""),console.log("\uD83D\uDE80 Next steps:"),console.log("1. Restart your terminal or run: source ~/.zshrc (or your shell config)"),console.log("2. Install packages: launchpad install node python"),console.log("3. Create shims: launchpad shim node"),console.log("4. List installed: launchpad list");else console.log(`\u26A0\uFE0F Bootstrap completed with ${W.length} failed component(s)`),console.log(""),console.log("\uD83D\uDD27 You can continue using Launchpad, but some features may not work optimally")});T.command("setup","Download and install Launchpad binary to /usr/local/bin").option("--force","Force download even if binary already exists").option("--verbose","Enable verbose output").option("--release <version>",`Specific version to download (default: ${F0})`).option("--target <path>","Target installation path (default: /usr/local/bin/launchpad)").example("launchpad setup").example("launchpad setup --force --verbose").example("launchpad setup --release v0.3.5").example("launchpad setup --target ~/bin/launchpad").action(async(O)=>{if(O?.verbose)L.verbose=!0;let $=O?.release||F0,w=O?.target||"/usr/local/bin/launchpad";console.log("\uD83D\uDE80 Setting up Launchpad binary..."),console.log("");try{let A=await l0({targetVersion:$,targetPath:w,force:O?.force||!1,verbose:O?.verbose||!1});if(console.log(""),A)console.log("\uD83C\uDF89 Setup completed successfully!"),console.log(""),console.log("\uD83D\uDE80 Next steps:"),console.log("1. Restart your terminal or reload your shell configuration"),console.log("2. Run: launchpad --version"),console.log("3. Get started: launchpad bootstrap");else console.log("\u26A0\uFE0F Setup completed with verification issues"),console.log(""),console.log("\u26A0\uFE0F The binary was installed but failed verification."),console.log("It may still work, but there could be compatibility issues."),console.log(""),console.log("\uD83D\uDD27 Recommended actions:"),console.log("1. Try running: launchpad --version"),console.log("2. If it hangs, try a different version with --release"),console.log("3. Consider building from source if issues persist"),console.log(""),console.log("\uD83D\uDCA1 Alternative: Build from source:"),console.log(" git clone https://github.com/stacksjs/launchpad.git"),console.log(" cd launchpad && bun install && bun run build")}catch(A){console.error("Setup failed:",A instanceof Error?A.message:String(A)),console.log(""),console.log("\uD83D\uDD27 Troubleshooting:"),console.log("\u2022 Check your internet connection"),console.log("\u2022 Verify the version exists on GitHub releases: https://github.com/stacksjs/launchpad/releases"),console.log("\u2022 Try a different version with --release (e.g., --release v0.3.5)"),console.log("\u2022 Try a different target path with --target"),console.log("\u2022 Use --verbose for more detailed output"),console.log(""),console.log("\uD83D\uDCA1 Alternative: Build from source:"),console.log(" git clone https://github.com/stacksjs/launchpad.git"),console.log(" cd launchpad && bun install && bun run build"),Y.exit(1)}});T.command("debug:deps","Debug global dependencies and show their sources").option("--package <name>","Filter by specific package name").option("--version <version>","Filter by specific version").action(async(O)=>{console.log(`\uD83D\uDD0D Debugging global dependencies... `);let $=["deps.yaml","deps.yml","dependencies.yaml","dependencies.yml"],w=[N(),X.join(N(),".dotfiles"),X.join(N(),".config"),X.join(N(),"Projects"),X.join(N(),"Code"),X.join(N(),"Development"),X.join(N(),"dev"),X.join(N(),"workspace"),X.join(N(),"src"),X.join(N(),"Desktop"),"/opt","/usr/local"],A=[],q=new Map;for(let W of w){if(!U.existsSync(W))continue;for(let K of $){async function _(M,J=0){if(J>6)return;try{let Z=await U.promises.readdir(M,{withFileTypes:!0});for(let E of Z){let x=X.join(M,E.name);if(E.isDirectory()){if(["node_modules","vendor",".git",".svn",".hg","dist","build","target","venv","__pycache__",".vscode",".idea","coverage",".nyc_output","logs","test-envs","test","tests","__tests__"].includes(E.name))continue;await _(x,J+1)}else if(E.name===K)try{let R=await U.promises.readFile(x,"utf-8"),{default:b}=await import("../chunk-xcf3khvr.js"),C=(await b({string:X.dirname(x)})).pkgs.map((H)=>({name:H.project,version:String(H.constraint)}));A.push({file:x,packages:C});for(let H of C){if(!q.has(H.name))q.set(H.name,[]);q.get(H.name).push({file:x,version:String(H.version)})}}catch{}}}catch{}}if(W===N()){let M=X.join(W,K);if(U.existsSync(M))try{let J=await U.promises.readFile(M,"utf-8"),{default:Z}=await import("../chunk-xcf3khvr.js"),x=(await Z({string:W})).pkgs.map((R)=>({name:R.project,version:String(R.constraint)}));A.push({file:M,packages:x});for(let R of x){if(!q.has(R.name))q.set(R.name,[]);q.get(R.name).push({file:M,version:String(R.version)})}}catch{}}else await _(W,0)}}let j=q;if(O.package){let W=new Map;for(let[K,_]of q)if(K.toLowerCase().includes(O.package.toLowerCase()))W.set(K,_);j=W}if(O.version){let W=new Map;for(let[K,_]of j){let M=_.filter((J)=>J.version&&J.version.includes(O.version));if(M.length>0)W.set(K,M)}j=W}if(console.log(`\uD83D\uDCC4 Found ${A.length} dependency files`),console.log(`\uD83D\uDCE6 Found ${q.size} unique packages `),O.package||O.version)console.log(`\uD83D\uDD0D Filtered results: `);for(let[W,K]of j){console.log(`\uD83D\uDCE6 ${W}`);let _=new Map;for(let M of K){let J=M.version||"unspecified";if(!_.has(J))_.set(J,[]);_.get(J).push(M.file)}for(let[M,J]of _){console.log(` \uD83D\uDCCC ${M}`);for(let Z of J)console.log(` \uD83D\uDCC4 ${Z}`)}console.log()}let Q=Array.from(q.entries()).filter(([W,K])=>{return new Set(K.map((M)=>M.version).filter(Boolean)).size>1});if(Q.length>0){console.log(`\u26A0\uFE0F Version conflicts detected: `);for(let[W,K]of Q){console.log(`\uD83D\uDCE6 ${W}`);let _=new Map;for(let M of K){let J=M.version||"unspecified";if(!_.has(J))_.set(J,[]);_.get(J).push(M.file)}for(let[M,J]of _)console.log(` \u26A0\uFE0F ${M} (${J.length} files)`);console.log()}}console.log("\uD83D\uDCA1 Usage examples:"),console.log(" launchpad debug:deps --package bun"),console.log(" launchpad debug:deps --version 1.2.3"),console.log(" launchpad debug:deps --package php --version 8.4")});T.command("upgrade","Upgrade Launchpad to the latest version").alias("self-update").option("--force","Force upgrade even if already on latest version").option("--verbose","Enable verbose output").option("--target <path>","Target installation path (default: current binary location)").option("--release <version>","Upgrade to specific version (default: latest)").option("--dry-run","Show what would be upgraded without actually upgrading").example("launchpad upgrade").example("launchpad upgrade --force").example("launchpad upgrade --release v0.3.5").example("launchpad upgrade --dry-run --verbose").action(async(O)=>{if(O?.verbose)L.verbose=!0;try{let $;try{let{execSync:q}=await import("child_process"),Q=q("which launchpad",{encoding:"utf8",stdio:"pipe"}).trim();if(!Q.includes("/packages/")&&!Q.includes("/dist/")&&!Q.includes("/src/"))$=Q;else{let W=await import("fs"),K=["/usr/local/bin/launchpad","/usr/bin/launchpad",X.join(Y.env.HOME||"~",".local/bin/launchpad"),X.join(Y.env.HOME||"~",".bun/bin/launchpad"),X.join(Y.env.HOME||"~","bin/launchpad")];$=Q;for(let _ of K)if(W.existsSync(_))try{if(W.lstatSync(_).isSymbolicLink()){let J=W.readlinkSync(_);if(!J.includes("/packages/")&&!J.includes("/dist/")){$=_;break}}else{$=_;break}}catch{$=_;break}}}catch{if(Y.argv[1]&&Y.argv[1].includes("launchpad")&&!Y.argv[1].includes(".test.")&&!Y.argv[1].includes("/test/")&&!Y.argv[1].includes("/packages/")&&!Y.argv[1].includes("/dist/"))$=Y.argv[1];else{let q=await import("fs"),j=["/usr/local/bin/launchpad","/usr/bin/launchpad",X.join(Y.env.HOME||"~",".local/bin/launchpad"),X.join(Y.env.HOME||"~",".bun/bin/launchpad"),X.join(Y.env.HOME||"~","bin/launchpad")];$="/usr/local/bin/launchpad";for(let Q of j)if(q.existsSync(Q)){$=Q;break}}}let w=O?.target||$;if(O?.verbose)console.log(`\uD83D\uDD0D Detected current binary: ${$}`),console.log(`\uD83C\uDFAF Upgrade target: ${w}`);let A=O?.release;if(!A)try{let q=await globalThis.fetch("https://api.github.com/repos/stacksjs/launchpad/releases/latest");if(!q.ok)throw new Error(`GitHub API request failed: ${q.status} ${q.statusText}`);A=(await q.json()).tag_name}catch(q){console.error("Failed to check latest version:",q instanceof Error?q.message:String(q)),console.log("You can specify a version manually with --release"),Y.exit(1)}if(O?.verbose)console.log(`\uD83D\uDCCB Current version: v${d}`),console.log(`\uD83D\uDCCB Target version: ${A}`);if(!O?.force&&A===`v${d}`){if(console.log(`\u2705 You're already on the latest version of Launchpad \x1B[2m\x1B[3m(v${d})\x1B[0m`),O?.verbose)console.log("\uD83D\uDCA1 Use --force to reinstall the same version");return}if(O?.verbose&&A!==`v${d}`)console.log(`\uD83D\uDE80 Upgrading from v${d} to ${A}`);if(O?.dryRun){if(console.log(` \uD83D\uDD0D DRY RUN MODE - Showing what would be upgraded: `),console.log(`\uD83D\uDCCB Current binary: ${$}`),console.log(`\uD83D\uDCCB Current version: v${d}`),console.log(`\uD83D\uDCCB Target version: ${A}`),console.log(`\uD83D\uDCCB Target path: ${w}`),A===`v${d}`)console.log(` \u2705 Already on target version - no upgrade needed`),console.log("\uD83D\uDCA1 Use --force to reinstall the same version");else console.log(` \uD83D\uDE80 Would upgrade from v${d} to ${A}`),console.log(`\uD83D\uDCE5 Would download: ${A} binary`),console.log(`\uD83D\uDCCD Would install to: ${w}`),console.log(` \uD83D\uDCA1 Run without --dry-run to perform the actual upgrade`);return}try{if(await l0({targetVersion:A,targetPath:w,force:!0,verbose:O?.verbose||!1}))console.log(`Congrats! Launchpad was updated to ${A}`);else if(U.existsSync(w))if(U.statSync(w).size>1e6)console.log(`Congrats! Launchpad was updated to ${A}`);else console.log("Upgrade completed with verification issues"),console.log("The binary may still work, but there could be compatibility issues."),console.log("Try running: launchpad --version");else console.log("Upgrade failed - binary not found at target location")}catch(q){if(console.error("Upgrade failed:",q instanceof Error?q.message:String(q)),O?.verbose)console.log("Try running the setup command manually:"),console.log(` launchpad setup --release ${A} --target "${w}" --force`);Y.exit(1)}}catch($){console.error("Upgrade failed:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("shim [packages...]","Create shims for packages").alias("stub").option("--verbose","Enable verbose output").option("--path <path>","Custom shim installation path").option("--force","Force creation of shims even if they already exist").option("--no-auto-path","Do not automatically add shim directory to PATH").example("launchpad shim node").example("launchpad shim node python --path ~/bin").action(async(O,$)=>{if($?.verbose)L.verbose=!0;if($?.force)L.forceReinstall=!0;if($?.autoPath===!1)L.autoAddToPath=!1;let w=Array.isArray(O)?O:[O].filter(Boolean);if(w.length===0)console.error("No packages specified"),Y.exit(1);try{let A=$?.path||y0().string;console.log(`Creating shims for: ${w.join(", ")}`);let q=await b0(w,A);if(q.length>0)console.log(`Successfully created ${q.length} shims:`),q.forEach((j)=>{console.log(` ${j}`)});else console.log("No shims were created")}catch(A){console.error("Failed to create shims:",A instanceof Error?A.message:String(A)),Y.exit(1)}});T.command("dev:shellcode","Generate shell integration code").option("--test-mode","Generate shellcode for testing (bypasses test environment checks)").action(({testMode:O})=>{console.log(u0(O))});T.command("dev [dir]","Set up development environment for project dependencies").option("--dry-run","Show packages that would be installed without installing them").option("--quiet","Suppress non-error output").option("--shell","Output shell code for evaluation (use with eval)").action(async(O,$)=>{try{let w=O?X.resolve(O):Y.cwd(),A=$?.shell||!1;if(A)Y.env.LAUNCHPAD_SHELL_INTEGRATION="1";await Y0(w,{dryrun:$?.dryRun||!1,quiet:$?.quiet||A,shellOutput:A,skipGlobal:Y.env.NODE_ENV==="test"||Y.env.LAUNCHPAD_SKIP_GLOBAL_AUTO_SCAN==="true"})}catch(w){if(!$?.quiet&&!$?.shell)console.error("Failed to set up dev environment:",w instanceof Error?w.message:String(w));else if($?.shell){console.log("# Environment setup failed, using system fallback"),console.log("# Ensure basic system paths are available"),console.log("for sys_path in /usr/local/bin /usr/bin /bin /usr/sbin /sbin; do"),console.log(' if [[ -d "$sys_path" && ":$PATH:" != *":$sys_path:"* ]]; then'),console.log(' export PATH="$PATH:$sys_path"'),console.log(" fi"),console.log("done"),console.log("# Clear command hash to ensure fresh lookups"),console.log("hash -r 2>/dev/null || true");return}if(!$?.shell)Y.exit(1)}});T.command("dev:integrate","Install shell integration hooks").option("--uninstall","Remove shell integration hooks").option("--dry-run","Show what would be changed without making changes").action(async(O)=>{try{let $=O?.uninstall?"uninstall":"install",w=O?.dryRun||!1;await Z0($,{dryrun:w})}catch($){console.error("Failed to integrate shell hooks:",$ instanceof Error?$.message:String($)),Y.exit(1)}});T.command("dev:on [dir]","Activate development environment (use `launchpad dev` instead)").option("--silent","Suppress output messages").option("--shell-safe","Output shell-safe message without ANSI escape sequences").action(async(O,$)=>{try{let w=O?X.resolve(O):Y.cwd();if(!$?.silent){if(L.showShellMessages&&L.shellActivationMessage){let A=L.shellActivationMessage.replace("{path}",X.basename(w));if($?.shellSafe)A=A.replace(/\u001B\[[0-9;]*m/g,"");console.log(A