@visulima/cerebro 3.0.0-alpha.1 → 3.0.0-alpha.10

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/LICENSE.md +1810 -98
  3. package/dist/cli.d.ts +22 -0
  4. package/dist/commands/completion-command.js +204 -5
  5. package/dist/commands/help-command.js +200 -1
  6. package/dist/commands/readme-command.js +326 -32
  7. package/dist/commands/version-command.js +18 -1
  8. package/dist/default-env.d.ts +1 -1
  9. package/dist/index.js +7 -1
  10. package/dist/logger/create-pail-logger.js +34 -1
  11. package/dist/packem_chunks/has-new-version.js +264 -1
  12. package/dist/packem_shared/Cerebro-bgCm5Tb1.js +3444 -0
  13. package/dist/packem_shared/VERBOSITY_QUIET-Dp46zlLW.js +10 -0
  14. package/dist/packem_shared/VisulimaError-DA7QsCxH.js +34 -0
  15. package/dist/packem_shared/cerebro-error-GmJ3jN7Q.js +16 -0
  16. package/dist/packem_shared/index-CS31xKFe.js +264 -0
  17. package/dist/packem_shared/runtime-process-B6ZplyWn.js +187 -0
  18. package/dist/plugins/error-handler-plugin.js +648 -1
  19. package/dist/plugins/runtime-version-check-plugin.js +77 -1
  20. package/dist/plugins/update-notifier/update-notifier-plugin.js +517 -1
  21. package/dist/types/cli.d.ts +11 -0
  22. package/dist/types/command-line-usage.d.ts +1 -1
  23. package/dist/types/command.d.ts +10 -10
  24. package/dist/util/command-processing/option-processor.d.ts +8 -8
  25. package/dist/util/general/compile-cache.d.ts +41 -0
  26. package/dist/util/general/compile-cache.js +16 -0
  27. package/dist/util/general/heap-tuning.d.ts +81 -0
  28. package/dist/util/general/heap-tuning.js +91 -0
  29. package/dist/util/general/register-exception-handler.d.ts +1 -1
  30. package/dist/util/process-env-variables.d.ts +1 -1
  31. package/package.json +15 -7
  32. package/dist/packem_shared/Cerebro-Bj2O5JeH.js +0 -4
  33. package/dist/packem_shared/VERBOSITY_QUIET-XPultrIA.js +0 -1
  34. package/dist/packem_shared/VisulimaError-BJideSBf.js +0 -76
  35. package/dist/packem_shared/cerebro-error-BnJTixb2.js +0 -1
  36. package/dist/packem_shared/help-command-CIRIXN03.js +0 -1
  37. package/dist/packem_shared/index-DQ3pvLQH.js +0 -6
  38. package/dist/packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js +0 -1
  39. package/dist/packem_shared/renderError-ZMlMvw1N-eVUSdl6c.js +0 -24
  40. package/dist/packem_shared/runtime-process-G-n-wOub.js +0 -1
