@unitsvc/cc-helper 1.5.8 → 1.5.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.
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var cr=Object.create;var S=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var dr=(r,n)=>{for(var e in n)S(r,e,{get:n[e],enumerable:!0})},Z=(r,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of pr(n))!mr.call(r,t)&&t!==e&&S(r,t,{get:()=>n[t],enumerable:!(o=lr(n,t))||o.enumerable});return r};var m=(r,n,e)=>(e=r!=null?cr(fr(r)):{},Z(n||!r||!r.__esModule?S(e,"default",{value:r,enumerable:!0}):e,r)),ur=r=>Z(S({},"__esModule",{value:!0}),r);var vr={};dr(vr,{ensureBinary:()=>F,getBinaryPath:()=>w,main:()=>nr,uninstall:()=>C});module.exports=ur(vr);var tr=require("child_process");var l=m(require("fs")),W=m(require("os")),v=m(require("path")),Q=require("child_process");var k=m(require("os")),M=m(require("path")),gr={darwin:"darwin",linux:"linux",win32:"windows"},hr={x64:"amd64",arm64:"arm64"};function $(){let r=k.default.platform(),n=k.default.arch(),e=gr[r],o=hr[n];if(!e)throw new Error(`Unsupported platform: ${r}`);if(!o)throw new Error(`Unsupported arch: ${n}`);return{platform:e,arch:o}}var R=r=>r==="windows"?"cc-helper.exe":"cc-helper";function P(r,n,e){let o=r.replace(/^v/,"");return n==="windows"?`cc-helper_${o}_${n}_${e}.zip`:`cc-helper_${o}_${n}_${e}.tar.gz`}var w=()=>{let{platform:r}=$();return M.default.join(__dirname,"bin",R(r))};var y=m(require("fs")),H=m(require("path")),q=m(require("http")),G=m(require("https"));function I(r){try{y.default.existsSync(r)&&y.default.unlinkSync(r)}catch{}}async function A(r,n,e=3){for(let o=0;o<e;o++)try{await new Promise((t,i)=>{let p=(r.startsWith("https")?G.default:q.default).get(r,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},c=>{if(c.statusCode===301||c.statusCode===302){let d=c.headers.location;if(d){A(d,n,e).then(t).catch(i);return}}if(c.statusCode!==200){i(new Error(`HTTP ${c.statusCode}`));return}let s=H.default.dirname(n);y.default.existsSync(s)||y.default.mkdirSync(s,{recursive:!0});let g=y.default.createWriteStream(n);c.pipe(g),g.on("finish",()=>{g.close(d=>{d?i(d):t()})}),g.on("error",d=>{I(n),i(d)}),c.on("error",d=>{I(n),i(d)})});p.setTimeout(3e4,()=>{p.destroy(),i(new Error("Timeout"))}),p.on("error",c=>{I(n),i(c)})});return}catch(t){if(I(n),o===e-1)throw t;console.log(`warn cc-helper retry ${o+1}/${e}`),await new Promise(i=>setTimeout(i,1e3*(o+1)))}}var f=m(require("fs")),u=m(require("path")),_=m(require("zlib"));async function wr(r,n){let e=0;for(;e+512<=r.length;){let o=r.subarray(e,e+512);if(o.every(c=>c===0))break;let t=o.subarray(0,100).toString().replace(/\0.*$/,""),i=o.subarray(345,500).toString().replace(/\0.*$/,"");i&&(t=`${i}/${t}`),t.startsWith("package/")&&(t=t.slice(8)),t=t.replace(/\//g,u.default.sep);let a=parseInt(o.subarray(124,136).toString().trim(),8)||0,p=o[156];if(e+=512,a>0&&t&&(p===0||p===48)){let c=u.default.join(n,t);await f.default.promises.mkdir(u.default.dirname(c),{recursive:!0}),await f.default.promises.writeFile(c,r.subarray(e,e+a)),e+=Math.ceil(a/512)*512}}}async function yr(r,n){await f.default.promises.mkdir(n,{recursive:!0});let e=await f.default.promises.readFile(r),o;try{o=_.default.unzipSync(e)}catch(t){throw new Error(`Failed to decompress tar.gz: ${t.message}`)}await wr(o,n)}async function xr(r,n){await f.default.promises.mkdir(n,{recursive:!0});let e=await f.default.promises.readFile(r);if(e.length<22)throw new Error(`Invalid ZIP: file too small (${e.length} bytes)`);let o=Buffer.from([80,75,5,6]),t=e.length-22;for(;t>=0&&!e.subarray(t,t+4).equals(o);)t--;if(t<0)throw new Error(`Invalid ZIP: missing end of central directory (file may be corrupted or incomplete, size: ${e.length} bytes)`);if(t+22>e.length)throw new Error("Invalid ZIP: truncated EOCD record");let i=e.readUInt32LE(t+16),a=e.readUInt32LE(t+12),p=i+a;if(i>=e.length||p>e.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${i}, cdEnd: ${p}, fileSize: ${e.length})`);let c=Buffer.from([80,75,1,2]),s=i;for(;s<p;){if(s+46>e.length)throw new Error(`Invalid ZIP: truncated central directory at position ${s}`);if(!e.subarray(s,s+4).equals(c))throw new Error(`Invalid ZIP: invalid central directory signature at position ${s}`);let g=e.readUInt16LE(s+28),d=e.readUInt16LE(s+30),N=e.readUInt16LE(s+32),x=e.readUInt32LE(s+42),or=e.readUInt32LE(s+20),Er=e.readUInt32LE(s+24),Sr=e.readUInt16LE(s+10);if(s+46+g+d+N>e.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${s}`);let h=e.subarray(s+46,s+46+g).toString();if(s+=46+g+d+N,h.endsWith("/")){await f.default.promises.mkdir(u.default.join(n,h.replace(/\//g,u.default.sep)),{recursive:!0});continue}if(h=h.replace(/\//g,u.default.sep),x+30>e.length)throw new Error(`Invalid ZIP: local header out of bounds for ${h}`);let b=e.readUInt16LE(x+8),ir=e.readUInt16LE(x+26),sr=e.readUInt16LE(x+28),U=x+30+ir+sr,D=or;if(U+D>e.length)throw new Error(`Invalid ZIP: truncated file data for ${h}`);let O=e.subarray(U,U+D),L=u.default.join(n,h);await f.default.promises.mkdir(u.default.dirname(L),{recursive:!0});try{if(b===8)await f.default.promises.writeFile(L,_.default.inflateRawSync(O));else if(b===0)await f.default.promises.writeFile(L,O);else throw new Error(`Unsupported compression method ${b} for ${h}`)}catch(ar){throw new Error(`Failed to decompress ${h}: ${ar.message}`)}}}async function K(r,n,e){e==="windows"?await xr(r,n):await yr(r,n)}function V(r,n){let e=u.default.join(r,n);if(f.default.existsSync(e))return e;for(let o of f.default.readdirSync(r)){let t=u.default.join(r,o,n);if(f.default.statSync(u.default.join(r,o)).isDirectory()&&f.default.existsSync(t))return t}throw new Error(`Binary ${n} not found`)}var j=m(require("https"));var z="next-bin",B="cc-helper";function J(r){return new Promise((n,e)=>{let o=`https://api.github.com${r}`,t=j.default.get(o,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},i=>{let a="";i.on("data",p=>a+=p),i.on("end",()=>{i.statusCode!==200?e(new Error(`GitHub API error: ${i.statusCode}`)):n(JSON.parse(a))})});t.setTimeout(15e3,()=>{t.destroy(),e(new Error("GitHub API timeout"))}),t.on("error",e)})}async function T(){return(await J(`/repos/${z}/${B}/releases/latest`)).tag_name.replace(/^v/,"")}async function X(r,n){var t;let e=await J(`/repos/${z}/${B}/releases?per_page=10`),o=r==="windows"?`_${r}_${n}.zip`:`_${r}_${n}.tar.gz`;for(let i of e)if((t=i.assets)!=null&&t.some(a=>a.name.includes(o)))return i.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${r}-${n}`)}function Y(r,n,e,o){let t=r.startsWith("v")?r:`v${r}`,i=`https://github.com/${z}/${B}/releases/download/${t}/${P(r,n,e)}`;return o?`${o}/${i}`:i}async function E(r,n,e,o,t){let i=P(r,n,e),a=v.default.join(W.default.tmpdir(),i),p=Y(r,n,e,t);console.log(`info cc-helper@${r} Installing for ${n}-${e}`),t&&console.log("info cc-helper Using proxy:",t);try{await A(p,a)}catch(s){throw t||console.log("warn cc-helper Download failed, try: npx @unitsvc/cc-helper --proxy enable"),s}let c=v.default.join(W.default.tmpdir(),`cc-helper_${Date.now()}`);l.default.mkdirSync(c,{recursive:!0});try{await K(a,c,n);let s=V(c,R(n)),g=v.default.dirname(o);l.default.existsSync(g)||l.default.mkdirSync(g,{recursive:!0}),l.default.existsSync(o)&&l.default.unlinkSync(o),l.default.copyFileSync(s,o),process.platform!=="win32"&&l.default.chmodSync(o,493),console.log("info cc-helper Installed to",o)}finally{let s=l.default.rmSync||l.default.rmdirSync;try{s(c,{recursive:!0,force:!0})}catch{}l.default.existsSync(a)&&l.default.unlinkSync(a)}}async function F(r=null,n){let{platform:e,arch:o}=$(),t=w();if(l.default.existsSync(t))return t;if(r)try{return await E(r,e,o,t,n),t}catch(a){if(!a.message.includes("404"))throw a;console.log(`warn cc-helper@${r} not available, using latest`)}let i=await T();try{await E(i,e,o,t,n)}catch(a){if(!a.message.includes("404"))throw a;i=await X(e,o),await E(i,e,o,t,n)}return t}function C(){let r=w(),n=v.default.dirname(r);l.default.existsSync(r)?(l.default.unlinkSync(r),console.log("info cc-helper Removed binary:",r)):console.log("info cc-helper No binary found"),l.default.existsSync(n)&&l.default.readdirSync(n).length===0&&l.default.rmdirSync(n),console.log("info cc-helper To complete uninstallation, run:"),console.log(" npm uninstall -g @unitsvc/cc-helper")}async function $r(r){if(!l.default.existsSync(r))return null;try{return(0,Q.execSync)(`"${r}" --version`,{timeout:5e3}).toString().trim().replace(/^v/i,"")}catch{return null}}async function rr(r){let n=w(),e=await T(),o=await $r(n);return{current:o,latest:e,needsUpdate:!o||o!==e}}function er(r){let n=[],e,o="https://edgeone.gh-proxy.org";for(let t=0;t<r.length;t++)r[t]==="--proxy"?t+1<r.length&&(r[t+1].startsWith("http://")||r[t+1].startsWith("https://"))?(e=r[t+1],t++):e=o:r[t].startsWith("--proxy=")?e=r[t].slice(8)||o:n.push(r[t]);return{proxy:e,remainingArgs:n}}async function nr(){let r=process.argv.slice(2);if(r[0]==="uninstall"){C();return}if(r[0]==="update"){let{proxy:o}=er(r.slice(1)),{current:t,latest:i,needsUpdate:a}=await rr();if(!a){console.log(`info cc-helper Already at latest version: ${t}`);return}console.log(`info cc-helper Updating from ${t||"unknown"} to ${i}`);let{platform:p,arch:c}=$(),s=w();await E(i,p,c,s,o);return}let{proxy:n,remainingArgs:e}=er(r);try{let o=await F(null,n),t=(0,tr.spawn)(o,e,{stdio:"inherit"});t.on("close",i=>process.exit(i??1)),t.on("error",i=>{console.error("ERR! cc-helper",i.message),process.exit(1)})}catch(o){console.error("ERR! cc-helper",o.message),process.exit(1)}}require.main===module&&nr();0&&(module.exports={ensureBinary,getBinaryPath,main,uninstall});
|
|
2
|
+
"use strict";var dt=Object.create;var R=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var xt=(t,o)=>{for(var e in o)R(t,e,{get:o[e],enumerable:!0})},j=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ht(o))!wt.call(t,n)&&n!==e&&R(t,n,{get:()=>o[n],enumerable:!(r=$t(o,n))||r.enumerable});return t};var $=(t,o,e)=>(e=t!=null?dt(yt(t)):{},j(o||!t||!t.__esModule?R(e,"default",{value:t,enumerable:!0}):e,t)),vt=t=>j(R({},"__esModule",{value:!0}),t);var Rt={};xt(Rt,{ensureBinary:()=>Z,getBinaryPath:()=>w,getCurrentVersion:()=>H,main:()=>mt,uninstall:()=>G});module.exports=vt(Rt);var at=require("child_process"),lt=$(require("fs"));var g=$(require("fs")),O=$(require("os")),S=$(require("path")),it=require("child_process");var z=$(require("os")),K=$(require("path")),Et={darwin:"darwin",linux:"linux",win32:"windows"},St={x64:"amd64",arm64:"arm64"};function E(){let t=z.default.platform(),o=z.default.arch(),e=Et[t],r=St[o];if(!e)throw new Error(`Unsupported platform: ${t}`);if(!r)throw new Error(`Unsupported arch: ${o}`);return{platform:e,arch:r}}var B=t=>t==="windows"?"cc-helper.exe":"cc-helper";function T(t,o,e){let r=t.replace(/^v/,"");return o==="windows"?`cc-helper_${r}_${o}_${e}.zip`:`cc-helper_${r}_${o}_${e}.tar.gz`}var w=()=>{let{platform:t}=E();return K.default.join(__dirname,"bin",B(t))};var x=$(require("fs")),Y=$(require("path")),J=$(require("http")),X=$(require("https")),bt="\x1B[90m",Pt="\x1B[0m";function A(t){try{x.default.existsSync(t)&&x.default.unlinkSync(t)}catch{}}async function N(t,o,e=3){for(let r=0;r<e;r++)try{await new Promise((n,i)=>{let m=(t.startsWith("https")?X.default:J.default).get(t,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},c=>{if(c.statusCode===301||c.statusCode===302){let f=c.headers.location;if(f){N(f,o,e).then(n).catch(i);return}}if(c.statusCode!==200){i(new Error(`HTTP ${c.statusCode}`));return}let s=Y.default.dirname(o);x.default.existsSync(s)||x.default.mkdirSync(s,{recursive:!0});let u=x.default.createWriteStream(o);c.pipe(u),u.on("finish",()=>{u.close(f=>{f?i(f):x.default.existsSync(o)&&x.default.statSync(o).size>0?n():i(new Error("Downloaded file is empty or missing"))})}),u.on("error",f=>{A(o),i(f)}),c.on("error",f=>{A(o),i(f)})});m.setTimeout(3e4,()=>{m.destroy(),i(new Error("Timeout"))}),m.on("error",c=>{A(o),i(c)})});return}catch(n){if(A(o),r===e-1)throw n;console.log(`${bt}Retrying (${r+1}/${e})...${Pt}`),await new Promise(i=>setTimeout(i,1e3*(r+1)))}}var d=$(require("fs")),h=$(require("path")),F=$(require("zlib"));async function It(t,o){let e=0;for(;e+512<=t.length;){let r=t.subarray(e,e+512);if(r.every(c=>c===0))break;let n=r.subarray(0,100).toString().replace(/\0.*$/,""),i=r.subarray(345,500).toString().replace(/\0.*$/,"");i&&(n=`${i}/${n}`),n.startsWith("package/")&&(n=n.slice(8)),n=n.replace(/\//g,h.default.sep);let l=parseInt(r.subarray(124,136).toString().trim(),8)||0,m=r[156];if(e+=512,l>0&&n&&(m===0||m===48)){let c=h.default.join(o,n);await d.default.promises.mkdir(h.default.dirname(c),{recursive:!0}),await d.default.promises.writeFile(c,t.subarray(e,e+l)),e+=Math.ceil(l/512)*512}}}async function kt(t,o){await d.default.promises.mkdir(o,{recursive:!0});let e=await d.default.promises.readFile(t),r;try{r=F.default.unzipSync(e)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await It(r,o)}async function Ut(t,o){await d.default.promises.mkdir(o,{recursive:!0});let e=await d.default.promises.readFile(t);if(e.length<22)throw new Error(`Invalid ZIP: file too small (${e.length} bytes)`);let r=Buffer.from([80,75,5,6]),n=e.length-22;for(;n>=0&&!e.subarray(n,n+4).equals(r);)n--;if(n<0)throw new Error(`Invalid ZIP: missing end of central directory (file may be corrupted or incomplete, size: ${e.length} bytes)`);if(n+22>e.length)throw new Error("Invalid ZIP: truncated EOCD record");let i=e.readUInt32LE(n+16),l=e.readUInt32LE(n+12),m=i+l;if(i>=e.length||m>e.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${i}, cdEnd: ${m}, fileSize: ${e.length})`);let c=Buffer.from([80,75,1,2]),s=i;for(;s<m;){if(s+46>e.length)throw new Error(`Invalid ZIP: truncated central directory at position ${s}`);if(!e.subarray(s,s+4).equals(c))throw new Error(`Invalid ZIP: invalid central directory signature at position ${s}`);let u=e.readUInt16LE(s+28),f=e.readUInt16LE(s+30),P=e.readUInt16LE(s+32),v=e.readUInt32LE(s+42),ut=e.readUInt32LE(s+20),Tt=e.readUInt32LE(s+24),At=e.readUInt16LE(s+10);if(s+46+u+f+P>e.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${s}`);let y=e.subarray(s+46,s+46+u).toString();if(s+=46+u+f+P,y.endsWith("/")){await d.default.promises.mkdir(h.default.join(o,y.replace(/\//g,h.default.sep)),{recursive:!0});continue}if(y=y.replace(/\//g,h.default.sep),v+30>e.length)throw new Error(`Invalid ZIP: local header out of bounds for ${y}`);let C=e.readUInt16LE(v+8),pt=e.readUInt16LE(v+26),gt=e.readUInt16LE(v+28),W=v+30+pt+gt,q=ut;if(W+q>e.length)throw new Error(`Invalid ZIP: truncated file data for ${y}`);let V=e.subarray(W,W+q),_=h.default.join(o,y);await d.default.promises.mkdir(h.default.dirname(_),{recursive:!0});try{if(C===8)await d.default.promises.writeFile(_,F.default.inflateRawSync(V));else if(C===0)await d.default.promises.writeFile(_,V);else throw new Error(`Unsupported compression method ${C} for ${y}`)}catch(ft){throw new Error(`Failed to decompress ${y}: ${ft.message}`)}}}async function Q(t,o,e){e==="windows"?await Ut(t,o):await kt(t,o)}function tt(t,o){let e=h.default.join(t,o);if(d.default.existsSync(e))return e;for(let r of d.default.readdirSync(t)){let n=h.default.join(t,r,o);if(d.default.statSync(h.default.join(t,r)).isDirectory()&&d.default.existsSync(n))return n}throw new Error(`Binary ${o} not found`)}var et=$(require("https"));var D="next-bin",M="cc-helper";function ot(t){return new Promise((o,e)=>{let r=`https://api.github.com${t}`,n=et.default.get(r,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},i=>{let l="";i.on("data",m=>l+=m),i.on("end",()=>{i.statusCode!==200?e(new Error(`GitHub API error: ${i.statusCode}`)):o(JSON.parse(l))})});n.setTimeout(15e3,()=>{n.destroy(),e(new Error("GitHub API timeout"))}),n.on("error",e)})}async function nt(){return(await ot(`/repos/${D}/${M}/releases/latest`)).tag_name.replace(/^v/,"")}async function L(t,o){var n;let e=await ot(`/repos/${D}/${M}/releases?per_page=10`),r=t==="windows"?`_${t}_${o}.zip`:`_${t}_${o}.tar.gz`;for(let i of e)if((n=i.assets)!=null&&n.some(l=>l.name.includes(r)))return i.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${t}-${o}`)}function rt(t,o,e,r){let n=t.startsWith("v")?t:`v${t}`,i=`https://github.com/${D}/${M}/releases/download/${n}/${T(t,o,e)}`;return r?`${r}/${i}`:i}var I="\x1B[90m",k="\x1B[0m";async function U(t,o,e,r,n){let i=T(t,o,e),l=S.default.join(O.default.tmpdir(),i),m=rt(t,o,e,n);n&&console.log(`${I}Using proxy: ${n}${k}`);try{await N(m,l)}catch(s){throw s}let c=S.default.join(O.default.tmpdir(),`cc-helper_${Date.now()}`);g.default.mkdirSync(c,{recursive:!0});try{await Q(l,c,o);let s=tt(c,B(o)),u=S.default.dirname(r);g.default.existsSync(u)||g.default.mkdirSync(u,{recursive:!0}),g.default.existsSync(r)&&g.default.unlinkSync(r),g.default.copyFileSync(s,r),process.platform!=="win32"&&g.default.chmodSync(r,493)}finally{let s=g.default.rmSync||g.default.rmdirSync;try{s(c,{recursive:!0,force:!0})}catch{}g.default.existsSync(l)&&g.default.unlinkSync(l)}}async function Z(t=null,o){let{platform:e,arch:r}=E(),n=w();if(g.default.existsSync(n))return n;if(t)try{return await U(t,e,r,n,o),n}catch(l){if(!l.message.includes("404"))throw l}let i=await nt();try{await U(i,e,r,n,o)}catch(l){if(!l.message.includes("404"))throw l;i=await L(e,r),await U(i,e,r,n,o)}return n}function G(){let t=w(),o=S.default.dirname(t);g.default.existsSync(t)?(g.default.unlinkSync(t),console.log(`${I}Removed binary: ${t}${k}`)):console.log(`${I}No installation found${k}`),g.default.existsSync(o)&&g.default.readdirSync(o).length===0&&g.default.rmdirSync(o),console.log(`${I}To complete uninstallation, run:${k}`),console.log(`${I} npm uninstall -g @unitsvc/cc-helper${k}`)}async function H(t){if(!g.default.existsSync(t))return null;try{let o=S.default.resolve(t),r=(0,it.execSync)(`"${o}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return r?r[1]:null}catch{return null}}var st="\x1B[32m",b="\x1B[31m",p="\x1B[90m",a="\x1B[0m";function ct(t){let o=[],e,r="https://edgeone.gh-proxy.org";for(let n=0;n<t.length;n++)t[n]==="--proxy"?n+1<t.length&&(t[n+1].startsWith("http://")||t[n+1].startsWith("https://"))?(e=t[n+1],n++):e=r:t[n].startsWith("--proxy=")?e=t[n].slice(8)||r:o.push(t[n]);return{proxy:e,remainingArgs:o}}async function mt(){let t=process.argv.slice(2);if(t[0]==="uninstall"&&(G(),process.exit(0)),t[0]==="update"){let{proxy:l}=ct(t.slice(1)),{platform:m,arch:c}=E(),s=`${m}-${c}`;console.log("Checking for updates to latest version...");let u=null,f;u=await H(w());try{f=await L(m,c)}catch{console.log(`${b}Failed to check for updates (${s})${a}`),console.log(`${b}Unable to fetch latest version from npm registry${a}`),console.log(`${p}Possible causes:${a}`),console.log(`${p} \u2022 Network connectivity issues${a}`),console.log(`${p} \u2022 npm registry is unreachable${a}`),console.log(`${p} \u2022 Corporate proxy/firewall blocking npm${a}`),console.log(`${p}Try:${a}`),console.log(`${p} \u2022 Check your internet connection${a}`),console.log(`${p} \u2022 Manually check: npm view @unitsvc/cc-helper version${a}`),console.log(`${p} \u2022 Check if you need to login: npm whoami${a}`),process.exit(1)}u&&u===f&&(console.log(`${st}cc-helper is up to date (${u}) (${s})${a}`),process.exit(0)),console.log(`New version available: ${f}${u?` (current: ${u})`:""}`),console.log("Installing update...");let P=w();try{if(await U(f,m,c,P,l),!lt.default.existsSync(P))throw new Error("Installation completed but binary not found");console.log(`${st}Successfully updated${u?` from ${u}`:""} to version ${f} (${s})${a}`),process.exit(0)}catch{console.log(`${b}Failed to install update (${s})${a}`),console.log(`${b}Unable to download or install the new version${a}`),console.log(`${p}Possible causes:${a}`),console.log(`${p} \u2022 Network connectivity issues${a}`),console.log(`${p} \u2022 Permission issues${a}`),console.log(`${p}Try:${a}`),console.log(`${p} \u2022 Check your internet connection${a}`),console.log(`${p} \u2022 Manually install: npm install -g @unitsvc/cc-helper@latest${a}`),process.exit(1)}}let{proxy:o,remainingArgs:e}=ct(t),{platform:r,arch:n}=E(),i=`${r}-${n}`;try{let l=await Z(null,o),m=(0,at.spawn)(l,e,{stdio:"inherit"});m.on("close",c=>process.exit(c??1)),m.on("error",c=>{console.log(`${b}${c.message}${a}`),process.exit(1)})}catch{let c=t.some(s=>s==="--proxy"||s.startsWith("--proxy="))?t.join(" "):`--proxy ${t.join(" ")}`;console.log(`${b}Failed to install (${i})${a}`),console.log(`${p}Possible causes:${a}`),console.log(`${p} \u2022 Network connectivity issues${a}`),console.log(`${p} \u2022 Permission issues${a}`),console.log(`${p}Try:${a}`),console.log(`${p} \u2022 Check your internet connection${a}`),console.log(`${p} \u2022 npx @unitsvc/cc-helper@latest ${c}${a}`),process.exit(1)}}require.main===module&&mt();0&&(module.exports={ensureBinary,getBinaryPath,getCurrentVersion,main,uninstall});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var lt=Object.create;var U=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ft=Object.getPrototypeOf,ut=Object.prototype.hasOwnProperty;var pt=(r,e)=>{for(var t in e)U(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of dt(e))!ut.call(r,n)&&n!==t&&U(r,n,{get:()=>e[n],enumerable:!(o=mt(e,n))||o.enumerable});return r};var f=(r,e,t)=>(t=r!=null?lt(ft(r)):{},V(e||!r||!r.__esModule?U(t,"default",{value:r,enumerable:!0}):t,r)),gt=r=>V(U({},"__esModule",{value:!0}),r);var Pt={};pt(Pt,{checkForUpdate:()=>ot,ensureBinary:()=>Z,findReleaseWithBinary:()=>L,getArchiveName:()=>S,getBinaryName:()=>I,getBinaryPath:()=>E,getCurrentVersion:()=>M,getDownloadUrl:()=>R,getLatestVersion:()=>b,getPlatform:()=>x,install:()=>et,uninstall:()=>nt});module.exports=gt(Pt);var l=f(require("fs")),D=f(require("os")),v=f(require("path")),rt=require("child_process");var _=f(require("os")),q=f(require("path")),ht={darwin:"darwin",linux:"linux",win32:"windows"},wt={x64:"amd64",arm64:"arm64"};function x(){let r=_.default.platform(),e=_.default.arch(),t=ht[r],o=wt[e];if(!t)throw new Error(`Unsupported platform: ${r}`);if(!o)throw new Error(`Unsupported arch: ${e}`);return{platform:t,arch:o}}var I=r=>r==="windows"?"cc-helper.exe":"cc-helper";function S(r,e,t){let o=r.replace(/^v/,"");return e==="windows"?`cc-helper_${o}_${e}_${t}.zip`:`cc-helper_${o}_${e}_${t}.tar.gz`}var E=()=>{let{platform:r}=x();return q.default.join(__dirname,"bin",I(r))};var $=f(require("fs")),K=f(require("path")),j=f(require("http")),Y=f(require("https")),yt="\x1B[90m",$t="\x1B[0m";function k(r){try{$.default.existsSync(r)&&$.default.unlinkSync(r)}catch{}}async function A(r,e,t=3){for(let o=0;o<t;o++)try{await new Promise((n,i)=>{let m=(r.startsWith("https")?Y.default:j.default).get(r,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},c=>{if(c.statusCode===301||c.statusCode===302){let u=c.headers.location;if(u){A(u,e,t).then(n).catch(i);return}}if(c.statusCode!==200){i(new Error(`HTTP ${c.statusCode}`));return}let s=K.default.dirname(e);$.default.existsSync(s)||$.default.mkdirSync(s,{recursive:!0});let h=$.default.createWriteStream(e);c.pipe(h),h.on("finish",()=>{h.close(u=>{u?i(u):$.default.existsSync(e)&&$.default.statSync(e).size>0?n():i(new Error("Downloaded file is empty or missing"))})}),h.on("error",u=>{k(e),i(u)}),c.on("error",u=>{k(e),i(u)})});m.setTimeout(3e4,()=>{m.destroy(),i(new Error("Timeout"))}),m.on("error",c=>{k(e),i(c)})});return}catch(n){if(k(e),o===t-1)throw n;console.log(`${yt}Retrying (${o+1}/${t})...${$t}`),await new Promise(i=>setTimeout(i,1e3*(o+1)))}}var d=f(require("fs")),p=f(require("path")),W=f(require("zlib"));async function xt(r,e){let t=0;for(;t+512<=r.length;){let o=r.subarray(t,t+512);if(o.every(c=>c===0))break;let n=o.subarray(0,100).toString().replace(/\0.*$/,""),i=o.subarray(345,500).toString().replace(/\0.*$/,"");i&&(n=`${i}/${n}`),n.startsWith("package/")&&(n=n.slice(8)),n=n.replace(/\//g,p.default.sep);let a=parseInt(o.subarray(124,136).toString().trim(),8)||0,m=o[156];if(t+=512,a>0&&n&&(m===0||m===48)){let c=p.default.join(e,n);await d.default.promises.mkdir(p.default.dirname(c),{recursive:!0}),await d.default.promises.writeFile(c,r.subarray(t,t+a)),t+=Math.ceil(a/512)*512}}}async function St(r,e){await d.default.promises.mkdir(e,{recursive:!0});let t=await d.default.promises.readFile(r),o;try{o=W.default.unzipSync(t)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await xt(o,e)}async function Et(r,e){await d.default.promises.mkdir(e,{recursive:!0});let t=await d.default.promises.readFile(r);if(t.length<22)throw new Error(`Invalid ZIP: file too small (${t.length} bytes)`);let o=Buffer.from([80,75,5,6]),n=t.length-22;for(;n>=0&&!t.subarray(n,n+4).equals(o);)n--;if(n<0)throw new Error(`Invalid ZIP: missing end of central directory (file may be corrupted or incomplete, size: ${t.length} bytes)`);if(n+22>t.length)throw new Error("Invalid ZIP: truncated EOCD record");let i=t.readUInt32LE(n+16),a=t.readUInt32LE(n+12),m=i+a;if(i>=t.length||m>t.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${i}, cdEnd: ${m}, fileSize: ${t.length})`);let c=Buffer.from([80,75,1,2]),s=i;for(;s<m;){if(s+46>t.length)throw new Error(`Invalid ZIP: truncated central directory at position ${s}`);if(!t.subarray(s,s+4).equals(c))throw new Error(`Invalid ZIP: invalid central directory signature at position ${s}`);let h=t.readUInt16LE(s+28),u=t.readUInt16LE(s+30),O=t.readUInt16LE(s+32),P=t.readUInt32LE(s+42),it=t.readUInt32LE(s+20),It=t.readUInt32LE(s+24),bt=t.readUInt16LE(s+10);if(s+46+h+u+O>t.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${s}`);let y=t.subarray(s+46,s+46+h).toString();if(s+=46+h+u+O,y.endsWith("/")){await d.default.promises.mkdir(p.default.join(e,y.replace(/\//g,p.default.sep)),{recursive:!0});continue}if(y=y.replace(/\//g,p.default.sep),P+30>t.length)throw new Error(`Invalid ZIP: local header out of bounds for ${y}`);let T=t.readUInt16LE(P+8),st=t.readUInt16LE(P+26),at=t.readUInt16LE(P+28),z=P+30+st+at,G=it;if(z+G>t.length)throw new Error(`Invalid ZIP: truncated file data for ${y}`);let H=t.subarray(z,z+G),B=p.default.join(e,y);await d.default.promises.mkdir(p.default.dirname(B),{recursive:!0});try{if(T===8)await d.default.promises.writeFile(B,W.default.inflateRawSync(H));else if(T===0)await d.default.promises.writeFile(B,H);else throw new Error(`Unsupported compression method ${T} for ${y}`)}catch(ct){throw new Error(`Failed to decompress ${y}: ${ct.message}`)}}}async function J(r,e,t){t==="windows"?await Et(r,e):await St(r,e)}function Q(r,e){let t=p.default.join(r,e);if(d.default.existsSync(t))return t;for(let o of d.default.readdirSync(r)){let n=p.default.join(r,o,e);if(d.default.statSync(p.default.join(r,o)).isDirectory()&&d.default.existsSync(n))return n}throw new Error(`Binary ${e} not found`)}var X=f(require("https"));var N="next-bin",C="cc-helper";function tt(r){return new Promise((e,t)=>{let o=`https://api.github.com${r}`,n=X.default.get(o,{headers:{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"}},i=>{let a="";i.on("data",m=>a+=m),i.on("end",()=>{i.statusCode!==200?t(new Error(`GitHub API error: ${i.statusCode}`)):e(JSON.parse(a))})});n.setTimeout(15e3,()=>{n.destroy(),t(new Error("GitHub API timeout"))}),n.on("error",t)})}async function b(){return(await tt(`/repos/${N}/${C}/releases/latest`)).tag_name.replace(/^v/,"")}async function L(r,e){var n;let t=await tt(`/repos/${N}/${C}/releases?per_page=10`),o=r==="windows"?`_${r}_${e}.zip`:`_${r}_${e}.tar.gz`;for(let i of t)if((n=i.assets)!=null&&n.some(a=>a.name.includes(o)))return i.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${r}-${e}`)}function R(r,e,t,o){let n=r.startsWith("v")?r:`v${r}`,i=`https://github.com/${N}/${C}/releases/download/${n}/${S(r,e,t)}`;return o?`${o}/${i}`:i}var vt="\x1B[31m",w="\x1B[90m",g="\x1B[0m";async function F(r,e,t,o,n){let i=S(r,e,t),a=v.default.join(D.default.tmpdir(),i),m=R(r,e,t,n);n&&console.log(`${w}Using proxy: ${n}${g}`);try{await A(m,a)}catch(s){throw s}let c=v.default.join(D.default.tmpdir(),`cc-helper_${Date.now()}`);l.default.mkdirSync(c,{recursive:!0});try{await J(a,c,e);let s=Q(c,I(e)),h=v.default.dirname(o);l.default.existsSync(h)||l.default.mkdirSync(h,{recursive:!0}),l.default.existsSync(o)&&l.default.unlinkSync(o),l.default.copyFileSync(s,o),process.platform!=="win32"&&l.default.chmodSync(o,493)}finally{let s=l.default.rmSync||l.default.rmdirSync;try{s(c,{recursive:!0,force:!0})}catch{}l.default.existsSync(a)&&l.default.unlinkSync(a)}}async function Z(r=null,e){let{platform:t,arch:o}=x(),n=E();if(l.default.existsSync(n))return n;if(r)try{return await F(r,t,o,n,e),n}catch(a){if(!a.message.includes("404"))throw a}let i=await b();try{await F(i,t,o,n,e)}catch(a){if(!a.message.includes("404"))throw a;i=await L(t,o),await F(i,t,o,n,e)}return n}async function et(r=null,e,t=[]){try{await Z(r,e)}catch{let{platform:n,arch:i}=x(),a=`${n}-${i}`,c=t.some(s=>s==="--proxy"||s.startsWith("--proxy="))?t.join(" "):`--proxy ${t.join(" ")}`.trim();console.log(`${vt}Failed to install (${a})${g}`),console.log(`${w}Possible causes:${g}`),console.log(`${w} \u2022 Network connectivity issues${g}`),console.log(`${w} \u2022 Permission issues${g}`),console.log(`${w}Try:${g}`),console.log(`${w} \u2022 Check your internet connection${g}`),console.log(`${w} \u2022 npx @unitsvc/cc-helper@latest ${c}${g}`)}}function nt(){let r=E(),e=v.default.dirname(r);l.default.existsSync(r)?(l.default.unlinkSync(r),console.log(`${w}Removed binary: ${r}${g}`)):console.log(`${w}No installation found${g}`),l.default.existsSync(e)&&l.default.readdirSync(e).length===0&&l.default.rmdirSync(e),console.log(`${w}To complete uninstallation, run:${g}`),console.log(`${w} npm uninstall -g @unitsvc/cc-helper${g}`)}async function M(r){if(!l.default.existsSync(r))return null;try{let e=v.default.resolve(r),o=(0,rt.execSync)(`"${e}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return o?o[1]:null}catch{return null}}async function ot(r){let e=E(),t=await b(),o=await M(e);return{current:o,latest:t,needsUpdate:!o||o!==t}}0&&(module.exports={checkForUpdate,ensureBinary,findReleaseWithBinary,getArchiveName,getBinaryName,getBinaryPath,getCurrentVersion,getDownloadUrl,getLatestVersion,getPlatform,install,uninstall});
|