@unitsvc/cc-helper 1.5.14 → 1.5.16

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/README-zh.md CHANGED
@@ -44,16 +44,18 @@ cc-helper update
44
44
 
45
45
  ### 代理支持
46
46
 
47
- 如果下载失败,使用 `--proxy` 参数:
47
+ 如果下载失败,使用 `--dl-proxy` 参数:
48
48
 
49
49
  ```bash
50
50
  # 使用默认代理
51
- cc-helper --proxy enable
51
+ cc-helper --dl-proxy enable
52
52
 
53
53
  # 使用自定义代理
54
- cc-helper --proxy https://your-proxy.com enable
54
+ cc-helper --dl-proxy https://your-proxy.com enable
55
55
  ```
56
56
 
57
+ > **注意**:`--proxy` 仍为向后兼容而支持,但已废弃。请使用 `--dl-proxy`。
58
+
57
59
  ---
58
60
 
59
61
  ## 快速开始
package/README.md CHANGED
@@ -44,16 +44,18 @@ cc-helper update
44
44
 
45
45
  ### Proxy Support
46
46
 
47
- If download fails, use `--proxy` flag:
47
+ If download fails, use `--dl-proxy` flag:
48
48
 
49
49
  ```bash
50
50
  # Use default proxy
51
- cc-helper --proxy enable
51
+ cc-helper --dl-proxy enable
52
52
 
53
53
  # Use custom proxy
54
- cc-helper --proxy https://your-proxy.com enable
54
+ cc-helper --dl-proxy https://your-proxy.com enable
55
55
  ```
56
56
 
57
+ > **Note**: `--proxy` is still supported for backward compatibility but is deprecated. Use `--dl-proxy` instead.
58
+
57
59
  ---
58
60
 