@@ -1 +1,264 @@
1
- var Kt=Object.defineProperty;var j=(o,a)=>Kt(o,"name",{value:a,configurable:!0});import{createRequire as Qt}from"node:module";import{findCacheDirSync as rn}from"@visulima/find-cache-dir";import{c as on}from"../packem_shared/cerebro-error-BnJTixb2.js";const Xt=Qt(import.meta.url),I=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,xe=j(o=>{if(typeof I<"u"&&I.versions&&I.versions.node){const[a,l]=I.versions.node.split(".").map(Number);if(a>22||a===22&&l>=3||a===20&&l>=16)return I.getBuiltinModule(o)}return Xt(o)},"__cjs_getBuiltinModule"),{existsSync:$e,mkdirSync:en,writeFileSync:tn,readFileSync:nn}=xe("node:fs"),{get:sn}=xe("node:https");var an=Object.defineProperty,ln=j((o,a)=>an(o,"name",{value:a,configurable:!0}),"o$1");const cn=ln((o,a)=>{const l=o.split(".").map(Number),p=a.split(".").map(Number);for(const[h,d]of l.entries()){if(d>p[h])return!0;if(d<p[h])return!1}return!1},"semverGt");var un=Object.defineProperty,i=j((o,a)=>un(o,"name",{value:a,configurable:!0}),"s");let de=i(()=>{var o=(()=>{var a=Object.defineProperty,l=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,h=Object.prototype.hasOwnProperty,d=i((e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},"ne"),$=i((e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of p(t))!h.call(e,r)&&r!==n&&a(e,r,{get:i(()=>t[r],"get"),enumerable:!(s=l(t,r))||s.enumerable});return e},"ae"),m=i(e=>$(a({},"__esModule",{value:!0}),e),"oe"),y={};d(y,{zeptomatch:i(()=>he,"zeptomatch")});var H=i(e=>{const t=new Set,n=[e];for(let s=0;s<n.length;s++){const r=n[s];if(t.has(r))continue;t.add(r);const{children:c}=r;if(c?.length)for(let u=0,g=c.length;u<g;u++)n.push(c[u])}return Array.from(t)},"M"),_e=i(e=>{let t="";const n=H(e);for(let s=0,r=n.length;s<r;s++){const c=n[s];if(!c.regex)continue;const u=c.regex.flags;if(t||(t=u),t!==u)throw new Error(`Inconsistent RegExp flags used: "${t}" and "${u}"`)}return t},"se"),Y=i((e,t,n)=>{const s=n.get(e);if(s!==void 0)return s;const r=e.partial??t;let c="";if(e.regex&&(c+=r?"(?:$|":"",c+=e.regex.source),e.children?.length){const u=Ee(e.children.map(g=>Y(g,t,n)).filter(Boolean));if(u?.length){const g=e.children.some(P=>!P.regex||!(P.partial??t)),v=u.length>1||r&&(!c.length||g);c+=v?r?"(?:$|":"(?:":"",c+=u.join("|"),c+=v?")":""}}return e.regex&&(c+=r?")":""),n.set(e,c),c},"O"),ke=i((e,t)=>{const n=new Map,s=H(e);for(let r=s.length-1;r>=0;r--){const c=Y(s[r],t,n);if(!(r>0))return c}return""},"ie"),Ee=i(e=>Array.from(new Set(e)),"ue"),B=i((e,t,n)=>B.compile(e,n).test(t),"R");B.compile=(e,t)=>{const n=t?.partial??!1,s=ke(e,n),r=_e(e);return new RegExp(`^(?:${s})$`,r)};var Oe=B,Re=i((e,t)=>{const n=Oe.compile(e,t),s=`${n.source.slice(0,-1)}[\\\\/]?$`,r=n.flags;return new RegExp(s,r)},"le"),Me=Re,Ae=i(e=>{const t=e.map(s=>s.source).join("|")||"$^",n=e[0]?.flags;return new RegExp(t,n)},"ve"),Ne=Ae,K=i(e=>Array.isArray(e),"j"),z=i(e=>typeof e=="function","_"),ze=i(e=>e.length===0,"he"),Ce=(()=>{const{toString:e}=Function.prototype,t=/(?:^\(\s*(?:[^,.()]|\.(?!\.\.))*\s*\)\s*=>|^\s*[a-zA-Z$_][a-zA-Z0-9$_]*\s*=>)/;return n=>(n.length===0||n.length===1)&&t.test(e.call(n))})(),Pe=i(e=>typeof e=="number","de"),Se=i(e=>typeof e=="object"&&e!==null,"xe"),Ie=i(e=>e instanceof RegExp,"me"),Ue=(()=>{const e=/\\\(|\((?!\?(?::|=|!|<=|<!))/;return t=>e.test(t.source)})(),Te=(()=>{const e=/^[a-zA-Z0-9_-]+$/;return t=>e.test(t.source)&&!t.flags.includes("i")})(),Q=i(e=>typeof e=="string","A"),_=i(e=>e===void 0,"f"),Be=i(e=>{const t=new Map;return n=>{const s=t.get(n);if(s!==void 0)return s;const r=e(n);return t.set(n,r),r}},"ye"),X=i((e,t,n={})=>{const s={cache:{},input:e,index:0,indexBacktrackMax:0,options:n,output:[]},r=k(t)(s),c=Math.max(s.index,s.indexBacktrackMax);if(r&&s.index===e.length)return s.output;throw new Error(`Failed to parse at index ${c}`)},"I"),f=i((e,t)=>K(e)?De(e,t):Q(e)?ee(e,t):Fe(e,t),"i"),De=i((e,t)=>{const n={};for(const s of e){if(s.length!==1)throw new Error(`Invalid character: "${s}"`);const r=s.charCodeAt(0);n[r]=!0}return s=>{const r=s.input;let c=s.index,u=c;for(;u<r.length&&r.charCodeAt(u)in n;)u+=1;if(u>c){if(!_(t)&&!s.options.silent){const g=r.slice(c,u),v=z(t)?t(g,r,`${c}`):t;_(v)||s.output.push(v)}s.index=u}return!0}},"we"),Fe=i((e,t)=>{if(Te(e))return ee(e.source,t);{const n=e.source,s=e.flags.replace(/y|$/,"y"),r=new RegExp(n,s);return Ue(e)&&z(t)&&!Ce(t)?Le(r,t):Ze(r,t)}},"$e"),Le=i((e,t)=>n=>{const s=n.index,r=n.input;e.lastIndex=s;const c=e.exec(r);if(c){const u=e.lastIndex;if(!n.options.silent){const g=t(...c,r,`${s}`);_(g)||n.output.push(g)}return n.index=u,!0}else return!1},"Ee"),Ze=i((e,t)=>n=>{const s=n.index,r=n.input;if(e.lastIndex=s,e.test(r)){const c=e.lastIndex;if(!_(t)&&!n.options.silent){const u=z(t)?t(r.slice(s,c),r,`${s}`):t;_(u)||n.output.push(u)}return n.index=c,!0}else return!1},"Ce"),ee=i((e,t)=>n=>{const s=n.index,r=n.input;if(r.startsWith(e,s)){if(!_(t)&&!n.options.silent){const c=z(t)?t(e,r,`${s}`):t;_(c)||n.output.push(c)}return n.index+=e.length,!0}else return!1},"F"),D=i((e,t,n,s)=>{const r=k(e),c=t>1;return L(F(ne(u=>{let g=0;for(;g<n;){const v=u.index;if(!r(u)||(g+=1,u.index===v))break}return g>=t},c),s))},"k"),te=i((e,t)=>D(e,0,1,t),"L"),T=i((e,t)=>D(e,0,1/0,t),"$"),qe=i((e,t)=>D(e,1,1/0,t),"Re"),M=i((e,t)=>{const n=e.map(k);return L(F(ne(s=>{for(let r=0,c=n.length;r<c;r++)if(!n[r](s))return!1;return!0}),t))},"x"),w=i((e,t)=>{const n=e.map(k);return L(F(s=>{for(let r=0,c=n.length;r<c;r++)if(n[r](s))return!0;return!1},t))},"p"),ne=i((e,t=!0,n=!1)=>{const s=k(e);return t?r=>{const c=r.index,u=r.output.length,g=s(r);return!g&&!n&&(r.indexBacktrackMax=Math.max(r.indexBacktrackMax,r.index)),(!g||n)&&(r.index=c,r.output.length!==u&&(r.output.length=u)),g}:s},"q"),F=i((e,t)=>{const n=k(e);return t?s=>{if(s.options.silent)return n(s);const r=s.output.length;if(n(s)){const c=s.output.splice(r,1/0),u=t(c);return _(u)||s.output.push(u),!0}else return!1}:n},"B"),L=(()=>{let e=0;return t=>{const n=k(t),s=e+=1;return r=>{var c;if(r.options.memoization===!1)return n(r);const u=r.index,g=(c=r.cache)[s]||(c[s]={indexMax:-1,queue:[]}),v=g.queue;if(u<=g.indexMax){const S=g.store||(g.store=new Map);if(v.length){for(let N=0,Jt=v.length;N<Jt;N+=2){const Ht=v[N*2],Yt=v[N*2+1];S.set(Ht,Yt)}v.length=0}const b=S.get(u);if(b===!1)return!1;if(Pe(b))return r.index=b,!0;if(b)return r.index=b.index,b.output?.length&&r.output.push(...b.output),!0}const P=r.output.length,Gt=n(r);if(g.indexMax=Math.max(g.indexMax,u),Gt){const S=r.index,b=r.output.length;if(b>P){const N=r.output.slice(P,b);v.push(u,{index:S,output:N})}else v.push(u,S);return!0}else return v.push(u,!1),!1}}})(),re=i(e=>{let t;return n=>(t||(t=k(e())),t(n))},"G"),k=Be(e=>{if(z(e))return ze(e)?re(e):e;if(Q(e)||Ie(e))return f(e);if(K(e))return M(e);if(Se(e))return w(Object.values(e));throw new Error("Invalid rule")}),O=i(e=>e,"d"),We=i(e=>typeof e=="string","ke"),Ve=i(e=>{const t=new WeakMap,n=new WeakMap;return(s,r)=>{const c=r?.partial?n:t,u=c.get(s);if(u!==void 0)return u;const g=e(s,r);return c.set(s,g),g}},"Be"),Ge=i(e=>{const t={},n={};return(s,r)=>{const c=r?.partial?n:t;return c[s]??(c[s]=e(s,r))}},"Pe"),Je=f(/\\./,O),He=f(/./,O),Ye=f(/\*\*\*+/,"*"),Ke=f(/([^/{[(!])\*\*/,(e,t)=>`${t}*`),Qe=f(/(^|.)\*\*(?=[^*/)\]}])/,(e,t)=>`${t}*`),Xe=T(w([Je,Ye,Ke,Qe,He])),et=Xe,tt=i(e=>X(e,et,{memoization:!1}).join(""),"Ie"),nt=tt,oe="abcdefghijklmnopqrstuvwxyz",rt=i(e=>{let t="";for(;e>0;){const n=(e-1)%26;t=oe[n]+t,e=Math.floor((e-1)/26)}return t},"Le"),se=i(e=>{let t=0;for(let n=0,s=e.length;n<s;n++)t=t*26+oe.indexOf(e[n])+1;return t},"V"),Z=i((e,t)=>{if(t<e)return Z(t,e);const n=[];for(;e<=t;)n.push(e++);return n},"b"),ot=i((e,t,n)=>Z(e,t).map(s=>String(s).padStart(n,"0")),"qe"),ae=i((e,t)=>Z(se(e),se(t)).map(rt),"W"),x=i(e=>({partial:!1,regex:new RegExp(e,"s"),children:[]}),"c"),C=i(e=>({children:e}),"y"),A=(()=>{const e=i((t,n,s)=>{if(s.has(t))return;s.add(t);const{children:r}=t;if(!r.length)r.push(n);else for(let c=0,u=r.length;c<u;c++)e(r[c],n,s)},"e");return t=>{if(!t.length)return C([]);for(let n=t.length-1;n>=1;n--){const s=new Set,r=t[n-1],c=t[n];e(r,c,s)}return t[0]}})(),E=i(()=>({regex:new RegExp("[\\\\/]","s"),children:[]}),"g"),st=f(/\\./,x),at=f(/[$.*+?^(){}[\]\|]/,e=>x(`\\${e}`)),it=f(/[\\\/]/,E),lt=f(/[^$.*+?^(){}[\]\|\\\/]+/,x),ct=f(/^(?:!!)*!(.*)$/,(e,t)=>x(`(?!^${he.compile(t).source}$).*?`)),ut=f(/^(!!)+/),pt=w([ct,ut]),ft=f(/\/(\*\*\/)+/,()=>C([A([E(),x(".+?"),E()]),E()])),gt=f(/^(\*\*\/)+/,()=>C([x("^"),A([x(".*?"),E()])])),ht=f(/\/(\*\*)$/,()=>C([A([E(),x(".*?")]),x("$")])),dt=f(/\*\*/,()=>x(".*?")),ie=w([ft,gt,ht,dt]),mt=f(/\*\/(?!\*\*\/|\*$)/,()=>A([x("[^\\\\/]*?"),E()])),xt=f(/\*/,()=>x("[^\\\\/]*")),le=w([mt,xt]),ce=f("?",()=>x("[^\\\\/]")),$t=f("[",O),vt=f("]",O),yt=f(/[!^]/,"^\\\\/"),wt=f(/[a-z]-[a-z]|[0-9]-[0-9]/i,O),bt=f(/\\./,O),jt=f(/[$.*+?^(){}[\|]/,e=>`\\${e}`),_t=f(/[\\\/]/,"\\\\/"),kt=f(/[^$.*+?^(){}[\]\|\\\/]+/,O),Et=w([bt,jt,_t,wt,kt]),ue=M([$t,te(yt),T(Et),vt],e=>x(e.join(""))),Ot=f("{","(?:"),Rt=f("}",")"),Mt=f(/(\d+)\.\.(\d+)/,(e,t,n)=>ot(+t,+n,Math.min(t.length,n.length)).join("|")),At=f(/([a-z]+)\.\.([a-z]+)/,(e,t,n)=>ae(t,n).join("|")),Nt=f(/([A-Z]+)\.\.([A-Z]+)/,(e,t,n)=>ae(t.toLowerCase(),n.toLowerCase()).join("|").toUpperCase()),zt=w([Mt,At,Nt]),pe=M([Ot,zt,Rt],e=>x(e.join(""))),Ct=f("{"),Pt=f("}"),St=f(","),It=f(/\\./,x),Ut=f(/[$.*+?^(){[\]\|]/,e=>x(`\\${e}`)),Tt=f(/[\\\/]/,E),Bt=f(/[^$.*+?^(){}[\]\|\\\/,]+/,x),Dt=re(()=>ge),Ft=f("",()=>x("(?:)")),Lt=qe(w([ie,le,ce,ue,pe,Dt,It,Ut,Tt,Bt]),A),fe=w([Lt,Ft]),ge=M([Ct,te(M([fe,T(M([St,fe]))])),Pt],C),Zt=T(w([pt,ie,le,ce,ue,pe,ge,st,at,it,lt]),A),qt=Zt,Wt=i(e=>X(e,qt,{memoization:!1})[0],"kr"),Vt=Wt,q=i((e,t,n)=>q.compile(e,n).test(t),"N");q.compile=(()=>{const e=Ge((n,s)=>Me(Vt(nt(n)),s)),t=Ve((n,s)=>Ne(n.map(r=>e(r,s))));return(n,s)=>We(n)?e(n,s):t(n,s)})();var he=q;return m(y)})();return o.default||o},"_lazyMatch"),W;const pn=i((o,a)=>(W||(W=de(),de=null),W(o,a)),"zeptomatch"),fn=/^[A-Z]:\//i,R=i((o="")=>o&&o.replaceAll("\\","/").replace(fn,a=>a.toUpperCase()),"normalizeWindowsPath"),gn=/^[/\\]{2}/,hn=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,ve=/^[A-Z]:$/i,me=/^\/([A-Z]:)?$/i,dn=/.(\.[^./]+)$/,mn=/^[/\\]|^[a-z]:[/\\]/i,xn=i(()=>typeof process.cwd=="function"?process.cwd().replaceAll("\\","/"):"/","cwd"),ye=i((o,a)=>{let l="",p=0,h=-1,d=0,$;for(let m=0;m<=o.length;++m){if(m<o.length)$=o[m];else{if($==="/")break;$="/"}if($==="/"){if(!(h===m-1||d===1))if(d===2){if(l.length<2||p!==2||!l.endsWith(".")||l.at(-2)!=="."){if(l.length>2){const y=l.lastIndexOf("/");y===-1?(l="",p=0):(l=l.slice(0,y),p=l.length-1-l.lastIndexOf("/")),h=m,d=0;continue}else if(l.length>0){l="",p=0,h=m,d=0;continue}}a&&(l+=l.length>0?"/..":"..",p=2)}else l.length>0?l+=`/${o.slice(h+1,m)}`:l=o.slice(h+1,m),p=m-h-1;h=m,d=0}else $==="."&&d!==-1?++d:d=-1}return l},"normalizeString"),U=i(o=>hn.test(o),"isAbsolute"),we=i(function(o){if(o.length===0)return".";o=R(o);const a=gn.exec(o),l=U(o),p=o.at(-1)==="/";return o=ye(o,!l),o.length===0?l?"/":p?"./":".":(p&&(o+="/"),ve.test(o)&&(o+="/"),a?l?`//${o}`:`//./${o}`:l&&!U(o)?`/${o}`:o)},"normalize"),$n=i((...o)=>{let a="";for(const l of o)if(l)if(a.length>0){const p=a[a.length-1]==="/",h=l[0]==="/";p&&h?a+=l.slice(1):a+=p||h?l:`/${l}`}else a+=l;return we(a)},"join"),V=i(function(...o){o=o.map(p=>R(p));let a="",l=!1;for(let p=o.length-1;p>=-1&&!l;p--){const h=p>=0?o[p]:xn();!h||h.length===0||(a=`${h}/${a}`,l=U(h))}return a=ye(a,!l),l&&!U(a)?`/${a}`:a.length>0?a:"."},"resolve");i(function(o){return R(o)},"toNamespacedPath");const vn=i(function(o){return dn.exec(R(o))?.[1]??""},"extname");i(function(o,a){const l=V(o).replace(me,"$1").split("/"),p=V(a).replace(me,"$1").split("/");if(p[0][1]===":"&&l[0][1]===":"&&l[0]!==p[0])return p.join("/");const h=[...l];for(const d of h){if(p[0]!==d)break;l.shift(),p.shift()}return[...l.map(()=>".."),...p].join("/")},"relative");const be=i(o=>{const a=R(o).replace(/\/$/,"").split("/").slice(0,-1);return a.length===1&&ve.test(a[0])&&(a[0]+="/"),a.join("/")||(U(o)?"/":".")},"dirname");i(function(o){const a=[o.root,o.dir,o.base??o.name+o.ext].filter(Boolean);return R(o.root?V(...a):a.join("/"))},"format");const yn=i((o,a)=>{const l=R(o).split("/").pop();return a&&l.endsWith(a)?l.slice(0,-a.length):l},"basename");i(function(o){const a=mn.exec(o)?.[0]?.replaceAll("\\","/")??"",l=yn(o),p=vn(l);return{base:l,dir:be(o),ext:p,name:l.slice(0,l.length-p.length),root:a}},"parse");i((o,a)=>pn(a,we(o)),"matchesGlob");var wn=Object.defineProperty,bn=j((o,a)=>wn(o,"name",{value:a,configurable:!0}),"e");let G=class extends on{static{j(this,"p")}static{bn(this,"UpdateNotifierError")}constructor(a,l="UPDATE_NOTIFIER_ERROR",p){super(a,l,p),this.name="UpdateNotifierError"}};var jn=Object.defineProperty,J=j((o,a)=>jn(o,"name",{value:a,configurable:!0}),"n");const _n="last-update-check.json",je=J(o=>{const a=rn(o);if(a===void 0)throw new G("Could not find cache directory","CACHE_DIRECTORY_NOT_FOUND",{packageName:o});return $n(a,_n)},"getConfigFile"),kn=J(o=>{const a=je(o);try{if(!$e(a))return;const{lastUpdateCheck:l}=JSON.parse(nn(a,"utf8"));return l}catch{return}},"getLastUpdate"),En=J(o=>{const a=je(o),l=be(a);$e(l)||en(l,{recursive:!0}),tn(a,JSON.stringify({lastUpdateCheck:Date.now()}))},"saveLastUpdate");var On=Object.defineProperty,Rn=j((o,a)=>On(o,"name",{value:a,configurable:!0}),"g");const Mn=Rn(async(o,a,l)=>{const p=l.replace("__NAME__",o);return await new Promise((h,d)=>{sn(p,$=>{let m="";$.on("data",y=>m+=y),$.on("end",()=>{try{const y=JSON.parse(m)[a];y||d(new G("Error getting version","VERSION_FETCH_ERROR",{distributionTag:a,packageName:o})),h(y)}catch{d(new G("Could not parse version response","VERSION_PARSE_ERROR",{distributionTag:a,packageName:o}))}})}).on("error",$=>d($))})},"getDistributionVersion");var An=Object.defineProperty,Nn=j((o,a)=>An(o,"name",{value:a,configurable:!0}),"i");const Un=Nn(async({alwaysRun:o,debug:a,distTag:l="latest",pkg:p,registryUrl:h="https://registry.npmjs.org/-/package/__NAME__/dist-tags",updateCheckInterval:d=1e3*60*60*24})=>{const $=kn(p.name);if(o||!$||$<Date.now()-d){const m=await Mn(p.name,l,h);if(En(p.name),cn(m,p.version))return m;a&&console.error(`Latest version (${m}) not newer than current version (${p.version})`)}else a&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${d}ms but only ${Date.now()-$}ms since last check.`)},"hasNewVersion");export{Un as default};
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ existsSync,
22
+ readFileSync,
23
+ mkdirSync,
24
+ writeFileSync
25
+ } = __cjs_getBuiltinModule("node:fs");
26
+ import { findCacheDirSync } from '@visulima/find-cache-dir';
27
+ import { C as CerebroError } from '../packem_shared/cerebro-error-GmJ3jN7Q.js';
28
+ const {
29
+ get
30
+ } = __cjs_getBuiltinModule("node:https");
31
+
32
+ const semverGt = (version1, version2) => {
33
+ const v1Components = version1.split(".").map(Number);
34
+ const v2Components = version2.split(".").map(Number);
35
+ for (const [index, v1Component] of v1Components.entries()) {
36
+ if (v1Component > v2Components[index]) {
37
+ return true;
38
+ }
39
+ if (v1Component < v2Components[index]) {
40
+ return false;
41
+ }
42
+ }
43
+ return false;
44
+ };
45
+
46
+ const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
47
+ const normalizeWindowsPath = (input = "") => {
48
+ if (!input) {
49
+ return input;
50
+ }
51
+ return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
52
+ };
53
+ const UNC_REGEX = /^[/\\]{2}/;
54
+ const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
55
+ const DRIVE_LETTER_RE = /^[A-Z]:$/i;
56
+ const TRAILING_SLASH_RE = /\/$/;
57
+ const normalizeString = (path2, allowAboveRoot) => {
58
+ let result = "";
59
+ let lastSegmentLength = 0;
60
+ let lastSlash = -1;
61
+ let dots = 0;
62
+ let char;
63
+ for (let index = 0; index <= path2.length; ++index) {
64
+ if (index < path2.length) {
65
+ char = path2[index];
66
+ } else if (char === "/") {
67
+ break;
68
+ } else {
69
+ char = "/";
70
+ }
71
+ if (char === "/") {
72
+ if (lastSlash === index - 1 || dots === 1) ;
73
+ else if (dots === 2) {
74
+ if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
75
+ if (result.length > 2) {
76
+ const lastSlashIndex = result.lastIndexOf("/");
77
+ if (lastSlashIndex === -1) {
78
+ result = "";
79
+ lastSegmentLength = 0;
80
+ } else {
81
+ result = result.slice(0, lastSlashIndex);
82
+ lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
83
+ }
84
+ lastSlash = index;
85
+ dots = 0;
86
+ continue;
87
+ } else if (result.length > 0) {
88
+ result = "";
89
+ lastSegmentLength = 0;
90
+ lastSlash = index;
91
+ dots = 0;
92
+ continue;
93
+ }
94
+ }
95
+ if (allowAboveRoot) {
96
+ result += result.length > 0 ? "/.." : "..";
97
+ lastSegmentLength = 2;
98
+ }
99
+ } else {
100
+ if (result.length > 0) {
101
+ result += `/${path2.slice(lastSlash + 1, index)}`;
102
+ } else {
103
+ result = path2.slice(lastSlash + 1, index);
104
+ }
105
+ lastSegmentLength = index - lastSlash - 1;
106
+ }
107
+ lastSlash = index;
108
+ dots = 0;
109
+ } else if (char === "." && dots !== -1) {
110
+ ++dots;
111
+ } else {
112
+ dots = -1;
113
+ }
114
+ }
115
+ return result;
116
+ };
117
+ const isAbsolute = (path2) => IS_ABSOLUTE_RE.test(path2);
118
+ const normalize = function(path2) {
119
+ if (path2.length === 0) {
120
+ return ".";
121
+ }
122
+ path2 = normalizeWindowsPath(path2);
123
+ const isUNCPath = UNC_REGEX.exec(path2);
124
+ const isPathAbsolute = isAbsolute(path2);
125
+ const trailingSeparator = path2.at(-1) === "/";
126
+ path2 = normalizeString(path2, !isPathAbsolute);
127
+ if (path2.length === 0) {
128
+ if (isPathAbsolute) {
129
+ return "/";
130
+ }
131
+ return trailingSeparator ? "./" : ".";
132
+ }
133
+ if (trailingSeparator) {
134
+ path2 += "/";
135
+ }
136
+ if (DRIVE_LETTER_RE.test(path2)) {
137
+ path2 += "/";
138
+ }
139
+ if (isUNCPath) {
140
+ if (!isPathAbsolute) {
141
+ return `//./${path2}`;
142
+ }
143
+ return `//${path2}`;
144
+ }
145
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
146
+ };
147
+ const join = (...segments) => {
148
+ let path2 = "";
149
+ for (const seg of segments) {
150
+ if (!seg) {
151
+ continue;
152
+ }
153
+ if (path2.length > 0) {
154
+ const pathTrailing = path2.at(-1) === "/";
155
+ const segLeading = seg[0] === "/";
156
+ const both = pathTrailing && segLeading;
157
+ if (both) {
158
+ path2 += seg.slice(1);
159
+ } else {
160
+ path2 += pathTrailing || segLeading ? seg : `/${seg}`;
161
+ }
162
+ } else {
163
+ path2 += seg;
164
+ }
165
+ }
166
+ return normalize(path2);
167
+ };
168
+ const dirname = (path2) => {
169
+ const segments = normalizeWindowsPath(path2).replace(TRAILING_SLASH_RE, "").split("/").slice(0, -1);
170
+ if (segments.length === 1 && DRIVE_LETTER_RE.test(segments[0])) {
171
+ segments[0] = `${segments[0]}/`;
172
+ }
173
+ return segments.join("/") || (isAbsolute(path2) ? "/" : ".");
174
+ };
175
+
176
+ class UpdateNotifierError extends CerebroError {
177
+ constructor(message, code = "UPDATE_NOTIFIER_ERROR", context) {
178
+ super(message, code, context);
179
+ this.name = "UpdateNotifierError";
180
+ }
181
+ }
182
+
183
+ const FILE_NAME = "last-update-check.json";
184
+ const getConfigFile = (packageName) => {
185
+ const cacheDirectory = findCacheDirSync(packageName);
186
+ if (cacheDirectory === void 0) {
187
+ throw new UpdateNotifierError("Could not find cache directory", "CACHE_DIRECTORY_NOT_FOUND", { packageName });
188
+ }
189
+ return join(cacheDirectory, FILE_NAME);
190
+ };
191
+ const getLastUpdate = (packageName) => {
192
+ const configFile = getConfigFile(packageName);
193
+ try {
194
+ if (!existsSync(configFile)) {
195
+ return void 0;
196
+ }
197
+ const { lastUpdateCheck } = JSON.parse(readFileSync(configFile, "utf8"));
198
+ return lastUpdateCheck;
199
+ } catch {
200
+ return void 0;
201
+ }
202
+ };
203
+ const saveLastUpdate = (packageName) => {
204
+ const configFile = getConfigFile(packageName);
205
+ const configDirectory = dirname(configFile);
206
+ if (!existsSync(configDirectory)) {
207
+ mkdirSync(configDirectory, { recursive: true });
208
+ }
209
+ writeFileSync(configFile, JSON.stringify({ lastUpdateCheck: Date.now() }));
210
+ };
211
+
212
+ const getDistributionVersion = async (packageName, distributionTag, registryUrl) => {
213
+ const url = registryUrl.replace("__NAME__", packageName);
214
+ return await new Promise((resolve, reject) => {
215
+ get(url, (message) => {
216
+ let body = "";
217
+ message.on("data", (chunk) => body += String(chunk));
218
+ message.on("end", () => {
219
+ try {
220
+ const json = JSON.parse(body);
221
+ const version = json[distributionTag];
222
+ if (!version) {
223
+ reject(new UpdateNotifierError("Error getting version", "VERSION_FETCH_ERROR", { distributionTag, packageName }));
224
+ }
225
+ resolve(version);
226
+ } catch {
227
+ reject(new UpdateNotifierError("Could not parse version response", "VERSION_PARSE_ERROR", { distributionTag, packageName }));
228
+ }
229
+ });
230
+ }).on("error", (error) => {
231
+ reject(error);
232
+ });
233
+ });
234
+ };
235
+
236
+ const hasNewVersion = async ({
237
+ alwaysRun,
238
+ debug,
239
+ distTag: distributionTag = "latest",
240
+ pkg,
241
+ registryUrl = "https://registry.npmjs.org/-/package/__NAME__/dist-tags",
242
+ updateCheckInterval = 1e3 * 60 * 60 * 24
243
+ }) => {
244
+ const lastUpdateCheck = getLastUpdate(pkg.name);
245
+ if (alwaysRun || !lastUpdateCheck || lastUpdateCheck < Date.now() - updateCheckInterval) {
246
+ const latestVersion = await getDistributionVersion(pkg.name, distributionTag, registryUrl);
247
+ saveLastUpdate(pkg.name);
248
+ if (semverGt(latestVersion, pkg.version)) {
249
+ return latestVersion;
250
+ }
251
+ if (debug) {
252
+ console.error(`Latest version (${latestVersion}) not newer than current version (${pkg.version})`);
253
+ }
254
+ } else if (debug) {
255
+ console.error(
256
+ `Too recent to check for a new update. simpleUpdateNotifier() interval set to ${String(updateCheckInterval)}ms but only ${String(
257
+ Date.now() - lastUpdateCheck
258
+ )}ms since last check.`
259
+ );
260
+ }
261
+ return void 0;
262
+ };
263
+
264
+ export { hasNewVersion as default };