UNPKG

@lonewolfyx/nu

Version:

a npm dependencies check update

4 lines (3 loc) 12.8 kB
#!/usr/bin/env node var A="0.0.2";import Ie from"cac";import{createRequire as G}from"node:module";import{spawn as me}from"child_process";import{normalize as ge}from"path";import{cwd as ve}from"process";import{delimiter as D,resolve as xe,dirname as ye}from"path";import{PassThrough as Oe}from"stream";import $e from"readline";var $=G(import.meta.url),U=Object.create,R=Object.defineProperty,V=Object.getOwnPropertyDescriptor,Z=Object.getOwnPropertyNames,K=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty,b=(o=>typeof $<"u"?$:typeof Proxy<"u"?new Proxy(o,{get:(e,r)=>(typeof $<"u"?$:e)[r]}):o)(function(o){if(typeof $<"u")return $.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')}),x=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),ee=(o,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Z(e))!Q.call(o,i)&&i!==r&&R(o,i,{get:()=>e[i],enumerable:!(s=V(e,i))||s.enumerable});return o},te=(o,e,r)=>(r=o!=null?U(K(o)):{},ee(e||!o||!o.__esModule?R(r,"default",{value:o,enumerable:!0}):r,o)),re=x((o,e)=>{"use strict";e.exports=n,n.sync=d;var r=b("fs");function s(t,c){var u=c.pathExt!==void 0?c.pathExt:process.env.PATHEXT;if(!u||(u=u.split(";"),u.indexOf("")!==-1))return!0;for(var a=0;a<u.length;a++){var l=u[a].toLowerCase();if(l&&t.substr(-l.length).toLowerCase()===l)return!0}return!1}function i(t,c,u){return!t.isSymbolicLink()&&!t.isFile()?!1:s(c,u)}function n(t,c,u){r.stat(t,function(a,l){u(a,a?!1:i(l,t,c))})}function d(t,c){return i(r.statSync(t),t,c)}}),oe=x((o,e)=>{"use strict";e.exports=s,s.sync=i;var r=b("fs");function s(t,c,u){r.stat(t,function(a,l){u(a,a?!1:n(l,c))})}function i(t,c){return n(r.statSync(t),c)}function n(t,c){return t.isFile()&&d(t,c)}function d(t,c){var u=t.mode,a=t.uid,l=t.gid,p=c.uid!==void 0?c.uid:process.getuid&&process.getuid(),f=c.gid!==void 0?c.gid:process.getgid&&process.getgid(),m=parseInt("100",8),g=parseInt("010",8),y=parseInt("001",8),w=m|g,O=u&y||u&g&&l===f||u&m&&a===p||u&w&&p===0;return O}}),se=x((o,e)=>{"use strict";var r=b("fs"),s;process.platform==="win32"||global.TESTING_WINDOWS?s=re():s=oe(),e.exports=i,i.sync=n;function i(d,t,c){if(typeof t=="function"&&(c=t,t={}),!c){if(typeof Promise!="function")throw new TypeError("callback not provided");return new Promise(function(u,a){i(d,t||{},function(l,p){l?a(l):u(p)})})}s(d,t||{},function(u,a){u&&(u.code==="EACCES"||t&&t.ignoreErrors)&&(u=null,a=!1),c(u,a)})}function n(d,t){try{return s.sync(d,t||{})}catch(c){if(t&&t.ignoreErrors||c.code==="EACCES")return!1;throw c}}}),ne=x((o,e)=>{"use strict";var r=process.platform==="win32"||process.env.OSTYPE==="cygwin"||process.env.OSTYPE==="msys",s=b("path"),i=r?";":":",n=se(),d=a=>Object.assign(new Error(`not found: ${a}`),{code:"ENOENT"}),t=(a,l)=>{let p=l.colon||i,f=a.match(/\//)||r&&a.match(/\\/)?[""]:[...r?[process.cwd()]:[],...(l.path||process.env.PATH||"").split(p)],m=r?l.pathExt||process.env.PATHEXT||".EXE;.CMD;.BAT;.COM":"",g=r?m.split(p):[""];return r&&a.indexOf(".")!==-1&&g[0]!==""&&g.unshift(""),{pathEnv:f,pathExt:g,pathExtExe:m}},c=(a,l,p)=>{typeof l=="function"&&(p=l,l={}),l||(l={});let{pathEnv:f,pathExt:m,pathExtExe:g}=t(a,l),y=[],w=v=>new Promise((C,E)=>{if(v===f.length)return l.all&&y.length?C(y):E(d(a));let _=f[v],S=/^".*"$/.test(_)?_.slice(1,-1):_,k=s.join(S,a),j=!S&&/^\.[\\\/]/.test(a)?a.slice(0,2)+k:k;C(O(j,v,0))}),O=(v,C,E)=>new Promise((_,S)=>{if(E===m.length)return _(w(C+1));let k=m[E];n(v+k,{pathExt:g},(j,W)=>{if(!j&&W)if(l.all)y.push(v+k);else return _(v+k);return _(O(v,C,E+1))})});return p?w(0).then(v=>p(null,v),p):w(0)},u=(a,l)=>{l=l||{};let{pathEnv:p,pathExt:f,pathExtExe:m}=t(a,l),g=[];for(let y=0;y<p.length;y++){let w=p[y],O=/^".*"$/.test(w)?w.slice(1,-1):w,v=s.join(O,a),C=!O&&/^\.[\\\/]/.test(a)?a.slice(0,2)+v:v;for(let E=0;E<f.length;E++){let _=C+f[E];try{if(n.sync(_,{pathExt:m}))if(l.all)g.push(_);else return _}catch{}}}if(l.all&&g.length)return g;if(l.nothrow)return null;throw d(a)};e.exports=c,c.sync=u}),ie=x((o,e)=>{"use strict";var r=(s={})=>{let i=s.env||process.env;return(s.platform||process.platform)!=="win32"?"PATH":Object.keys(i).reverse().find(n=>n.toUpperCase()==="PATH")||"Path"};e.exports=r,e.exports.default=r}),ce=x((o,e)=>{"use strict";var r=b("path"),s=ne(),i=ie();function n(t,c){let u=t.options.env||process.env,a=process.cwd(),l=t.options.cwd!=null,p=l&&process.chdir!==void 0&&!process.chdir.disabled;if(p)try{process.chdir(t.options.cwd)}catch{}let f;try{f=s.sync(t.command,{path:u[i({env:u})],pathExt:c?r.delimiter:void 0})}catch{}finally{p&&process.chdir(a)}return f&&(f=r.resolve(l?t.options.cwd:"",f)),f}function d(t){return n(t)||n(t,!0)}e.exports=d}),ae=x((o,e)=>{"use strict";var r=/([()\][%!^"`<>&|;, *?])/g;function s(n){return n=n.replace(r,"^$1"),n}function i(n,d){return n=`${n}`,n=n.replace(/(\\*)"/g,'$1$1\\"'),n=n.replace(/(\\*)$/,"$1$1"),n=`"${n}"`,n=n.replace(r,"^$1"),d&&(n=n.replace(r,"^$1")),n}e.exports.command=s,e.exports.argument=i}),pe=x((o,e)=>{"use strict";e.exports=/^#!(.*)/}),le=x((o,e)=>{"use strict";var r=pe();e.exports=(s="")=>{let i=s.match(r);if(!i)return null;let[n,d]=i[0].replace(/#! ?/,"").split(" "),t=n.split("/").pop();return t==="env"?d:d?`${t} ${d}`:t}}),ue=x((o,e)=>{"use strict";var r=b("fs"),s=le();function i(n){let d=Buffer.alloc(150),t;try{t=r.openSync(n,"r"),r.readSync(t,d,0,150,0),r.closeSync(t)}catch{}return s(d.toString())}e.exports=i}),de=x((o,e)=>{"use strict";var r=b("path"),s=ce(),i=ae(),n=ue(),d=process.platform==="win32",t=/\.(?:com|exe)$/i,c=/node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;function u(p){p.file=s(p);let f=p.file&&n(p.file);return f?(p.args.unshift(p.file),p.command=f,s(p)):p.file}function a(p){if(!d)return p;let f=u(p),m=!t.test(f);if(p.options.forceShell||m){let g=c.test(f);p.command=r.normalize(p.command),p.command=i.command(p.command),p.args=p.args.map(w=>i.argument(w,g));let y=[p.command].concat(p.args).join(" ");p.args=["/d","/s","/c",`"${y}"`],p.command=process.env.comspec||"cmd.exe",p.options.windowsVerbatimArguments=!0}return p}function l(p,f,m){f&&!Array.isArray(f)&&(m=f,f=null),f=f?f.slice(0):[],m=Object.assign({},m);let g={command:p,args:f,options:m,file:void 0,original:{command:p,args:f}};return m.shell?g:a(g)}e.exports=l}),fe=x((o,e)=>{"use strict";var r=process.platform==="win32";function s(t,c){return Object.assign(new Error(`${c} ${t.command} ENOENT`),{code:"ENOENT",errno:"ENOENT",syscall:`${c} ${t.command}`,path:t.command,spawnargs:t.args})}function i(t,c){if(!r)return;let u=t.emit;t.emit=function(a,l){if(a==="exit"){let p=n(l,c,"spawn");if(p)return u.call(t,"error",p)}return u.apply(t,arguments)}}function n(t,c){return r&&t===1&&!c.file?s(c.original,"spawn"):null}function d(t,c){return r&&t===1&&!c.file?s(c.original,"spawnSync"):null}e.exports={hookChildProcess:i,verifyENOENT:n,verifyENOENTSync:d,notFoundError:s}}),he=x((o,e)=>{"use strict";var r=b("child_process"),s=de(),i=fe();function n(t,c,u){let a=s(t,c,u),l=r.spawn(a.command,a.args,a.options);return i.hookChildProcess(l,a),l}function d(t,c,u){let a=s(t,c,u),l=r.spawnSync(a.command,a.args,a.options);return l.error=l.error||i.verifyENOENTSync(l.status,a),l}e.exports=n,e.exports.spawn=n,e.exports.sync=d,e.exports._parse=s,e.exports._enoent=i}),we=/^path$/i,I={key:"PATH",value:""};function _e(o){for(let e in o){if(!Object.prototype.hasOwnProperty.call(o,e)||!we.test(e))continue;let r=o[e];return r?{key:e,value:r}:I}return I}function Ee(o,e){let r=e.value.split(D),s=o,i;do r.push(xe(s,"node_modules",".bin")),i=s,s=ye(s);while(s!==i);return{key:e.key,value:r.join(D)}}function be(o,e){let r={...process.env,...e},s=Ee(o,_e(r));return r[s.key]=s.value,r}var Ce=o=>{let e=o.length,r=new Oe,s=()=>{--e===0&&r.emit("end")};for(let i of o)i.pipe(r,{end:!1}),i.on("end",s);return r},ke=te(he(),1),L=class extends Error{result;output;get exitCode(){if(this.result.exitCode!==null)return this.result.exitCode}constructor(o,e){super(`Process exited with non-zero status (${o.exitCode})`),this.result=o,this.output=e}},Te={timeout:void 0,persist:!1},Se={windowsHide:!0};function je(o,e){return{command:ge(o),args:e??[]}}function Pe(o){let e=new AbortController;for(let r of o){if(r.aborted)return e.abort(),r;let s=()=>{e.abort(r.reason)};r.addEventListener("abort",s,{signal:e.signal})}return e.signal}var Ne=class{_process;_aborted=!1;_options;_command;_args;_resolveClose;_processClosed;_thrownError;get process(){return this._process}get pid(){return this._process?.pid}get exitCode(){if(this._process&&this._process.exitCode!==null)return this._process.exitCode}constructor(o,e,r){this._options={...Te,...r},this._command=o,this._args=e??[],this._processClosed=new Promise(s=>{this._resolveClose=s})}kill(o){return this._process?.kill(o)===!0}get aborted(){return this._aborted}get killed(){return this._process?.killed===!0}pipe(o,e,r){return Ae(o,e,{...r,stdin:this})}async*[Symbol.asyncIterator](){let o=this._process;if(!o)return;let e=[];this._streamErr&&e.push(this._streamErr),this._streamOut&&e.push(this._streamOut);let r=Ce(e),s=$e.createInterface({input:r});for await(let i of s)yield i.toString();if(await this._processClosed,o.removeAllListeners(),this._thrownError)throw this._thrownError;if(this._options?.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new L(this)}async _waitForOutput(){let o=this._process;if(!o)throw new Error("No process was started");let e="",r="";if(this._streamOut)for await(let i of this._streamOut)r+=i.toString();if(this._streamErr)for await(let i of this._streamErr)e+=i.toString();if(await this._processClosed,this._options?.stdin&&await this._options.stdin,o.removeAllListeners(),this._thrownError)throw this._thrownError;let s={stderr:e,stdout:r,exitCode:this.exitCode};if(this._options.throwOnError&&this.exitCode!==0&&this.exitCode!==void 0)throw new L(this,s);return s}then(o,e){return this._waitForOutput().then(o,e)}_streamOut;_streamErr;spawn(){let o=ve(),e=this._options,r={...Se,...e.nodeOptions},s=[];this._resetState(),e.timeout!==void 0&&s.push(AbortSignal.timeout(e.timeout)),e.signal!==void 0&&s.push(e.signal),e.persist===!0&&(r.detached=!0),s.length>0&&(r.signal=Pe(s)),r.env=be(o,r.env);let{command:i,args:n}=je(this._command,this._args),d=(0,ke._parse)(i,n,r),t=me(d.command,d.args,d.options);if(t.stderr&&(this._streamErr=t.stderr),t.stdout&&(this._streamOut=t.stdout),this._process=t,t.once("error",this._onError),t.once("close",this._onClose),e.stdin!==void 0&&t.stdin&&e.stdin.process){let{stdout:c}=e.stdin.process;c&&c.pipe(t.stdin)}}_resetState(){this._aborted=!1,this._processClosed=new Promise(o=>{this._resolveClose=o}),this._thrownError=void 0}_onError=o=>{if(o.name==="AbortError"&&(!(o.cause instanceof Error)||o.cause.name!=="TimeoutError")){this._aborted=!0;return}this._thrownError=o};_onClose=()=>{this._resolveClose&&this._resolveClose()}},T=(o,e,r)=>{let s=new Ne(o,e,r);return s.spawn(),s},Ae=T;import*as N from"node:process";var P,F,H,q,M=!0;typeof process<"u"&&({FORCE_COLOR:P,NODE_DISABLE_COLORS:F,NO_COLOR:H,TERM:q}=process.env||{},M=process.stdout&&process.stdout.isTTY);var De={enabled:!F&&H==null&&q!=="dumb"&&(P!=null&&P!=="0"||M)};function h(o,e){let r=new RegExp(`\\x1b\\[${e}m`,"g"),s=`\x1B[${o}m`,i=`\x1B[${e}m`;return function(n){return!De.enabled||n==null?n:s+(~(""+n).indexOf(i)?n.replace(r,i+s):n)+i}}var Ue=h(0,0),Ve=h(1,22),Ze=h(2,22),Ke=h(3,23),Qe=h(4,24),et=h(7,27),tt=h(8,28),rt=h(9,29),ot=h(30,39),Y=h(31,39),z=h(32,39),st=h(33,39),nt=h(34,39),it=h(35,39),ct=h(36,39),at=h(37,39),pt=h(90,39),lt=h(90,39),ut=h(40,49),dt=h(41,49),ft=h(42,49),ht=h(43,49),mt=h(44,49),gt=h(45,49),vt=h(46,49),xt=h(47,49);import Le from"node:path";import Re from"node:fs";var J=Ie("npm-check"),B=N.cwd();J.command("","npm dependencies check update").action(async()=>{try{console.log(""),console.log("Checking for outdated packages...");let{stdout:o}=await T("npm",["outdated","--json"],{nodeOptions:{cwd:B}});if(!o||o.trim()===""){console.log("\u6240\u6709\u4F9D\u8D56\u5305\u5747\u4E3A\u6700\u65B0\uFF01");return}let e=JSON.parse(o),r=Le.resolve(N.cwd(),"package.json"),s=JSON.parse(Re.readFileSync(r,"utf-8")),i=["dependencies","devDependencies","peerDependencies","optionalDependencies"];console.log(`Found ${Y(Object.keys(e).length)} outdated packages: `);let n={};for(let d of i)n[d]={};n.unknown={};for(let[d,t]of Object.entries(e)){let c="unknown";for(let u of i)if(s[u]&&s[u][d]){c=u;break}n[c][d]=`${t.current} -> ${z(t.latest)}`}for(let[d,t]of Object.entries(n))if(Object.keys(t).length>0){console.log(`${d}:`);for(let[c,u]of Object.entries(t)){console.log(` ${c} ${u}`);let a=["install",`${c}@latest`];d==="devDependencies"&&a.push("-D"),await T("npm",a,{nodeOptions:{cwd:B}})}console.log("")}console.log("All packages updated successfully!")}catch(o){console.error(o)}});J.help().version(A).parse();