59
61
  ## Quick Start
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var dt=Object.create;var U=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var ht=Object.getOwnPropertyNames;var $t=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var wt=(t,o)=>{for(var e in o)U(t,e,{get:o[e],enumerable:!0})},V=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ht(o))!yt.call(t,n)&&n!==e&&U(t,n,{get:()=>o[n],enumerable:!(r=gt(o,n))||r.enumerable});return t};var h=(t,o,e)=>(e=t!=null?dt($t(t)):{},V(o||!t||!t.__esModule?U(e,"default",{value:t,enumerable:!0}):e,t)),xt=t=>V(U({},"__esModule",{value:!0}),t);var Rt={};wt(Rt,{ensureBinary:()=>Z,getBinaryPath:()=>x,getCurrentVersion:()=>H,main:()=>lt,uninstall:()=>G});module.exports=xt(Rt);var at=require("child_process"),ct=h(require("fs"));var p=h(require("fs")),M=h(require("os")),b=h(require("path")),rt=require("child_process");var R=h(require("os")),Y=h(require("path")),bt={darwin:"darwin",linux:"linux",win32:"windows",freebsd:"freebsd",openbsd:"openbsd",aix:"aix"},vt={x64:"amd64",arm64:"arm64",arm:"arm",ia32:"386",mips:"mips",mipsel:"mipsle",ppc64:"ppc64",ppc64le:"ppc64le",s390x:"s390x",riscv64:"riscv64"},K=["darwin_amd64","darwin_arm64","linux_386","linux_amd64","linux_arm","linux_arm64","linux_ppc64le","linux_s390x","linux_riscv64","windows_386","windows_amd64","windows_arm64","freebsd_amd64","freebsd_arm64","openbsd_amd64","openbsd_arm64"];function S(){let t=R.platform(),o=R.arch(),e=bt[t],r=vt[o];if(!e)throw new Error(`Unsupported platform: ${t}`);if(!r)throw new Error(`Unsupported arch: ${o}`);let n=`${e}_${r}`;if(!K.includes(n))throw new Error(`No binary available for ${n}. Supported combinations: ${K.join(", ")}`);return{platform:e,arch:r}}var N=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 x=()=>{let{platform:t}=S();return Y.join(__dirname,"bin",N(t))};var y=h(require("fs")),J=h(require("path")),St=h(require("http")),Et=h(require("https")),Pt="\x1B[90m",It="\x1B[0m";function A(t){try{y.existsSync(t)&&y.unlinkSync(t)}catch{}}async function F(t,o,e=3){for(let r=0;r<e;r++)try{await new Promise((n,s)=>{let f=(t.startsWith("https")?Et:St).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"}},a=>{if(a.statusCode===301||a.statusCode===302){let d=a.headers.location;if(d){F(d,o,e).then(n).catch(s);return}}if(a.statusCode!==200){s(new Error(`HTTP ${a.statusCode}`));return}let i=J.dirname(o);y.existsSync(i)||y.mkdirSync(i,{recursive:!0});let m=y.createWriteStream(o);a.pipe(m),m.on("finish",()=>{m.close(d=>{d?s(d):y.existsSync(o)&&y.statSync(o).size>0?n():s(new Error("Downloaded file is empty or missing"))})}),m.on("error",d=>{A(o),s(d)}),a.on("error",d=>{A(o),s(d)})});f.setTimeout(18e4,()=>{f.destroy(),s(new Error("Timeout"))}),f.on("error",a=>{A(o),s(a)})});return}catch(n){if(A(o),r===e-1)throw n;console.log(`${Pt}Retrying (${r+1}/${e})...${It}`),await new Promise(s=>setTimeout(s,1e3*(r+1)))}}var g=h(require("fs")),$=h(require("path")),L=h(require("zlib"));async function _t(t,o){let e=0;for(;e+512<=t.length;){let r=t.subarray(e,e+512);if(r.every(a=>a===0))break;let n=r.subarray(0,100).toString().replace(/\0.*$/,""),s=r.subarray(345,500).toString().replace(/\0.*$/,"");s&&(n=`${s}/${n}`),n.startsWith("package/")&&(n=n.slice(8)),n=n.replace(/\//g,$.sep);let l=parseInt(r.subarray(124,136).toString().trim(),8)||0,f=r[156];if(e+=512,l>0&&n&&(f===0||f===48)){let a=$.join(o,n);await g.promises.mkdir($.dirname(a),{recursive:!0}),await g.promises.writeFile(a,t.subarray(e,e+l)),e+=Math.ceil(l/512)*512}}}async function kt(t,o){await g.promises.mkdir(o,{recursive:!0});let e=await g.promises.readFile(t),r;try{r=L.unzipSync(e)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await _t(r,o)}async function Ut(t,o){await g.promises.mkdir(o,{recursive:!0});let e=await g.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 s=e.readUInt32LE(n+16),l=e.readUInt32LE(n+12),f=s+l;if(s>=e.length||f>e.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${s}, cdEnd: ${f}, fileSize: ${e.length})`);let a=Buffer.from([80,75,1,2]),i=s;for(;i<f;){if(i+46>e.length)throw new Error(`Invalid ZIP: truncated central directory at position ${i}`);if(!e.subarray(i,i+4).equals(a))throw new Error(`Invalid ZIP: invalid central directory signature at position ${i}`);let m=e.readUInt16LE(i+28),d=e.readUInt16LE(i+30),P=e.readUInt16LE(i+32),v=e.readUInt32LE(i+42),pt=e.readUInt32LE(i+20),Tt=e.readUInt32LE(i+24),At=e.readUInt16LE(i+10);if(i+46+m+d+P>e.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${i}`);let w=e.subarray(i+46,i+46+m).toString();if(i+=46+m+d+P,w.endsWith("/")){await g.promises.mkdir($.join(o,w.replace(/\//g,$.sep)),{recursive:!0});continue}if(w=w.replace(/\//g,$.sep),v+30>e.length)throw new Error(`Invalid ZIP: local header out of bounds for ${w}`);let z=e.readUInt16LE(v+8),ft=e.readUInt16LE(v+26),mt=e.readUInt16LE(v+28),W=v+30+ft+mt,j=pt;if(W+j>e.length)throw new Error(`Invalid ZIP: truncated file data for ${w}`);let q=e.subarray(W,W+j),B=$.join(o,w);await g.promises.mkdir($.dirname(B),{recursive:!0});try{if(z===8)await g.promises.writeFile(B,L.inflateRawSync(q));else if(z===0)await g.promises.writeFile(B,q);else throw new Error(`Unsupported compression method ${z} for ${w}`)}catch(ut){throw new Error(`Failed to decompress ${w}: ${ut.message}`)}}}async function X(t,o,e){e==="windows"?await Ut(t,o):await kt(t,o)}function Q(t,o){let e=$.join(t,o);if(g.existsSync(e))return e;for(let r of g.readdirSync(t)){let n=$.join(t,r,o);if(g.statSync($.join(t,r)).isDirectory()&&g.existsSync(n))return n}throw new Error(`Binary ${o} not found`)}var tt=h(require("https"));var D="next-bin",O="cc-helper";function et(t){return new Promise((o,e)=>{let r=`https://api.github.com${t}`,n=tt.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"}},s=>{let l="";s.on("data",f=>l+=f),s.on("end",()=>{s.statusCode!==200?e(new Error(`GitHub API error: ${s.statusCode}`)):o(JSON.parse(l))})});n.setTimeout(15e3,()=>{n.destroy(),e(new Error("GitHub API timeout"))}),n.on("error",e)})}async function ot(){return(await et(`/repos/${D}/${O}/releases/latest`)).tag_name.replace(/^v/,"")}async function C(t,o){var n;let e=await et(`/repos/${D}/${O}/releases?per_page=10`),r=t==="windows"?`_${t}_${o}.zip`:`_${t}_${o}.tar.gz`;for(let s of e)if((n=s.assets)!=null&&n.some(l=>l.name.includes(r)))return s.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${t}-${o}`)}function nt(t,o,e,r){let n=t.startsWith("v")?t:`v${t}`,s=`https://github.com/${D}/${O}/releases/download/${n}/${T(t,o,e)}`;return r?`${r}/${s}`:s}var I="\x1B[90m",_="\x1B[0m";async function k(t,o,e,r,n){let s=T(t,o,e),l=b.join(M.tmpdir(),s),f=nt(t,o,e,n);n&&console.log(`${I}Using proxy: ${n}${_}`);try{await F(f,l)}catch(i){throw i}let a=b.join(M.tmpdir(),`cc-helper_${Date.now()}`);p.mkdirSync(a,{recursive:!0});try{await X(l,a,o);let i=Q(a,N(o)),m=b.dirname(r);p.existsSync(m)||p.mkdirSync(m,{recursive:!0}),p.existsSync(r)&&p.unlinkSync(r),p.copyFileSync(i,r),process.platform!=="win32"&&p.chmodSync(r,493)}finally{let i=p.rmSync||p.rmdirSync;try{i(a,{recursive:!0,force:!0})}catch{}p.existsSync(l)&&p.unlinkSync(l)}}async function Z(t=null,o){let{platform:e,arch:r}=S(),n=x();if(p.existsSync(n))return n;if(t)try{return await k(t,e,r,n,o),n}catch(l){if(!l.message.includes("404"))throw l}let s=await ot();try{await k(s,e,r,n,o)}catch(l){if(!l.message.includes("404"))throw l;s=await C(e,r),await k(s,e,r,n,o)}return n}function G(){let t=x(),o=b.dirname(t);p.existsSync(t)?(p.unlinkSync(t),console.log(`${I}Removed binary: ${t}${_}`)):console.log(`${I}No installation found${_}`),p.existsSync(o)&&p.readdirSync(o).length===0&&p.rmdirSync(o),console.log(`${I}To complete uninstallation, run:${_}`),console.log(`${I} npm uninstall -g @unitsvc/cc-helper${_}`)}async function H(t){if(!p.existsSync(t))return null;try{let o=b.resolve(t),r=(0,rt.execSync)(`"${o}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return r?r[1]:null}catch{return null}}var st="\x1B[32m",E="\x1B[31m",u="\x1B[90m",c="\x1B[0m";function it(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 lt(){let t=process.argv.slice(2);if(t[0]==="uninstall"&&(G(),process.exit(0)),t[0]==="update"){let{proxy:l}=it(t.slice(1)),{platform:f,arch:a}=S(),i=`${f}-${a}`;console.log("Checking for updates to latest version...");let m=null,d;m=await H(x());try{d=await C(f,a)}catch{console.log(`${E}Failed to check for updates (${i})${c}`),console.log(`${E}Unable to fetch latest version from npm registry${c}`),console.log(`${u}Possible causes:${c}`),console.log(`${u} \u2022 Network connectivity issues${c}`),console.log(`${u} \u2022 npm registry is unreachable${c}`),console.log(`${u} \u2022 Corporate proxy/firewall blocking npm${c}`),console.log(`${u}Try:${c}`),console.log(`${u} \u2022 Check your internet connection${c}`),console.log(`${u} \u2022 Manually check: npm view @unitsvc/cc-helper version${c}`),console.log(`${u} \u2022 Check if you need to login: npm whoami${c}`),process.exit(1)}m&&m===d&&(console.log(`${st}cc-helper is up to date (${m}) (${i})${c}`),process.exit(0)),console.log(`New version available: ${d}${m?` (current: ${m})`:""}`),console.log("Installing update...");let P=x();try{if(await k(d,f,a,P,l),!ct.existsSync(P))throw new Error("Installation completed but binary not found");console.log(`${st}Successfully updated${m?` from ${m}`:""} to version ${d} (${i})${c}`),process.exit(0)}catch{console.log(`${E}Failed to install update (${i})${c}`),console.log(`${E}Unable to download or install the new version${c}`),console.log(`${u}Possible causes:${c}`),console.log(`${u} \u2022 Network connectivity issues${c}`),console.log(`${u} \u2022 Permission issues${c}`),console.log(`${u}Try:${c}`),console.log(`${u} \u2022 Check your internet connection${c}`),console.log(`${u} \u2022 Manually install: npm install -g @unitsvc/cc-helper@latest${c}`),process.exit(1)}}let{proxy:o,remainingArgs:e}=it(t),{platform:r,arch:n}=S(),s=`${r}-${n}`;try{let l=await Z(null,o),f=(0,at.spawn)(l,e,{stdio:"inherit"});f.on("close",a=>process.exit(a??1)),f.on("error",a=>{console.log(`${E}${a.message}${c}`),process.exit(1)})}catch{let a=t.some(i=>i==="--proxy"||i.startsWith("--proxy="))?t.join(" "):`--proxy ${t.join(" ")}`;console.log(`${E}Failed to install (${s})${c}`),console.log(`${u}Possible causes:${c}`),console.log(`${u} \u2022 Network connectivity issues${c}`),console.log(`${u} \u2022 Permission issues${c}`),console.log(`${u}Try:${c}`),console.log(`${u} \u2022 Check your internet connection${c}`),console.log(`${u} \u2022 npx @unitsvc/cc-helper@latest ${a}${c}`),process.exit(1)}}require.main===module&&lt();0&&(module.exports={ensureBinary,getBinaryPath,getCurrentVersion,main,uninstall});
2
+ "use strict";var xe=Object.create;var C=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Pe=Object.prototype.hasOwnProperty;var Ee=(e,o)=>{for(var t in o)C(e,t,{get:o[t],enumerable:!0})},oe=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of be(o))!Pe.call(e,n)&&n!==t&&C(e,n,{get:()=>o[n],enumerable:!(r=we(o,n))||r.enumerable});return e};var y=(e,o,t)=>(t=e!=null?xe(ve(e)):{},oe(o||!e||!e.__esModule?C(t,"default",{value:e,enumerable:!0}):t,e)),Se=e=>oe(C({},"__esModule",{value:!0}),e);var Ce={};Ee(Ce,{ensureBinary:()=>V,getBinaryPath:()=>P,getCurrentVersion:()=>X,main:()=>ye,parseDlProxyArg:()=>J,parseLegacyProxyArg:()=>Q,uninstall:()=>K});module.exports=Se(Ce);var ge=require("child_process"),he=y(require("fs"));var p=y(require("fs")),q=y(require("os")),E=y(require("path")),de=require("child_process");var D=y(require("os")),re=y(require("path")),Ie={darwin:"darwin",linux:"linux",win32:"windows",freebsd:"freebsd",openbsd:"openbsd",aix:"aix"},_e={x64:"amd64",arm64:"arm64",arm:"arm",ia32:"386",mips:"mips",mipsel:"mipsle",ppc64:"ppc64",ppc64le:"ppc64le",s390x:"s390x",riscv64:"riscv64"},ne=["darwin_amd64","darwin_arm64","linux_386","linux_amd64","linux_arm","linux_arm64","linux_ppc64le","linux_s390x","linux_riscv64","windows_386","windows_amd64","windows_arm64","freebsd_amd64","freebsd_arm64","openbsd_amd64","openbsd_arm64"];function I(){let e=D.platform(),o=D.arch(),t=Ie[e],r=_e[o];if(!t)throw new Error(`Unsupported platform: ${e}`);if(!r)throw new Error(`Unsupported arch: ${o}`);let n=`${t}_${r}`;if(!ne.includes(n))throw new Error(`No binary available for ${n}. Supported combinations: ${ne.join(", ")}`);return{platform:t,arch:r}}var G=e=>e==="windows"?"cc-helper.exe":"cc-helper";function N(e,o,t){let r=e.replace(/^v/,"");return o==="windows"?`cc-helper_${r}_${o}_${t}.zip`:`cc-helper_${r}_${o}_${t}.tar.gz`}var P=()=>{let{platform:e}=I();return re.join(__dirname,"bin",G(e))};var b=y(require("fs")),se=y(require("path")),Ue=y(require("http")),ke=y(require("https")),Ae="\x1B[90m",We="\x1B[0m";function z(e){try{b.existsSync(e)&&b.unlinkSync(e)}catch{}}async function H(e,o,t=3){for(let r=0;r<t;r++)try{await new Promise((n,i)=>{let d=(e.startsWith("https")?ke:Ue).get(e,{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"}},l=>{if(l.statusCode===301||l.statusCode===302){let u=l.headers.location;if(u){H(u,o,t).then(n).catch(i);return}}if(l.statusCode!==200){i(new Error(`HTTP ${l.statusCode}`));return}let s=se.dirname(o);b.existsSync(s)||b.mkdirSync(s,{recursive:!0});let m=b.createWriteStream(o);l.pipe(m),m.on("finish",()=>{m.close(u=>{u?i(u):b.existsSync(o)&&b.statSync(o).size>0?n():i(new Error("Downloaded file is empty or missing"))})}),m.on("error",u=>{z(o),i(u)}),l.on("error",u=>{z(o),i(u)})});d.setTimeout(18e4,()=>{d.destroy(),i(new Error("Timeout"))}),d.on("error",l=>{z(o),i(l)})});return}catch(n){if(z(o),r===t-1)throw n;console.log(`${Ae}Retrying (${r+1}/${t})...${We}`),await new Promise(i=>setTimeout(i,1e3*(r+1)))}}var g=y(require("fs")),$=y(require("path")),B=y(require("zlib"));async function Re(e,o){let t=0;for(;t+512<=e.length;){let r=e.subarray(t,t+512);if(r.every(l=>l===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,$.sep);let c=parseInt(r.subarray(124,136).toString().trim(),8)||0,d=r[156];if(t+=512,c>0&&n&&(d===0||d===48)){let l=$.join(o,n);await g.promises.mkdir($.dirname(l),{recursive:!0}),await g.promises.writeFile(l,e.subarray(t,t+c)),t+=Math.ceil(c/512)*512}}}async function Le(e,o){await g.promises.mkdir(o,{recursive:!0});let t=await g.promises.readFile(e),r;try{r=B.unzipSync(t)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await Re(r,o)}async function Te(e,o){await g.promises.mkdir(o,{recursive:!0});let t=await g.promises.readFile(e);if(t.length<22)throw new Error(`Invalid ZIP: file too small (${t.length} bytes)`);let r=Buffer.from([80,75,5,6]),n=t.length-22;for(;n>=0&&!t.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: ${t.length} bytes)`);if(n+22>t.length)throw new Error("Invalid ZIP: truncated EOCD record");let i=t.readUInt32LE(n+16),c=t.readUInt32LE(n+12),d=i+c;if(i>=t.length||d>t.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${i}, cdEnd: ${d}, fileSize: ${t.length})`);let l=Buffer.from([80,75,1,2]),s=i;for(;s<d;){if(s+46>t.length)throw new Error(`Invalid ZIP: truncated central directory at position ${s}`);if(!t.subarray(s,s+4).equals(l))throw new Error(`Invalid ZIP: invalid central directory signature at position ${s}`);let m=t.readUInt16LE(s+28),u=t.readUInt16LE(s+30),v=t.readUInt16LE(s+32),x=t.readUInt32LE(s+42),M=t.readUInt32LE(s+20),R=t.readUInt32LE(s+24),L=t.readUInt16LE(s+10);if(s+46+m+u+v>t.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${s}`);let h=t.subarray(s+46,s+46+m).toString();if(s+=46+m+u+v,h.endsWith("/")){await g.promises.mkdir($.join(o,h.replace(/\//g,$.sep)),{recursive:!0});continue}if(h=h.replace(/\//g,$.sep),x+30>t.length)throw new Error(`Invalid ZIP: local header out of bounds for ${h}`);let w=t.readUInt16LE(x+8),S=t.readUInt16LE(x+26),T=t.readUInt16LE(x+28),U=x+30+S+T,ee=M;if(U+ee>t.length)throw new Error(`Invalid ZIP: truncated file data for ${h}`);let te=t.subarray(U,U+ee),Z=$.join(o,h);await g.promises.mkdir($.dirname(Z),{recursive:!0});try{if(w===8)await g.promises.writeFile(Z,B.inflateRawSync(te));else if(w===0)await g.promises.writeFile(Z,te);else throw new Error(`Unsupported compression method ${w} for ${h}`)}catch($e){throw new Error(`Failed to decompress ${h}: ${$e.message}`)}}}async function ie(e,o,t){t==="windows"?await Te(e,o):await Le(e,o)}function ae(e,o){let t=$.join(e,o);if(g.existsSync(t))return t;for(let r of g.readdirSync(e)){let n=$.join(e,r,o);if(g.statSync($.join(e,r)).isDirectory()&&g.existsSync(n))return n}throw new Error(`Binary ${o} not found`)}var ce=y(require("https"));var Y="next-bin",j="cc-helper";function le(e){return new Promise((o,t)=>{let r=`https://api.github.com${e}`,n=ce.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 c="";i.on("data",d=>c+=d),i.on("end",()=>{i.statusCode!==200?t(new Error(`GitHub API error: ${i.statusCode}`)):o(JSON.parse(c))})});n.setTimeout(15e3,()=>{n.destroy(),t(new Error("GitHub API timeout"))}),n.on("error",t)})}async function pe(){return(await le(`/repos/${Y}/${j}/releases/latest`)).tag_name.replace(/^v/,"")}async function F(e,o){var n;let t=await le(`/repos/${Y}/${j}/releases?per_page=10`),r=e==="windows"?`_${e}_${o}.zip`:`_${e}_${o}.tar.gz`;for(let i of t)if((n=i.assets)!=null&&n.some(c=>c.name.includes(r)))return i.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${e}-${o}`)}function fe(e,o,t,r){let n=e.startsWith("v")?e:`v${e}`,i=`https://github.com/${Y}/${j}/releases/download/${n}/${N(e,o,t)}`;return r?`${r}/${i}`:i}var k="\x1B[90m",A="\x1B[0m";async function W(e,o,t,r,n){let i=N(e,o,t),c=E.join(q.tmpdir(),i),d=fe(e,o,t,n);n&&console.log(`${k}Using proxy: ${n}${A}`);try{await H(d,c)}catch(s){throw s}let l=E.join(q.tmpdir(),`cc-helper_${Date.now()}`);p.mkdirSync(l,{recursive:!0});try{await ie(c,l,o);let s=ae(l,G(o)),m=E.dirname(r);p.existsSync(m)||p.mkdirSync(m,{recursive:!0}),p.existsSync(r)&&p.unlinkSync(r),p.copyFileSync(s,r),process.platform!=="win32"&&p.chmodSync(r,493)}finally{let s=p.rmSync||p.rmdirSync;try{s(l,{recursive:!0,force:!0})}catch{}p.existsSync(c)&&p.unlinkSync(c)}}async function V(e=null,o){let{platform:t,arch:r}=I(),n=P();if(p.existsSync(n))return n;if(e)try{return await W(e,t,r,n,o),n}catch(c){if(!c.message.includes("404"))throw c}let i=await pe();try{await W(i,t,r,n,o)}catch(c){if(!c.message.includes("404"))throw c;i=await F(t,r),await W(i,t,r,n,o)}return n}function K(){let e=P(),o=E.dirname(e);p.existsSync(e)?(p.unlinkSync(e),console.log(`${k}Removed binary: ${e}${A}`)):console.log(`${k}No installation found${A}`),p.existsSync(o)&&p.readdirSync(o).length===0&&p.rmdirSync(o),console.log(`${k}To complete uninstallation, run:${A}`),console.log(`${k} npm uninstall -g @unitsvc/cc-helper${A}`)}async function X(e){if(!p.existsSync(e))return null;try{let o=E.resolve(e),r=(0,de.execSync)(`"${o}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return r?r[1]:null}catch{return null}}var me="\x1B[32m",_="\x1B[31m",f="\x1B[90m",ue="\x1B[33m",O="\x1B[1m",a="\x1B[0m";function J(e){let o=[],t,r="https://edgeone.gh-proxy.org";for(let n=0;n<e.length;n++)e[n]==="--dl-proxy"?n+1<e.length&&(e[n+1].startsWith("http://")||e[n+1].startsWith("https://"))?(t=e[n+1],n++):t=r:e[n].startsWith("--dl-proxy=")?t=e[n].slice(11)||r:o.push(e[n]);return{proxy:t,remainingArgs:o}}function Q(e){var l;let o="https://edgeone.gh-proxy.org",t=e[0]==="--proxy"||(((l=e[0])==null?void 0:l.startsWith("--proxy="))??!1),r=e[0]==="update"||e[0]==="enable";if(!(t||r))return{proxy:void 0,remainingArgs:[...e],usedDeprecated:!1};let i=[],c,d=!1;for(let s=0;s<e.length;s++)if((e[s]==="--proxy"||e[s].startsWith("--proxy="))&&!d){if(e[s]==="--proxy"?s+1<e.length&&(e[s+1].startsWith("http://")||e[s+1].startsWith("https://"))?(c=e[s+1],s++):c=o:c=e[s].slice(8)||o,d=!0,!t)continue}else e[s]==="--proxy"||e[s].startsWith("--proxy="),i.push(e[s]);return{proxy:c,remainingArgs:i,usedDeprecated:c!==void 0}}async function ye(){let e=process.argv.slice(2);if(e[0]==="uninstall"&&(K(),process.exit(0)),e[0]==="update"){let m=e.slice(1),{proxy:u}=J(m),{proxy:v,usedDeprecated:x}=Q(m),M=u??v;x&&console.log(`${O}npm${a} ${O}${ue}WARN${a} deprecated --proxy: Use --dl-proxy instead. --proxy will be removed in a future version.`);let{platform:R,arch:L}=I(),h=`${R}-${L}`;console.log("Checking for updates to latest version...");let w=null,S;w=await X(P());try{S=await F(R,L)}catch{console.log(`${_}Failed to check for updates (${h})${a}`),console.log(`${_}Unable to fetch latest version from npm registry${a}`),console.log(`${f}Possible causes:${a}`),console.log(`${f} \u2022 Network connectivity issues${a}`),console.log(`${f} \u2022 npm registry is unreachable${a}`),console.log(`${f} \u2022 Corporate proxy/firewall blocking npm${a}`),console.log(`${f}Try:${a}`),console.log(`${f} \u2022 Check your internet connection${a}`),console.log(`${f} \u2022 Manually check: npm view @unitsvc/cc-helper version${a}`),console.log(`${f} \u2022 Check if you need to login: npm whoami${a}`),process.exit(1)}w&&w===S&&(console.log(`${me}cc-helper is up to date (${w}) (${h})${a}`),process.exit(0)),console.log(`New version available: ${S}${w?` (current: ${w})`:""}`),console.log("Installing update...");let T=P();try{if(await W(S,R,L,T,M),!he.existsSync(T))throw new Error("Installation completed but binary not found");console.log(`${me}Successfully updated${w?` from ${w}`:""} to version ${S} (${h})${a}`),process.exit(0)}catch{console.log(`${_}Failed to install update (${h})${a}`),console.log(`${_}Unable to download or install the new version${a}`),console.log(`${f}Possible causes:${a}`),console.log(`${f} \u2022 Network connectivity issues${a}`),console.log(`${f} \u2022 Permission issues${a}`),console.log(`${f}Try:${a}`),console.log(`${f} \u2022 Check your internet connection${a}`),console.log(`${f} \u2022 Manually install: npm install -g @unitsvc/cc-helper@latest${a}`),process.exit(1)}}let{proxy:o,remainingArgs:t}=J(e),{proxy:r,remainingArgs:n,usedDeprecated:i}=Q(t),c=o??r;i&&console.log(`${O}npm${a} ${O}${ue}WARN${a} deprecated --proxy: Use --dl-proxy instead. --proxy will be removed in a future version.`);let{platform:d,arch:l}=I(),s=`${d}-${l}`;try{let m=await V(null,c),u=(0,ge.spawn)(m,n,{stdio:"inherit"});u.on("close",v=>process.exit(v??1)),u.on("error",v=>{console.log(`${_}${v.message}${a}`),process.exit(1)})}catch{let v=e.some(x=>x==="--dl-proxy"||x.startsWith("--dl-proxy=")||x==="--proxy"||x.startsWith("--proxy="))?e.join(" "):`--dl-proxy ${e.join(" ")}`;console.log(`${_}Failed to install (${s})${a}`),console.log(`${f}Possible causes:${a}`),console.log(`${f} \u2022 Network connectivity issues${a}`),console.log(`${f} \u2022 Permission issues${a}`),console.log(`${f}Try:${a}`),console.log(`${f} \u2022 Check your internet connection${a}`),console.log(`${f} \u2022 npx @unitsvc/cc-helper@latest ${v}${a}`),process.exit(1)}}require.main===module&&ye();0&&(module.exports={ensureBinary,getBinaryPath,getCurrentVersion,main,parseDlProxyArg,parseLegacyProxyArg,uninstall});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ct=Object.create;var _=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var dt=(r,e)=>{for(var t in e)_(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ft(e))!pt.call(r,n)&&n!==t&&_(r,n,{get:()=>e[n],enumerable:!(o=lt(e,n))||o.enumerable});return r};var d=(r,e,t)=>(t=r!=null?ct(mt(r)):{},V(e||!r||!r.__esModule?_(t,"default",{value:r,enumerable:!0}):t,r)),ut=r=>V(_({},"__esModule",{value:!0}),r);var Pt={};dt(Pt,{checkForUpdate:()=>nt,ensureBinary:()=>O,findReleaseWithBinary:()=>R,getArchiveName:()=>b,getBinaryName:()=>P,getBinaryPath:()=>E,getCurrentVersion:()=>M,getDownloadUrl:()=>z,getLatestVersion:()=>I,getPlatform:()=>S,install:()=>rt,uninstall:()=>et});module.exports=ut(Pt);var a=d(require("fs")),F=d(require("os")),x=d(require("path")),tt=require("child_process");var U=d(require("os")),K=d(require("path")),gt={darwin:"darwin",linux:"linux",win32:"windows",freebsd:"freebsd",openbsd:"openbsd",aix:"aix"},ht={x64:"amd64",arm64:"arm64",arm:"arm",ia32:"386",mips:"mips",mipsel:"mipsle",ppc64:"ppc64",ppc64le:"ppc64le",s390x:"s390x",riscv64:"riscv64"},q=["darwin_amd64","darwin_arm64","linux_386","linux_amd64","linux_arm","linux_arm64","linux_ppc64le","linux_s390x","linux_riscv64","windows_386","windows_amd64","windows_arm64","freebsd_amd64","freebsd_arm64","openbsd_amd64","openbsd_arm64"];function S(){let r=U.platform(),e=U.arch(),t=gt[r],o=ht[e];if(!t)throw new Error(`Unsupported platform: ${r}`);if(!o)throw new Error(`Unsupported arch: ${e}`);let n=`${t}_${o}`;if(!q.includes(n))throw new Error(`No binary available for ${n}. Supported combinations: ${q.join(", ")}`);return{platform:t,arch:o}}var P=r=>r==="windows"?"cc-helper.exe":"cc-helper";function b(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}=S();return K.join(__dirname,"bin",P(r))};var g=d(require("fs")),j=d(require("path")),wt=d(require("http")),yt=d(require("https")),$t="\x1B[90m",xt="\x1B[0m";function k(r){try{g.existsSync(r)&&g.unlinkSync(r)}catch{}}async function N(r,e,t=3){for(let o=0;o<t;o++)try{await new Promise((n,s)=>{let m=(r.startsWith("https")?yt:wt).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"}},l=>{if(l.statusCode===301||l.statusCode===302){let u=l.headers.location;if(u){N(u,e,t).then(n).catch(s);return}}if(l.statusCode!==200){s(new Error(`HTTP ${l.statusCode}`));return}let i=j.dirname(e);g.existsSync(i)||g.mkdirSync(i,{recursive:!0});let w=g.createWriteStream(e);l.pipe(w),w.on("finish",()=>{w.close(u=>{u?s(u):g.existsSync(e)&&g.statSync(e).size>0?n():s(new Error("Downloaded file is empty or missing"))})}),w.on("error",u=>{k(e),s(u)}),l.on("error",u=>{k(e),s(u)})});m.setTimeout(18e4,()=>{m.destroy(),s(new Error("Timeout"))}),m.on("error",l=>{k(e),s(l)})});return}catch(n){if(k(e),o===t-1)throw n;console.log(`${$t}Retrying (${o+1}/${t})...${xt}`),await new Promise(s=>setTimeout(s,1e3*(o+1)))}}var f=d(require("fs")),p=d(require("path")),L=d(require("zlib"));async function St(r,e){let t=0;for(;t+512<=r.length;){let o=r.subarray(t,t+512);if(o.every(l=>l===0))break;let n=o.subarray(0,100).toString().replace(/\0.*$/,""),s=o.subarray(345,500).toString().replace(/\0.*$/,"");s&&(n=`${s}/${n}`),n.startsWith("package/")&&(n=n.slice(8)),n=n.replace(/\//g,p.sep);let c=parseInt(o.subarray(124,136).toString().trim(),8)||0,m=o[156];if(t+=512,c>0&&n&&(m===0||m===48)){let l=p.join(e,n);await f.promises.mkdir(p.dirname(l),{recursive:!0}),await f.promises.writeFile(l,r.subarray(t,t+c)),t+=Math.ceil(c/512)*512}}}async function bt(r,e){await f.promises.mkdir(e,{recursive:!0});let t=await f.promises.readFile(r),o;try{o=L.unzipSync(t)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await St(o,e)}async function Et(r,e){await f.promises.mkdir(e,{recursive:!0});let t=await f.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 s=t.readUInt32LE(n+16),c=t.readUInt32LE(n+12),m=s+c;if(s>=t.length||m>t.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${s}, cdEnd: ${m}, fileSize: ${t.length})`);let l=Buffer.from([80,75,1,2]),i=s;for(;i<m;){if(i+46>t.length)throw new Error(`Invalid ZIP: truncated central directory at position ${i}`);if(!t.subarray(i,i+4).equals(l))throw new Error(`Invalid ZIP: invalid central directory signature at position ${i}`);let w=t.readUInt16LE(i+28),u=t.readUInt16LE(i+30),Z=t.readUInt16LE(i+32),v=t.readUInt32LE(i+42),ot=t.readUInt32LE(i+20),It=t.readUInt32LE(i+24),_t=t.readUInt16LE(i+10);if(i+46+w+u+Z>t.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${i}`);let $=t.subarray(i+46,i+46+w).toString();if(i+=46+w+u+Z,$.endsWith("/")){await f.promises.mkdir(p.join(e,$.replace(/\//g,p.sep)),{recursive:!0});continue}if($=$.replace(/\//g,p.sep),v+30>t.length)throw new Error(`Invalid ZIP: local header out of bounds for ${$}`);let T=t.readUInt16LE(v+8),st=t.readUInt16LE(v+26),it=t.readUInt16LE(v+28),B=v+30+st+it,G=ot;if(B+G>t.length)throw new Error(`Invalid ZIP: truncated file data for ${$}`);let H=t.subarray(B,B+G),A=p.join(e,$);await f.promises.mkdir(p.dirname(A),{recursive:!0});try{if(T===8)await f.promises.writeFile(A,L.inflateRawSync(H));else if(T===0)await f.promises.writeFile(A,H);else throw new Error(`Unsupported compression method ${T} for ${$}`)}catch(at){throw new Error(`Failed to decompress ${$}: ${at.message}`)}}}async function Y(r,e,t){t==="windows"?await Et(r,e):await bt(r,e)}function J(r,e){let t=p.join(r,e);if(f.existsSync(t))return t;for(let o of f.readdirSync(r)){let n=p.join(r,o,e);if(f.statSync(p.join(r,o)).isDirectory()&&f.existsSync(n))return n}throw new Error(`Binary ${e} not found`)}var Q=d(require("https"));var W="next-bin",C="cc-helper";function X(r){return new Promise((e,t)=>{let o=`https://api.github.com${r}`,n=Q.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"}},s=>{let c="";s.on("data",m=>c+=m),s.on("end",()=>{s.statusCode!==200?t(new Error(`GitHub API error: ${s.statusCode}`)):e(JSON.parse(c))})});n.setTimeout(15e3,()=>{n.destroy(),t(new Error("GitHub API timeout"))}),n.on("error",t)})}async function I(){return(await X(`/repos/${W}/${C}/releases/latest`)).tag_name.replace(/^v/,"")}async function R(r,e){var n;let t=await X(`/repos/${W}/${C}/releases?per_page=10`),o=r==="windows"?`_${r}_${e}.zip`:`_${r}_${e}.tar.gz`;for(let s of t)if((n=s.assets)!=null&&n.some(c=>c.name.includes(o)))return s.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${r}-${e}`)}function z(r,e,t,o){let n=r.startsWith("v")?r:`v${r}`,s=`https://github.com/${W}/${C}/releases/download/${n}/${b(r,e,t)}`;return o?`${o}/${s}`:s}var vt="\x1B[31m",y="\x1B[90m",h="\x1B[0m";async function D(r,e,t,o,n){let s=b(r,e,t),c=x.join(F.tmpdir(),s),m=z(r,e,t,n);n&&console.log(`${y}Using proxy: ${n}${h}`);try{await N(m,c)}catch(i){throw i}let l=x.join(F.tmpdir(),`cc-helper_${Date.now()}`);a.mkdirSync(l,{recursive:!0});try{await Y(c,l,e);let i=J(l,P(e)),w=x.dirname(o);a.existsSync(w)||a.mkdirSync(w,{recursive:!0}),a.existsSync(o)&&a.unlinkSync(o),a.copyFileSync(i,o),process.platform!=="win32"&&a.chmodSync(o,493)}finally{let i=a.rmSync||a.rmdirSync;try{i(l,{recursive:!0,force:!0})}catch{}a.existsSync(c)&&a.unlinkSync(c)}}async function O(r=null,e){let{platform:t,arch:o}=S(),n=E();if(a.existsSync(n))return n;if(r)try{return await D(r,t,o,n,e),n}catch(c){if(!c.message.includes("404"))throw c}let s=await I();try{await D(s,t,o,n,e)}catch(c){if(!c.message.includes("404"))throw c;s=await R(t,o),await D(s,t,o,n,e)}return n}async function rt(r=null,e,t=[]){try{await O(r,e)}catch{let{platform:n,arch:s}=S(),c=`${n}-${s}`,l=t.some(i=>i==="--proxy"||i.startsWith("--proxy="))?t.join(" "):`--proxy ${t.join(" ")}`.trim();console.log(`${vt}Failed to install (${c})${h}`),console.log(`${y}Possible causes:${h}`),console.log(`${y} \u2022 Network connectivity issues${h}`),console.log(`${y} \u2022 Permission issues${h}`),console.log(`${y}Try:${h}`),console.log(`${y} \u2022 Check your internet connection${h}`),console.log(`${y} \u2022 npx @unitsvc/cc-helper@latest ${l}${h}`)}}function et(){let r=E(),e=x.dirname(r);a.existsSync(r)?(a.unlinkSync(r),console.log(`${y}Removed binary: ${r}${h}`)):console.log(`${y}No installation found${h}`),a.existsSync(e)&&a.readdirSync(e).length===0&&a.rmdirSync(e),console.log(`${y}To complete uninstallation, run:${h}`),console.log(`${y} npm uninstall -g @unitsvc/cc-helper${h}`)}async function M(r){if(!a.existsSync(r))return null;try{let e=x.resolve(r),o=(0,tt.execSync)(`"${e}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return o?o[1]:null}catch{return null}}async function nt(r){let e=E(),t=await I(),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});
1
+ "use strict";var ct=Object.create;var _=Object.defineProperty;var lt=Object.getOwnPropertyDescriptor;var ft=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var dt=(r,e)=>{for(var t in e)_(r,t,{get:e[t],enumerable:!0})},V=(r,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ft(e))!pt.call(r,n)&&n!==t&&_(r,n,{get:()=>e[n],enumerable:!(o=lt(e,n))||o.enumerable});return r};var d=(r,e,t)=>(t=r!=null?ct(mt(r)):{},V(e||!r||!r.__esModule?_(t,"default",{value:r,enumerable:!0}):t,r)),ut=r=>V(_({},"__esModule",{value:!0}),r);var Pt={};dt(Pt,{checkForUpdate:()=>nt,ensureBinary:()=>O,findReleaseWithBinary:()=>R,getArchiveName:()=>b,getBinaryName:()=>P,getBinaryPath:()=>E,getCurrentVersion:()=>M,getDownloadUrl:()=>z,getLatestVersion:()=>I,getPlatform:()=>S,install:()=>rt,uninstall:()=>et});module.exports=ut(Pt);var a=d(require("fs")),F=d(require("os")),x=d(require("path")),tt=require("child_process");var U=d(require("os")),K=d(require("path")),gt={darwin:"darwin",linux:"linux",win32:"windows",freebsd:"freebsd",openbsd:"openbsd",aix:"aix"},ht={x64:"amd64",arm64:"arm64",arm:"arm",ia32:"386",mips:"mips",mipsel:"mipsle",ppc64:"ppc64",ppc64le:"ppc64le",s390x:"s390x",riscv64:"riscv64"},q=["darwin_amd64","darwin_arm64","linux_386","linux_amd64","linux_arm","linux_arm64","linux_ppc64le","linux_s390x","linux_riscv64","windows_386","windows_amd64","windows_arm64","freebsd_amd64","freebsd_arm64","openbsd_amd64","openbsd_arm64"];function S(){let r=U.platform(),e=U.arch(),t=gt[r],o=ht[e];if(!t)throw new Error(`Unsupported platform: ${r}`);if(!o)throw new Error(`Unsupported arch: ${e}`);let n=`${t}_${o}`;if(!q.includes(n))throw new Error(`No binary available for ${n}. Supported combinations: ${q.join(", ")}`);return{platform:t,arch:o}}var P=r=>r==="windows"?"cc-helper.exe":"cc-helper";function b(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}=S();return K.join(__dirname,"bin",P(r))};var g=d(require("fs")),j=d(require("path")),wt=d(require("http")),yt=d(require("https")),$t="\x1B[90m",xt="\x1B[0m";function k(r){try{g.existsSync(r)&&g.unlinkSync(r)}catch{}}async function W(r,e,t=3){for(let o=0;o<t;o++)try{await new Promise((n,s)=>{let m=(r.startsWith("https")?yt:wt).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"}},l=>{if(l.statusCode===301||l.statusCode===302){let u=l.headers.location;if(u){W(u,e,t).then(n).catch(s);return}}if(l.statusCode!==200){s(new Error(`HTTP ${l.statusCode}`));return}let i=j.dirname(e);g.existsSync(i)||g.mkdirSync(i,{recursive:!0});let w=g.createWriteStream(e);l.pipe(w),w.on("finish",()=>{w.close(u=>{u?s(u):g.existsSync(e)&&g.statSync(e).size>0?n():s(new Error("Downloaded file is empty or missing"))})}),w.on("error",u=>{k(e),s(u)}),l.on("error",u=>{k(e),s(u)})});m.setTimeout(18e4,()=>{m.destroy(),s(new Error("Timeout"))}),m.on("error",l=>{k(e),s(l)})});return}catch(n){if(k(e),o===t-1)throw n;console.log(`${$t}Retrying (${o+1}/${t})...${xt}`),await new Promise(s=>setTimeout(s,1e3*(o+1)))}}var f=d(require("fs")),p=d(require("path")),L=d(require("zlib"));async function St(r,e){let t=0;for(;t+512<=r.length;){let o=r.subarray(t,t+512);if(o.every(l=>l===0))break;let n=o.subarray(0,100).toString().replace(/\0.*$/,""),s=o.subarray(345,500).toString().replace(/\0.*$/,"");s&&(n=`${s}/${n}`),n.startsWith("package/")&&(n=n.slice(8)),n=n.replace(/\//g,p.sep);let c=parseInt(o.subarray(124,136).toString().trim(),8)||0,m=o[156];if(t+=512,c>0&&n&&(m===0||m===48)){let l=p.join(e,n);await f.promises.mkdir(p.dirname(l),{recursive:!0}),await f.promises.writeFile(l,r.subarray(t,t+c)),t+=Math.ceil(c/512)*512}}}async function bt(r,e){await f.promises.mkdir(e,{recursive:!0});let t=await f.promises.readFile(r),o;try{o=L.unzipSync(t)}catch(n){throw new Error(`Failed to decompress tar.gz: ${n.message}`)}await St(o,e)}async function Et(r,e){await f.promises.mkdir(e,{recursive:!0});let t=await f.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 s=t.readUInt32LE(n+16),c=t.readUInt32LE(n+12),m=s+c;if(s>=t.length||m>t.length)throw new Error(`Invalid ZIP: central directory out of bounds (cdOffset: ${s}, cdEnd: ${m}, fileSize: ${t.length})`);let l=Buffer.from([80,75,1,2]),i=s;for(;i<m;){if(i+46>t.length)throw new Error(`Invalid ZIP: truncated central directory at position ${i}`);if(!t.subarray(i,i+4).equals(l))throw new Error(`Invalid ZIP: invalid central directory signature at position ${i}`);let w=t.readUInt16LE(i+28),u=t.readUInt16LE(i+30),Z=t.readUInt16LE(i+32),v=t.readUInt32LE(i+42),ot=t.readUInt32LE(i+20),It=t.readUInt32LE(i+24),_t=t.readUInt16LE(i+10);if(i+46+w+u+Z>t.length)throw new Error(`Invalid ZIP: truncated central directory entry at position ${i}`);let $=t.subarray(i+46,i+46+w).toString();if(i+=46+w+u+Z,$.endsWith("/")){await f.promises.mkdir(p.join(e,$.replace(/\//g,p.sep)),{recursive:!0});continue}if($=$.replace(/\//g,p.sep),v+30>t.length)throw new Error(`Invalid ZIP: local header out of bounds for ${$}`);let T=t.readUInt16LE(v+8),st=t.readUInt16LE(v+26),it=t.readUInt16LE(v+28),B=v+30+st+it,G=ot;if(B+G>t.length)throw new Error(`Invalid ZIP: truncated file data for ${$}`);let H=t.subarray(B,B+G),A=p.join(e,$);await f.promises.mkdir(p.dirname(A),{recursive:!0});try{if(T===8)await f.promises.writeFile(A,L.inflateRawSync(H));else if(T===0)await f.promises.writeFile(A,H);else throw new Error(`Unsupported compression method ${T} for ${$}`)}catch(at){throw new Error(`Failed to decompress ${$}: ${at.message}`)}}}async function Y(r,e,t){t==="windows"?await Et(r,e):await bt(r,e)}function J(r,e){let t=p.join(r,e);if(f.existsSync(t))return t;for(let o of f.readdirSync(r)){let n=p.join(r,o,e);if(f.statSync(p.join(r,o)).isDirectory()&&f.existsSync(n))return n}throw new Error(`Binary ${e} not found`)}var Q=d(require("https"));var N="next-bin",C="cc-helper";function X(r){return new Promise((e,t)=>{let o=`https://api.github.com${r}`,n=Q.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"}},s=>{let c="";s.on("data",m=>c+=m),s.on("end",()=>{s.statusCode!==200?t(new Error(`GitHub API error: ${s.statusCode}`)):e(JSON.parse(c))})});n.setTimeout(15e3,()=>{n.destroy(),t(new Error("GitHub API timeout"))}),n.on("error",t)})}async function I(){return(await X(`/repos/${N}/${C}/releases/latest`)).tag_name.replace(/^v/,"")}async function R(r,e){var n;let t=await X(`/repos/${N}/${C}/releases?per_page=10`),o=r==="windows"?`_${r}_${e}.zip`:`_${r}_${e}.tar.gz`;for(let s of t)if((n=s.assets)!=null&&n.some(c=>c.name.includes(o)))return s.tag_name.replace(/^v/,"");throw new Error(`No binary found for ${r}-${e}`)}function z(r,e,t,o){let n=r.startsWith("v")?r:`v${r}`,s=`https://github.com/${N}/${C}/releases/download/${n}/${b(r,e,t)}`;return o?`${o}/${s}`:s}var vt="\x1B[31m",y="\x1B[90m",h="\x1B[0m";async function D(r,e,t,o,n){let s=b(r,e,t),c=x.join(F.tmpdir(),s),m=z(r,e,t,n);n&&console.log(`${y}Using proxy: ${n}${h}`);try{await W(m,c)}catch(i){throw i}let l=x.join(F.tmpdir(),`cc-helper_${Date.now()}`);a.mkdirSync(l,{recursive:!0});try{await Y(c,l,e);let i=J(l,P(e)),w=x.dirname(o);a.existsSync(w)||a.mkdirSync(w,{recursive:!0}),a.existsSync(o)&&a.unlinkSync(o),a.copyFileSync(i,o),process.platform!=="win32"&&a.chmodSync(o,493)}finally{let i=a.rmSync||a.rmdirSync;try{i(l,{recursive:!0,force:!0})}catch{}a.existsSync(c)&&a.unlinkSync(c)}}async function O(r=null,e){let{platform:t,arch:o}=S(),n=E();if(a.existsSync(n))return n;if(r)try{return await D(r,t,o,n,e),n}catch(c){if(!c.message.includes("404"))throw c}let s=await I();try{await D(s,t,o,n,e)}catch(c){if(!c.message.includes("404"))throw c;s=await R(t,o),await D(s,t,o,n,e)}return n}async function rt(r=null,e,t=[]){try{await O(r,e)}catch{let{platform:n,arch:s}=S(),c=`${n}-${s}`,l=t.some(i=>i==="--dl-proxy"||i.startsWith("--dl-proxy=")||i==="--proxy"||i.startsWith("--proxy="))?t.join(" "):`--dl-proxy ${t.join(" ")}`.trim();console.log(`${vt}Failed to install (${c})${h}`),console.log(`${y}Possible causes:${h}`),console.log(`${y} \u2022 Network connectivity issues${h}`),console.log(`${y} \u2022 Permission issues${h}`),console.log(`${y}Try:${h}`),console.log(`${y} \u2022 Check your internet connection${h}`),console.log(`${y} \u2022 npx @unitsvc/cc-helper@latest ${l}${h}`)}}function et(){let r=E(),e=x.dirname(r);a.existsSync(r)?(a.unlinkSync(r),console.log(`${y}Removed binary: ${r}${h}`)):console.log(`${y}No installation found${h}`),a.existsSync(e)&&a.readdirSync(e).length===0&&a.rmdirSync(e),console.log(`${y}To complete uninstallation, run:${h}`),console.log(`${y} npm uninstall -g @unitsvc/cc-helper${h}`)}async function M(r){if(!a.existsSync(r))return null;try{let e=x.resolve(r),o=(0,tt.execSync)(`"${e}" --version`,{timeout:5e3}).toString().trim().match(/(\d+\.\d+\.\d+)/);return o?o[1]:null}catch{return null}}async function nt(r){let e=E(),t=await I(),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});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitsvc/cc-helper",
3
- "version": "1.5.14",
3
+ "version": "1.5.16",
4
4
  "description": "Claude Code multi-provider & channels toolkit (by next-bin)",
5
5
  "main": "dist/index.js",
6
6
  "bin": {