UNPKG

@shopify/cli

Version:

A CLI tool to build for the Shopify platform

19 lines (15 loc) • 33 kB
import{a as Q}from"./chunk-Z35BTAM6.js";import{a as Me}from"./chunk-75VPUOC5.js";import{a as He}from"./chunk-HZA6IAA4.js";import{a as Ce}from"./chunk-PD5ZHJWI.js";import{l as ze,r as F}from"./chunk-LDGAHMS7.js";import{a as Ve,b as Ge}from"./chunk-ZR76GGZ6.js";import{a as ve,c as Z,e as b,g}from"./chunk-VPRTJUIN.js";var me=Z((Bn,je)=>{g();function Ye(i){t.debug=t,t.default=t,t.coerce=l,t.disable=c,t.enable=s,t.enabled=o,t.humanize=Ve(),t.destroy=f,Object.keys(i).forEach(a=>{t[a]=i[a]}),t.names=[],t.skips=[],t.formatters={};function e(a){let u=0;for(let d=0;d<a.length;d++)u=(u<<5)-u+a.charCodeAt(d),u|=0;return t.colors[Math.abs(u)%t.colors.length]}t.selectColor=e;function t(a){let u,d=null,p,m;function w(...C){if(!w.enabled)return;let I=w,P=Number(new Date),D=P-(u||P);I.diff=D,I.prev=u,I.curr=P,u=P,C[0]=t.coerce(C[0]),typeof C[0]!="string"&&C.unshift("%O");let K=0;C[0]=C[0].replace(/%([a-zA-Z%])/g,(de,We)=>{if(de==="%%")return"%";K++;let be=t.formatters[We];if(typeof be=="function"){let qe=C[K];de=be.call(I,qe),C.splice(K,1),K--}return de}),t.formatArgs.call(I,C),(I.log||t.log).apply(I,C)}return w.namespace=a,w.useColors=t.useColors(),w.color=t.selectColor(a),w.extend=n,w.destroy=t.destroy,Object.defineProperty(w,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(p!==t.namespaces&&(p=t.namespaces,m=t.enabled(a)),m),set:C=>{d=C}}),typeof t.init=="function"&&t.init(w),w}function n(a,u){let d=t(this.namespace+(typeof u>"u"?":":u)+a);return d.log=this.log,d}function s(a){t.save(a),t.namespaces=a,t.names=[],t.skips=[];let u=(typeof a=="string"?a:"").trim().replace(" ",",").split(",").filter(Boolean);for(let d of u)d[0]==="-"?t.skips.push(d.slice(1)):t.names.push(d)}function r(a,u){let d=0,p=0,m=-1,w=0;for(;d<a.length;)if(p<u.length&&(u[p]===a[d]||u[p]==="*"))u[p]==="*"?(m=p,w=d,p++):(d++,p++);else if(m!==-1)p=m+1,w++,d=w;else return!1;for(;p<u.length&&u[p]==="*";)p++;return p===u.length}function c(){let a=[...t.names,...t.skips.map(u=>"-"+u)].join(",");return t.enable(""),a}function o(a){for(let u of t.skips)if(r(a,u))return!1;for(let u of t.names)if(r(a,u))return!0;return!1}function l(a){return a instanceof Error?a.stack||a.message:a}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return t.enable(t.load()),t}je.exports=Ye});var Pe=Z((x,X)=>{g();x.formatArgs=Ze;x.save=Qe;x.load=Xe;x.useColors=Ke;x.storage=et();x.destroy=(()=>{let i=!1;return()=>{i||(i=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();x.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Ke(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let i;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(i=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(i[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ze(i){if(i[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+i[0]+(this.useColors?"%c ":" ")+"+"+X.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;i.splice(1,0,e,"color: inherit");let t=0,n=0;i[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(t++,s==="%c"&&(n=t))}),i.splice(n,0,e)}x.log=console.debug||console.log||(()=>{});function Qe(i){try{i?x.storage.setItem("debug",i):x.storage.removeItem("debug")}catch{}}function Xe(){let i;try{i=x.storage.getItem("debug")}catch{}return!i&&typeof process<"u"&&"env"in process&&(i=process.env.DEBUG),i}function et(){try{return localStorage}catch{}}X.exports=me()(x);var{formatters:tt}=X.exports;tt.j=function(i){try{return JSON.stringify(i)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var xe=Z((v,te)=>{g();var nt=ve("tty"),ee=ve("util");v.init=ct;v.log=rt;v.formatArgs=st;v.save=at;v.load=lt;v.useColors=it;v.destroy=ee.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");v.colors=[6,2,3,4,5,1];try{let i=Ge();i&&(i.stderr||i).level>=2&&(v.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}v.inspectOpts=Object.keys(process.env).filter(i=>/^debug_/i.test(i)).reduce((i,e)=>{let t=e.substring(6).toLowerCase().replace(/_([a-z])/g,(s,r)=>r.toUpperCase()),n=process.env[e];return/^(yes|on|true|enabled)$/i.test(n)?n=!0:/^(no|off|false|disabled)$/i.test(n)?n=!1:n==="null"?n=null:n=Number(n),i[t]=n,i},{});function it(){return"colors"in v.inspectOpts?!!v.inspectOpts.colors:nt.isatty(process.stderr.fd)}function st(i){let{namespace:e,useColors:t}=this;if(t){let n=this.color,s="\x1B[3"+(n<8?n:"8;5;"+n),r=` ${s};1m${e} \x1B[0m`;i[0]=r+i[0].split(` `).join(` `+r),i.push(s+"m+"+te.exports.humanize(this.diff)+"\x1B[0m")}else i[0]=ot()+e+" "+i[0]}function ot(){return v.inspectOpts.hideDate?"":new Date().toISOString()+" "}function rt(...i){return process.stderr.write(ee.formatWithOptions(v.inspectOpts,...i)+` `)}function at(i){i?process.env.DEBUG=i:delete process.env.DEBUG}function lt(){return process.env.DEBUG}function ct(i){i.inspectOpts={};let e=Object.keys(v.inspectOpts);for(let t=0;t<e.length;t++)i.inspectOpts[e[t]]=v.inspectOpts[e[t]]}te.exports=me()(v);var{formatters:ke}=te.exports;ke.o=function(i){return this.inspectOpts.colors=this.useColors,ee.inspect(i,this.inspectOpts).split(` `).map(e=>e.trim()).join(" ")};ke.O=function(i){return this.inspectOpts.colors=this.useColors,ee.inspect(i,this.inspectOpts)}});var T=Z((Rn,he)=>{g();typeof process>"u"||process.type==="renderer"||process.browser===!0||process.__nwjs?he.exports=Pe():he.exports=xe()});g();g();var ge=b(F(),1);g();var $e=b(ze(),1);var{Ansis:St,ansi256:Bt,fg:Jt,bgAnsi256:At,bg:Ut,rgb:Rt,bgRgb:Tt,hex:_t,bgHex:Wt,reset:qt,inverse:Vt,hidden:Gt,visible:zt,bold:E,dim:k,italic:Ht,underline:Mt,strikethrough:Yt,strike:Kt,black:Zt,red:Qt,green:Xt,yellow:en,blue:tn,magenta:nn,cyan:R,white:sn,grey:on,gray:rn,blackBright:an,redBright:ln,greenBright:cn,yellowBright:un,blueBright:gn,magentaBright:fn,cyanBright:pn,whiteBright:dn,bgBlack:mn,bgRed:hn,bgGreen:yn,bgYellow:wn,bgBlue:bn,bgMagenta:vn,bgCyan:Cn,bgWhite:$n,bgGrey:jn,bgGray:Pn,bgBlackBright:kn,bgRedBright:xn,bgGreenBright:Fn,bgYellowBright:Ln,bgBlueBright:Nn,bgMagentaBright:In,bgCyanBright:On,bgWhiteBright:En}=$e.default;g();var $=b(F(),1);var Be=b(T(),1),B=b(He(),1);import{spawn as wt}from"node:child_process";import{access as bt,mkdir as vt,readFile as Ct,rename as $t,rm as Oe,writeFile as jt}from"node:fs/promises";import{basename as Pt,dirname as Ee,join as j,parse as De,resolve as we}from"node:path";import{fileURLToPath as kt}from"node:url";g();var re=b(F(),1),Le=b(T(),1);import{readFile as gt}from"node:fs/promises";import{createRequire as ft}from"node:module";import{join as pt,sep as dt}from"node:path";g();var _=b(F(),1),Fe=b(T(),1);import{spawn as ut}from"node:child_process";var ne=(0,Fe.default)("@oclif/plugin-plugins:spawn");async function ie(i,e=[],{cwd:t,logLevel:n}){return new Promise((s,r)=>{process.platform==="win32"&&i.endsWith(".js")&&(e.unshift(`"${i}"`),i="node"),ne("modulePath",i),ne("args",e);let c=ut(i,e,{cwd:t,env:{...Ce(),HUSKY:"0"},stdio:"pipe",windowsVerbatimArguments:!0,...process.platform==="win32"&&i.toLowerCase().endsWith(".cmd")&&{shell:!0}}),o=["up to date","added"],l=[],f=[],a=[],u=[],d=p=>{let m=a.length===0&&u.length===0,w=o.some(C=>p.startsWith(C));return m&&w&&n==="notice"?!1:n!=="silent"};c.stderr?.setEncoding("utf8"),c.stderr?.on("data",p=>{let m=p.toString().trim();l.push(m),d(m)?(a.push(m),_.ux.stdout(m)):ne(m)}),c.stdout?.setEncoding("utf8"),c.stdout?.on("data",p=>{let m=p.toString().trim();f.push(m),d(m)?(u.push(m),_.ux.stdout(m)):ne(m)}),c.on("error",r),c.on("exit",p=>{p===0?s({stderr:l,stdout:f}):r(new _.Errors.CLIError(`${i} ${e.join(" ")} exited with code ${p}`,{suggestions:["Run with DEBUG=@oclif/plugin-plugins* to see debug output."]}))})})}var se=(0,Le.default)("@oclif/plugin-plugins:npm"),oe=class{bin;config;logLevel;constructor({config:e,logLevel:t}){this.config=e,this.logLevel=t}async exec(e=[],t){let n=await this.findNpm();se("npm binary path",n),e.push(`--loglevel=${this.logLevel}`,"--no-fund"),this.config.npmRegistry&&e.push(`--registry=${this.config.npmRegistry}`),t.logLevel!=="notice"&&t.logLevel!=="silent"&&re.ux.stderr(`${t.cwd}: ${n} ${e.join(" ")}`),se(`${t.cwd}: ${n} ${e.join(" ")}`);try{let s=await ie(n,e,t);return se("npm done"),s}catch(s){throw se("npm error",s),s}}async install(e,t){let n=t.prod?["--omit","dev"]:[];return this.exec(["install",...e,...n,"--no-audit"],t)}async uninstall(e,t){return this.exec(["uninstall",...e],t)}async update(e,t){return this.exec(["update",...e],t)}async view(e,t){return this.exec(["view",...e],{...t,logLevel:"silent"})}async findNpm(){if(this.bin)return this.bin;try{let e=ft(import.meta.url).resolve("npm/package.json"),t=JSON.parse(await gt(e,{encoding:"utf8"})),n=e.slice(0,Math.max(0,e.lastIndexOf(dt)));this.bin=pt(n,t.bin.npm)}catch{let{default:e}=await import("./lib-WU3FEA6I.js");this.bin=await e("npm")}if(!this.bin)throw new re.Errors.CLIError("npm not found");return this.bin}};g();function ye(i,e){let t=i===void 0?0:i,n=e===void 0?0:e;if(Array.isArray(t)&&Array.isArray(n)){if(t.length===0&&n.length===0)return 0;let s=ye(t[0],n[0]);return s!==0?s:ye(t.slice(1),n.slice(1))}return t<n?-1:t>n?1:0}function A(i,e){return i.sort((t,n)=>ye(e(t),e(n)))}function Ne(i,e){return i.filter((t,n)=>!i.some((s,r)=>r>n&&e(t,s)))}g();var ce=b(F(),1),Ie=b(T(),1);import{createRequire as mt}from"node:module";import{fileURLToPath as ht}from"node:url";var yt=mt(import.meta.url),ae=(0,Ie.default)("@oclif/plugin-plugins:yarn"),le=class{bin;config;logLevel;constructor({config:e,logLevel:t}){this.config=e,this.logLevel=t}async exec(e=[],t){let n=await this.findYarn();ae("yarn binary path",n),t.logLevel==="verbose"&&e.push("--verbose"),this.config.npmRegistry&&e.push(`--registry=${this.config.npmRegistry}`),t.logLevel!=="notice"&&t.logLevel!=="silent"&&ce.ux.stderr(`${t.cwd}: ${n} ${e.join(" ")}`),ae(`${t.cwd}: ${n} ${e.join(" ")}`);try{let s=await ie(n,e,t);return ae("yarn done"),s}catch(s){throw ae("yarn error",s),s}}async install(e,t){return this.exec(["install",...e],t)}async findYarn(){if(this.bin)return this.bin;try{this.bin=yt.resolve("yarn/bin/yarn.js",{paths:[this.config.root,ht(import.meta.url)]})}catch{let{default:e}=await import("./lib-WU3FEA6I.js");this.bin=await e("yarn")}if(!this.bin)throw new ce.Errors.CLIError("yarn not found");return this.bin}};var ue={dependencies:{},oclif:{plugins:[],schema:1},private:!0};async function U(i){try{return await bt(i),!0}catch{return!1}}function Je(i){return Ne(i,(e,t)=>e.name===t.name||e.type==="link"&&t.type==="link"&&e.root===t.root)}function xt(i,e){if(i)return typeof i=="string"?i:i.url;if(e)return typeof e=="string"?e:e.url.replace("git+","").replace(".git","")}function Se(i,e){[...e.stdout,...e.stderr].some(n=>n.includes("npm WARN"))&&($.ux.stderr(E.yellow(` These warnings can only be addressed by the owner(s) of ${i.name}.`)),(i.pjson.bugs||i.pjson.repository)&&$.ux.stderr(`We suggest that you create an issue at ${xt(i.pjson.bugs,i.pjson.repository)} and ask the plugin owners to address them. `))}var h=class{config;npm;debug;logLevel;constructor(e){this.config=e.config,this.debug=(0,Be.default)("@oclif/plugin-plugins"),this.logLevel=e.logLevel??"notice",this.npm=new oe({config:this.config,logLevel:this.logLevel})}get pjsonPath(){return j(this.config.dataDir,"package.json")}async add(...e){let t=await this.pjson(),n=[...t.oclif.plugins||[],...e];await this.savePJSON({...t,oclif:{...t.oclif,plugins:Je(n)}})}friendlyName(e){let{pluginPrefix:t,scope:n}=this.config.pjson.oclif;return n?e.match(`@${n}/${t??"plugin"}-(.+)`)?.[1]??e:e}async hasPlugin(e){let t=await this.list(),n=this.friendlyName(e),s=this.unfriendlyName(e)??e;return t.find(r=>this.friendlyName(r.name)===n)??t.find(r=>this.unfriendlyName(r.name)===s)??t.find(r=>r.type==="link"&&we(r.root)===we(e))??!1}async install(e,{force:t=!1,tag:n="latest"}={}){await this.maybeCleanUp();try{this.debug(`installing plugin ${e}`);let s={cwd:this.config.dataDir,logLevel:this.logLevel,prod:!0};await this.ensurePJSON();let r,c=t?["--force"]:[];if(e.includes(":")){let o=e,l=await this.npm.install([...c,o],s),{dependencies:f}=await this.pjson(),{default:a}=await import("./npa-ICFSA3NL.js"),u=a(o),p=Object.entries(f??{}).find(([,P])=>{let D=a(P);return D.type==="file"&&D.raw?De(o).base===De(D.raw).base:D.hosted?.type===u.hosted?.type&&D.hosted?.user===u.hosted?.user&&D.hosted?.project===u.hosted?.project})?.[0];if(!p)throw new $.Errors.CLIError(`Could not find plugin name for ${o}`);let m=j(this.config.dataDir,"node_modules",p);r=await $.Config.load({devPlugins:!1,name:p,root:m,userPlugins:!1}),Se(r,l),this.isValidPlugin(r),await this.add({name:p,type:"user",url:o});let w=new Set(["npm-shrinkwrap.json","oclif.lock","oclif.manifest.json"]),C=(r.pjson.files??[]).map(P=>j(m,P)).filter(P=>!w.has(Pt(P)));this.debug(`checking for existence of files: ${C.join(", ")}`);let I=Object.fromEntries(await Promise.all(C?.map(async P=>[P,await U(P)])??[]));this.debug(I),Object.values(I).every(Boolean)||$.ux.warn("This plugin may not work as expected because the prepare script did not produce all the expected files.")}else{let o=(0,B.validRange)(n),l=this.unfriendlyName(e);l&&await this.npmHasPackage(l)&&(e=l),await this.npmHasPackage(e,!0);let f=await this.npm.install([...c,`${e}@${n}`],s);this.debug(`loading plugin ${e}...`),r=await $.Config.load({devPlugins:!1,name:e,root:j(this.config.dataDir,"node_modules",e),userPlugins:!1}),this.debug(`finished loading plugin ${e} at root ${r.root}`),Se(r,f),this.isValidPlugin(r),await this.add({name:e,tag:o??n,type:"user"})}return await Oe(j(this.config.dataDir,"yarn.lock"),{force:!0}),r}catch(s){throw this.debug("error installing plugin:",s),await this.uninstall(e).catch(r=>this.debug(r)),String(s).includes("EACCES")?new $.Errors.CLIError(s,{suggestions:[`Plugin failed to install because of a permissions error. Does your current user own the directory ${this.config.dataDir}?`]}):s}}async link(e,{install:t}){let n=await $.Config.load(we(e));return this.isValidPlugin(n),t&&(await U(j(n.root,"yarn.lock"))?(this.debug("installing dependencies with yarn"),await new le({config:this.config,logLevel:this.logLevel}).install([],{cwd:n.root,logLevel:this.logLevel})):await U(j(n.root,"package-lock.json"))?(this.debug("installing dependencies with npm"),await this.npm.install([],{cwd:n.root,logLevel:this.logLevel,prod:!1})):await U(j(n.root,"pnpm-lock.yaml"))?$.ux.warn(`pnpm is not supported for installing after a link. The link succeeded, but you may need to run 'pnpm install' in ${n.root}.`):$.ux.warn(`No lockfile found in ${n.root}. The link succeeded, but you may need to install the dependencies in your project.`)),await this.add({name:n.name,root:n.root,type:"link"}),n}async list(){return(await this.pjson()).oclif.plugins}async maybeUnfriendlyName(e){await this.ensurePJSON();let t=this.unfriendlyName(e);return this.debug(`checking registry for expanded package name ${t}`),t&&await this.npmHasPackage(t)?t:(this.debug(`expanded package name ${t} not found, using given package name ${e}`),e)}async pjson(){let e=await this.readPJSON(),t=e?Ft(e.oclif.plugins):[];return{...ue,...e,oclif:{...ue.oclif,...e?.oclif,plugins:t}}}async remove(e){let t=await this.pjson();t.dependencies&&delete t.dependencies[e],await this.savePJSON({...t,oclif:{...t.oclif,plugins:t.oclif.plugins.filter(n=>n.name!==e)}})}unfriendlyName(e){if(e.includes("@"))return;let{pluginPrefix:t,scope:n}=this.config.pjson.oclif;if(n)return`@${n}/${t??"plugin"}-${e}`}async uninstall(e){try{((await this.pjson()).oclif.plugins??[]).some(n=>typeof n=="object"&&n.type==="user"&&n.name===e)&&await this.npm.uninstall([e],{cwd:this.config.dataDir,logLevel:this.logLevel})}catch(t){$.ux.warn(t)}finally{await this.remove(e)}}async update(){let e=(await this.list()).filter(o=>o.type==="user");if(e.length===0)return;await this.maybeCleanUp();let t=this.config.pjson.oclif.aliases||{};for(let[o,l]of Object.entries(t))e.find(a=>a.name===o)&&(l&&await this.install(l),await this.uninstall(o),e=e.filter(a=>a.name!==o));let n=e.filter(o=>!!o.url);n.length>0&&await this.npm.update(n.map(o=>o.name),{cwd:this.config.dataDir,logLevel:this.logLevel});let s=e.filter(o=>!o.url),r=this.config.pjson.oclif.jitPlugins??{},c=[];s.length>0&&await this.npm.install(s.map(o=>{if(!(0,B.valid)(o.tag))return`${o.name}@${o.tag}`;if(o.tag&&(0,B.valid)(o.tag)&&r[o.name]&&(0,B.gt)(o.tag,r[o.name]))return`${o.name}@${o.tag}`;let l=r[o.name]??o.tag;return c.push({...o,tag:l}),`${o.name}@${l}`}),{cwd:this.config.dataDir,logLevel:this.logLevel,prod:!0}),await this.add(...c)}async ensurePJSON(){await U(this.pjsonPath)||(this.debug(`creating ${this.pjsonPath} with pjson: ${JSON.stringify(ue,null,2)}`),await this.savePJSON(ue))}isValidPlugin(e){if(e.valid||this.config.plugins.get("@oclif/plugin-legacy")||e._base.includes("@oclif/plugin-legacy"))return!0;throw new $.Errors.CLIError("plugin is invalid",{suggestions:[`Plugin failed to install because it does not appear to be a valid CLI plugin. If you are sure it is, contact the CLI developer noting this error.`]})}async maybeCleanUp(){if(await U(j(this.config.dataDir,"yarn.lock")))try{this.debug("Found yarn.lock! Removing yarn.lock and node_modules..."),await Promise.all([$t(j(this.config.dataDir,"node_modules"),j(this.config.dataDir,"node_modules.old")),Oe(j(this.config.dataDir,"yarn.lock"),{force:!0})]);let e=j(Ee(kt(import.meta.url)),"rm.js");this.debug(`spawning ${e} to remove node_modules.old`),wt(process.argv[0],[e,j(this.config.dataDir,"node_modules.old")],{detached:!0,stdio:"ignore",...this.config.windows?{shell:!0}:{}}).unref()}catch(e){this.debug("Error cleaning up yarn.lock and node_modules:",e)}}async npmHasPackage(e,t=!1){try{return await this.npm.view([e],{cwd:this.config.dataDir,logLevel:this.logLevel}),this.debug(`Found ${e} in the registry.`),!0}catch(n){if(this.debug(n),t)throw new $.Errors.CLIError(`${e} does not exist in the registry.`);return!1}}async readPJSON(){try{return JSON.parse(await Ct(this.pjsonPath,"utf8"))}catch(e){this.debug(e);let t=e;t.code!=="ENOENT"&&process.emitWarning(t)}}async savePJSON(e){await vt(Ee(this.pjsonPath),{recursive:!0}),await jt(this.pjsonPath,JSON.stringify({name:this.config.name,...e},null,2))}},Ft=i=>{let e=(i??[]).map(t=>typeof t=="string"?{name:t,tag:"latest",type:"user"}:t);return Je(e)};var W=class i extends ge.Command{static description="List installed plugins.";static enableJsonFlag=!0;static examples=["<%= config.bin %> <%= command.id %>"];static flags={core:ge.Flags.boolean({description:"Show core plugins."})};plugins;async run(){let{flags:e}=await this.parse(i);this.plugins=new h({config:this.config});let t=this.config.getPluginsList();A(t,o=>this.plugins.friendlyName(o.name)),e.core||(t=t.filter(o=>o.type!=="core"&&o.type!=="dev")),t.length===0&&this.log("No plugins installed.");let n=this.config.getPluginsList(),s=new Set(n.filter(o=>o.type==="user"||o.type==="link").map(o=>o.name)),r=this.config.pjson.oclif.jitPlugins??{},c=Object.entries(r).map(([o,l])=>({name:o,type:"jit",version:l})).filter(o=>!s.has(o.name));return A(c,o=>o.name),this.jsonEnabled()||(this.display(t),this.displayJitPlugins(c)),[...n.filter(o=>!o.parent).map(o=>{let{config:l,...f}=o;return f}),...c]}createTree(e){let t={};for(let n of e.children??[])t[this.formatPlugin(n)]=this.createTree(n);return t}display(e){let t=e.find(n=>n.root===this.config.root);for(let n of e.filter(s=>!s.parent))if(n.name!==t?.name&&(this.log(this.formatPlugin(n)),n.children&&n.children.length>0)){let s=this.createTree(n);this.log(Q(s))}}displayJitPlugins(e){if(e.length!==0){this.log(k(` Uninstalled JIT Plugins:`));for(let{name:t,version:n}of e)this.log(`${this.plugins.friendlyName(t)} ${k(n)}`)}}formatPlugin(e){let t=`${this.plugins.friendlyName(e.name)} ${k(e.version)}`;return e.type!=="user"&&(t+=k(` (${e.type})`)),e.type==="link"?t+=` ${e.root}`:e.tag&&e.tag!=="latest"&&(t+=k(` (${String(e.tag)})`)),t}};g();var J=b(F(),1);import{readFile as Ae}from"node:fs/promises";import{dirname as Nt,join as fe,sep as Ue}from"node:path";g();var Lt=["silent","error","warn","notice","http","info","verbose","silly"];function O(i,e,t){if(e.verbose)return"verbose";if(e.silent)return"silent";let n=i.scopedEnvVar("NPM_LOG_LEVEL");return Lt.includes(n)?n:t}function It(i,e){let t=i.split(Ue),n=t.reduce((r,c,o)=>c===e?[...r,o]:r,[]),s=Math.max(...n);return s===-1?i:t.slice(0,s+1).join(Ue)}var q=class i extends J.Command{static args={plugin:J.Args.string({default:".",description:"Plugin to inspect.",required:!0})};static description="Displays installation properties of a plugin.";static enableJsonFlag=!0;static examples=['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> '];static flags={help:J.Flags.help({char:"h"}),verbose:J.Flags.boolean({char:"v"})};static strict=!1;static usage="plugins:inspect PLUGIN...";plugins;async findDep(e,t){let n=fe(...t.split("/")),s=fe(e.root,"node_modules"),r=[s];for(;(s.match(/node_modules/g)??[]).length>1;)s=It(Nt(s),"node_modules"),r.push(s);for(let c of r)try{let o=fe(c,n),l=fe(o,"package.json"),f=JSON.parse(await Ae(l,"utf8"));return{pkgPath:o,version:f.version}}catch{}return{pkgPath:null,version:null}}findPlugin(e){let t=this.config.getPluginsList().find(n=>n.name===e);if(t)return t;throw this.config.pjson.oclif.jitPlugins?.[e]&&this.warn(`Plugin ${e} is a JIT plugin. It will be installed the first time you run one of it's commands.`),new Error(`${e} not installed`)}async inspect(e,t=!1){let n=this.findPlugin(e),s={},r={};for(let o of A(Object.keys({...n.pjson.dependencies}),l=>l)){let{pkgPath:l,version:f}=await this.findDep(n,o);if(!f)continue;let a=n.pjson.dependencies?.[o],u=k(a?`${a} => ${f}`:f),d=t?`${o} ${u} ${l}`:`${o} ${u}`;s[d]=null,r[o]={from:a,version:f}}let c={[E.cyan(n.name)]:{[`version ${n.version}`]:null,...n.tag?{[`tag ${n.tag}`]:null}:{},...n.pjson.homepage?{[`homepage ${n.pjson.homepage}`]:null}:{},[`location ${n.root}`]:null,commands:Object.fromEntries(A(n.commandIDs,o=>o).map(o=>[o,null])),dependencies:s}};return this.log(Q(c)),{...n,deps:r}}async run(){let{argv:e,flags:t}=await this.parse(i);this.plugins=new h({config:this.config,logLevel:O(this.config,t,"silent")});let n=this.config.pjson.oclif.aliases??{},s=[];for(let r of e){r==="."&&(r=JSON.parse(await Ae("package.json","utf8")).name),n[r]===null&&this.error(`${r} is blocked`),r=n[r]??r;let c=await this.plugins.maybeUnfriendlyName(r)??r;try{s.push(await this.inspect(c,t.verbose))}catch(o){throw this.log(E.red("failed")),o}}return s}};g();var y=b(F(),1);var Re=b(Me(),1);var V=class i extends y.Command{static aliases=["plugins:add"];static args={plugin:y.Args.string({description:"Plugin to install.",required:!0})};static description=`Uses npm to install plugins. Installation of a user-installed plugin will override a core plugin. Use the <%= config.scopedEnvVarKey('NPM_LOG_LEVEL') %> environment variable to set the npm loglevel. Use the <%= config.scopedEnvVarKey('NPM_REGISTRY') %> environment variable to set the npm registry.`;static enableJsonFlag=!0;static examples=[{command:'<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> ',description:"Install a plugin from npm registry."},{command:"<%= config.bin %> <%= command.id %> https://github.com/someuser/someplugin",description:"Install a plugin from a github url."},{command:"<%= config.bin %> <%= command.id %> someuser/someplugin",description:"Install a plugin from a github slug."}];static flags={force:y.Flags.boolean({char:"f",description:"Force npm to fetch remote resources even if a local copy exists on disk."}),help:y.Flags.help({char:"h"}),jit:y.Flags.boolean({hidden:!0,async parse(e,t){if(e===!1||e===void 0)return e;let n=t.argv.filter(l=>!l.startsWith("-"));if(n.length===0)return e;let s=t.config.pjson.oclif.jitPlugins??{};if(Object.keys(s).length===0)return e;let r=new h({config:t.config}),o=(await Promise.all(n.map(async l=>{let f=await r.maybeUnfriendlyName(l);return{jit:!!s[f],name:f}}))).filter(l=>!l.jit).map(l=>l.name);if(o.length>0)throw new y.Errors.CLIError(`The following plugins are not JIT plugins: ${o.join(", ")}`);return e}}),silent:y.Flags.boolean({char:"s",description:"Silences npm output.",exclusive:["verbose"]}),verbose:y.Flags.boolean({char:"v",description:"Show verbose npm output.",exclusive:["silent"]})};static strict=!1;static summary="Installs a plugin into <%= config.bin %>.";flags;async parsePlugin(e,t){if(t.startsWith("git+ssh://")||t.endsWith(".git"))return{type:"repo",url:t};let n=async c=>{let o=/(?<!^)@/,[l,f="latest"]=c.split(o),a=l.startsWith("@")?l:await e.maybeUnfriendlyName(l);if(Ot(a),this.flags.jit){let u=this.config.pjson.oclif?.jitPlugins?.[a];return u?(o.test(c)&&this.warn(`--jit flag is present along side a tag. Ignoring tag ${f} and using the version specified in package.json (${u}).`),{name:a,tag:u}):(this.warn(`--jit flag is present but ${a} is not a JIT plugin. Installing ${f} instead.`),{name:a,tag:f})}return{name:a,tag:f}};if(t.startsWith("@")&&t.includes("/")){let{name:c,tag:o}=await n(t);return{name:c,tag:o,type:"npm"}}if(t.includes("/"))return t.includes(":")?{type:"repo",url:t}:{type:"repo",url:`https://github.com/${t}`};let{name:s,tag:r}=await n(t);return{name:s,tag:r,type:"npm"}}async run(){let{argv:e,flags:t}=await this.parse(i);this.flags=t;let n=new h({config:this.config,logLevel:O(this.config,this.flags,"notice")}),s=this.config.pjson.oclif.aliases||{},r=e.length;for(let c of e){if(s[c]===null&&this.error(`${c} is blocked`),c=s[c]||c,c===this.config.name){let a=this.config.binPath&&this.config.plugins.get("@oclif/plugin-update")?` Use "${this.config.bin} update" to update ${this.config.name}.`:"",u=`Ignoring top-level CLI plugin ${this.config.name}.${a}`;r===1?this.error(u):this.warn(u);continue}let o=await this.parsePlugin(n,c),l;await this.config.runHook("plugins:preinstall",{plugin:o});try{o.type==="npm"?(y.ux.action.start(`${this.config.name}: Installing plugin ${R(n.friendlyName(o.name)+"@"+o.tag)}`),l=await n.install(o.name,{force:t.force,tag:o.tag})):(y.ux.action.start(`${this.config.name}: Installing plugin ${R(o.url)}`),l=await n.install(o.url,{force:t.force}))}catch(a){throw y.ux.action.stop(E.red("failed")),a}let f=new y.Plugin(l);await f.load(),this.config.plugins.set(f.name,f),await this.config.runHook("plugins:postinstall",{}),y.ux.action.stop(`installed v${l.version}`)}}};function Ot(i){if(!(0,Re.default)(i).validForNewPackages)throw new y.Errors.CLIError("Invalid npm package name.")}g();var L=b(F(),1);var G=class i extends L.Command{static args={path:L.Args.string({default:".",description:"path to plugin",name:"path",required:!0})};static description=`Installation of a linked plugin will override a user-installed or core plugin. e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello' command will override the user-installed or core plugin implementation. This is useful for development work. `;static examples=['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %> '];static flags={help:L.Flags.help({char:"h"}),install:L.Flags.boolean({allowNo:!0,default:!0,description:"Install dependencies after linking the plugin."}),verbose:L.Flags.boolean({char:"v"})};static summary="Links a plugin into the CLI for development.";async run(){let{args:e,flags:t}=await this.parse(i),n=new h({config:this.config,logLevel:O(this.config,t,"silent")});L.ux.action.start(`${this.config.name}: Linking plugin ${R(e.path)}`),await n.link(e.path,{install:t.install}),L.ux.action.stop()}};g();var z=b(F(),1);import{rm as Et}from"node:fs/promises";import{join as pe}from"node:path";var H=class i extends z.Command{static flags={hard:z.Flags.boolean({summary:"Delete node_modules and package manager related files in addition to uninstalling plugins."}),reinstall:z.Flags.boolean({summary:"Reinstall all plugins after uninstalling."})};static summary="Remove all user-installed and linked plugins.";async run(){let{flags:e}=await this.parse(i),t=new h({config:this.config}),n=await t.list();this.log(`Found ${n.length} plugin${n.length===0?"":"s"}:`);for(let s of n)this.log(`- ${s.name} ${k(this.config.plugins.get(s.name)?.version??"")} ${k(`(${s.type})`)}`);if(e.hard){let s=[pe(this.config.dataDir,"node_modules"),pe(this.config.dataDir,"package.json"),pe(this.config.dataDir,"yarn.lock"),pe(this.config.dataDir,"package-lock.json")];this.log("\u2705 Removed the following files:");for(let r of s)this.log(`- ${r}`);await Promise.all(s.map(r=>Et(r,{force:!0,recursive:!0})));for(let r of n)this.log(`\u2705 ${r.type==="link"?"Unlinked":"Uninstalled"} ${r.name}`)}else for(let s of n)try{await t.uninstall(s.name),this.log(`\u2705 ${s.type==="link"?"Unlinked":"Uninstalled"} ${s.name}`)}catch{this.warn(`Failed to uninstall ${s.name}`)}if(e.reinstall){this.log("Reinstall flag passed:");for(let s of n){if(s.type==="link")try{let r=await t.link(s.root,{install:!1}),c=k(`-> ${r.version}`);this.log(`\u2705 Relinked ${s.name} ${c}`)}catch{this.warn(`Failed to relink ${s.name}`)}if(s.type==="user")try{let r=s.url?await t.install(s.url):await t.install(s.name,{tag:s.tag}),c=k(`-> ${r.version}`),o=s.tag?`@${s.tag}`:s.url?` (${s.url})`:"";this.log(`\u2705 Reinstalled ${s.name}${o} ${c}`)}catch{this.warn(`Failed to reinstall ${s.name}`)}}}}};g();var N=b(F(),1);function Te(i){if(i.includes("@")){let e=i.split("@");return!e.at(-1)?.includes("/")&&e.length>1&&e.pop(),e.join("@")}return i}var M=class i extends N.Command{static aliases=["plugins:unlink","plugins:remove"];static args={plugin:N.Args.string({description:"plugin to uninstall"})};static description="Removes a plugin from the CLI.";static examples=['<%= config.bin %> <%= command.id %> <%- config.pjson.oclif.examplePlugin || "myplugin" %>'];static flags={help:N.Flags.help({char:"h"}),verbose:N.Flags.boolean({char:"v"})};static strict=!1;async run(){let{argv:e,flags:t}=await this.parse(i),n=new h({config:this.config,logLevel:O(this.config,t,"silent")}),s=[];e.length===0&&e.push(".");for(let r of e){let c=Te(n.friendlyName(r)),o=await n.hasPlugin(Te(r));if(!o){let l=this.config.getPluginsList().find(f=>f.name===r);return l?.parent?this.error(`${c} is installed via plugin ${l.parent.name}, uninstall ${l.parent.name} instead`):this.error(`${c} is not installed`)}try{let{name:l}=o,f=c==="."?l:c??l;N.ux.action.start(`${this.config.name}: Uninstalling ${f}`),await n.uninstall(l),s.push(l)}catch(l){throw N.ux.action.stop(E.red("failed")),l}N.ux.action.stop()}for(let r of s)this.config.plugins.delete(r);await this.config.runHook("plugins:postuninstall",{})}};g();var S=b(F(),1);var Y=class i extends S.Command{static description="Update installed plugins.";static flags={help:S.Flags.help({char:"h"}),verbose:S.Flags.boolean({char:"v"})};async run(){let{flags:e}=await this.parse(i),t=new h({config:this.config,logLevel:O(this.config,e,"silent")});S.ux.action.start(`${this.config.name}: Updating plugins`),await t.update(),S.ux.action.stop()}};g();var _e=async function(){let i=new h({config:this.config});try{await i.update()}catch(e){e instanceof Error&&this.error(e.message)}};var ps={plugins:W,"plugins:inspect":q,"plugins:install":V,"plugins:link":G,"plugins:reset":H,"plugins:uninstall":M,"plugins:update":Y},ds={update:_e};export{ps as a,ds as b};