icoa-cli 2.19.620 → 2.19.621
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/lib/update-check.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFileSync as
|
|
1
|
+
import{readFileSync as o,writeFileSync as e,existsSync as n,accessSync as t,realpathSync as r,constants as s}from"node:fs";import{join as i,dirname as a,basename as l,sep as c}from"node:path";import{fileURLToPath as u}from"node:url";import{homedir as g,platform as p}from"node:os";import{spawnSync as d}from"node:child_process";import chalk from"chalk";import{getIcoaDir as f}from"./config.js";const y=a(u(import.meta.url)),m=i(y,"..",".."),h=y,v=h.startsWith(g()+c)||h.includes(`${c}.nvm${c}`)||h.includes(`${c}.fnm${c}`)||h.includes(`${c}.volta${c}`),w="win32"===p()||"darwin"===p()||v?"":"sudo ",$=o=>`${w}npm install -g icoa-cli@${o}`,k=["https://registry.npmjs.org","https://registry.npmmirror.com"],b=36e5;function C(){return JSON.parse(o(i(m,"package.json"),"utf-8")).version}function x(o,e){const n=o.split(".").map(Number),t=e.split(".").map(Number);for(let o=0;o<Math.max(n.length,t.length);o++){const e=n[o]??0,r=t[o]??0;if(e>r)return!0;if(e<r)return!1}return!1}function O(){return i(f(),"update-check.json")}function A(o){try{const n={lastCheck:Date.now(),latestVersion:o.version,registries:o.registries};e(O(),JSON.stringify(n,null,2))}catch{}}async function S(o){const e=await Promise.all(k.map(async e=>{const n=Date.now(),t=new AbortController,r=setTimeout(()=>t.abort(),o);try{const o=await fetch(`${e}/icoa-cli/latest`,{signal:t.signal,headers:{Accept:"application/json"}});return o.ok?{reg:e,version:(await o.json()).version??null,ms:Date.now()-n}:{reg:e,version:null,ms:1/0}}catch{return{reg:e,version:null,ms:1/0}}finally{clearTimeout(r)}}));let n=null;for(const o of e)!o.version||n&&!x(o.version,n)||(n=o.version);if(!n)return null;const t=[...e].sort((o,e)=>(o.version===n?0:1)-(e.version===n?0:1)||o.ms-e.ms);return{version:n,registries:t.map(o=>o.reg)}}async function N(e){const t=function(){try{return n(O())?JSON.parse(o(O(),"utf-8")):null}catch{return null}}();if(t?.latestVersion&&Date.now()-t.lastCheck<e.maxAgeMs)return{version:t.latestVersion,registries:t.registries?.length?t.registries:k};const r=await S(e.timeoutMs);return r&&A(r),r}function T(o,e){const n=function(o,e){const n=o.split(".").map(Number),t=e.split(".").map(Number);return n[0]!==t[0]||n[1]!==t[1]?-1:(n[2]??0)-(t[2]??0)}(e,o),t=n>0?chalk.gray(` (${n} version${1===n?"":"s"} behind)`):"",r=chalk.yellow(" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");if(console.log(),console.log(r),console.log(chalk.bold.yellow(" ⬆ New version available!")),console.log(),console.log(chalk.white(" Current: ")+chalk.gray(`v${o}`)),console.log(chalk.white(" Latest: ")+chalk.bold.green(`v${e}`)+t),console.log(),E().ok)console.log(chalk.white(" Update: ")+chalk.gray("type ")+chalk.bold.cyan("upgrade")+chalk.gray(" at icoa>")),console.log(chalk.gray(" or in your shell: ")+chalk.cyan($(e)));else{console.log(chalk.white(" Update: ")+chalk.bold.cyan($(e)));const o="darwin"===p()?"Cmd+C":"win32"===p()?"Ctrl+C":"Ctrl+Shift+C";console.log(chalk.gray(` ↑ select & ${o} to copy — typos break it`))}console.log(r),console.log()}export function checkForUpdates(){setTimeout(async()=>{try{const o=C(),e=await N({maxAgeMs:b,timeoutMs:5e3});e&&x(e.version,o)&&T(o,e.version)}catch{}},0)}let _=null;function E(){return _||(_=(()=>{if("win32"===p())return{ok:!1,reason:"native Windows install"};let o;try{o=r(m)}catch{return{ok:!1,reason:"cannot resolve install directory"}}const e=a(o);if("node_modules"!==l(e)||"lib"!==l(a(e)))return{ok:!1,reason:"not an npm global install (dev tree?)"};const n=a(a(e));let c;try{c=r(i(a(process.execPath),"npm"))}catch{return{ok:!1,reason:"npm not found next to node"}}let u=!1;for(const o of[e,i(n,"bin")])try{t(o,s.W_OK)}catch{u=!0}return u&&0!==d("sudo",["-V"],{stdio:"ignore"}).status?{ok:!1,reason:"needs sudo, and sudo is not available"}:{ok:!0,npm:[process.execPath,c],prefix:n,needsSudo:u}})(),_)}function M(o,e,n){console.log(chalk.yellow(" ⚠ icoa cannot upgrade itself here")+chalk.gray(` — ${n}.`)),console.log(chalk.white(" Run this in your shell instead: ")+chalk.bold.cyan($(e))),console.log(chalk.gray(" then ")+chalk.cyan("hash -r")+chalk.gray(" and ")+chalk.cyan("icoa --version")+chalk.gray(` (now v${o})`))}export async function runUpgrade(o){const e=C(),n=o.ask?await N({maxAgeMs:b,timeoutMs:2e3}):await S(8e3);if(!n)return o.ask||(console.log(chalk.yellow(" ⚠ could not reach the npm registry")+chalk.gray(` — you are on v${e}.`)),console.log(chalk.gray(" Check the network (")+chalk.cyan("doctor")+chalk.gray(") and try again."))),"offline";if(o.ask||A(n),!x(n.version,e))return o.ask||console.log(chalk.green(` ✅ icoa v${e} is the latest version.`)),"current";const t=E();if(!t.ok)return o.ask?T(e,n.version):M(e,n.version,t.reason),"skipped";if(o.ask){console.log(),console.log(chalk.bold.yellow(" ⬆ New version: ")+chalk.gray(`v${e}`)+chalk.white(" → ")+chalk.bold.green(`v${n.version}`));const{confirm:o}=await import("@inquirer/prompts");let t=!0;try{t=await o({message:"Upgrade now? (Enter = yes, n = later)",default:!0})}catch{t=!1}if(!t)return console.log(chalk.gray(" Later — type ")+chalk.cyan("upgrade")+chalk.gray(" at icoa> any time.")),"skipped"}return function(o,e,n){const t=process.stdin;try{t.isTTY&&t.setRawMode&&t.setRawMode(!1)}catch{}o.needsSudo&&console.log(chalk.gray(" icoa is installed system-wide — sudo will ask for your computer password."));for(const t of n)for(const n of[!1,!0]){console.log(chalk.gray(` ⬇ icoa-cli@${e} from ${t.replace(/^https:\/\//,"")}${n?" (refreshing)":""} …`));const r=[o.npm[1],"install","-g",`icoa-cli@${e}`,`--prefix=${o.prefix}`,`--registry=${t}/`,...n?["--prefer-online"]:[],"--no-fund","--no-progress","--no-audit","--loglevel=error","--fetch-timeout=30000","--fetch-retries=1"],s=o.needsSudo?d("sudo",[o.npm[0],...r],{stdio:"inherit"}):d(o.npm[0],r,{stdio:"inherit"});let i="";try{i=C()}catch{}if(i===e)return!0;console.log(chalk.yellow(" ⚠ that did not work")+chalk.gray(0===s.status?` (npm finished but icoa is still v${i||"?"})`:` (npm exit ${s.status})`))}return!1}(t,n.version,n.registries)?(console.log(chalk.green(` ✅ upgraded to v${n.version}`)+("1"===process.env.ICOA_SUPERVISED?chalk.gray(" — restarting icoa …"):chalk.gray(" — run ")+chalk.cyan("icoa")+chalk.gray(" to start it."))),console.log(),"upgraded"):(console.log(chalk.red(` ✗ upgrade failed — still v${e}.`)),M(e,n.version,"every source failed"),"failed")}export function bootUpgradeEligible(o){return!0===process.stdin.isTTY&&"1"===process.env.ICOA_SUPERVISED&&"1"!==process.env.ICOA_RELAUNCH&&"1"!==process.env.ICOA_NO_UPDATE&&!process.env.ICOA_TEST_BOOT_MODE&&!o}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icoa-cli",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.621",
|
|
4
4
|
"description": "ICOA CLI — AI-native competition runtime of the International Cyber Olympiad in AI: learn, practise, and compete in AI & cybersecurity from the terminal (AI4CTF · CTF4AI · CTF4EAI)",
|
|
5
5
|
"author": "Charlie Zhu",
|
|
6
6
|
"type": "module",
|