@unitsvc/cc-helper 1.5.12 → 1.5.14
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 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(3e4,()=>{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&<();0&&(module.exports={ensureBinary,getBinaryPath,getCurrentVersion,main,uninstall});
|
|
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&<();0&&(module.exports={ensureBinary,getBinaryPath,getCurrentVersion,main,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(
|
|
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});
|