chipctx 0.2.0 → 0.2.2

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -4
package/dist/index.js CHANGED
@@ -1079,4 +1079,4 @@ ${Y}`,_)}});if(_.json)console.log(e({success:!0,authenticated:!0,scope:j.scope,a
1079
1079
  Scope: ${T.scope}
1080
1080
  Expires At: ${T.access_token_expires_at}
1081
1081
  Refresh Token: ${T.refresh_available?"available":"missing"}`,q);return 0}import{spawn as Pg}from"child_process";import{homedir as b4}from"os";import{join as C4}from"path";import{createRequire as Ry}from"module";import{existsSync as CH}from"fs";import{mkdir as Uy,readFile as Fy,writeFile as mH}from"fs/promises";import{dirname as Qy}from"path";var{create:Iy,getPrototypeOf:uy,defineProperty:bH,getOwnPropertyNames:yy}=Object,gy=Object.prototype.hasOwnProperty;function Dy(q){return this[q]}var dy,Ly,ny=(q,_,$)=>{var K=q!=null&&typeof q==="object";if(K){var P=_?dy??=new WeakMap:Ly??=new WeakMap,f=P.get(q);if(f)return f}$=q!=null?Iy(uy(q)):{};let j=_||!q||!q.__esModule?bH($,"default",{value:q,enumerable:!0}):$;for(let Y of yy(q))if(!gy.call(j,Y))bH(j,Y,{get:Dy.bind(q,Y),enumerable:!0});if(K)P.set(q,j);return j},m6=(q,_)=>()=>(_||q((_={exports:{}}).exports,_),_.exports),Rq=Ry(import.meta.url),py=m6((q,_)=>{var $=Rq("constants"),K=process.cwd,P=null,f=process.env.GRACEFUL_FS_PLATFORM||process.platform;process.cwd=function(){if(!P)P=K.call(process);return P};try{process.cwd()}catch(w){}if(typeof process.chdir==="function"){if(j=process.chdir,process.chdir=function(w){P=null,j.call(process,w)},Object.setPrototypeOf)Object.setPrototypeOf(process.chdir,j)}var j;_.exports=Y;function Y(w){if($.hasOwnProperty("O_SYMLINK")&&process.version.match(/^v0\.6\.[0-2]|^v0\.5\./))T(w);if(!w.lutimes)z(w);if(w.chown=O(w.chown),w.fchown=O(w.fchown),w.lchown=O(w.lchown),w.chmod=v(w.chmod),w.fchmod=v(w.fchmod),w.lchmod=v(w.lchmod),w.chownSync=J(w.chownSync),w.fchownSync=J(w.fchownSync),w.lchownSync=J(w.lchownSync),w.chmodSync=W(w.chmodSync),w.fchmodSync=W(w.fchmodSync),w.lchmodSync=W(w.lchmodSync),w.stat=Z(w.stat),w.fstat=Z(w.fstat),w.lstat=Z(w.lstat),w.statSync=A(w.statSync),w.fstatSync=A(w.fstatSync),w.lstatSync=A(w.lstatSync),w.chmod&&!w.lchmod)w.lchmod=function(H,X,k){if(k)process.nextTick(k)},w.lchmodSync=function(){};if(w.chown&&!w.lchown)w.lchown=function(H,X,k,h){if(h)process.nextTick(h)},w.lchownSync=function(){};if(f==="win32")w.rename=typeof w.rename!=="function"?w.rename:function(H){function X(k,h,M){var S=Date.now(),C=0;H(k,h,function N(R){if(R&&(R.code==="EACCES"||R.code==="EPERM"||R.code==="EBUSY")&&Date.now()-S<60000){if(setTimeout(function(){w.stat(h,function(V,I){if(V&&V.code==="ENOENT")H(k,h,N);else M(R)})},C),C<100)C+=10;return}if(M)M(R)})}if(Object.setPrototypeOf)Object.setPrototypeOf(X,H);return X}(w.rename);w.read=typeof w.read!=="function"?w.read:function(H){function X(k,h,M,S,C,N){var R;if(N&&typeof N==="function"){var V=0;R=function(I,l,c){if(I&&I.code==="EAGAIN"&&V<10)return V++,H.call(w,k,h,M,S,C,R);N.apply(this,arguments)}}return H.call(w,k,h,M,S,C,R)}if(Object.setPrototypeOf)Object.setPrototypeOf(X,H);return X}(w.read),w.readSync=typeof w.readSync!=="function"?w.readSync:function(H){return function(X,k,h,M,S){var C=0;while(!0)try{return H.call(w,X,k,h,M,S)}catch(N){if(N.code==="EAGAIN"&&C<10){C++;continue}throw N}}}(w.readSync);function T(H){H.lchmod=function(X,k,h){H.open(X,$.O_WRONLY|$.O_SYMLINK,k,function(M,S){if(M){if(h)h(M);return}H.fchmod(S,k,function(C){H.close(S,function(N){if(h)h(C||N)})})})},H.lchmodSync=function(X,k){var h=H.openSync(X,$.O_WRONLY|$.O_SYMLINK,k),M=!0,S;try{S=H.fchmodSync(h,k),M=!1}finally{if(M)try{H.closeSync(h)}catch(C){}else H.closeSync(h)}return S}}function z(H){if($.hasOwnProperty("O_SYMLINK")&&H.futimes)H.lutimes=function(X,k,h,M){H.open(X,$.O_SYMLINK,function(S,C){if(S){if(M)M(S);return}H.futimes(C,k,h,function(N){H.close(C,function(R){if(M)M(N||R)})})})},H.lutimesSync=function(X,k,h){var M=H.openSync(X,$.O_SYMLINK),S,C=!0;try{S=H.futimesSync(M,k,h),C=!1}finally{if(C)try{H.closeSync(M)}catch(N){}else H.closeSync(M)}return S};else if(H.futimes)H.lutimes=function(X,k,h,M){if(M)process.nextTick(M)},H.lutimesSync=function(){}}function v(H){if(!H)return H;return function(X,k,h){return H.call(w,X,k,function(M){if(G(M))M=null;if(h)h.apply(this,arguments)})}}function W(H){if(!H)return H;return function(X,k){try{return H.call(w,X,k)}catch(h){if(!G(h))throw h}}}function O(H){if(!H)return H;return function(X,k,h,M){return H.call(w,X,k,h,function(S){if(G(S))S=null;if(M)M.apply(this,arguments)})}}function J(H){if(!H)return H;return function(X,k,h){try{return H.call(w,X,k,h)}catch(M){if(!G(M))throw M}}}function Z(H){if(!H)return H;return function(X,k,h){if(typeof k==="function")h=k,k=null;function M(S,C){if(C){if(C.uid<0)C.uid+=4294967296;if(C.gid<0)C.gid+=4294967296}if(h)h.apply(this,arguments)}return k?H.call(w,X,k,M):H.call(w,X,M)}}function A(H){if(!H)return H;return function(X,k){var h=k?H.call(w,X,k):H.call(w,X);if(h){if(h.uid<0)h.uid+=4294967296;if(h.gid<0)h.gid+=4294967296}return h}}function G(H){if(!H)return!0;if(H.code==="ENOSYS")return!0;var X=!process.getuid||process.getuid()!==0;if(X){if(H.code==="EINVAL"||H.code==="EPERM")return!0}return!1}}}),ly=m6((q,_)=>{var $=Rq("stream").Stream;_.exports=K;function K(P){return{ReadStream:f,WriteStream:j};function f(Y,w){if(!(this instanceof f))return new f(Y,w);$.call(this);var T=this;this.path=Y,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=65536,w=w||{};var z=Object.keys(w);for(var v=0,W=z.length;v<W;v++){var O=z[v];this[O]=w[O]}if(this.encoding)this.setEncoding(this.encoding);if(this.start!==void 0){if(typeof this.start!=="number")throw TypeError("start must be a Number");if(this.end===void 0)this.end=1/0;else if(typeof this.end!=="number")throw TypeError("end must be a Number");if(this.start>this.end)throw Error("start must be <= end");this.pos=this.start}if(this.fd!==null){process.nextTick(function(){T._read()});return}P.open(this.path,this.flags,this.mode,function(J,Z){if(J){T.emit("error",J),T.readable=!1;return}T.fd=Z,T.emit("open",Z),T._read()})}function j(Y,w){if(!(this instanceof j))return new j(Y,w);$.call(this),this.path=Y,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,w=w||{};var T=Object.keys(w);for(var z=0,v=T.length;z<v;z++){var W=T[z];this[W]=w[W]}if(this.start!==void 0){if(typeof this.start!=="number")throw TypeError("start must be a Number");if(this.start<0)throw Error("start must be >= zero");this.pos=this.start}if(this.busy=!1,this._queue=[],this.fd===null)this._open=P.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush()}}}),xy=m6((q,_)=>{_.exports=K;var $=Object.getPrototypeOf||function(P){return P.__proto__};function K(P){if(P===null||typeof P!=="object")return P;if(P instanceof Object)var f={__proto__:$(P)};else var f=Object.create(null);return Object.getOwnPropertyNames(P).forEach(function(j){Object.defineProperty(f,j,Object.getOwnPropertyDescriptor(P,j))}),f}}),EH=m6((q,_)=>{var $=Rq("fs"),K=py(),P=ly(),f=xy(),j=Rq("util"),Y,w;if(typeof Symbol==="function"&&typeof Symbol.for==="function")Y=Symbol.for("graceful-fs.queue"),w=Symbol.for("graceful-fs.previous");else Y="___graceful-fs.queue",w="___graceful-fs.previous";function T(){}function z(H,X){Object.defineProperty(H,Y,{get:function(){return X}})}var v=T;if(j.debuglog)v=j.debuglog("gfs4");else if(/\bgfs4\b/i.test(process.env.NODE_DEBUG||""))v=function(){var H=j.format.apply(j,arguments);H="GFS4: "+H.split(/\n/).join(`
1082
- GFS4: `),console.error(H)};if(!$[Y]){if(W=global[Y]||[],z($,W),$.close=function(H){function X(k,h){return H.call($,k,function(M){if(!M)A();if(typeof h==="function")h.apply(this,arguments)})}return Object.defineProperty(X,w,{value:H}),X}($.close),$.closeSync=function(H){function X(k){H.apply($,arguments),A()}return Object.defineProperty(X,w,{value:H}),X}($.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||""))process.on("exit",function(){v($[Y]),Rq("assert").equal($[Y].length,0)})}var W;if(!global[Y])z(global,$[Y]);if(_.exports=O(f($)),process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!$.__patched)_.exports=O($),$.__patched=!0;function O(H){K(H),H.gracefulify=O,H.createReadStream=P6,H.createWriteStream=s8;var X=H.readFile;H.readFile=k;function k(t,U,s){if(typeof U==="function")s=U,U=null;return D8(t,U,s);function D8(d8,A8,j8,z8){return X(d8,A8,function(d){if(d&&(d.code==="EMFILE"||d.code==="ENFILE"))J([D8,[d8,A8,j8],d,z8||Date.now(),Date.now()]);else if(typeof j8==="function")j8.apply(this,arguments)})}}var h=H.writeFile;H.writeFile=M;function M(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return h(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var S=H.appendFile;if(S)H.appendFile=C;function C(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return S(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var N=H.copyFile;if(N)H.copyFile=R;function R(t,U,s,D8){if(typeof s==="function")D8=s,s=0;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return N(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var V=H.readdir;H.readdir=l;var I=/^v[0-5]\./;function l(t,U,s){if(typeof U==="function")s=U,U=null;var D8=I.test(process.version)?function(j8,z8,d,x){return V(j8,d8(j8,z8,d,x))}:function(j8,z8,d,x){return V(j8,z8,d8(j8,z8,d,x))};return D8(t,U,s);function d8(A8,j8,z8,d){return function(x,r){if(x&&(x.code==="EMFILE"||x.code==="ENFILE"))J([D8,[A8,j8,z8],x,d||Date.now(),Date.now()]);else{if(r&&r.sort)r.sort();if(typeof z8==="function")z8.call(this,x,r)}}}}if(process.version.substr(0,4)==="v0.8"){var c=P(H);n=c.ReadStream,F=c.WriteStream}var b=H.ReadStream;if(b)n.prototype=Object.create(b.prototype),n.prototype.open=a;var y=H.WriteStream;if(y)F.prototype=Object.create(y.prototype),F.prototype.open=e8;Object.defineProperty(H,"ReadStream",{get:function(){return n},set:function(t){n=t},enumerable:!0,configurable:!0}),Object.defineProperty(H,"WriteStream",{get:function(){return F},set:function(t){F=t},enumerable:!0,configurable:!0});var L=n;Object.defineProperty(H,"FileReadStream",{get:function(){return L},set:function(t){L=t},enumerable:!0,configurable:!0});var w8=F;Object.defineProperty(H,"FileWriteStream",{get:function(){return w8},set:function(t){w8=t},enumerable:!0,configurable:!0});function n(t,U){if(this instanceof n)return b.apply(this,arguments),this;else return n.apply(Object.create(n.prototype),arguments)}function a(){var t=this;r8(t.path,t.flags,t.mode,function(U,s){if(U){if(t.autoClose)t.destroy();t.emit("error",U)}else t.fd=s,t.emit("open",s),t.read()})}function F(t,U){if(this instanceof F)return y.apply(this,arguments),this;else return F.apply(Object.create(F.prototype),arguments)}function e8(){var t=this;r8(t.path,t.flags,t.mode,function(U,s){if(U)t.destroy(),t.emit("error",U);else t.fd=s,t.emit("open",s)})}function P6(t,U){return new H.ReadStream(t,U)}function s8(t,U){return new H.WriteStream(t,U)}var hq=H.open;H.open=r8;function r8(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return hq(A8,j8,z8,function(r,c8){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}return H}function J(H){v("ENQUEUE",H[0].name,H[1]),$[Y].push(H),G()}var Z;function A(){var H=Date.now();for(var X=0;X<$[Y].length;++X)if($[Y][X].length>2)$[Y][X][3]=H,$[Y][X][4]=H;G()}function G(){if(clearTimeout(Z),Z=void 0,$[Y].length===0)return;var H=$[Y].shift(),X=H[0],k=H[1],h=H[2],M=H[3],S=H[4];if(M===void 0)v("RETRY",X.name,k),X.apply(null,k);else if(Date.now()-M>=60000){v("TIMEOUT",X.name,k);var C=k.pop();if(typeof C==="function")C.call(null,h)}else{var N=Date.now()-S,R=Math.max(S-M,1),V=Math.min(R*1.2,100);if(N>=V)v("RETRY",X.name,k),X.apply(null,k.concat([M]));else $[Y].push(H)}if(Z===void 0)Z=setTimeout(G,0)}}),ry=m6((q,_)=>{function $(K,P){if(typeof P==="boolean")P={forever:P};if(this._originalTimeouts=JSON.parse(JSON.stringify(K)),this._timeouts=K,this._options=P||{},this._maxRetryTime=P&&P.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever)this._cachedTimeouts=this._timeouts.slice(0)}_.exports=$,$.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},$.prototype.stop=function(){if(this._timeout)clearTimeout(this._timeout);this._timeouts=[],this._cachedTimeouts=null},$.prototype.retry=function(K){if(this._timeout)clearTimeout(this._timeout);if(!K)return!1;var P=new Date().getTime();if(K&&P-this._operationStart>=this._maxRetryTime)return this._errors.unshift(Error("RetryOperation timeout occurred")),!1;this._errors.push(K);var f=this._timeouts.shift();if(f===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),f=this._timeouts.shift();else return!1;var j=this,Y=setTimeout(function(){if(j._attempts++,j._operationTimeoutCb){if(j._timeout=setTimeout(function(){j._operationTimeoutCb(j._attempts)},j._operationTimeout),j._options.unref)j._timeout.unref()}j._fn(j._attempts)},f);if(this._options.unref)Y.unref();return!0},$.prototype.attempt=function(K,P){if(this._fn=K,P){if(P.timeout)this._operationTimeout=P.timeout;if(P.cb)this._operationTimeoutCb=P.cb}var f=this;if(this._operationTimeoutCb)this._timeout=setTimeout(function(){f._operationTimeoutCb()},f._operationTimeout);this._operationStart=new Date().getTime(),this._fn(this._attempts)},$.prototype.try=function(K){console.log("Using RetryOperation.try() is deprecated"),this.attempt(K)},$.prototype.start=function(K){console.log("Using RetryOperation.start() is deprecated"),this.attempt(K)},$.prototype.start=$.prototype.try,$.prototype.errors=function(){return this._errors},$.prototype.attempts=function(){return this._attempts},$.prototype.mainError=function(){if(this._errors.length===0)return null;var K={},P=null,f=0;for(var j=0;j<this._errors.length;j++){var Y=this._errors[j],w=Y.message,T=(K[w]||0)+1;if(K[w]=T,T>=f)P=Y,f=T}return P}}),cy=m6((q)=>{var _=ry();q.operation=function($){var K=q.timeouts($);return new _(K,{forever:$&&$.forever,unref:$&&$.unref,maxRetryTime:$&&$.maxRetryTime})},q.timeouts=function($){if($ instanceof Array)return[].concat($);var K={retries:10,factor:2,minTimeout:1000,maxTimeout:1/0,randomize:!1};for(var P in $)K[P]=$[P];if(K.minTimeout>K.maxTimeout)throw Error("minTimeout is greater than maxTimeout");var f=[];for(var j=0;j<K.retries;j++)f.push(this.createTimeout(j,K));if($&&$.forever&&!f.length)f.push(this.createTimeout(j,K));return f.sort(function(Y,w){return Y-w}),f},q.createTimeout=function($,K){var P=K.randomize?Math.random()+1:1,f=Math.round(P*K.minTimeout*Math.pow(K.factor,$));return f=Math.min(f,K.maxTimeout),f},q.wrap=function($,K,P){if(K instanceof Array)P=K,K=null;if(!P){P=[];for(var f in $)if(typeof $[f]==="function")P.push(f)}for(var j=0;j<P.length;j++){var Y=P[j],w=$[Y];$[Y]=function(z){var v=q.operation(K),W=Array.prototype.slice.call(arguments,1),O=W.pop();W.push(function(J){if(v.retry(J))return;if(J)arguments[0]=v.mainError();O.apply(this,arguments)}),v.attempt(function(){z.apply($,W)})}.bind($,w),$[Y].options=K}}}),iy=m6((q,_)=>{if(_.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],process.platform!=="win32")_.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(process.platform==="linux")_.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}),ay=m6((q,_)=>{var $=global.process,K=function(H){return H&&typeof H==="object"&&typeof H.removeListener==="function"&&typeof H.emit==="function"&&typeof H.reallyExit==="function"&&typeof H.listeners==="function"&&typeof H.kill==="function"&&typeof H.pid==="number"&&typeof H.on==="function"};if(!K($))_.exports=function(){return function(){}};else{if(P=Rq("assert"),f=iy(),j=/^win/i.test($.platform),Y=Rq("events"),typeof Y!=="function")Y=Y.EventEmitter;if($.__signal_exit_emitter__)w=$.__signal_exit_emitter__;else w=$.__signal_exit_emitter__=new Y,w.count=0,w.emitted={};if(!w.infinite)w.setMaxListeners(1/0),w.infinite=!0;_.exports=function(H,X){if(!K(global.process))return function(){};if(P.equal(typeof H,"function","a callback must be provided for exit handler"),W===!1)O();var k="exit";if(X&&X.alwaysLast)k="afterexit";var h=function(){if(w.removeListener(k,H),w.listeners("exit").length===0&&w.listeners("afterexit").length===0)T()};return w.on(k,H),h},T=function(){if(!W||!K(global.process))return;W=!1,f.forEach(function(X){try{$.removeListener(X,v[X])}catch(k){}}),$.emit=A,$.reallyExit=J,w.count-=1},_.exports.unload=T,z=function(X,k,h){if(w.emitted[X])return;w.emitted[X]=!0,w.emit(X,k,h)},v={},f.forEach(function(H){v[H]=function(){if(!K(global.process))return;var k=$.listeners(H);if(k.length===w.count){if(T(),z("exit",null,H),z("afterexit",null,H),j&&H==="SIGHUP")H="SIGINT";$.kill($.pid,H)}}}),_.exports.signals=function(){return f},W=!1,O=function(){if(W||!K(global.process))return;W=!0,w.count+=1,f=f.filter(function(X){try{return $.on(X,v[X]),!0}catch(k){return!1}}),$.emit=G,$.reallyExit=Z},_.exports.load=O,J=$.reallyExit,Z=function(X){if(!K(global.process))return;$.exitCode=X||0,z("exit",$.exitCode,null),z("afterexit",$.exitCode,null),J.call($,$.exitCode)},A=$.emit,G=function(X,k){if(X==="exit"&&K(global.process)){if(k!==void 0)$.exitCode=k;var h=A.apply(this,arguments);return z("exit",$.exitCode,null),z("afterexit",$.exitCode,null),h}else return A.apply(this,arguments)}}var P,f,j,Y,w,T,z,v,W,O,J,Z,A,G}),oy=m6((q,_)=>{var $=Symbol();function K(f,j,Y){let w=j[$];if(w)return j.stat(f,(z,v)=>{if(z)return Y(z);Y(null,v.mtime,w)});let T=new Date(Math.ceil(Date.now()/1000)*1000+5);j.utimes(f,T,T,(z)=>{if(z)return Y(z);j.stat(f,(v,W)=>{if(v)return Y(v);let O=W.mtime.getTime()%1000===0?"s":"ms";Object.defineProperty(j,$,{value:O}),Y(null,W.mtime,O)})})}function P(f){let j=Date.now();if(f==="s")j=Math.ceil(j/1000)*1000;return new Date(j)}q.probe=K,q.getMtime=P}),ty=m6((q,_)=>{var $=Rq("path"),K=EH(),P=cy(),f=ay(),j=oy(),Y={};function w(X,k){return k.lockfilePath||`${X}.lock`}function T(X,k,h){if(!k.realpath)return h(null,$.resolve(X));k.fs.realpath(X,h)}function z(X,k,h){let M=w(X,k);k.fs.mkdir(M,(S)=>{if(!S)return j.probe(M,k.fs,(C,N,R)=>{if(C)return k.fs.rmdir(M,()=>{}),h(C);h(null,N,R)});if(S.code!=="EEXIST")return h(S);if(k.stale<=0)return h(Object.assign(Error("Lock file is already being held"),{code:"ELOCKED",file:X}));k.fs.stat(M,(C,N)=>{if(C){if(C.code==="ENOENT")return z(X,{...k,stale:0},h);return h(C)}if(!v(N,k))return h(Object.assign(Error("Lock file is already being held"),{code:"ELOCKED",file:X}));W(X,k,(R)=>{if(R)return h(R);z(X,{...k,stale:0},h)})})})}function v(X,k){return X.mtime.getTime()<Date.now()-k.stale}function W(X,k,h){k.fs.rmdir(w(X,k),(M)=>{if(M&&M.code!=="ENOENT")return h(M);h()})}function O(X,k){let h=Y[X];if(h.updateTimeout)return;if(h.updateDelay=h.updateDelay||k.update,h.updateTimeout=setTimeout(()=>{h.updateTimeout=null,k.fs.stat(h.lockfilePath,(M,S)=>{let C=h.lastUpdate+k.stale<Date.now();if(M){if(M.code==="ENOENT"||C)return J(X,h,Object.assign(M,{code:"ECOMPROMISED"}));return h.updateDelay=1000,O(X,k)}if(h.mtime.getTime()!==S.mtime.getTime())return J(X,h,Object.assign(Error("Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"}));let R=j.getMtime(h.mtimePrecision);k.fs.utimes(h.lockfilePath,R,R,(V)=>{let I=h.lastUpdate+k.stale<Date.now();if(h.released)return;if(V){if(V.code==="ENOENT"||I)return J(X,h,Object.assign(V,{code:"ECOMPROMISED"}));return h.updateDelay=1000,O(X,k)}h.mtime=R,h.lastUpdate=Date.now(),h.updateDelay=null,O(X,k)})})},h.updateDelay),h.updateTimeout.unref)h.updateTimeout.unref()}function J(X,k,h){if(k.released=!0,k.updateTimeout)clearTimeout(k.updateTimeout);if(Y[X]===k)delete Y[X];k.options.onCompromised(h)}function Z(X,k,h){k={stale:1e4,update:null,realpath:!0,retries:0,fs:K,onCompromised:(M)=>{throw M},...k},k.retries=k.retries||0,k.retries=typeof k.retries==="number"?{retries:k.retries}:k.retries,k.stale=Math.max(k.stale||0,2000),k.update=k.update==null?k.stale/2:k.update||0,k.update=Math.max(Math.min(k.update,k.stale/2),1000),T(X,k,(M,S)=>{if(M)return h(M);let C=P.operation(k.retries);C.attempt(()=>{z(S,k,(N,R,V)=>{if(C.retry(N))return;if(N)return h(C.mainError());let I=Y[S]={lockfilePath:w(S,k),mtime:R,mtimePrecision:V,options:k,lastUpdate:Date.now()};O(S,k),h(null,(l)=>{if(I.released)return l&&l(Object.assign(Error("Lock is already released"),{code:"ERELEASED"}));A(S,{...k,realpath:!1},l)})})})})}function A(X,k,h){k={fs:K,realpath:!0,...k},T(X,k,(M,S)=>{if(M)return h(M);let C=Y[S];if(!C)return h(Object.assign(Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));C.updateTimeout&&clearTimeout(C.updateTimeout),C.released=!0,delete Y[S],W(S,k,h)})}function G(X,k,h){k={stale:1e4,realpath:!0,fs:K,...k},k.stale=Math.max(k.stale||0,2000),T(X,k,(M,S)=>{if(M)return h(M);k.fs.stat(w(S,k),(C,N)=>{if(C)return C.code==="ENOENT"?h(null,!1):h(C);return h(null,!v(N,k))})})}function H(){return Y}f(()=>{for(let X in Y){let k=Y[X].options;try{k.fs.rmdirSync(w(X,k))}catch(h){}}}),q.lock=Z,q.unlock=A,q.check=G,q.getLocks=H}),ey=m6((q,_)=>{var $=EH();function K(Y){let w=["mkdir","realpath","stat","rmdir","utimes"],T={...Y};return w.forEach((z)=>{T[z]=(...v)=>{let W=v.pop(),O;try{O=Y[`${z}Sync`](...v)}catch(J){return W(J)}W(null,O)}}),T}function P(Y){return(...w)=>new Promise((T,z)=>{w.push((v,W)=>{if(v)z(v);else T(W)}),Y(...w)})}function f(Y){return(...w)=>{let T,z;if(w.push((v,W)=>{T=v,z=W}),Y(...w),T)throw T;return z}}function j(Y){if(Y={...Y},Y.fs=K(Y.fs||$),typeof Y.retries==="number"&&Y.retries>0||Y.retries&&typeof Y.retries.retries==="number"&&Y.retries.retries>0)throw Object.assign(Error("Cannot use retries with the sync api"),{code:"ESYNC"});return Y}_.exports={toPromise:P,toSync:f,toSyncOptions:j}}),By=m6((q,_)=>{var $=ty(),{toPromise:K,toSync:P,toSyncOptions:f}=ey();async function j(W,O){let J=await K($.lock)(W,O);return K(J)}function Y(W,O){let J=P($.lock)(W,f(O));return P(J)}function w(W,O){return K($.unlock)(W,O)}function T(W,O){return P($.unlock)(W,f(O))}function z(W,O){return K($.check)(W,O)}function v(W,O){return P($.check)(W,f(O))}_.exports=j,_.exports.lock=j,_.exports.unlock=w,_.exports.lockSync=Y,_.exports.unlockSync=T,_.exports.check=z,_.exports.checkSync=v}),sy=ny(By(),1);class $P{path;constructor(q){this.path=q}async load(){if(!CH(this.path))return null;try{let q=await Fy(this.path,"utf8"),_=JSON.parse(q);if(_&&_.version===1)return _;return null}catch{return null}}async save(q){if(await Uy(Qy(this.path),{recursive:!0}),!CH(this.path))await mH(this.path,"{}");let _=async()=>{};try{_=await sy.default.lock(this.path,{retries:{retries:3,minTimeout:50,maxTimeout:200}}),await mH(this.path,JSON.stringify(q,null,2))}finally{try{await _()}catch{}}}async markPrompted(q,_){let $=await this.load();if(!$)return;$.last_prompted_by_target[q]=_,await this.save($)}}class m1{baseUrl;app;channel;constructor(q,_,$="stable"){this.baseUrl=q,this.app=_,this.channel=$}async query(q){let _=new URL(`/v1/packages/${this.app}/version`,this.baseUrl);_.searchParams.set("current",q.current),_.searchParams.set("os",q.os),_.searchParams.set("arch",q.arch),_.searchParams.set("channel",this.channel);let $=await fetch(_.toString(),{method:"GET",headers:{"User-Agent":q.userAgent,Accept:"application/json"},signal:q.signal});if(!$.ok)throw Error(`version query failed: ${$.status}`);return await $.json()}}var qg=86400000;class KP{adapter;cache;timeoutMs;task=null;constructor(q){this.adapter=q.adapter,this.cache=q.cache,this.timeoutMs=q.timeoutMs??5000}init(){if(this.task)return this.task;return this.task=new Promise((q)=>{queueMicrotask(()=>{this.runRefresh().catch(()=>{return}).finally(()=>q())})}),this.task}async runRefresh(){let q=await this.cache.load();if(q&&q.ttl_expires_at>Date.now()&&q.severity!=="critical")return;let _=new m1(this.adapter.baseUrl,this.adapter.app_id,this.adapter.channel),$=new AbortController,K=setTimeout(()=>$.abort(),this.timeoutMs);try{let P=await _.query({current:this.adapter.currentVersion(),os:this.adapter.os(),arch:this.adapter.arch(),userAgent:`${this.adapter.app_id}-cli/${this.adapter.currentVersion()} ${this.adapter.os()}-${this.adapter.arch()}`,signal:$.signal}),f=Date.now(),j={version:1,app:this.adapter.app_id,current:this.adapter.currentVersion(),last_check_at:f,ttl_expires_at:f+qg,latest:P.latest,min_required:P.min_required,severity:P.severity,dist_type:P.dist_type,dist:P.dist,last_prompted_by_target:q?.last_prompted_by_target??{}};await this.cache.save(j)}finally{clearTimeout(K)}}}function RH(q){let _=q.spawn;return{async run({dist:$}){let K=await _(["npm",["i","-g",`${$.package}@${$.version}`]]);if(K.exitCode!==0)throw Error(`npm install failed (${K.exitCode}): ${K.stderr}`);await q.writeLastInstalled($.version)},async rollback(){let $=q.readLastInstalled?await q.readLastInstalled():null;if(!$)throw Error("rollback not available: last installed version unknown");if(!q.packageName)throw Error("rollback requires packageName in NpmRunDeps");let K=await _(["npm",["i","-g",`${q.packageName}@${$}`]]);if(K.exitCode!==0)throw Error(`npm rollback failed (${K.exitCode}): ${K.stderr}`)}}}X4();var S4={name:"chipctx",version:"0.2.0",description:"CLI tool for CMSIS-based embedded project development",type:"module",bin:{chipctx:"./bin/chipctx.js","chipctx-gen":"./bin/chipctx-gen.js"},files:["dist/","bin/"],engines:{node:">=20.12.0"},publishConfig:{access:"public"},scripts:{dev:"bun run src/index.ts",build:"bun run scripts/build.ts",deploy:"bun run scripts/deploy-cli.ts",prepublishOnly:"bun run build",test:"bun test","type-check":"tsc --noEmit -p tsconfig.typecheck.json",lint:"biome check src/ tests/",format:"biome format --write src/ tests/"},dependencies:{"@chipctx/cli-updater":"link:@chipctx/cli-updater"},devDependencies:{"@biomejs/biome":"^1.9.4","@iarna/toml":"^2.2.5","@inquirer/prompts":"^8.3.2","@types/bun":"^1.2.0",chalk:"^5.4.1",commander:"^13.1.0","fast-xml-parser":"^5.2.0",handlebars:"^4.7.8"}};function $g(){return process.platform==="darwin"?"darwin":process.platform==="win32"?"win32":"linux"}function Kg(){return process.arch==="arm64"?"arm64":"x64"}function IH(q){return{app_id:"chipctx",channel:"stable",currentVersion:q.currentVersion,os:$g,arch:Kg,isNonInteractive:q.nonInteractive,runnerBackend:"npm",baseUrl:q.baseUrl,confirmUpgrade:q.confirmUpgrade}}async function fg(q){if(q.mode==="rollback")return await q.rollback(),q.print("rollback complete"),0;let _=await q.queryVersion();if(q.mode==="check"){if(q.print(`current ${q.currentVersion}, latest ${_.latest}, severity ${_.severity}`),_.severity==="critical")return 20;if(_.severity==="recommended")return 10;return 0}if(_.severity==="none"&&q.mode!=="force")return q.print("already at latest"),0;return await q.runUpgrade(_.latest),q.print(`upgraded to ${_.latest}`),0}function uH(){return IH({baseUrl:process.env.CHIPCTX_BASE_URL??"https://chipctx.com",currentVersion:()=>S4.version,nonInteractive:()=>Boolean(process.env.CI||process.env.CHIPCTX_NON_INTERACTIVE)||!process.stdout.isTTY,confirmUpgrade:async({target:q,current:_})=>X1({message:`Upgrade chipctx from ${_} to ${q}?`,default:!0})})}function yH(){return new q8("update").description("Check and apply chipctx updates").option("--check","Only check, do not upgrade").option("--force","Force re-install").option("--rollback","Install the previous version").action(async(q)=>{let _=uH(),$=new m1(_.baseUrl,"chipctx","stable"),K=q.rollback?"rollback":q.check?"check":q.force?"force":"run",P=RH({spawn:async([j,Y])=>await new Promise((w)=>{Pg(j,Y,{stdio:"inherit"}).on("exit",(z)=>w({exitCode:z??0,stdout:"",stderr:""}))}),lastInstalledFile:C4(b4(),".chipctx","last-installed.txt"),writeLastInstalled:async(j)=>{let{writeFile:Y,mkdir:w}=await import("fs/promises");await w(C4(b4(),".chipctx"),{recursive:!0}),await Y(C4(b4(),".chipctx","last-installed.txt"),j)},readLastInstalled:async()=>{let{readFile:j}=await import("fs/promises");try{return(await j(C4(b4(),".chipctx","last-installed.txt"),"utf8")).trim()}catch{return null}},packageName:"chipctx"}),f=await fg({mode:K,currentVersion:S4.version,queryVersion:()=>$.query({current:S4.version,os:_.os(),arch:_.arch(),userAgent:`chipctx-cli/${S4.version} ${_.os()}-${_.arch()}`}),runUpgrade:async(j)=>{await P.run({target:j,dist:{package:"chipctx",version:j,registry:"https://registry.npmjs.org"}})},rollback:()=>P.rollback(),print:(j)=>console.log(j)});process.exit(f)})}function gH(){try{let q=new $P(C4(b4(),".chipctx","update-state.json")),_=uH();new KP({adapter:_,cache:q,timeoutMs:5000}).init().catch(()=>{})}catch{}}function jg(){return I4()}function Yg(){let q=new q8;return q.name("chipctx").description("CLI tool for CMSIS-based embedded project development").version(jg()).option("--config <path>","Path to config file (default: ~/.chipctx/config.toml)").option("--api-url <url>","Override backend API URL").option("--no-color","Disable colored output").option("--json","Output in JSON format").option("-v, --verbose","Enable verbose debug logging"),q.hook("preAction",(_,$)=>{let K=$.optsWithGlobals();mP(Boolean(K.verbose))}),q.addCommand(Zf()),q.addCommand(gO()),q.addCommand(IO()),q.addCommand(ET()),q.addCommand(aT()),q.addCommand(QO()),q.addCommand(sO()),q.addCommand(qH()),q.addCommand($H()),q.addCommand(KH()),q.addCommand(TH()),q.addCommand(BO()),q.addCommand(VH()),q.addCommand(MH()),q.addCommand(NH()),q.addCommand(SH()),q.addCommand(yH()),q}if(import.meta.main)gH(),Yg().parse();export{jg as resolveCliVersion,Yg as createProgram};
1082
+ GFS4: `),console.error(H)};if(!$[Y]){if(W=global[Y]||[],z($,W),$.close=function(H){function X(k,h){return H.call($,k,function(M){if(!M)A();if(typeof h==="function")h.apply(this,arguments)})}return Object.defineProperty(X,w,{value:H}),X}($.close),$.closeSync=function(H){function X(k){H.apply($,arguments),A()}return Object.defineProperty(X,w,{value:H}),X}($.closeSync),/\bgfs4\b/i.test(process.env.NODE_DEBUG||""))process.on("exit",function(){v($[Y]),Rq("assert").equal($[Y].length,0)})}var W;if(!global[Y])z(global,$[Y]);if(_.exports=O(f($)),process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH&&!$.__patched)_.exports=O($),$.__patched=!0;function O(H){K(H),H.gracefulify=O,H.createReadStream=P6,H.createWriteStream=s8;var X=H.readFile;H.readFile=k;function k(t,U,s){if(typeof U==="function")s=U,U=null;return D8(t,U,s);function D8(d8,A8,j8,z8){return X(d8,A8,function(d){if(d&&(d.code==="EMFILE"||d.code==="ENFILE"))J([D8,[d8,A8,j8],d,z8||Date.now(),Date.now()]);else if(typeof j8==="function")j8.apply(this,arguments)})}}var h=H.writeFile;H.writeFile=M;function M(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return h(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var S=H.appendFile;if(S)H.appendFile=C;function C(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return S(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var N=H.copyFile;if(N)H.copyFile=R;function R(t,U,s,D8){if(typeof s==="function")D8=s,s=0;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return N(A8,j8,z8,function(r){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}var V=H.readdir;H.readdir=l;var I=/^v[0-5]\./;function l(t,U,s){if(typeof U==="function")s=U,U=null;var D8=I.test(process.version)?function(j8,z8,d,x){return V(j8,d8(j8,z8,d,x))}:function(j8,z8,d,x){return V(j8,z8,d8(j8,z8,d,x))};return D8(t,U,s);function d8(A8,j8,z8,d){return function(x,r){if(x&&(x.code==="EMFILE"||x.code==="ENFILE"))J([D8,[A8,j8,z8],x,d||Date.now(),Date.now()]);else{if(r&&r.sort)r.sort();if(typeof z8==="function")z8.call(this,x,r)}}}}if(process.version.substr(0,4)==="v0.8"){var c=P(H);n=c.ReadStream,F=c.WriteStream}var b=H.ReadStream;if(b)n.prototype=Object.create(b.prototype),n.prototype.open=a;var y=H.WriteStream;if(y)F.prototype=Object.create(y.prototype),F.prototype.open=e8;Object.defineProperty(H,"ReadStream",{get:function(){return n},set:function(t){n=t},enumerable:!0,configurable:!0}),Object.defineProperty(H,"WriteStream",{get:function(){return F},set:function(t){F=t},enumerable:!0,configurable:!0});var L=n;Object.defineProperty(H,"FileReadStream",{get:function(){return L},set:function(t){L=t},enumerable:!0,configurable:!0});var w8=F;Object.defineProperty(H,"FileWriteStream",{get:function(){return w8},set:function(t){w8=t},enumerable:!0,configurable:!0});function n(t,U){if(this instanceof n)return b.apply(this,arguments),this;else return n.apply(Object.create(n.prototype),arguments)}function a(){var t=this;r8(t.path,t.flags,t.mode,function(U,s){if(U){if(t.autoClose)t.destroy();t.emit("error",U)}else t.fd=s,t.emit("open",s),t.read()})}function F(t,U){if(this instanceof F)return y.apply(this,arguments),this;else return F.apply(Object.create(F.prototype),arguments)}function e8(){var t=this;r8(t.path,t.flags,t.mode,function(U,s){if(U)t.destroy(),t.emit("error",U);else t.fd=s,t.emit("open",s)})}function P6(t,U){return new H.ReadStream(t,U)}function s8(t,U){return new H.WriteStream(t,U)}var hq=H.open;H.open=r8;function r8(t,U,s,D8){if(typeof s==="function")D8=s,s=null;return d8(t,U,s,D8);function d8(A8,j8,z8,d,x){return hq(A8,j8,z8,function(r,c8){if(r&&(r.code==="EMFILE"||r.code==="ENFILE"))J([d8,[A8,j8,z8,d],r,x||Date.now(),Date.now()]);else if(typeof d==="function")d.apply(this,arguments)})}}return H}function J(H){v("ENQUEUE",H[0].name,H[1]),$[Y].push(H),G()}var Z;function A(){var H=Date.now();for(var X=0;X<$[Y].length;++X)if($[Y][X].length>2)$[Y][X][3]=H,$[Y][X][4]=H;G()}function G(){if(clearTimeout(Z),Z=void 0,$[Y].length===0)return;var H=$[Y].shift(),X=H[0],k=H[1],h=H[2],M=H[3],S=H[4];if(M===void 0)v("RETRY",X.name,k),X.apply(null,k);else if(Date.now()-M>=60000){v("TIMEOUT",X.name,k);var C=k.pop();if(typeof C==="function")C.call(null,h)}else{var N=Date.now()-S,R=Math.max(S-M,1),V=Math.min(R*1.2,100);if(N>=V)v("RETRY",X.name,k),X.apply(null,k.concat([M]));else $[Y].push(H)}if(Z===void 0)Z=setTimeout(G,0)}}),ry=m6((q,_)=>{function $(K,P){if(typeof P==="boolean")P={forever:P};if(this._originalTimeouts=JSON.parse(JSON.stringify(K)),this._timeouts=K,this._options=P||{},this._maxRetryTime=P&&P.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._options.forever)this._cachedTimeouts=this._timeouts.slice(0)}_.exports=$,$.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts},$.prototype.stop=function(){if(this._timeout)clearTimeout(this._timeout);this._timeouts=[],this._cachedTimeouts=null},$.prototype.retry=function(K){if(this._timeout)clearTimeout(this._timeout);if(!K)return!1;var P=new Date().getTime();if(K&&P-this._operationStart>=this._maxRetryTime)return this._errors.unshift(Error("RetryOperation timeout occurred")),!1;this._errors.push(K);var f=this._timeouts.shift();if(f===void 0)if(this._cachedTimeouts)this._errors.splice(this._errors.length-1,this._errors.length),this._timeouts=this._cachedTimeouts.slice(0),f=this._timeouts.shift();else return!1;var j=this,Y=setTimeout(function(){if(j._attempts++,j._operationTimeoutCb){if(j._timeout=setTimeout(function(){j._operationTimeoutCb(j._attempts)},j._operationTimeout),j._options.unref)j._timeout.unref()}j._fn(j._attempts)},f);if(this._options.unref)Y.unref();return!0},$.prototype.attempt=function(K,P){if(this._fn=K,P){if(P.timeout)this._operationTimeout=P.timeout;if(P.cb)this._operationTimeoutCb=P.cb}var f=this;if(this._operationTimeoutCb)this._timeout=setTimeout(function(){f._operationTimeoutCb()},f._operationTimeout);this._operationStart=new Date().getTime(),this._fn(this._attempts)},$.prototype.try=function(K){console.log("Using RetryOperation.try() is deprecated"),this.attempt(K)},$.prototype.start=function(K){console.log("Using RetryOperation.start() is deprecated"),this.attempt(K)},$.prototype.start=$.prototype.try,$.prototype.errors=function(){return this._errors},$.prototype.attempts=function(){return this._attempts},$.prototype.mainError=function(){if(this._errors.length===0)return null;var K={},P=null,f=0;for(var j=0;j<this._errors.length;j++){var Y=this._errors[j],w=Y.message,T=(K[w]||0)+1;if(K[w]=T,T>=f)P=Y,f=T}return P}}),cy=m6((q)=>{var _=ry();q.operation=function($){var K=q.timeouts($);return new _(K,{forever:$&&$.forever,unref:$&&$.unref,maxRetryTime:$&&$.maxRetryTime})},q.timeouts=function($){if($ instanceof Array)return[].concat($);var K={retries:10,factor:2,minTimeout:1000,maxTimeout:1/0,randomize:!1};for(var P in $)K[P]=$[P];if(K.minTimeout>K.maxTimeout)throw Error("minTimeout is greater than maxTimeout");var f=[];for(var j=0;j<K.retries;j++)f.push(this.createTimeout(j,K));if($&&$.forever&&!f.length)f.push(this.createTimeout(j,K));return f.sort(function(Y,w){return Y-w}),f},q.createTimeout=function($,K){var P=K.randomize?Math.random()+1:1,f=Math.round(P*K.minTimeout*Math.pow(K.factor,$));return f=Math.min(f,K.maxTimeout),f},q.wrap=function($,K,P){if(K instanceof Array)P=K,K=null;if(!P){P=[];for(var f in $)if(typeof $[f]==="function")P.push(f)}for(var j=0;j<P.length;j++){var Y=P[j],w=$[Y];$[Y]=function(z){var v=q.operation(K),W=Array.prototype.slice.call(arguments,1),O=W.pop();W.push(function(J){if(v.retry(J))return;if(J)arguments[0]=v.mainError();O.apply(this,arguments)}),v.attempt(function(){z.apply($,W)})}.bind($,w),$[Y].options=K}}}),iy=m6((q,_)=>{if(_.exports=["SIGABRT","SIGALRM","SIGHUP","SIGINT","SIGTERM"],process.platform!=="win32")_.exports.push("SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");if(process.platform==="linux")_.exports.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT","SIGUNUSED")}),ay=m6((q,_)=>{var $=global.process,K=function(H){return H&&typeof H==="object"&&typeof H.removeListener==="function"&&typeof H.emit==="function"&&typeof H.reallyExit==="function"&&typeof H.listeners==="function"&&typeof H.kill==="function"&&typeof H.pid==="number"&&typeof H.on==="function"};if(!K($))_.exports=function(){return function(){}};else{if(P=Rq("assert"),f=iy(),j=/^win/i.test($.platform),Y=Rq("events"),typeof Y!=="function")Y=Y.EventEmitter;if($.__signal_exit_emitter__)w=$.__signal_exit_emitter__;else w=$.__signal_exit_emitter__=new Y,w.count=0,w.emitted={};if(!w.infinite)w.setMaxListeners(1/0),w.infinite=!0;_.exports=function(H,X){if(!K(global.process))return function(){};if(P.equal(typeof H,"function","a callback must be provided for exit handler"),W===!1)O();var k="exit";if(X&&X.alwaysLast)k="afterexit";var h=function(){if(w.removeListener(k,H),w.listeners("exit").length===0&&w.listeners("afterexit").length===0)T()};return w.on(k,H),h},T=function(){if(!W||!K(global.process))return;W=!1,f.forEach(function(X){try{$.removeListener(X,v[X])}catch(k){}}),$.emit=A,$.reallyExit=J,w.count-=1},_.exports.unload=T,z=function(X,k,h){if(w.emitted[X])return;w.emitted[X]=!0,w.emit(X,k,h)},v={},f.forEach(function(H){v[H]=function(){if(!K(global.process))return;var k=$.listeners(H);if(k.length===w.count){if(T(),z("exit",null,H),z("afterexit",null,H),j&&H==="SIGHUP")H="SIGINT";$.kill($.pid,H)}}}),_.exports.signals=function(){return f},W=!1,O=function(){if(W||!K(global.process))return;W=!0,w.count+=1,f=f.filter(function(X){try{return $.on(X,v[X]),!0}catch(k){return!1}}),$.emit=G,$.reallyExit=Z},_.exports.load=O,J=$.reallyExit,Z=function(X){if(!K(global.process))return;$.exitCode=X||0,z("exit",$.exitCode,null),z("afterexit",$.exitCode,null),J.call($,$.exitCode)},A=$.emit,G=function(X,k){if(X==="exit"&&K(global.process)){if(k!==void 0)$.exitCode=k;var h=A.apply(this,arguments);return z("exit",$.exitCode,null),z("afterexit",$.exitCode,null),h}else return A.apply(this,arguments)}}var P,f,j,Y,w,T,z,v,W,O,J,Z,A,G}),oy=m6((q,_)=>{var $=Symbol();function K(f,j,Y){let w=j[$];if(w)return j.stat(f,(z,v)=>{if(z)return Y(z);Y(null,v.mtime,w)});let T=new Date(Math.ceil(Date.now()/1000)*1000+5);j.utimes(f,T,T,(z)=>{if(z)return Y(z);j.stat(f,(v,W)=>{if(v)return Y(v);let O=W.mtime.getTime()%1000===0?"s":"ms";Object.defineProperty(j,$,{value:O}),Y(null,W.mtime,O)})})}function P(f){let j=Date.now();if(f==="s")j=Math.ceil(j/1000)*1000;return new Date(j)}q.probe=K,q.getMtime=P}),ty=m6((q,_)=>{var $=Rq("path"),K=EH(),P=cy(),f=ay(),j=oy(),Y={};function w(X,k){return k.lockfilePath||`${X}.lock`}function T(X,k,h){if(!k.realpath)return h(null,$.resolve(X));k.fs.realpath(X,h)}function z(X,k,h){let M=w(X,k);k.fs.mkdir(M,(S)=>{if(!S)return j.probe(M,k.fs,(C,N,R)=>{if(C)return k.fs.rmdir(M,()=>{}),h(C);h(null,N,R)});if(S.code!=="EEXIST")return h(S);if(k.stale<=0)return h(Object.assign(Error("Lock file is already being held"),{code:"ELOCKED",file:X}));k.fs.stat(M,(C,N)=>{if(C){if(C.code==="ENOENT")return z(X,{...k,stale:0},h);return h(C)}if(!v(N,k))return h(Object.assign(Error("Lock file is already being held"),{code:"ELOCKED",file:X}));W(X,k,(R)=>{if(R)return h(R);z(X,{...k,stale:0},h)})})})}function v(X,k){return X.mtime.getTime()<Date.now()-k.stale}function W(X,k,h){k.fs.rmdir(w(X,k),(M)=>{if(M&&M.code!=="ENOENT")return h(M);h()})}function O(X,k){let h=Y[X];if(h.updateTimeout)return;if(h.updateDelay=h.updateDelay||k.update,h.updateTimeout=setTimeout(()=>{h.updateTimeout=null,k.fs.stat(h.lockfilePath,(M,S)=>{let C=h.lastUpdate+k.stale<Date.now();if(M){if(M.code==="ENOENT"||C)return J(X,h,Object.assign(M,{code:"ECOMPROMISED"}));return h.updateDelay=1000,O(X,k)}if(h.mtime.getTime()!==S.mtime.getTime())return J(X,h,Object.assign(Error("Unable to update lock within the stale threshold"),{code:"ECOMPROMISED"}));let R=j.getMtime(h.mtimePrecision);k.fs.utimes(h.lockfilePath,R,R,(V)=>{let I=h.lastUpdate+k.stale<Date.now();if(h.released)return;if(V){if(V.code==="ENOENT"||I)return J(X,h,Object.assign(V,{code:"ECOMPROMISED"}));return h.updateDelay=1000,O(X,k)}h.mtime=R,h.lastUpdate=Date.now(),h.updateDelay=null,O(X,k)})})},h.updateDelay),h.updateTimeout.unref)h.updateTimeout.unref()}function J(X,k,h){if(k.released=!0,k.updateTimeout)clearTimeout(k.updateTimeout);if(Y[X]===k)delete Y[X];k.options.onCompromised(h)}function Z(X,k,h){k={stale:1e4,update:null,realpath:!0,retries:0,fs:K,onCompromised:(M)=>{throw M},...k},k.retries=k.retries||0,k.retries=typeof k.retries==="number"?{retries:k.retries}:k.retries,k.stale=Math.max(k.stale||0,2000),k.update=k.update==null?k.stale/2:k.update||0,k.update=Math.max(Math.min(k.update,k.stale/2),1000),T(X,k,(M,S)=>{if(M)return h(M);let C=P.operation(k.retries);C.attempt(()=>{z(S,k,(N,R,V)=>{if(C.retry(N))return;if(N)return h(C.mainError());let I=Y[S]={lockfilePath:w(S,k),mtime:R,mtimePrecision:V,options:k,lastUpdate:Date.now()};O(S,k),h(null,(l)=>{if(I.released)return l&&l(Object.assign(Error("Lock is already released"),{code:"ERELEASED"}));A(S,{...k,realpath:!1},l)})})})})}function A(X,k,h){k={fs:K,realpath:!0,...k},T(X,k,(M,S)=>{if(M)return h(M);let C=Y[S];if(!C)return h(Object.assign(Error("Lock is not acquired/owned by you"),{code:"ENOTACQUIRED"}));C.updateTimeout&&clearTimeout(C.updateTimeout),C.released=!0,delete Y[S],W(S,k,h)})}function G(X,k,h){k={stale:1e4,realpath:!0,fs:K,...k},k.stale=Math.max(k.stale||0,2000),T(X,k,(M,S)=>{if(M)return h(M);k.fs.stat(w(S,k),(C,N)=>{if(C)return C.code==="ENOENT"?h(null,!1):h(C);return h(null,!v(N,k))})})}function H(){return Y}f(()=>{for(let X in Y){let k=Y[X].options;try{k.fs.rmdirSync(w(X,k))}catch(h){}}}),q.lock=Z,q.unlock=A,q.check=G,q.getLocks=H}),ey=m6((q,_)=>{var $=EH();function K(Y){let w=["mkdir","realpath","stat","rmdir","utimes"],T={...Y};return w.forEach((z)=>{T[z]=(...v)=>{let W=v.pop(),O;try{O=Y[`${z}Sync`](...v)}catch(J){return W(J)}W(null,O)}}),T}function P(Y){return(...w)=>new Promise((T,z)=>{w.push((v,W)=>{if(v)z(v);else T(W)}),Y(...w)})}function f(Y){return(...w)=>{let T,z;if(w.push((v,W)=>{T=v,z=W}),Y(...w),T)throw T;return z}}function j(Y){if(Y={...Y},Y.fs=K(Y.fs||$),typeof Y.retries==="number"&&Y.retries>0||Y.retries&&typeof Y.retries.retries==="number"&&Y.retries.retries>0)throw Object.assign(Error("Cannot use retries with the sync api"),{code:"ESYNC"});return Y}_.exports={toPromise:P,toSync:f,toSyncOptions:j}}),By=m6((q,_)=>{var $=ty(),{toPromise:K,toSync:P,toSyncOptions:f}=ey();async function j(W,O){let J=await K($.lock)(W,O);return K(J)}function Y(W,O){let J=P($.lock)(W,f(O));return P(J)}function w(W,O){return K($.unlock)(W,O)}function T(W,O){return P($.unlock)(W,f(O))}function z(W,O){return K($.check)(W,O)}function v(W,O){return P($.check)(W,f(O))}_.exports=j,_.exports.lock=j,_.exports.unlock=w,_.exports.lockSync=Y,_.exports.unlockSync=T,_.exports.check=z,_.exports.checkSync=v}),sy=ny(By(),1);class $P{path;constructor(q){this.path=q}async load(){if(!CH(this.path))return null;try{let q=await Fy(this.path,"utf8"),_=JSON.parse(q);if(_&&_.version===1)return _;return null}catch{return null}}async save(q){if(await Uy(Qy(this.path),{recursive:!0}),!CH(this.path))await mH(this.path,"{}");let _=async()=>{};try{_=await sy.default.lock(this.path,{retries:{retries:3,minTimeout:50,maxTimeout:200}}),await mH(this.path,JSON.stringify(q,null,2))}finally{try{await _()}catch{}}}async markPrompted(q,_){let $=await this.load();if(!$)return;$.last_prompted_by_target[q]=_,await this.save($)}}class m1{baseUrl;app;channel;constructor(q,_,$="stable"){this.baseUrl=q,this.app=_,this.channel=$}async query(q){let _=new URL(`/v1/packages/${this.app}/version`,this.baseUrl);_.searchParams.set("current",q.current),_.searchParams.set("os",q.os),_.searchParams.set("arch",q.arch),_.searchParams.set("channel",this.channel);let $=await fetch(_.toString(),{method:"GET",headers:{"User-Agent":q.userAgent,Accept:"application/json"},signal:q.signal});if(!$.ok)throw Error(`version query failed: ${$.status}`);return await $.json()}}var qg=86400000;class KP{adapter;cache;timeoutMs;task=null;constructor(q){this.adapter=q.adapter,this.cache=q.cache,this.timeoutMs=q.timeoutMs??5000}init(){if(this.task)return this.task;return this.task=new Promise((q)=>{queueMicrotask(()=>{this.runRefresh().catch(()=>{return}).finally(()=>q())})}),this.task}async runRefresh(){let q=await this.cache.load();if(q&&q.ttl_expires_at>Date.now()&&q.severity!=="critical")return;let _=new m1(this.adapter.baseUrl,this.adapter.app_id,this.adapter.channel),$=new AbortController,K=setTimeout(()=>$.abort(),this.timeoutMs);try{let P=await _.query({current:this.adapter.currentVersion(),os:this.adapter.os(),arch:this.adapter.arch(),userAgent:`${this.adapter.app_id}-cli/${this.adapter.currentVersion()} ${this.adapter.os()}-${this.adapter.arch()}`,signal:$.signal}),f=Date.now(),j={version:1,app:this.adapter.app_id,current:this.adapter.currentVersion(),last_check_at:f,ttl_expires_at:f+qg,latest:P.latest,min_required:P.min_required,severity:P.severity,dist_type:P.dist_type,dist:P.dist,last_prompted_by_target:q?.last_prompted_by_target??{}};await this.cache.save(j)}finally{clearTimeout(K)}}}function RH(q){let _=q.spawn;return{async run({dist:$}){let K=await _(["npm",["i","-g",`${$.package}@${$.version}`]]);if(K.exitCode!==0)throw Error(`npm install failed (${K.exitCode}): ${K.stderr}`);await q.writeLastInstalled($.version)},async rollback(){let $=q.readLastInstalled?await q.readLastInstalled():null;if(!$)throw Error("rollback not available: last installed version unknown");if(!q.packageName)throw Error("rollback requires packageName in NpmRunDeps");let K=await _(["npm",["i","-g",`${q.packageName}@${$}`]]);if(K.exitCode!==0)throw Error(`npm rollback failed (${K.exitCode}): ${K.stderr}`)}}}X4();var S4={name:"chipctx",version:"0.2.2",description:"CLI tool for CMSIS-based embedded project development",type:"module",bin:{chipctx:"./bin/chipctx.js","chipctx-gen":"./bin/chipctx-gen.js"},files:["dist/","bin/"],engines:{node:">=20.12.0"},publishConfig:{access:"public"},scripts:{dev:"bun run src/index.ts",build:"bun run scripts/build.ts",deploy:"bun run scripts/deploy-cli.ts",prepublishOnly:"bun run build",test:"bun test","type-check":"tsc --noEmit -p tsconfig.typecheck.json",lint:"biome check src/ tests/",format:"biome format --write src/ tests/"},devDependencies:{"@chipctx/cli-updater":"link:@chipctx/cli-updater","@biomejs/biome":"^1.9.4","@iarna/toml":"^2.2.5","@inquirer/prompts":"^8.3.2","@types/bun":"^1.2.0",chalk:"^5.4.1",commander:"^13.1.0","fast-xml-parser":"^5.2.0",handlebars:"^4.7.8"}};function $g(){return process.platform==="darwin"?"darwin":process.platform==="win32"?"win32":"linux"}function Kg(){return process.arch==="arm64"?"arm64":"x64"}function IH(q){return{app_id:"chipctx",channel:"stable",currentVersion:q.currentVersion,os:$g,arch:Kg,isNonInteractive:q.nonInteractive,runnerBackend:"npm",baseUrl:q.baseUrl,confirmUpgrade:q.confirmUpgrade}}async function fg(q){if(q.mode==="rollback")return await q.rollback(),q.print("rollback complete"),0;let _=await q.queryVersion();if(q.mode==="check"){if(q.print(`current ${q.currentVersion}, latest ${_.latest}, severity ${_.severity}`),_.severity==="critical")return 20;if(_.severity==="recommended")return 10;return 0}if(_.severity==="none"&&q.mode!=="force")return q.print("already at latest"),0;return await q.runUpgrade(_.latest),q.print(`upgraded to ${_.latest}`),0}function uH(){return IH({baseUrl:process.env.CHIPCTX_BASE_URL??"https://chipctx.com",currentVersion:()=>S4.version,nonInteractive:()=>Boolean(process.env.CI||process.env.CHIPCTX_NON_INTERACTIVE)||!process.stdout.isTTY,confirmUpgrade:async({target:q,current:_})=>X1({message:`Upgrade chipctx from ${_} to ${q}?`,default:!0})})}function yH(){return new q8("update").description("Check and apply chipctx updates").option("--check","Only check, do not upgrade").option("--force","Force re-install").option("--rollback","Install the previous version").action(async(q)=>{let _=uH(),$=new m1(_.baseUrl,"chipctx","stable"),K=q.rollback?"rollback":q.check?"check":q.force?"force":"run",P=RH({spawn:async([j,Y])=>await new Promise((w)=>{Pg(j,Y,{stdio:"inherit"}).on("exit",(z)=>w({exitCode:z??0,stdout:"",stderr:""}))}),lastInstalledFile:C4(b4(),".chipctx","last-installed.txt"),writeLastInstalled:async(j)=>{let{writeFile:Y,mkdir:w}=await import("fs/promises");await w(C4(b4(),".chipctx"),{recursive:!0}),await Y(C4(b4(),".chipctx","last-installed.txt"),j)},readLastInstalled:async()=>{let{readFile:j}=await import("fs/promises");try{return(await j(C4(b4(),".chipctx","last-installed.txt"),"utf8")).trim()}catch{return null}},packageName:"chipctx"}),f=await fg({mode:K,currentVersion:S4.version,queryVersion:()=>$.query({current:S4.version,os:_.os(),arch:_.arch(),userAgent:`chipctx-cli/${S4.version} ${_.os()}-${_.arch()}`}),runUpgrade:async(j)=>{await P.run({target:j,dist:{package:"chipctx",version:j,registry:"https://registry.npmjs.org"}})},rollback:()=>P.rollback(),print:(j)=>console.log(j)});process.exit(f)})}function gH(){try{let q=new $P(C4(b4(),".chipctx","update-state.json")),_=uH();new KP({adapter:_,cache:q,timeoutMs:5000}).init().catch(()=>{})}catch{}}function jg(){return I4()}function Yg(){let q=new q8;return q.name("chipctx").description("CLI tool for CMSIS-based embedded project development").version(jg()).option("--config <path>","Path to config file (default: ~/.chipctx/config.toml)").option("--api-url <url>","Override backend API URL").option("--no-color","Disable colored output").option("--json","Output in JSON format").option("-v, --verbose","Enable verbose debug logging"),q.hook("preAction",(_,$)=>{let K=$.optsWithGlobals();mP(Boolean(K.verbose))}),q.addCommand(Zf()),q.addCommand(gO()),q.addCommand(IO()),q.addCommand(ET()),q.addCommand(aT()),q.addCommand(QO()),q.addCommand(sO()),q.addCommand(qH()),q.addCommand($H()),q.addCommand(KH()),q.addCommand(TH()),q.addCommand(BO()),q.addCommand(VH()),q.addCommand(MH()),q.addCommand(NH()),q.addCommand(SH()),q.addCommand(yH()),q}if(import.meta.main)gH(),Yg().parse();export{jg as resolveCliVersion,Yg as createProgram};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chipctx",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "CLI tool for CMSIS-based embedded project development",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,10 +27,8 @@
27
27
  "lint": "biome check src/ tests/",
28
28
  "format": "biome format --write src/ tests/"
29
29
  },
30
- "dependencies": {
31
- "@chipctx/cli-updater": "link:@chipctx/cli-updater"
32
- },
33
30
  "devDependencies": {
31
+ "@chipctx/cli-updater": "link:@chipctx/cli-updater",
34
32
  "@biomejs/biome": "^1.9.4",
35
33
  "@iarna/toml": "^2.2.5",
36
34
  "@inquirer/prompts": "^8.3.2",