@junobuild/cli-tools 0.12.3 → 0.12.4-next-2026-03-20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +2 -2
- package/package.json +9 -9
package/dist/node/index.mjs
CHANGED
|
@@ -32,7 +32,7 @@ const require = topLevelCreateRequire(resolve(process.cwd(), '.juno-pseudo-requi
|
|
|
32
32
|
`),console.log("\u{1F194} ",Number(a)),console.log("\u23F3 ",Object.keys(m)[0]??m),cl(d)&&(p.stop(),console.log("\u274C Hash undefined. This is unexpected."),process.exit(1)),console.log("\u{1F512} ",pl(d)),{sha256:d}}catch(l){throw p.stop(),l}},{sha256:r}=await o();return n?(await(async()=>{console.log("");let p=zt("Committing proposal...").start();try{await ul({proposal:{proposal_id:a,sha256:r},cdn:e}),p.stop(),console.log(`\u{1F3AF} Change #${a} applied.`)}catch(l){throw p.stop(),l}})(),{proposalId:a}):{proposalId:a}};var Ca=i=>{let e=i>=1e3?"megabyte":"kilobyte";return new Intl.NumberFormat("en",{style:"unit",unit:e}).format(i/(e==="megabyte"?1e6:1e3))};var Ta=Be(Aa(),1);var ka=Ta.default;var _r=Be(Ba(),1);import{inspect as Of,styleText as Bf}from"node:util";import{format as Pf}from"util";import{EOL as se}from"os";import{StringDecoder as Rf}from"string_decoder";import{Writable as _f}from"stream";import{randomUUID as If}from"crypto";var Sr="\x1B[",Ar={CURSOR_HIDE:Sr+"?25l",CURSOR_SHOW:Sr+"?25h"},An=(function(i){return i.FORCE_UNICODE="LISTR_FORCE_UNICODE",i.FORCE_TTY="LISTR_FORCE_TTY",i.DISABLE_COLOR="NO_COLOR",i.FORCE_COLOR="FORCE_COLOR",i})({}),xi=(function(i){return i.WILL_RETRY="WILL_RETRY",i.WILL_ROLLBACK="WILL_ROLLBACK",i.HAS_FAILED_TO_ROLLBACK="HAS_FAILED_TO_ROLLBACK",i.HAS_FAILED="HAS_FAILED",i.HAS_FAILED_WITHOUT_ERROR="HAS_FAILED_WITHOUT_ERROR",i})({}),xe=(function(i){return i.SHOULD_REFRESH_RENDER="SHOUD_REFRESH_RENDER",i})({}),gi=(function(i){return i.PRIMARY="PRIMARY",i.SECONDARY="SECONDARY",i.SILENT="SILENT",i})({}),v=(function(i){return i.TITLE="TITLE",i.STATE="STATE",i.ENABLED="ENABLED",i.SUBTASK="SUBTASK",i.PROMPT="PROMPT",i.OUTPUT="OUTPUT",i.MESSAGE="MESSAGE",i.CLOSED="CLOSED",i})({}),E=(function(i){return i.WAITING="WAITING",i.STARTED="STARTED",i.COMPLETED="COMPLETED",i.FAILED="FAILED",i.SKIPPED="SKIPPED",i.ROLLING_BACK="ROLLING_BACK",i.ROLLED_BACK="ROLLED_BACK",i.RETRY="RETRY",i.PAUSED="PAUSED",i.PROMPT="PROMPT",i.PROMPT_COMPLETED="PROMPT_COMPLETED",i.PROMPT_FAILED="PROMPT_FAILED",i})({}),Ir=class{emitter=new ka;emit(i,e){this.emitter.emit(i,e)}on(i,e){this.emitter.addListener(i,e)}once(i,e){this.emitter.once(i,e)}off(i,e){this.emitter.off(i,e)}complete(){this.emitter.removeAllListeners()}};function jf(i){return!!i&&typeof i=="object"&&typeof i.subscribe=="function"}function Lf(i){return!!i&&typeof i=="object"&&i.readable===!0&&typeof i.read=="function"&&typeof i.on=="function"}function jr(){return!!process.env[An.FORCE_UNICODE]||process.platform!=="win32"||!!process.env.CI||!!process.env.WT_SESSION||process.env.TERM_PROGRAM==="vscode"||process.env.TERM==="xterm-256color"||process.env.TERM==="alacritty"}var Nf="(?:\\u001b|\\u009b)\\[[\\=><~/#&.:=?%@~_-]*[0-9]*[\\a-ln-tqyz=><~/#&.:=?%@~_-]+",Uf=/\u0007/;function bi(i){return String(i).replace(new RegExp(Nf,"gmi"),"").replace(new RegExp(Uf,"gmi"),"").trim()}var T=Object.fromEntries(Object.keys(Of.colors).map(i=>[i,e=>Bf(i,String(e))]));function Tr(i,e){return i.replace(/^(?!\s*$)/gm," ".repeat(e))}var Lr={warning:"\u26A0",cross:"\u2716",arrowDown:"\u2193",tick:"\u2714",arrowRight:"\u2192",pointer:"\u276F",checkboxOn:"\u2612",arrowLeft:"\u2190",squareSmallFilled:"\u25FC",pointerSmall:"\u203A"},Mf={...Lr,warning:"\u203C",cross:"\xD7",tick:"\u221A",pointer:">",checkboxOn:"[\xD7]",squareSmallFilled:"\u25A0"},I=jr()?Lr:Mf;function Di(i,...e){return Pf(String(i),...e)}var D=(function(i){return i.STARTED="STARTED",i.COMPLETED="COMPLETED",i.FAILED="FAILED",i.SKIPPED="SKIPPED",i.OUTPUT="OUTPUT",i.TITLE="TITLE",i.ROLLBACK="ROLLBACK",i.RETRY="RETRY",i.PROMPT="PROMPT",i.PAUSED="PAUSED",i})({}),rt={icon:{[D.STARTED]:I.pointer,[D.FAILED]:I.cross,[D.SKIPPED]:I.arrowDown,[D.COMPLETED]:I.tick,[D.OUTPUT]:I.pointerSmall,[D.TITLE]:I.arrowRight,[D.RETRY]:I.warning,[D.ROLLBACK]:I.arrowLeft,[D.PAUSED]:I.squareSmallFilled},color:{[D.STARTED]:T.yellow,[D.FAILED]:T.red,[D.SKIPPED]:T.yellow,[D.COMPLETED]:T.green,[D.RETRY]:T.yellowBright,[D.ROLLBACK]:T.redBright,[D.PAUSED]:T.yellowBright}},Nr=[D.RETRY,D.ROLLBACK,D.FAILED],ct=class{process;constructor(i){this.options=i,this.options={useIcons:!0,toStderr:[],...i??{}},this.options.fields??={},this.options.fields.prefix??=[],this.options.fields.suffix??=[],this.process=this.options.processOutput??new zf}log(i,e,t){let n=this.format(i,e,t);if(this.options.toStderr.includes(i)){this.process.toStderr(n);return}this.process.toStdout(n)}toStdout(i,e,t=!0){this.process.toStdout(this.format(null,i,e),t)}toStderr(i,e,t=!0){this.process.toStderr(this.format(null,i,e),t)}wrap(i,e){return i&&this.applyFormat(`[${i}]`,e)}splat(...i){let e=i.shift()??"";return i.length===0?e:Di(e,i)}suffix(i,...e){return e.filter(Boolean).forEach(t=>{if(i+=this.spacing(i),typeof t=="string")i+=this.wrap(t);else if(typeof t=="object"){if(t.args??=[],typeof t.condition=="function"?!t.condition(...t.args):!(t.condition??!0))return i;i+=this.wrap(typeof t.field=="function"?t.field(...t.args):t.field,{format:t?.format(...t.args)})}}),i}prefix(i,...e){return e.filter(Boolean).forEach(t=>{if(i=this.spacing(i)+i,typeof t=="string")i=this.wrap(t)+i;else if(typeof t=="object"){if(t.args??=[],typeof t.condition=="function"?!t.condition(...t.args):!(t.condition??!0))return i;i=this.wrap(typeof t.field=="function"?t.field(...t.args):t.field,{format:t?.format()})+i}}),i}fields(i,e){return this.options?.fields?.prefix&&(i=this.prefix(i,...this.options.fields.prefix)),e?.prefix&&(i=this.prefix(i,...e.prefix)),e?.suffix&&(i=this.suffix(i,...e.suffix)),this.options?.fields?.suffix&&(i=this.suffix(i,...this.options.fields.suffix)),i}icon(i,e){if(!i)return null;if(!e){let n=this.options.icon?.[i];e=typeof n=="function"?n():n}let t=this.options.color?.[i];return e&&t&&(e=t(e)),e}format(i,e,t){return Array.isArray(e)||(e=[e]),e=this.splat(e.shift(),...e).toString().split(se).filter(n=>!n||n.trim()!=="").map(n=>this.style(i,this.fields(n,{prefix:Array.isArray(t?.prefix)?t.prefix:[t?.prefix],suffix:Array.isArray(t?.suffix)?t.suffix:[t?.suffix]}))).join(se),e}style(i,e){if(!i||!e)return e;let t=this.icon(i,!this.options.useIcons&&this.wrap(i));return t&&(e=t+" "+e),e}applyFormat(i,e){return e?.format?e.format(i):i}spacing(i){return typeof i>"u"||i.trim()===""?"":" "}},Tn=class{buffer=[];decoder=new Rf;constructor(i){this.options=i}get all(){return this.buffer}get last(){return this.buffer.at(-1)}get length(){return this.buffer.length}write(i,...e){let t=e[e.length-1];return this.buffer.push({time:Date.now(),stream:this.options?.stream,entry:this.decoder.write(typeof i=="string"?Buffer.from(i,typeof e[0]=="string"?e[0]:void 0):Buffer.from(i))}),this.options?.limit&&(this.buffer=this.buffer.slice(-this.options.limit)),typeof t=="function"&&t(),!0}reset(){this.buffer=[]}},kr=class{method;buffer;constructor(i){this.stream=i,this.method=i.write,this.buffer=new Tn({stream:i})}get out(){let i=this;return new Proxy(this.stream,{get(e,t,n){return t==="write"?i.write.bind(i):Reflect.get(e,t,n)}})}hijack(){this.stream.write=this.buffer.write.bind(this.buffer)}release(){this.stream.write=this.method;let i=[...this.buffer.all];return this.buffer.reset(),i}write(...i){return this.method.apply(this.stream,i)}},zf=class{stream;active;constructor(i,e,t){this.options=t,this.stream={stdout:new kr(i??process.stdout),stderr:new kr(e??process.stderr)},this.options={dump:["stdout","stderr"],leaveEmptyLine:!0,...t}}get stdout(){return this.stream.stdout.out}get stderr(){return this.stream.stderr.out}hijack(){if(this.active)throw new Error("ProcessOutput has been already hijacked!");this.stream.stdout.write(Ar.CURSOR_HIDE),Object.values(this.stream).forEach(i=>i.hijack()),this.active=!0}release(){let i=Object.entries(this.stream).map(([e,t])=>({name:e,buffer:t.release()})).filter(e=>this.options.dump.includes(e.name)).flatMap(e=>e.buffer).sort((e,t)=>e.time-t.time).map(e=>({...e,entry:bi(e.entry)})).filter(e=>e.entry);i.length>0&&(this.options.leaveEmptyLine&&this.stdout.write(se),i.forEach(e=>{(e.stream??this.stdout).write(e.entry+se)})),this.stream.stdout.write(Ar.CURSOR_SHOW),this.active=!1}toStdout(i,e=!0){return e&&(i=i+se),this.stream.stdout.write(i)}toStderr(i,e=!0){return e&&(i=i+se),this.stream.stderr.write(i)}};function $f(i){let e=new _f;return e.rows=1/0,e.columns=1/0,e.write=t=>(i(t.toString()),!0),e}var Wf=class{spinner=jr()?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"];id;spinnerPosition=0;spin(){this.spinnerPosition=++this.spinnerPosition%this.spinner.length}fetch(){return this.spinner[this.spinnerPosition]}isRunning(){return!!this.id}start(i,e=100){this.id=setInterval(()=>{this.spin(),i&&i()},e)}stop(){clearInterval(this.id),this.id=void 0}},b=(function(i){return i.SKIPPED_WITH_COLLAPSE="SKIPPED_WITH_COLLAPSE",i.SKIPPED_WITHOUT_COLLAPSE="SKIPPED_WITHOUT_COLLAPSE",i.OUTPUT="OUTPUT",i.OUTPUT_WITH_BOTTOMBAR="OUTPUT_WITH_BOTTOMBAR",i.PENDING="PENDING",i.COMPLETED="COMPLETED",i.COMPLETED_WITH_FAILED_SUBTASKS="COMPLETED_WITH_FAILED_SUBTASKS",i.COMPLETED_WITH_FAILED_SISTER_TASKS="COMPLETED_WITH_SISTER_TASKS_FAILED",i.RETRY="RETRY",i.ROLLING_BACK="ROLLING_BACK",i.ROLLED_BACK="ROLLED_BACK",i.FAILED="FAILED",i.FAILED_WITH_FAILED_SUBTASKS="FAILED_WITH_SUBTASKS",i.WAITING="WAITING",i.PAUSED="PAUSED",i})({}),Or={icon:{[b.SKIPPED_WITH_COLLAPSE]:I.arrowDown,[b.SKIPPED_WITHOUT_COLLAPSE]:I.warning,[b.OUTPUT]:I.pointerSmall,[b.OUTPUT_WITH_BOTTOMBAR]:I.pointerSmall,[b.PENDING]:I.pointer,[b.COMPLETED]:I.tick,[b.COMPLETED_WITH_FAILED_SUBTASKS]:I.warning,[b.COMPLETED_WITH_FAILED_SISTER_TASKS]:I.squareSmallFilled,[b.RETRY]:I.warning,[b.ROLLING_BACK]:I.warning,[b.ROLLED_BACK]:I.arrowLeft,[b.FAILED]:I.cross,[b.FAILED_WITH_FAILED_SUBTASKS]:I.pointer,[b.WAITING]:I.squareSmallFilled,[b.PAUSED]:I.squareSmallFilled},color:{[b.SKIPPED_WITH_COLLAPSE]:T.yellow,[b.SKIPPED_WITHOUT_COLLAPSE]:T.yellow,[b.PENDING]:T.yellow,[b.COMPLETED]:T.green,[b.COMPLETED_WITH_FAILED_SUBTASKS]:T.yellow,[b.COMPLETED_WITH_FAILED_SISTER_TASKS]:T.red,[b.RETRY]:T.yellowBright,[b.ROLLING_BACK]:T.redBright,[b.ROLLED_BACK]:T.redBright,[b.FAILED]:T.red,[b.FAILED_WITH_FAILED_SUBTASKS]:T.red,[b.WAITING]:T.dim,[b.PAUSED]:T.yellowBright}};function Gf(i){let e=Math.floor(i/1e3),t=Math.floor(e/60),n;return e===0&&t===0&&(n=`0.${Math.floor(i/100)}s`),e>0&&(n=`${e%60}s`),t>0&&(n=`${t}m${n}`),n}var Pn={condition:!0,field:Gf,format:()=>T.dim};var qf=class kn{static nonTTY=!1;static rendererOptions={indentation:2,clearOutput:!1,showSubtasks:!0,collapseSubtasks:!0,collapseSkips:!0,showSkipMessage:!0,suffixSkips:!1,collapseErrors:!0,showErrorMessage:!0,suffixRetries:!0,lazy:!1,removeEmptyLines:!0,formatOutput:"wrap",pausedTimer:{...Pn,format:()=>T.yellowBright}};static rendererTaskOptions={outputBar:!0};prompt;activePrompt;spinner;logger;updater;truncate;wrap;buffer={output:new Map,bottom:new Map};cache={render:new Map,rendererOptions:new Map,rendererTaskOptions:new Map};constructor(e,t,n){this.tasks=e,this.options=t,this.events=n,this.options={...kn.rendererOptions,...this.options,icon:{...Or.icon,...t?.icon??{}},color:{...Or.color,...t?.color??{}}},this.spinner=this.options.spinner??new Wf,this.logger=this.options.logger??new ct({useIcons:!0,toStderr:[]}),this.logger.options.icon=this.options.icon,this.logger.options.color=this.options.color}async render(){let{createLogUpdate:e}=await Promise.resolve().then(()=>(wo(),yo)),{default:t}=await Promise.resolve().then(()=>(Xo(),Zo)),{default:n}=await Promise.resolve().then(()=>(Cr(),wr));this.updater=e(this.logger.process.stdout),this.truncate=t,this.wrap=n,this.logger.process.hijack(),this.options?.lazy||this.spinner.start(()=>{this.update()}),this.events.on(xe.SHOULD_REFRESH_RENDER,()=>{this.update()})}update(){this.updater(this.create())}end(){this.spinner.stop(),this.updater.clear(),this.updater.done(),this.options.clearOutput||this.logger.process.toStdout(this.create({prompt:!1})),this.logger.process.release()}create(e){e={tasks:!0,bottomBar:!0,prompt:!0,...e};let t=[],n=this.renderer(this.tasks),s=this.renderBottomBar(),a=this.renderPrompt();return e.tasks&&n.length>0&&t.push(...n),e.bottomBar&&s.length>0&&(t.length>0&&t.push(""),t.push(...s)),e.prompt&&a.length>0&&(t.length>0&&t.push(""),t.push(...a)),t.join(se)}style(e,t=!1){let n=this.cache.rendererOptions.get(e.id);if(e.isSkipped()){if(t||n.collapseSkips)return this.logger.icon(b.SKIPPED_WITH_COLLAPSE);if(n.collapseSkips===!1)return this.logger.icon(b.SKIPPED_WITHOUT_COLLAPSE)}if(t)return this.shouldOutputToBottomBar(e)?this.logger.icon(b.OUTPUT_WITH_BOTTOMBAR):this.logger.icon(b.OUTPUT);if(e.hasSubtasks()){if(e.isStarted()||e.isPrompt()&&n.showSubtasks!==!1&&!e.subtasks.every(s=>!s.hasTitle()))return this.logger.icon(b.PENDING);if(e.isCompleted()&&e.subtasks.some(s=>s.hasFailed()))return this.logger.icon(b.COMPLETED_WITH_FAILED_SUBTASKS);if(e.hasFailed())return this.logger.icon(b.FAILED_WITH_FAILED_SUBTASKS)}return e.isStarted()||e.isPrompt()?this.logger.icon(b.PENDING,!this.options?.lazy&&this.spinner.fetch()):e.isCompleted()?this.logger.icon(b.COMPLETED):e.isRetrying()?this.logger.icon(b.RETRY,!this.options?.lazy&&this.spinner.fetch()):e.isRollingBack()?this.logger.icon(b.ROLLING_BACK,!this.options?.lazy&&this.spinner.fetch()):e.hasRolledBack()?this.logger.icon(b.ROLLED_BACK):e.hasFailed()?this.logger.icon(b.FAILED):e.isPaused()?this.logger.icon(b.PAUSED):this.logger.icon(b.WAITING)}format(e,t,n){if(e.trim()==="")return[];t&&(e=t+" "+e);let s,a=(process.stdout.columns??80)-n*this.options.indentation-2;switch(this.options.formatOutput){case"truncate":s=e.split(se).map((o,r)=>this.truncate(this.indent(o,r),a));break;case"wrap":s=this.wrap(e,a,{hard:!0,trim:!1}).split(se).map((o,r)=>this.indent(o,r));break;default:throw new Pr("Format option for the renderer is wrong.")}return this.options.removeEmptyLines&&(s=s.filter(Boolean)),s.map(o=>Tr(o,n*this.options.indentation))}shouldOutputToOutputBar(e){let t=this.cache.rendererTaskOptions.get(e.id).outputBar;return typeof t=="number"&&t!==0||typeof t=="boolean"&&t!==!1}shouldOutputToBottomBar(e){let t=this.cache.rendererTaskOptions.get(e.id).bottomBar;return typeof t=="number"&&t!==0||typeof t=="boolean"&&t!==!1||!e.hasTitle()}renderer(e,t=0){return e.flatMap(n=>{if(!n.isEnabled())return[];if(this.cache.render.has(n.id))return this.cache.render.get(n.id);this.calculate(n),this.setupBuffer(n);let s=this.cache.rendererOptions.get(n.id),a=this.cache.rendererTaskOptions.get(n.id),o=[];if(n.isPrompt()){if(this.activePrompt&&this.activePrompt!==n.id)throw new Pr("Only one prompt can be active at the given time, please re-evaluate your task design.");this.activePrompt||(n.on(v.PROMPT,r=>{let c=bi(r);c&&(this.prompt=c)}),n.on(v.STATE,r=>{(r===E.PROMPT_COMPLETED||n.hasFinalized()||n.hasReset())&&(this.prompt=null,this.activePrompt=null,n.off(v.PROMPT))}),this.activePrompt=n.id)}if(n.hasTitle()&&(e.some(r=>r.hasFailed())&&!n.hasFailed()&&n.options.exitOnError!==!1&&!(n.isCompleted()||n.isSkipped())?o.push(...this.format(n.title,this.logger.icon(b.COMPLETED_WITH_FAILED_SISTER_TASKS),t)):n.hasFailed()&&s.collapseErrors?o.push(...this.format(!n.hasSubtasks()&&n.message.error&&s.showErrorMessage?n.message.error:n.title,this.style(n),t)):n.isSkipped()&&s.collapseSkips?o.push(...this.format(this.logger.suffix(n.message.skip&&s.showSkipMessage?n.message.skip:n.title,{field:D.SKIPPED,condition:s.suffixSkips,format:()=>T.dim}),this.style(n),t)):n.isRetrying()?o.push(...this.format(this.logger.suffix(n.title,{field:`${D.RETRY}:${n.message.retry.count}`,format:()=>T.yellow,condition:s.suffixRetries}),this.style(n),t)):n.isCompleted()&&n.hasTitle()&&Ge(a.timer?.condition,n.message.duration)?o.push(...this.format(this.logger.suffix(n?.title,{...a.timer,args:[n.message.duration]}),this.style(n),t)):n.isPaused()?o.push(...this.format(this.logger.suffix(n.title,{...s.pausedTimer,args:[n.message.paused-Date.now()]}),this.style(n),t)):o.push(...this.format(n.title,this.style(n),t))),(!n.hasSubtasks()||!s.showSubtasks)&&(n.hasFailed()&&s.collapseErrors===!1&&(s.showErrorMessage||!s.showSubtasks)?o.push(...this.dump(n,t,D.FAILED)):n.isSkipped()&&s.collapseSkips===!1&&(s.showSkipMessage||!s.showSubtasks)&&o.push(...this.dump(n,t,D.SKIPPED))),(n.isPending()||a.persistentOutput)&&o.push(...this.renderOutputBar(n,t)),s.showSubtasks!==!1&&n.hasSubtasks()&&(n.isPending()||n.hasFinalized()&&!n.hasTitle()||n.isCompleted()&&s.collapseSubtasks===!1&&!n.subtasks.some(r=>this.cache.rendererOptions.get(r.id)?.collapseSubtasks===!0)||n.subtasks.some(r=>this.cache.rendererOptions.get(r.id)?.collapseSubtasks===!1)||n.subtasks.some(r=>r.hasFailed())||n.subtasks.some(r=>r.hasRolledBack()))){let r=n.hasTitle()?t+1:t,c=this.renderer(n.subtasks,r);o.push(...c)}return n.hasFinalized()&&(a.persistentOutput||(this.buffer.bottom.delete(n.id),this.buffer.output.delete(n.id))),n.isClosed()&&(this.cache.render.set(n.id,o),this.reset(n)),o})}renderOutputBar(e,t){let n=this.buffer.output.get(e.id);return n?n.all.flatMap(s=>this.dump(e,t,D.OUTPUT,s.entry)):[]}renderBottomBar(){return this.buffer.bottom.size===0?[]:Array.from(this.buffer.bottom.values()).flatMap(e=>e.all).sort((e,t)=>e.time-t.time).map(e=>e.entry)}renderPrompt(){return this.prompt?[this.prompt]:[]}calculate(e){if(this.cache.rendererOptions.has(e.id)&&this.cache.rendererTaskOptions.has(e.id))return;let t={...this.options,...e.rendererOptions};this.cache.rendererOptions.set(e.id,t),this.cache.rendererTaskOptions.set(e.id,{...kn.rendererTaskOptions,timer:t.timer,...e.rendererTaskOptions})}setupBuffer(e){if(this.buffer.bottom.has(e.id)||this.buffer.output.has(e.id))return;let t=this.cache.rendererTaskOptions.get(e.id);this.shouldOutputToBottomBar(e)&&!this.buffer.bottom.has(e.id)?(this.buffer.bottom.set(e.id,new Tn({limit:typeof t.bottomBar=="number"?t.bottomBar:1})),e.on(v.OUTPUT,n=>{let s=this.dump(e,-1,D.OUTPUT,n);this.buffer.bottom.get(e.id).write(s.join(se))}),e.on(v.STATE,n=>{n===(E.RETRY||E.ROLLING_BACK)&&this.buffer.bottom.delete(e.id)})):this.shouldOutputToOutputBar(e)&&!this.buffer.output.has(e.id)&&(this.buffer.output.set(e.id,new Tn({limit:typeof t.outputBar=="number"?t.outputBar:1})),e.on(v.OUTPUT,n=>{this.buffer.output.get(e.id).write(n)}),e.on(v.STATE,n=>{n===(E.RETRY||E.ROLLING_BACK)&&this.buffer.output.delete(e.id)}))}reset(e){this.cache.rendererOptions.delete(e.id),this.cache.rendererTaskOptions.delete(e.id),this.buffer.output.delete(e.id)}dump(e,t,n=D.OUTPUT,s){if(!s)switch(n){case D.OUTPUT:s=e.output;break;case D.SKIPPED:s=e.message.skip;break;case D.FAILED:s=e.message.error;break}return e.hasTitle()&&n===D.FAILED&&s===e.title||typeof s!="string"?[]:(n===D.OUTPUT&&(s=bi(s)),this.format(s,this.style(e,!0),t+1))}indent(e,t){return t>0?Tr(e.trimEnd(),this.options.indentation):e.trimEnd()}},Hf=class{static nonTTY=!0;static rendererOptions;static rendererTaskOptions;constructor(i,e){this.tasks=i,this.options=e}render(){}end(){}},Kf=class On{static nonTTY=!0;static rendererOptions={pausedTimer:{...Pn,field:e=>`${D.PAUSED}:${e}`,format:()=>T.yellowBright}};static rendererTaskOptions={};logger;cache={rendererOptions:new Map,rendererTaskOptions:new Map};constructor(e,t){this.tasks=e,this.options=t,this.options={...On.rendererOptions,...t,icon:{...rt.icon,...t?.icon??{}},color:{...rt.color,...t?.color??{}}},this.logger=this.options.logger??new ct({useIcons:!0,toStderr:Nr}),this.logger.options.icon=this.options.icon,this.logger.options.color=this.options.color,this.options.timestamp&&this.logger.options.fields.prefix.unshift(this.options.timestamp)}end(){}render(){this.renderer(this.tasks)}renderer(e){e.forEach(t=>{this.calculate(t),t.once(v.CLOSED,()=>{this.reset(t)});let n=this.cache.rendererOptions.get(t.id),s=this.cache.rendererTaskOptions.get(t.id);t.on(v.SUBTASK,a=>{this.renderer(a)}),t.on(v.STATE,a=>{if(t.hasTitle())if(a===E.STARTED)this.logger.log(D.STARTED,t.title);else if(a===E.COMPLETED){let o=s?.timer;this.logger.log(D.COMPLETED,t.title,o&&{suffix:{...o,condition:!!t.message?.duration&&o.condition,args:[t.message.duration]}})}else a===E.PROMPT?(this.logger.process.hijack(),t.on(v.PROMPT,o=>{this.logger.process.toStderr(o,!1)})):a===E.PROMPT_COMPLETED&&(t.off(v.PROMPT),this.logger.process.release())}),t.on(v.OUTPUT,a=>{this.logger.log(D.OUTPUT,a)}),t.on(v.MESSAGE,a=>{if(a.error)this.logger.log(D.FAILED,t.title,{suffix:{field:`${D.FAILED}: ${a.error}`,format:()=>T.red}});else if(a.skip)this.logger.log(D.SKIPPED,t.title,{suffix:{field:`${D.SKIPPED}: ${a.skip}`,format:()=>T.yellow}});else if(a.rollback)this.logger.log(D.ROLLBACK,t.title,{suffix:{field:`${D.ROLLBACK}: ${a.rollback}`,format:()=>T.red}});else if(a.retry)this.logger.log(D.RETRY,t.title,{suffix:{field:`${D.RETRY}:${a.retry.count}`,format:()=>T.red}});else if(a.paused){let o=n?.pausedTimer;this.logger.log(D.PAUSED,t.title,o&&{suffix:{...o,condition:!!a?.paused&&o.condition,args:[a.paused-Date.now()]}})}})})}calculate(e){if(this.cache.rendererOptions.has(e.id)&&this.cache.rendererTaskOptions.has(e.id))return;let t={...this.options,...e.rendererOptions};this.cache.rendererOptions.set(e.id,t),this.cache.rendererTaskOptions.set(e.id,{...On.rendererTaskOptions,timer:t.timer,...e.rendererTaskOptions})}reset(e){this.cache.rendererOptions.delete(e.id),this.cache.rendererTaskOptions.delete(e.id)}},Yf=class{constructor(i){this.options=i}serialize(i,e,t){return JSON.stringify(this.generate(i,e,t))}generate(i,e,t){let n={event:i,data:e};if(typeof this.options?.task!="boolean"){let s=Object.fromEntries(this.options.task.map(a=>{let o=t[a];return typeof o=="function"?[a,o.call(t)]:[a,o]}));Object.keys(t).length>0&&(n.task=s)}return n}},Vf=class Ur{static nonTTY=!0;static rendererOptions={subtasks:!0,state:Object.values(E),output:!0,prompt:!0,title:!0,messages:["skip","error","retry","rollback","paused"],messagesToStderr:["error","rollback","retry"],task:["hasRolledBack","isRollingBack","isCompleted","isSkipped","hasFinalized","hasSubtasks","title","hasReset","hasTitle","isPrompt","isPaused","isPending","isSkipped","isStarted","hasFailed","isEnabled","isRetrying","path"]};static rendererTaskOptions;logger;serializer;constructor(e,t){this.tasks=e,this.options=t,this.options={...Ur.rendererOptions,...this.options},this.logger=this.options.logger??new ct({useIcons:!1}),this.serializer=new Yf(this.options)}render(){this.renderer(this.tasks)}end(){}renderer(e){e.forEach(t=>{this.options.subtasks&&t.on(v.SUBTASK,n=>{this.renderer(n)}),this.options.state&&t.on(v.STATE,n=>{this.logger.toStdout(this.serializer.serialize(v.STATE,n,t))}),this.options.output&&t.on(v.OUTPUT,n=>{this.logger.toStdout(this.serializer.serialize(v.OUTPUT,n,t))}),this.options.prompt&&t.on(v.PROMPT,n=>{this.logger.toStdout(this.serializer.serialize(v.PROMPT,n,t))}),this.options.title&&t.on(v.TITLE,n=>{this.logger.toStdout(this.serializer.serialize(v.TITLE,n,t))}),t.on(v.MESSAGE,n=>{let s=Object.fromEntries(Object.entries(n).map(([a,o])=>{if(this.options.messages.includes(a))return[a,o]}).filter(Boolean));if(Object.keys(s).length>0){let a=this.serializer.serialize(v.MESSAGE,s,t);this.options.messagesToStderr.some(o=>Object.keys(s).includes(o))?this.logger.toStderr(a):this.logger.toStdout(a)}})})}},Zf=class Bn{static nonTTY=!0;static rendererOptions={logTitleChange:!1,pausedTimer:{...Pn,format:()=>T.yellowBright}};static rendererTaskOptions;logger;cache={rendererOptions:new Map,rendererTaskOptions:new Map};constructor(e,t){this.tasks=e,this.options=t,this.options={...Bn.rendererOptions,...this.options,icon:{...rt.icon,...t?.icon??{}},color:{...rt.color,...t?.color??{}}},this.logger=this.options.logger??new ct({useIcons:!1,toStderr:Nr}),this.logger.options.icon=this.options.icon,this.logger.options.color=this.options.color,this.options.timestamp&&this.logger.options.fields.prefix.unshift(this.options.timestamp)}render(){this.renderer(this.tasks)}end(){}renderer(e){e.forEach(t=>{this.calculate(t),t.once(v.CLOSED,()=>{this.reset(t)});let n=this.cache.rendererOptions.get(t.id),s=this.cache.rendererTaskOptions.get(t.id);t.on(v.SUBTASK,a=>{this.renderer(a)}),t.on(v.STATE,a=>{if(t.hasTitle()){if(a===E.STARTED)this.logger.log(D.STARTED,t.title);else if(a===E.COMPLETED){let o=s.timer;this.logger.log(D.COMPLETED,t.title,o&&{suffix:{...o,condition:!!t.message?.duration&&o.condition,args:[t.message.duration]}})}}}),t.on(v.OUTPUT,a=>{this.logger.log(D.OUTPUT,a)}),t.on(v.PROMPT,a=>{let o=bi(a);o&&this.logger.log(D.PROMPT,o)}),this.options?.logTitleChange!==!1&&t.on(v.TITLE,a=>{this.logger.log(D.TITLE,a)}),t.on(v.MESSAGE,a=>{if(a?.error)this.logger.log(D.FAILED,a.error);else if(a?.skip)this.logger.log(D.SKIPPED,a.skip);else if(a?.rollback)this.logger.log(D.ROLLBACK,a.rollback);else if(a?.retry)this.logger.log(D.RETRY,t.title,{suffix:a.retry.count.toString()});else if(a?.paused){let o=n?.pausedTimer;this.logger.log(D.PAUSED,t.title,o&&{suffix:{...o,condition:!!a?.paused&&o.condition,args:[a.paused-Date.now()]}})}})})}calculate(e){if(this.cache.rendererOptions.has(e.id)&&this.cache.rendererTaskOptions.has(e.id))return;let t={...this.options,...e.rendererOptions};this.cache.rendererOptions.set(e.id,t),this.cache.rendererTaskOptions.set(e.id,{...Bn.rendererTaskOptions,timer:t.timer,...e.rendererTaskOptions})}reset(e){this.cache.rendererOptions.delete(e.id),this.cache.rendererTaskOptions.delete(e.id)}},Sn={default:qf,simple:Kf,verbose:Zf,test:Vf,silent:Hf};function Xf(i){return process.stdout.isTTY===!0||i.nonTTY===!0}function ot(i){return typeof i=="string"?Sn[i]??Sn.default:typeof i=="function"?i:Sn.default}function Jf(i){if(Ge(i?.silentRendererCondition))return{renderer:ot("silent"),selection:gi.SILENT};let e={renderer:ot(i.renderer),options:i.rendererOptions,selection:gi.PRIMARY};return!Xf(e.renderer)||Ge(i?.fallbackRendererCondition)?{renderer:ot(i.fallbackRenderer),options:i.fallbackRendererOptions,selection:gi.SECONDARY}:e}function Ge(i,...e){return typeof i=="function"?i(...e):i}var Qf=(0,_r.default)({circles:!0});function Br(i){return Qf(i)}var eh=class{concurrency;count;queue;constructor(i){this.concurrency=i.concurrency,this.count=0,this.queue=new Set}add(i){return this.count<this.concurrency?this.run(i):new Promise(e=>{let t=()=>e(this.run(i));this.queue.add(t)})}flush(){for(let i of this.queue){if(this.count>=this.concurrency)break;this.queue.delete(i),i()}}run(i){this.count++;let e=i(),t=()=>{this.count--,this.flush()};return e.then(t,()=>{this.queue.clear()}),e}};function ih(i){return new Promise(e=>{setTimeout(e,i)})}var th=class extends Error{path;ctx;constructor(i,e,t){super(i.message),this.error=i,this.type=e,this.task=t,this.name="ListrError",this.path=t.path,t?.options.collectErrors==="full"&&(this.task=Br(t),this.ctx=Br(t.listr.ctx)),this.stack=i?.stack}},Pr=class extends Error{},nh=class extends Error{},sh=class{constructor(i){this.task=i}get title(){return this.task.title}set title(i){i=Array.isArray(i)?i:[i],this.task.title$=Di(i.shift(),...i)}get output(){return this.task.output}set output(i){i=Array.isArray(i)?i:[i],this.task.output$=Di(i.shift(),...i)}set promptOutput(i){this.task.promptOutput$=i}newListr(i,e){let t;return typeof i=="function"?t=i(this):t=i,new ge(t,e,this.task)}report(i,e){this.task.options.collectErrors!==!1&&this.task.listr.errors.push(new th(i,e,this.task)),this.task.message$={error:i.message??this.task?.title}}skip(i,...e){this.task.state$=E.SKIPPED,i&&(this.task.message$={skip:i?Di(i,...e):this.task?.title})}isRetrying(){return this.task.isRetrying()?this.task.retry:{count:0}}prompt(i){return this.task.prompt?this.task.prompt:new i(this.task,this)}stdout(i){return $f(e=>{i===v.PROMPT?this.promptOutput=e:this.output=e})}run(i){return this.task.run(i,this)}},ah=class extends Ir{},oh=class extends ah{id=If();state=E.WAITING;subtasks;title;initialTitle;output;retry;message={};prompt;parent;enabled;taskFn;closed;constructor(i,e,t,n,s){if(super(),this.listr=i,this.task=e,this.options=t,this.rendererOptions=n,this.rendererTaskOptions=s,e.title){let a=Array.isArray(e?.title)?e.title:[e.title];this.title=Di(a.shift(),...a),this.initialTitle=this.title}this.taskFn=e.task,this.parent=i.parentTask}set state$(i){if(this.state=i,this.emit(v.STATE,i),this.hasSubtasks()&&this.hasFailed())for(let e of this.subtasks)e.state===E.STARTED&&(e.state$=E.FAILED);this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)}set output$(i){this.output=i,this.emit(v.OUTPUT,i),this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)}set promptOutput$(i){this.emit(v.PROMPT,i),bi(i)&&this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)}set message$(i){this.message={...this.message,...i},this.emit(v.MESSAGE,i),this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)}set title$(i){this.title=i,this.emit(v.TITLE,i),this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)}get path(){return[...this.listr.path,this.initialTitle]}async check(i){return this.state===E.WAITING&&(this.enabled=await Ge(this.task?.enabled??!0,i),this.emit(v.ENABLED,this.enabled),this.listr.events.emit(xe.SHOULD_REFRESH_RENDER)),this.enabled}hasSubtasks(){return this.subtasks?.length>0}hasFinalized(){return this.isCompleted()||this.hasFailed()||this.isSkipped()||this.hasRolledBack()}isPending(){return this.isStarted()||this.isPrompt()||this.hasReset()}isStarted(){return this.state===E.STARTED}isSkipped(){return this.state===E.SKIPPED}isCompleted(){return this.state===E.COMPLETED}hasFailed(){return this.state===E.FAILED}isRollingBack(){return this.state===E.ROLLING_BACK}hasRolledBack(){return this.state===E.ROLLED_BACK}isRetrying(){return this.state===E.RETRY}hasReset(){return this.state===E.RETRY||this.state===E.ROLLING_BACK}isEnabled(){return this.enabled}hasTitle(){return typeof this?.title=="string"}isPrompt(){return this.state===E.PROMPT}isPaused(){return this.state===E.PAUSED}isClosed(){return this.closed}async pause(i){let e=this.state;this.state$=E.PAUSED,this.message$={paused:Date.now()+i},await ih(i),this.state$=e,this.message$={paused:null}}async run(i,e){let t=a=>(a instanceof ge?(a.options={...this.options,...a.options},a.rendererClass=ot("silent"),this.subtasks=a.tasks,a.errors=this.listr.errors,this.emit(v.SUBTASK,this.subtasks),a=a.run(i)):a instanceof Promise?a=a.then(t):Lf(a)?a=new Promise((o,r)=>{a.on("data",c=>{this.output$=c.toString()}),a.on("error",c=>r(c)),a.on("end",()=>o(null))}):jf(a)&&(a=new Promise((o,r)=>{a.subscribe({next:c=>{this.output$=c},error:r,complete:o})})),a),n=Date.now();this.state$=E.STARTED;let s=await Ge(this.task?.skip??!1,i);if(s){typeof s=="string"?this.message$={skip:s}:this.hasTitle()?this.message$={skip:this.title}:this.message$={skip:"Skipped task without a title."},this.state$=E.SKIPPED;return}try{let a=typeof this.task?.retry=="number"&&this.task.retry>0?this.task.retry+1:typeof this.task?.retry=="object"&&this.task.retry.tries>0?this.task.retry.tries+1:1,o=typeof this.task.retry=="object"&&this.task.retry.delay;for(let r=1;r<=a;r++)try{await t(this.taskFn(i,e));break}catch(c){if(r!==a)this.retry={count:r,error:c},this.message$={retry:this.retry},this.title$=this.initialTitle,this.output=void 0,e.report(c,xi.WILL_RETRY),this.state$=E.RETRY,o&&await this.pause(o);else throw c}(this.isStarted()||this.isRetrying())&&(this.message$={duration:Date.now()-n},this.state$=E.COMPLETED)}catch(a){if(this.prompt instanceof nh&&(a=this.prompt),this.task?.rollback){e.report(a,xi.WILL_ROLLBACK);try{this.state$=E.ROLLING_BACK,await this.task.rollback(i,e),this.message$={rollback:this.title},this.state$=E.ROLLED_BACK}catch(o){throw this.state$=E.FAILED,e.report(o,xi.HAS_FAILED_TO_ROLLBACK),this.close(),o}if(this.listr.options?.exitAfterRollback!==!1)throw this.close(),a}else{if(this.state$=E.FAILED,this.listr.options.exitOnError!==!1&&await Ge(this.task?.exitOnError,i)!==!1)throw e.report(a,xi.HAS_FAILED),this.close(),a;this.hasSubtasks()||e.report(a,xi.HAS_FAILED_WITHOUT_ERROR)}}finally{this.close()}}close(){this.emit(v.CLOSED),this.listr.events.emit(xe.SHOULD_REFRESH_RENDER),this.complete()}},Rr=class extends Ir{},ge=class{tasks=[];errors=[];ctx;events;path=[];rendererClass;rendererClassOptions;rendererSelection;boundSignalHandler;concurrency;renderer;constructor(i,e,t){this.task=i,this.options=e,this.parentTask=t,this.options={concurrent:!1,renderer:"default",fallbackRenderer:"simple",exitOnError:!0,exitAfterRollback:!0,collectErrors:!1,registerSignalListeners:!0,...this.parentTask?.options??{},...e},this.options.concurrent===!0?this.options.concurrent=1/0:typeof this.options.concurrent!="number"&&(this.options.concurrent=1),this.concurrency=new eh({concurrency:this.options.concurrent}),t&&(this.path=[...t.listr.path,t.title],this.errors=t.listr.errors),this.parentTask?.listr.events instanceof Rr?this.events=this.parentTask.listr.events:this.events=new Rr,(this.options?.forceTTY||process.env[An.FORCE_TTY])&&(process.stdout.isTTY=!0,process.stderr.isTTY=!0),this.options?.forceUnicode&&(process.env[An.FORCE_UNICODE]="1");let n=Jf({renderer:this.options.renderer,rendererOptions:this.options.rendererOptions,fallbackRenderer:this.options.fallbackRenderer,fallbackRendererOptions:this.options.fallbackRendererOptions,fallbackRendererCondition:this.options?.fallbackRendererCondition,silentRendererCondition:this.options?.silentRendererCondition});this.rendererClass=n.renderer,this.rendererClassOptions=n.options,this.rendererSelection=n.selection,this.add(i??[]),this.options.registerSignalListeners&&(this.boundSignalHandler=this.signalHandler.bind(this),process.once("SIGINT",this.boundSignalHandler).setMaxListeners(0))}isRoot(){return!this.parentTask}isSubtask(){return!!this.parentTask}add(i){this.tasks.push(...this.generate(i))}async run(i){this.renderer||(this.renderer=new this.rendererClass(this.tasks,this.rendererClassOptions,this.events)),await this.renderer.render(),this.ctx=this.options?.ctx??i??{};try{await Promise.all(this.tasks.map(e=>e.check(this.ctx))),await Promise.all(this.tasks.map(e=>this.concurrency.add(()=>this.runTask(e)))),this.renderer.end(),this.removeSignalHandler()}catch(e){if(this.options.exitOnError!==!1)throw this.renderer.end(e),this.removeSignalHandler(),e}return this.ctx}generate(i){return i=Array.isArray(i)?i:[i],i.map(e=>{let t;return this.rendererSelection===gi.PRIMARY?t=e.rendererOptions:this.rendererSelection===gi.SECONDARY&&(t=e.fallbackRendererOptions),new oh(this,e,this.options,this.rendererClassOptions,t)})}async runTask(i){if(await i.check(this.ctx))return new sh(i).run(this.ctx)}signalHandler(){this.tasks?.forEach(async i=>{i.isPending()&&(i.state$=E.FAILED)}),this.isRoot()&&(this.renderer?.end(new Error("Interrupted.")),process.exit(127))}removeSignalHandler(){this.boundSignalHandler&&process.removeListener("SIGINT",this.boundSignalHandler)}};import{relative as lh}from"node:path";import{nonNullish as zr,notEmptyString as $r}from"@dfinity/utils";import{readFile as ph}from"node:fs/promises";import{basename as uh}from"node:path";import{isNullish as rh,nonNullish as ch}from"@dfinity/utils";var Mr=i=>i.reduce(([e,t],n)=>[[...e,...ch(n.file.alternateFile)?[n]:[]],[...t,...rh(n.file.alternateFile)?[n]:[]]],[[],[]]);var pt=async({file:i,fullPath:e,collection:t,filePath:n,token:s,description:a})=>({filename:uh(n),fullPath:e,data:new Blob([await ph(i.file)]),collection:t,headers:[...i.mime===void 0?[]:[["Content-Type",i.mime]]],encoding:i.encoding,...zr(s)&&$r(s)&&{token:s},...zr(a)&&$r(a)&&{description:a}}),ut=async({files:i,uploadFiles:e})=>{let[t,n]=Mr(i);await e({groupFiles:t,step:"alternate"}),await e({groupFiles:n,step:"source"})};var Wr=async({uploadFiles:i,collection:e,...t})=>{await mh({upload:async({files:s,progress:a})=>{await dh({collection:e,files:s,uploadFiles:i,progress:a})},...t})},mh=async({files:i,sourceAbsolutePath:e,upload:t,batchSize:n})=>{await ut({files:i,uploadFiles:async({groupFiles:a,step:o})=>{let r=Math.ceil(a.length/n);for(let c=0;c<a.length;c+=n){let p=a.slice(c,c+n),l=()=>{let w;return{promise:new Promise(z=>w=z),resolve:w}},u=p.map(w=>({...w,...l()})),m=l(),d=l(),f=u.map(({file:w,promise:k})=>({title:`Uploading ${lh(e,w.file)}`,task:async()=>await k})),x=`[${Math.floor(c/n)+1}/${r}]`,F=o==="alternate"?"\u2728":"\u{1F4E6}",S=new ge([{title:`${F} Initializing ${x}`,task:async()=>await m.promise},{title:`${F} Uploading ${x}`,task:(w,k)=>k.newListr(f,{concurrent:!0})},{title:`${F} Committing ${x}`,task:async()=>await d.promise}],{concurrent:!1}).run();await t({files:p,progress:{onUploadedFileChunks:w=>{u.find(z=>z.paths.fullPath===w)?.resolve?.()},onInitiatedBatch:()=>m.resolve?.(),onCommittedBatch:()=>d.resolve?.()}}),await S}}})},dh=async({uploadFiles:i,files:e,collection:t,progress:n})=>{let s=await Promise.all(e.map(async({file:a,paths:o})=>await pt({collection:t,...o,file:a})));await i({files:s,progress:n})};import{relative as fh}from"node:path";var Gr=async({uploadFile:i,collection:e,...t})=>{await hh({upload:async({file:s,paths:a})=>{await xh({collection:e,...a,file:s,uploadFile:i})},...t})},hh=async({files:i,sourceAbsolutePath:e,upload:t,batchSize:n})=>{await ut({files:i,uploadFiles:async({groupFiles:a,step:o})=>{for(let r=0;r<a.length;r+=n){let c=a.slice(r,r+n);await new ge(c.map(({file:l,paths:u})=>({title:`${o==="alternate"?"\u2728":"\u{1F4E6}"} Uploading ${fh(e,l.file)}`,task:async()=>await t({file:l,paths:u})})),{concurrent:!0}).run()}}})},xh=async({uploadFile:i,...e})=>{let t=await pt(e);await i(t)};var vi=async({upload:i,files:e,...t})=>{if("uploadFiles"in i){await Wr({uploadFiles:i.uploadFiles,files:e,...t}),qr({files:e});return}await Gr({uploadFile:i.uploadFile,files:e,...t}),qr({files:e})},qr=({files:i})=>{let{count:e,size:t}=i.reduce(({count:n,size:s},{paths:a})=>({count:n+1,size:s+ba(a.filePath)}),{count:0,size:0});console.log(`
|
|
33
33
|
\u2714 ${e} files uploaded (total: ${Ca(t)})`)};var lt=async({deploy:{upload:i,files:e,sourceAbsolutePath:t,collection:n,batchSize:s},proposal:{proposalType:a,autoCommit:o,...r}})=>{let c=async l=>{if("uploadFiles"in i){await vi({files:e,sourceAbsolutePath:t,collection:n,batchSize:s,upload:{uploadFiles:d=>i.uploadFiles({...d,proposalId:l})}});return}await vi({files:e,sourceAbsolutePath:t,collection:n,batchSize:s,upload:{uploadFile:m=>i.uploadFile({...m,proposalId:l})}})},{proposalId:p}=await wa({...r,autoCommit:o,proposalType:a,executeChanges:c});return o?{result:"deployed",files:e.map(l=>l.file),proposalId:p}:{result:"submitted",files:e.map(l=>l.file),proposalId:p}};var zv=async({config:{predeploy:i}})=>{await xt(i)},$v=async({config:{postdeploy:i}})=>{await xt(i)},Wv=async({params:i,upload:e})=>{let t=await Hr(i);if(t.result==="skipped")return{result:"skipped"};let{files:n,sourceAbsolutePath:s}=t,o={files:Kr({files:n,sourceAbsolutePath:s}),sourceAbsolutePath:s,batchSize:i.uploadBatchSize??He};return await vi({...o,collection:dt,upload:e}),console.log(`
|
|
34
34
|
\u{1F680} Deploy complete!`),{result:"deployed",files:n}},Gv=async({deploy:{params:i,upload:e},proposal:{clearAssets:t,...n}})=>{let s=await Hr(i);if(s.result==="skipped")return{result:"skipped"};let{sourceAbsolutePath:a}=s,o=Kr(s),r=await lt({deploy:{upload:e,files:o,sourceAbsolutePath:a,collection:dt,batchSize:i.uploadBatchSize??He},proposal:{...n,proposalType:{AssetsUpgrade:{clear_existing_assets:Dh(t)}}}});return r.result==="deployed"&&console.log(`
|
|
35
|
-
\u{1F680} Deploy complete!`),r},Hr=async({assertMemory:i,...e})=>{let t=bh("Preparing deploy...").start();try{let{files:n,sourceAbsolutePath:s}=await ya(e);return n.length===0?(t.stop(),console.log(""),console.log("\u26A0\uFE0F No file changes detected. Upload skipped."),{result:"skipped"}):(gh(i)&&(t.text="Asserting memory..."),await i?.(),t.stop(),{result:"to-deploy",files:n,sourceAbsolutePath:s})}catch(n){throw t.stop(),n}},Kr=({files:i,sourceAbsolutePath:e})=>{let t=n=>{let s=n.alternateFile??n.file;return{fullPath:Le({file:s,sourceAbsolutePath:e}),filePath:s}};return i.map(n=>({file:n,paths:t(n)}))};import{isNullish as vh}from"@dfinity/utils";import{generateFunctions as Fh}from"@junobuild/functions-tools";import{writeFile as Eh}from"node:fs/promises";import{relative as yh}from"node:path";var Xv=async({outfileJs:i,outfileRs:e,...t})=>{let n=await wh(t);if(n.status==="error")return n;let{result:{code:s,...a}}=n,o=await Ch({code:s,outfileRs:e}),r=await Sh({code:s,outfileJs:i});return{status:"success",result:{build:{...a,...r},generate:o}}},wh=async({infile:i,banner:e})=>{let{metafile:t,errors:n,warnings:s,version:a,outputFiles:o}=await jn({infile:i,banner:e}),r=s.map(({text:u})=>u),c=n.map(({text:u})=>u);if(c.length>0)return{status:"error",errors:c,warnings:r};let p=Object.entries(t.outputs);if(p.length===0)return{status:"error",errors:["Unexpected: No metafile resulting from the build was found."]};let l=o?.[0]?.contents;return vh(l)?{status:"error",errors:["Unexpected: No script build for the functions."]}:{status:"success",result:{output:p[0],version:a,code:l}}},Ch=async({code:i,outfileRs:e})=>await Fh({code:i,outputFile:e}),Sh=async({code:i,outfileJs:e})=>(await Eh(e,i),{outputPath:yh(process.cwd(),e)});import Ph from"ora";import{join as kh}from"node:path";var Yr=({sourceAbsolutePath:i,ignore:e})=>{let n=ti(i).filter(s=>Th({file:s,ignore:e}));return new Set(n.map(s=>Le({file:s,sourceAbsolutePath:i})))},Ah=({file:i,ignore:e})=>e.some(t=>L(i,t,{matchBase:!0})),Th=i=>!Ah(i);var Vr=async({config:i,listAssets:e,assertSourceDirExists:t})=>{let{source:n=yi,ignore:s=wi}=i,a=kh(process.cwd(),n);t?.(a);let o=Yr({sourceAbsolutePath:a,ignore:s});return{files:(await Oh({localPaths:o,listAssets:e})).map(({fullPath:c})=>({fullPath:c}))}},Oh=async({localPaths:i,listAssets:e})=>(await e({})).filter(({fullPath:
|
|
35
|
+
\u{1F680} Deploy complete!`),r},Hr=async({assertMemory:i,...e})=>{let t=bh("Preparing deploy...").start();try{let{files:n,sourceAbsolutePath:s}=await ya(e);return n.length===0?(t.stop(),console.log(""),console.log("\u26A0\uFE0F No file changes detected. Upload skipped."),{result:"skipped"}):(gh(i)&&(t.text="Asserting memory..."),await i?.(),t.stop(),{result:"to-deploy",files:n,sourceAbsolutePath:s})}catch(n){throw t.stop(),n}},Kr=({files:i,sourceAbsolutePath:e})=>{let t=n=>{let s=n.alternateFile??n.file;return{fullPath:Le({file:s,sourceAbsolutePath:e}),filePath:s}};return i.map(n=>({file:n,paths:t(n)}))};import{isNullish as vh}from"@dfinity/utils";import{generateFunctions as Fh}from"@junobuild/functions-tools";import{writeFile as Eh}from"node:fs/promises";import{relative as yh}from"node:path";var Xv=async({outfileJs:i,outfileRs:e,...t})=>{let n=await wh(t);if(n.status==="error")return n;let{result:{code:s,...a}}=n,o=await Ch({code:s,outfileRs:e}),r=await Sh({code:s,outfileJs:i});return{status:"success",result:{build:{...a,...r},generate:o}}},wh=async({infile:i,banner:e})=>{let{metafile:t,errors:n,warnings:s,version:a,outputFiles:o}=await jn({infile:i,banner:e}),r=s.map(({text:u})=>u),c=n.map(({text:u})=>u);if(c.length>0)return{status:"error",errors:c,warnings:r};let p=Object.entries(t.outputs);if(p.length===0)return{status:"error",errors:["Unexpected: No metafile resulting from the build was found."]};let l=o?.[0]?.contents;return vh(l)?{status:"error",errors:["Unexpected: No script build for the functions."]}:{status:"success",result:{output:p[0],version:a,code:l}}},Ch=async({code:i,outfileRs:e})=>await Fh({code:i,outputFile:e}),Sh=async({code:i,outfileJs:e})=>(await Eh(e,i),{outputPath:yh(process.cwd(),e)});import Ph from"ora";import{join as kh}from"node:path";var Yr=({sourceAbsolutePath:i,ignore:e})=>{let n=ti(i).filter(s=>Th({file:s,ignore:e}));return new Set(n.map(s=>Le({file:s,sourceAbsolutePath:i})))},Ah=({file:i,ignore:e})=>e.some(t=>L(i,t,{matchBase:!0})),Th=i=>!Ah(i);var Vr=async({config:i,listAssets:e,assertSourceDirExists:t})=>{let{source:n=yi,ignore:s=wi}=i,a=kh(process.cwd(),n);t?.(a);let o=Yr({sourceAbsolutePath:a,ignore:s});return{files:(await Oh({localPaths:o,listAssets:e})).map(({fullPath:c})=>({fullPath:c}))}},Oh=async({localPaths:i,listAssets:e})=>(await e({})).filter(({fullPath:s})=>!i.has(s)).filter(({fullPath:s})=>!["/.well-known/ic-domains","/.well-known/ii-alternative-origins"].includes(s));var Zr=async({files:i,pruneFn:e,batchSize:t})=>{let n=Math.ceil(i.length/t);for(let s=0;s<i.length;s+=t){let a=i.slice(s,s+t),r=`[${Math.floor(s/t)+1}/${n}]`;await new ge([{title:`\u{1F5D1}\uFE0F Pruning assets ${r}`,task:async()=>await e({files:a})}],{concurrent:!1}).run()}console.log(`
|
|
36
36
|
\u2714 ${i.length} stale asset(s) pruned.`)};var fF=async({params:{dryRun:i,batchSize:e,...t},pruneFn:n})=>{let s=await Rh(t);if(s.result==="skipped")return{result:"skipped"};let{files:a}=s;console.log(`
|
|
37
37
|
Found ${a.length} stale asset(s):`);for(let{fullPath:o}of a)console.log(` - ${o}`);return console.log(""),i===!0?{result:"simulated",files:a}:(await Zr({files:a,pruneFn:n,batchSize:e??100}),{result:"pruned",files:a})},Rh=async i=>{let e=Ph("Preparing prune...").start();try{let{files:t}=await Vr(i);return e.stop(),t.length===0?(console.log(""),console.log("\u{1F44D} No stale assets found. Satellite is already clean."),{result:"skipped"}):{result:"to-prune",files:t}}catch(t){throw e.stop(),t}};import{toNullable as Rn}from"@dfinity/utils";var vF=async({publish:{assertMemory:i,filePath:e,fullPath:t,upload:n,...s},proposal:{version:a,...o}})=>{await i?.();let c=await lt({deploy:{...s,upload:n,files:[{file:{file:e},paths:{filePath:e,fullPath:t}}],collection:Mn,batchSize:He},proposal:{...o,proposalType:{SegmentsDeployment:{satellite_version:Rn(a),orbiter:Rn(),mission_control_version:Rn()}}}});return c.result==="deployed"&&console.log(`
|
|
38
38
|
\u{1F4E1} Satellite WASM published to CDN.`),c};var EF=({args:i,options:e})=>i?.find(t=>e.includes(t))!==void 0,yF=({args:i,option:e})=>{let t=(i??[]).findIndex(n=>n===e);if(t!==-1)return i?.[t+1]};import{nonNullish as Xr}from"@dfinity/utils";import{get as _h}from"http";import{get as Ih}from"https";var jh=async i=>await new Promise((e,t)=>{((typeof i=="string"?URL.parse(i)?.protocol:i.protocol)==="http:"?_h:Ih)(i,async a=>{Xr(a.statusCode)&&Xr(a.headers.location)&&[301,302].includes(a.statusCode)&&await jh(a.headers.location).then(e,t);let o=[];a.on("data",r=>o.push(r)),a.on("end",()=>{e(Buffer.concat(o))}),a.on("error",t)})});import{readFile as Lh}from"node:fs/promises";var OF=async({packageJsonPath:i})=>{let e=await Lh(i,"utf-8"),{dependencies:t,version:n,juno:s,name:a}=JSON.parse(e);return{name:a,version:n,dependencies:t,juno:s}};import{isNullish as Nh,nonNullish as Uh}from"@dfinity/utils";var RF=(i,e)=>{(Nh(i)||i==="")&&(Uh(e)&&console.error(e),process.exit(1))};export{Mn as COLLECTION_CDN_RELEASES,dt as COLLECTION_DAPP,Nn as DEPLOY_DEFAULT_ENCODING,wi as DEPLOY_DEFAULT_IGNORE,ce as DEPLOY_DEFAULT_PRECOMPRESS,yi as DEPLOY_DEFAULT_SOURCE,Un as IGNORE_OS_FILES,He as UPLOAD_DEFAULT_BATCH_SIZE,RF as assertAnswerCtrlC,x0 as brotliFile,Xv as buildAndGenerateFunctions,jn as buildFunctions,Wh as buildScript,xa as compressFiles,Wv as deploy,Gv as deployWithProposal,jh as downloadFromURL,qn as execute,E0 as fileExists,ba as fileSizeInBytes,ti as files,Ca as formatBytes,f0 as gunzipFile,h0 as gzipFile,EF as hasArgs,g0 as isGzip,yF as nextArg,$v as postDeploy,zv as preDeploy,fF as prune,vF as publishSatelliteWasmWithProposal,OF as readPackageJson,tx as spawn};
|