@visulima/cerebro 3.0.0-alpha.7 → 3.0.0-alpha.8

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