@visulima/vis 1.0.0-alpha.13 → 1.0.0-alpha.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/CHANGELOG.md +28 -0
- package/LICENSE.md +7242 -385
- package/dist/bin.js +1 -1
- package/dist/config/index.d.ts +493 -1
- package/dist/config/index.js +1 -1
- package/dist/packem_chunks/applyDefaults.js +2 -2
- package/dist/packem_chunks/bin.js +1134 -199
- package/dist/packem_chunks/doctor-probe.js +2 -2
- package/dist/packem_chunks/fix.js +11 -11
- package/dist/packem_chunks/handler.js +1 -1
- package/dist/packem_chunks/handler10.js +1 -1
- package/dist/packem_chunks/handler11.js +1 -1
- package/dist/packem_chunks/handler12.js +5 -5
- package/dist/packem_chunks/handler13.js +1 -1
- package/dist/packem_chunks/handler14.js +20 -18
- package/dist/packem_chunks/handler15.js +1 -20
- package/dist/packem_chunks/handler16.js +1 -1
- package/dist/packem_chunks/handler17.js +1 -1
- package/dist/packem_chunks/handler18.js +1 -1
- package/dist/packem_chunks/handler19.js +5 -1
- package/dist/packem_chunks/handler2.js +1 -1
- package/dist/packem_chunks/handler20.js +1 -5
- package/dist/packem_chunks/handler21.js +1 -1
- package/dist/packem_chunks/handler22.js +5 -1
- package/dist/packem_chunks/handler23.js +1 -5
- package/dist/packem_chunks/handler24.js +3 -1
- package/dist/packem_chunks/handler25.js +1 -3
- package/dist/packem_chunks/handler26.js +1 -1
- package/dist/packem_chunks/handler27.js +7 -1
- package/dist/packem_chunks/handler28.js +22 -6
- package/dist/packem_chunks/handler29.js +3 -23
- package/dist/packem_chunks/handler3.js +4 -4
- package/dist/packem_chunks/handler30.js +18 -3
- package/dist/packem_chunks/handler31.js +1 -1
- package/dist/packem_chunks/handler32.js +2 -2
- package/dist/packem_chunks/handler33.js +24 -24
- package/dist/packem_chunks/handler34.js +2 -2
- package/dist/packem_chunks/handler35.js +2 -2
- package/dist/packem_chunks/handler36.js +20 -20
- package/dist/packem_chunks/handler37.js +2 -2
- package/dist/packem_chunks/handler38.js +6 -22
- package/dist/packem_chunks/handler39.js +11 -11
- package/dist/packem_chunks/handler4.js +1 -1
- package/dist/packem_chunks/handler40.js +5 -22
- package/dist/packem_chunks/handler41.js +24 -6
- package/dist/packem_chunks/handler42.js +10 -5
- package/dist/packem_chunks/handler43.js +153 -10
- package/dist/packem_chunks/handler44.js +25 -153
- package/dist/packem_chunks/handler45.js +3 -25
- package/dist/packem_chunks/handler46.js +27 -3
- package/dist/packem_chunks/handler47.js +41 -26
- package/dist/packem_chunks/handler48.js +32 -40
- package/dist/packem_chunks/handler5.js +7 -7
- package/dist/packem_chunks/handler6.js +1 -1
- package/dist/packem_chunks/handler7.js +1 -1
- package/dist/packem_chunks/handler8.js +1 -1
- package/dist/packem_chunks/handler9.js +1 -1
- package/dist/packem_chunks/heal-accept.js +4 -4
- package/dist/packem_chunks/heal.js +3 -3
- package/dist/packem_chunks/help-command.js +18 -0
- package/dist/packem_chunks/index.js +4 -4
- package/dist/packem_chunks/loader.js +1 -1
- package/dist/packem_chunks/tar.js +1 -1
- package/dist/packem_shared/ai-analysis-Dzs_nUwM.js +68 -0
- package/dist/packem_shared/ai-cache-Dtvmbsru.js +1 -0
- package/dist/packem_shared/{ai-fix-nn4zOE95.js → ai-fix-BmLM72GS.js} +4 -4
- package/dist/packem_shared/cache-directory-xASJia6M.js +1 -0
- package/dist/packem_shared/dependency-scan-DmwPKwLy.js +2 -0
- package/dist/packem_shared/docker-CA-scYu0.js +2 -0
- package/dist/packem_shared/failure-log-fD4DiFb1.js +2 -0
- package/dist/packem_shared/flakiness-BIg1rwvp.js +1 -0
- package/dist/packem_shared/{giget-CcEy_Elm.js → giget-BX2ixMoa.js} +2 -2
- package/dist/packem_shared/index-OlP7U_t5.js +6 -0
- package/dist/packem_shared/lockfile-BXylopgH.js +1 -0
- package/dist/packem_shared/otelPlugin-y5hoCw4b.js +1 -0
- package/dist/packem_shared/registry-BHqKXiLb.js +2 -0
- package/dist/packem_shared/run-summary-utils-D39XBHWW.js +1 -0
- package/dist/packem_shared/runtime-check-BaKni2y1.js +1 -0
- package/dist/packem_shared/selectors-BvtUXWGY.js +3 -0
- package/dist/packem_shared/toolchain-B7sIiJxK.js +5 -0
- package/dist/packem_shared/typosquats-XkC1CnOa.js +1 -0
- package/dist/packem_shared/verify-BVTcVfoW.js +1 -0
- package/dist/packem_shared/{vis-update-app-D1jl0UZZ.js → vis-update-app-DR8c4OfG.js} +1 -1
- package/package.json +15 -30
- package/dist/packem_shared/ai-analysis-hm8d2W7z.js +0 -67
- package/dist/packem_shared/ai-cache-DoiF80AR.js +0 -1
- package/dist/packem_shared/cache-directory-CwHlJhgx.js +0 -1
- package/dist/packem_shared/dependency-scan-COr5n63B.js +0 -2
- package/dist/packem_shared/docker-D6OGr5_S.js +0 -2
- package/dist/packem_shared/failure-log-iUVLf6ts.js +0 -2
- package/dist/packem_shared/flakiness-D9wf0t56.js +0 -1
- package/dist/packem_shared/otel-DxDUPJJH.js +0 -6
- package/dist/packem_shared/otelPlugin-CQq6poq8.js +0 -1
- package/dist/packem_shared/registry-CkubDdiY.js +0 -2
- package/dist/packem_shared/run-summary-utils-BfBvjzhY.js +0 -1
- package/dist/packem_shared/runtime-check-BXZ43CBW.js +0 -1
- package/dist/packem_shared/selectors-BylODRiM.js +0 -3
- package/dist/packem_shared/toolchain-BgBOUHII.js +0 -5
- package/dist/packem_shared/typosquats-CcZl99B1.js +0 -1
- package/dist/packem_shared/verify-Baj5mFJ7.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var L=Object.defineProperty;var h=(e,t)=>L(e,"name",{value:t,configurable:!0});import{createRequire as O}from"node:module";import{isAccessible as V}from"@visulima/fs";import{p as d,
|
|
2
|
-
`);return}if(o.length===0){d.info("No running services registered for this workspace.");return}const s=Date.now(),i=o.map(p=>{const
|
|
1
|
+
var L=Object.defineProperty;var h=(e,t)=>L(e,"name",{value:t,configurable:!0});import{createRequire as O}from"node:module";import{isAccessible as V}from"@visulima/fs";import{p as d,av as z,y as q,aw as B}from"./bin.js";import{M as W}from"../packem_shared/index-OlP7U_t5.js";import{R as H,w as F,r as S,i as m,d as $,g as J,s as K,a as Y,b as I,S as Q,c as X,p as Z}from"../packem_shared/registry-BHqKXiLb.js";import{formatAge as te}from"./handler30.js";const G=O(import.meta.url),y=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=h(e=>{if(typeof y<"u"&&y.versions&&y.versions.node){const[t,r]=y.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return y.getBuiltinModule(e)}return G(e)},"__cjs_getBuiltinModule"),{open:E,stat:k,watch:U}=T("node:fs/promises"),{spawn:ee}=T("node:child_process");var re=Object.defineProperty,oe=h((e,t)=>re(e,"name",{value:t,configurable:!0}),"i");const M=process.platform==="win32",se=oe(async e=>{const{command:t,cwd:r,env:n,logFile:a}=e,o=await E(a,"a",H);let s;try{s=ee(M?"cmd":"/bin/sh",M?["/d","/s","/c",t]:["-c",t],{cwd:r,detached:!0,env:{...process.env,...n},stdio:["ignore",o.fd,o.fd],windowsHide:!0})}finally{await o.close().catch(()=>{})}if(s.pid===void 0&&await new Promise((i,c)=>{s.once("spawn",()=>{i()}),s.once("error",g=>{c(g)})}),s.pid===void 0)throw new Error(`Failed to spawn detached process for command: ${t}`);return s.unref(),{pid:s.pid}},"spawnDetached");var ie=Object.defineProperty,R=h((e,t)=>ie(e,"name",{value:t,configurable:!0}),"t");const _=5e3,D=R(async e=>F(e.workspaceRoot,e.id,async()=>{const t=await S(e.workspaceRoot,e.id);if(t&&m(t.pid))throw new Error(`Service ${e.id} is already running (pid ${String(t.pid)})`);t&&await $(e.workspaceRoot,e.id,t);const r=await J(e.workspaceRoot),n=K(e.id),a=W(r,`${n}.log`),{pid:o}=await se({command:e.command,cwd:e.cwd,env:e.env,logFile:a}),s={command:e.command,config:e.config,cwd:e.cwd,env:e.config.env??{},id:e.id,logFile:a,pid:o,slug:n,startedAt:new Date().toISOString(),visVersion:process.env.VIS_VERSION??"0.0.0"};if(await Y(e.workspaceRoot,s),e.skipReadiness!==!0)try{await I(e.config,{timeoutMs:e.readinessTimeoutMs})}catch(i){throw await P(o,e.config.killGracePeriodMs??_).catch(()=>{}),await $(e.workspaceRoot,e.id,s).catch(()=>{}),i}return{entry:s}}),"startService"),N=R(async e=>F(e.workspaceRoot,e.id,async()=>{const t=await S(e.workspaceRoot,e.id);if(!t)return{stopped:!1};if(!m(t.pid))return await $(e.workspaceRoot,e.id,t),{stopped:!1};const r=e.graceMs??t.config.killGracePeriodMs??_;return await P(t.pid,r),await $(e.workspaceRoot,e.id,t),{stopped:!0}}),"stopService"),P=R(async(e,t)=>{b(e,"SIGTERM");const r=Date.now();for(;Date.now()-r<t;){if(!m(e))return;await new Promise(n=>{setTimeout(n,100)})}m(e)&&b(e,"SIGKILL")},"stopServiceByPid"),b=R((e,t)=>{try{process.platform==="win32"?process.kill(e,t):process.kill(-e,t)}catch(r){if(r.code==="ESRCH")return;throw r}},"sendSignalToServiceGroup");var ae=Object.defineProperty,l=h((e,t)=>ae(e,"name",{value:t,configurable:!0}),"g");const ne=l(e=>{const t=e.trim(),r=t.lastIndexOf(":");if(!(r<=0||r===t.length-1))return{project:t.slice(0,r),target:t.slice(r+1)}},"splitTargetId"),ce=l((e,t,r)=>r||!t?e:t.startsWith("/")?t:`${e}/${t}`,"resolveCwd"),A=l(async(e,t,r)=>{const n=ne(r);if(!n){d.error(`Invalid target id "${r}". Expected "<project>:<target>", e.g. "@my/api:db".`);return}const a=await z(e),{projectOptions:o,workspace:s}=q(e,t,a),i=s.projects[n.project],c=o.get(n.project)?.[n.target];if(!i||!c){d.error(`Target "${r}" not found in this workspace.`);return}const g=c.options?.service;if(!g){d.error(`Target "${r}" is not a service. Add an \`options.service\` block to make it eligible for \`vis service\`.`);return}if(!c.command){d.error(`Target "${r}" has no command — services must be runnable.`);return}const u=ce(e,i.root,c.options?.runFromWorkspaceRoot===!0),w=c.options?.envFile?B(u,c.options.envFile):{};return{command:c.command,cwd:u,env:{...w,...g.env},service:g,target:c,targetId:r}},"resolveTarget"),v=l(e=>{if(!e)throw new Error("Could not determine workspace root. Run `vis service` inside a workspace.");return e},"requireWorkspace"),$e=l(async({argument:e,options:t,visConfig:r,workspaceRoot:n})=>{const a=v(n),o=e[0]?.trim();if(!o){d.error("Missing target id. Usage: vis service start <project>:<target>"),process.exitCode=1;return}const s=await A(a,r,o);if(!s){process.exitCode=1;return}try{const{entry:i}=await D({command:s.command,config:s.service,cwd:s.cwd,env:s.env,id:o,readinessTimeoutMs:t.timeout,skipReadiness:t.readiness===!1,workspaceRoot:a});d.success(`Started ${o} (pid ${String(i.pid)})`),d.info(` log: ${i.logFile}`)}catch(i){const c=i instanceof Error?i.message:String(i);i instanceof Q?d.error(`Readiness probe failed for ${o}: ${c}`):d.error(`Failed to start ${o}: ${c}`),process.exitCode=1}},"serviceStartExecute"),C=l(async(e,t,r)=>{const{stopped:n}=await N({graceMs:r,id:t,workspaceRoot:e});return n?(d.success(`Stopped ${t}`),!0):(d.info(`No running service registered for ${t}`),!1)},"stopOne"),Se=l(async({argument:e,options:t,workspaceRoot:r})=>{const n=v(r),{graceMs:a}=t,o=e[0]?.trim();if(t.all===!0){if(o){d.error("Cannot combine --all with a target id. Use one or the other."),process.exitCode=1;return}const s=await X(n);if(s.length===0){d.info("No running services registered for this workspace.");return}for(const i of s)await C(n,i.id,a);return}if(!o){d.error("Missing target id. Usage: vis service stop <project>:<target> | --all"),process.exitCode=1;return}await C(n,o,a)||(process.exitCode=1)},"serviceStopExecute"),de=l(e=>{const t=e.config.readiness?.tcp.port??e.config.port;return t===void 0?"—":String(t)},"formatPort"),j=new Set(["json","table"]),Re=l(async({logger:e,options:t,workspaceRoot:r})=>{const n=v(r),a=t.format??"table";if(!j.has(a)){d.error(`Invalid --format "${a}". Expected one of: ${[...j].sort().join(", ")}.`),process.exitCode=1;return}const{surviving:o}=await Z(n);if(a==="json"){const p=Date.now();process.stdout.write(`${JSON.stringify(o.map(f=>{const x=Date.parse(f.startedAt);return{ageMs:Number.isFinite(x)?p-x:null,alive:m(f.pid),command:f.command,cwd:f.cwd,env:f.env,id:f.id,logFile:f.logFile,pid:f.pid,port:f.config.readiness?.tcp.port??f.config.port??null,startedAt:f.startedAt,visVersion:f.visVersion}}),void 0,2)}
|
|
2
|
+
`);return}if(o.length===0){d.info("No running services registered for this workspace.");return}const s=Date.now(),i=o.map(p=>{const f=Date.parse(p.startedAt);return{age:Number.isFinite(f)?te(f,s):"?",id:p.id,log:p.logFile,pid:String(p.pid),port:de(p)}}),c=Math.max(2,...i.map(p=>p.id.length)),g=Math.max(3,...i.map(p=>p.pid.length)),u=Math.max(4,...i.map(p=>p.port.length)),w=Math.max(3,...i.map(p=>p.age.length));e.info(` ${"id".padEnd(c)} ${"pid".padEnd(g)} ${"port".padEnd(u)} ${"age".padEnd(w)} log`),e.info(` ${"-".repeat(c)} ${"-".repeat(g)} ${"-".repeat(u)} ${"-".repeat(w)} ---`);for(const p of i)e.info(` ${p.id.padEnd(c)} ${p.pid.padEnd(g)} ${p.port.padEnd(u)} ${p.age.padEnd(w)} ${p.log}`)},"serviceListExecute"),Ee=l(async({argument:e,options:t,workspaceRoot:r})=>{const n=v(r),a=e[0]?.trim();if(!a){d.error("Missing target id. Usage: vis service status <project>:<target>"),process.exitCode=1;return}const o=await S(n,a);if(!o){d.error(`No service registered for ${a}.`),process.exitCode=1;return}if(!m(o.pid)){d.error(`Service ${a} is not running (pid ${String(o.pid)} is dead). Run \`vis service start ${a}\` to recover.`),process.exitCode=1;return}try{await I(o.config,{timeoutMs:t.timeout}),d.success(`${a} healthy (pid ${String(o.pid)})`)}catch(s){const i=s instanceof Error?s.message:String(s);d.error(`${a} probe failed: ${i}`),process.exitCode=1}},"serviceStatusExecute"),xe=l(async({argument:e,options:t,visConfig:r,workspaceRoot:n})=>{const a=v(n),o=e[0]?.trim();if(!o){d.error("Missing target id. Usage: vis service restart <project>:<target>"),process.exitCode=1;return}await N({graceMs:t.graceMs,id:o,workspaceRoot:a});const s=await A(a,r,o);if(!s){process.exitCode=1;return}try{const{entry:i}=await D({command:s.command,config:s.service,cwd:s.cwd,env:s.env,id:o,readinessTimeoutMs:t.timeout,skipReadiness:t.readiness===!1,workspaceRoot:a});d.success(`Restarted ${o} (pid ${String(i.pid)})`)}catch(i){const c=i instanceof Error?i.message:String(i);d.error(`Failed to restart ${o}: ${c}`),process.exitCode=1}},"serviceRestartExecute"),pe=200,ge=1024*1024,le=l(async e=>{let t=0;try{t=(await k(e)).size}catch{t=0}const r=new AbortController;let n=!1;const a=l(()=>{n=!0,r.abort()},"onSigint"),o=l(()=>{r.abort()},"onSigterm");process.on("SIGINT",a),process.on("SIGTERM",o);let s=!1;const i=l(async()=>{if(!s){s=!0;try{const c=await k(e).catch(()=>{});if(!c||(c.size<t&&(t=0),c.size===t))return;const g=c.size-t,u=Math.min(g,ge),w=await E(e,"r");try{const p=Buffer.alloc(u);await w.read(p,0,u,t),process.stdout.write(p),t+=u}finally{await w.close().catch(()=>{})}}finally{s=!1}}},"tickOnce");try{const c=(async()=>{try{const g=U(e,{signal:r.signal});for(;!(await g.next()).done;)await i()}catch{}})();for(;!r.signal.aborted;)await i(),await new Promise(g=>{const u=setTimeout(g,pe);r.signal.addEventListener("abort",()=>{clearTimeout(u),g()},{once:!0})});await c.catch(()=>{}),await i().catch(()=>{})}finally{process.off("SIGINT",a),process.off("SIGTERM",o)}n&&(process.exitCode=130)},"tailLog"),ke=l(async({argument:e,options:t,workspaceRoot:r})=>{const n=v(r),a=e[0]?.trim();if(!a){d.error("Missing target id. Usage: vis service logs <project>:<target>"),process.exitCode=1;return}const o=await S(n,a);if(!o){d.error(`No service registered for ${a}.`),process.exitCode=1;return}if(!await V(o.logFile)){d.warn(`Log file is missing for ${a}: ${o.logFile}`),process.exitCode=1;return}if(t.follow===!0){await le(o.logFile);return}const s=await E(o.logFile,"r");try{const i=s.createReadStream();await new Promise((c,g)=>{i.on("end",c),i.on("error",g),i.pipe(process.stdout,{end:!1})})}finally{await s.close().catch(()=>{})}},"serviceLogsExecute");export{Re as serviceListExecute,ke as serviceLogsExecute,xe as serviceRestartExecute,$e as serviceStartExecute,Ee as serviceStatusExecute,Se as serviceStopExecute};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var R=Object.defineProperty;var
|
|
2
|
-
`)},"renderCodeowners");var
|
|
1
|
+
var R=Object.defineProperty;var y=(e,o)=>R(e,"name",{value:o,configurable:!0});import{createRequire as A}from"node:module";import{writeFileSync as q,writeJsonSync as T}from"@visulima/fs";import{M as w,z as I}from"../packem_shared/index-OlP7U_t5.js";import{o as L}from"../packem_shared/index-DH-5hsrC.js";import{y as U,ax as O,ay as W,Z as B}from"./bin.js";const x=A(import.meta.url),k=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,D=y(e=>{if(typeof k<"u"&&k.versions&&k.versions.node){const[o,t]=k.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return k.getBuiltinModule(e)}return x(e)},"__cjs_getBuiltinModule"),{readFileSync:M}=D("node:fs");var z=Object.defineProperty,C=y((e,o)=>z(e,"name",{value:o,configurable:!0}),"i");const K=C((e,o)=>{const t=o.replace(/^\.?\//,"");return t===""||t==="."?`/${e}/`:e===""||e==="."?`/${t}`:`/${e}/${t}`},"toWorkspacePath"),G=C((e,o)=>{const t=[];for(const[r,n]of Object.entries(o?.globalPaths??{}))t.push({owners:n,path:r});for(const[r,n]of Object.entries(e.projects)){const i=n.owners??[];for(const a of i)t.push({channel:a.channel,owners:a.owners,path:K(n.root??r,a.path),projectId:r})}return(o?.orderBy??"file-source")==="project-id"?t.sort((r,n)=>(r.projectId??"").localeCompare(n.projectId??"")||r.path.localeCompare(n.path)):t.sort((r,n)=>r.path.localeCompare(n.path)),t},"buildCodeownersLines"),V=["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.","# Update each project's project.json `owners` field and re-run the command.",""],Y=C((e,o="github")=>{const t=[...V];for(const r of e){const n=r.owners.join(" "),i=r.channel?` # notify: ${r.channel}`:"";t.push(`${r.path} ${n}${i}`)}return t.push(""),t.join(`
|
|
2
|
+
`)},"renderCodeowners");var Z=Object.defineProperty,u=y((e,o)=>Z(e,"name",{value:o,configurable:!0}),"s");const H=["author","bugs","homepage","license","repository","engines"],E=u(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isPlainObject"),b=u((e,o)=>{if(e===o)return!0;if(typeof e!=typeof o||e===null||o===null)return!1;if(Array.isArray(e)){if(!Array.isArray(o)||e.length!==o.length)return!1;for(const[t,r]of e.entries())if(!b(r,o[t]))return!1;return!0}if(typeof e=="object"&&typeof o=="object"){const t=Object.keys(e),r=Object.keys(o);if(t.length!==r.length)return!1;for(const n of t)if(!b(e[n],o[n]))return!1;return!0}return!1},"deepEqual"),N=u(e=>e===void 0?e:structuredClone(e),"cloneJson"),Q=u((e,o,t)=>{if(e==="repository"&&E(o)&&E(t)){const r={};for(const[n,i]of Object.entries(o))n!=="directory"&&(r[n]=N(i));return typeof t.directory=="string"&&(r.directory=t.directory),r}return N(o)},"buildTargetValue"),X=u((e,o,t)=>{const r=[];for(const n of t.fields){if(!Object.hasOwn(e,n))continue;const i=e[n],a=o[n],c=Q(n,i,a);b(c,a)||r.push({after:c,before:a,field:n,packageJsonPath:""})}return r},"computeFieldChanges"),ee=u((e,o)=>{for(const t of o)e[t.field]=t.after},"applyFieldChanges");var oe=Object.defineProperty,m=y((e,o)=>oe(e,"name",{value:o,configurable:!0}),"p");const _=["codeowners","package-json-fields"],te=m(e=>{const o=new Set,t=[];for(const r of e??[])for(const n of r.split(",")){const i=n.trim();i.length===0||o.has(i)||(o.add(i),t.push(i))}return t.length>0?t:[...H]},"parseFieldsOption"),re=m((e,o)=>o.some(t=>L(t,e)),"matchesAnyGlob"),ne=m(({logger:e,options:o,visConfig:t,workspaceRoot:r})=>{const{workspace:n}=U(r,t),i=G(n,t?.codeowners);if(i.length===0){e.info("No `owners` entries found in any project. Nothing to sync.");return}const a=Y(i,t?.codeowners?.provider??"github"),c=o.out?w(r,o.out):w(r,"CODEOWNERS");if(o.check){let g="";try{g=M(c,"utf8")}catch(d){if(d.code!=="ENOENT")throw d}if(g.trim()!==a.trim()){e.error(`${c} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}e.info(`${c} is up to date.`);return}q(c,a),e.info(`Wrote ${i.length} entries to ${c}`)},"runCodeowners"),se=m(({logger:e,options:o,visConfig:t,workspaceRoot:r})=>{const n=r,i=t?.editorconfig??!0,a=O(w(n,"package.json"));if(!a){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const c=te(o.fields),g=o.ignorePackageName??[],d=o.check===!0,F=(o.format??"human").toLowerCase(),v=o.quiet===!0,S=W(n).filter(s=>s!=="."),p=[];let j=0;for(const s of S){const l=w(n,s,"package.json"),h=O(l);if(!h)continue;const $=typeof h.name=="string"?h.name:void 0;if($!==void 0&&g.length>0&&re($,g))continue;j+=1;const P=X(a,h,{fields:c});P.length!==0&&p.push({filePath:l,packageJsonPath:I(n,l),packageName:$,pkg:h,pkgChanges:P})}if(!d)for(const s of p)ee(s.pkg,s.pkgChanges),T(s.filePath,s.pkg,{indent:B(s.filePath,{useEditorconfig:i}),overwrite:!0});const f=p.flatMap(s=>s.pkgChanges.map(l=>({after:l.after,before:l.before,field:l.field,packageJsonPath:s.packageJsonPath,packageName:s.packageName}))),J={changes:f,fields:c,kind:"package-json-fields",mode:d?"check":"write",totalChanges:f.length,totalPackages:j};if(F==="json")process.stdout.write(`${JSON.stringify(J,null,4)}
|
|
3
3
|
`);else if(f.length===0)e.info(`All ${j} package${j===1?"":"s"} in sync (fields: ${c.join(", ")}).`);else if(d){if(!v)for(const s of f)e.error(`${s.packageJsonPath}: ${s.field} drifts from root`);e.error(`Found ${f.length} field drift${f.length===1?"":"s"} across ${p.length} package${p.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!v)for(const s of p)e.info(`${s.packageJsonPath}: synced ${s.pkgChanges.map(l=>l.field).join(", ")}`);e.info(`Synced ${f.length} field${f.length===1?"":"s"} across ${p.length} package${p.length===1?"":"s"}.`)}d&&f.length>0&&(process.exitCode=1)},"runPackageJsonFields"),de=m(async e=>{const o=e.argument[0];if(!o)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${_.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(o==="codeowners"){ne(e);return}if(o==="package-json-fields"){se(e);return}throw new Error(`Unknown sync kind: "${o}". Known kinds: ${_.join(", ")}.`)},"execute");export{de as default};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var ae=Object.defineProperty;var j=(t,e)=>ae(t,"name",{value:e,configurable:!0});import{createRequire as ce}from"node:module";import{
|
|
2
|
-
`);for(const[
|
|
3
|
-
`)}for(;;){const
|
|
4
|
-
${p(`Enter choice (1-${String(r.length)}):`)} `);if(
|
|
1
|
+
var ae=Object.defineProperty;var j=(t,e)=>ae(t,"name",{value:e,configurable:!0});import{createRequire as ce}from"node:module";import{E as p,j as b,q as S,p as l}from"./bin.js";import{M as N,K as Y,O as L,z as Q,y as pe,C as fe}from"../packem_shared/index-OlP7U_t5.js";import{isAccessibleSync as _,walkSync as X,ensureDirSync as Z,writeFileSync as de}from"@visulima/fs";import{f as $e}from"../packem_shared/giget-BX2ixMoa.js";const le=ce(import.meta.url),x=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,D=j(t=>{if(typeof x<"u"&&x.versions&&x.versions.node){const[e,r]=x.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return x.getBuiltinModule(t)}return le(t)},"__cjs_getBuiltinModule"),{fileURLToPath:ue}=D("node:url"),{createInterface:me}=D("node:readline"),{mkdtempSync:he,rmSync:ge}=D("node:fs"),{tmpdir:we}=D("node:os"),{spawnSync:ye}=D("node:child_process");var ve=Object.defineProperty,y=j((t,e)=>ve(t,"name",{value:e,configurable:!0}),"i");const ee=[".ts",".mts",".cts",".js",".mjs",".cjs"],be="template.yml",Se=[".d",".test",".spec",".config",".bench",".stories"],Te=[".d.ts",".d.mts",".d.cts",".js.map",".mjs.map",".cjs.map",".ts.map"],te=y(t=>{for(const e of ee)if(t.endsWith(e))return t.slice(0,-e.length);return t},"stripExtension"),Oe=y(t=>{if(Te.some(r=>t.endsWith(r))||!ee.some(r=>t.endsWith(r)))return!1;const e=te(t);return!Se.some(r=>e.endsWith(r))},"isNativeFile"),J=y((t,e)=>{const r=[];if(!_(t))return r;for(const s of X(t,{includeDirs:!1,includeSymlinks:!1,maxDepth:1})){if(!Oe(s.name))continue;const o=te(s.name);r.push({load:y(()=>Ne(s.path),"load"),name:o,path:s.path,source:e})}return r},"scanNativeDirectory"),B=y((t,e)=>{const r=[];if(!_(t))return r;for(const s of X(t,{includeFiles:!1,includeSymlinks:!1,maxDepth:1})){if(s.path===t)continue;const o=N(s.path,be);_(o)&&r.push({load:y(()=>Re(s.path,s.name),"load"),name:s.name,path:s.path,source:e})}return r},"scanMoonDirectory"),je=y(()=>{try{const t=ue(import.meta.url),e=N(Y(t),"..","..","templates");return _(e)?e:void 0}catch{return}},"resolveBuiltinTemplatesDirectory"),I=y(t=>{const{extraDirectories:e=[],onWarning:r,workspaceRoot:s}=t,o=[...J(N(s,".vis","templates"),"native"),...B(N(s,".vis","templates"),"moon"),...B(N(s,".moon","templates"),"moon")];for(const n of e)o.push(...B(n,"config")),o.push(...J(n,"config"));const i=je();i&&o.push(...B(i,"builtin"));const a=new Map;for(const n of o){const c=a.get(n.name);if(!c){a.set(n.name,n);continue}r&&r(`Template "${n.name}" exists in multiple sources — using ${c.source} (${c.path}), ignoring ${n.source} (${n.path}).`)}return[...a.values()].sort((n,c)=>n.name.localeCompare(c.name))},"discoverTemplates"),Ne=y(async t=>{const{loadNativeTemplate:e}=await import("./loader.js");return e(t)},"loadNativeFromPath"),Re=y(async(t,e)=>{const{loadMoonTemplate:r}=await import("./index.js");return r(t,e)},"loadMoonFromPath");var Ee=Object.defineProperty,v=j((t,e)=>Ee(t,"name",{value:e,configurable:!0}),"c");const M=v((t,e)=>new Promise(r=>{t.question(e,s=>{r(s.trim())})}),"ask"),ke=v(async(t,e,r)=>{const s=await M(t,` ${e} ${p(r?"[Y/n]":"[y/N]")} `);return s===""?r:s.toLowerCase()==="y"||s.toLowerCase()==="yes"},"confirm"),xe=v(async(t,e,r,s)=>{process.stderr.write(` ${e}
|
|
2
|
+
`);for(const[o,i]of r.entries()){const a=b(S(` ${String(o+1)}.`)),n=i===s?p(" (default)"):"";process.stderr.write(`${a} ${i}${n}
|
|
3
|
+
`)}for(;;){const o=await M(t,`
|
|
4
|
+
${p(`Enter choice (1-${String(r.length)}):`)} `);if(o===""&&s!==void 0)return s;const i=Number.parseInt(o,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(n=>n===o);if(a)return a;process.stderr.write(` ${p("Invalid choice. Try again.")}
|
|
5
5
|
`)}},"selectOne"),_e=v(async(t,e,r,s)=>{process.stderr.write(` ${e} ${p("(comma-separated numbers)")}
|
|
6
|
-
`);for(const[
|
|
7
|
-
`)}for(;;){const
|
|
8
|
-
${p("Enter choices:")} `);if(
|
|
9
|
-
`)}},"selectMany"),De=v(t=>` ${p(`${t}:`)} `,"promptText"),Pe=v((t,e)=>e.prompt??t,"variableLabel"),
|
|
10
|
-
`)}}else{Z(e.destination);let
|
|
11
|
-
`),l.notice("Next steps:");for(const
|
|
12
|
-
`)}},"runTemplate");var
|
|
13
|
-
`)}},"printList"),Xe=$(t=>{const e={},r=[];for(const s of t){if(!s.startsWith("--")){r.push(s);continue}const
|
|
6
|
+
`);for(const[o,i]of r.entries()){const a=b(S(` ${String(o+1)}.`)),n=s.includes(i)?p(" (default)"):"";process.stderr.write(`${a} ${i}${n}
|
|
7
|
+
`)}for(;;){const o=await M(t,`
|
|
8
|
+
${p("Enter choices:")} `);if(o===""&&s.length>0)return s;const i=o.split(",").map(a=>Number.parseInt(a.trim(),10)).filter(a=>Number.isInteger(a)&&a>=1&&a<=r.length);if(i.length>0)return i.map(a=>r[a-1]);process.stderr.write(` ${p("Invalid choice. Try again.")}
|
|
9
|
+
`)}},"selectMany"),De=v(t=>` ${p(`${t}:`)} `,"promptText"),Pe=v((t,e)=>e.prompt??t,"variableLabel"),We=v(t=>Object.entries(t).sort(([e,r],[s,o])=>{const i=r.order??0,a=o.order??0;return i!==a?i-a:e.localeCompare(s)}),"sortVariables"),H=v((t,e)=>{switch(t.type){case"array":return e.split(",").map(r=>r.trim()).filter(Boolean);case"boolean":return e==="true"||e==="1"||e==="yes"||e==="y";case"enum":return t.multiple?e.split(",").map(r=>r.trim()).filter(Boolean):e;case"number":{const r=Number(e);if(Number.isNaN(r))throw new TypeError(`Expected a number, got "${e}"`);return r}default:return e}},"parseValue"),F=v((t,e,r)=>{if(e.type==="enum"){const s=Array.isArray(r)?r:[r];for(const o of s)if(typeof o!="string"||!e.values.includes(o))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(o)}")`)}},"validateValue"),qe=v(async t=>{const{defaults:e,interactive:r,overrides:s,variables:o}=t,i={},a=r?me({input:process.stdin,output:process.stderr}):null;try{for(const[n,c]of We(o)){if(Object.hasOwn(s,n)){const w=H(c,s[n]??"");F(n,c,w),i[n]=w;continue}if(e||!r||c.internal){if(c.default!==void 0){F(n,c,c.default),i[n]=c.default;continue}if(c.required)throw new Error(`Required variable "${n}" not provided. Pass --${n}=<value> or remove --defaults.`);continue}const g=Pe(n,c);let m;if(c.type==="boolean")m=await ke(a,g,!!(c.default??!1));else if(c.type==="enum")if(c.multiple){const w=Array.isArray(c.default)?c.default:[];m=await _e(a,g,c.values,w)}else{const w=typeof c.default=="string"?c.default:void 0;m=await xe(a,g,c.values,w)}else{const w=c.default===void 0?"":` (${String(c.default)})`,T=await M(a,De(`${g}${w}`));if(T===""&&c.default!==void 0)m=c.default;else if(T===""){if(c.required)throw new Error(`Variable "${n}" is required`);continue}else m=H(c,T)}F(n,c,m),i[n]=m}return i}finally{a?.close()}},"collectOptions");var Be=Object.defineProperty,V=j((t,e)=>Be(t,"name",{value:e,configurable:!0}),"o");const Ie=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],Me=V(t=>Ie.some(e=>t.startsWith(e)),"isRemoteSource"),Ae=V(async(t,e={})=>{const r=e.targetDirectory===void 0,s=e.targetDirectory??he(N(we(),"vis-generate-")),o=V(()=>{if(r)try{ge(s,{force:!0,recursive:!0})}catch{}},"cleanup");l.info(`Downloading ${t}…`);try{const i=await $e(t,{auth:e.auth||process.env.GIGET_AUTH||process.env.GITHUB_TOKEN||process.env.GH_TOKEN||void 0,dir:s,force:!0,preferOffline:e.preferOffline});return{cleanup:o,directory:i.dir}}catch(i){o();const a=i instanceof Error?i.message:String(i);throw l.warn(`Failed to download template: ${a}`),i}},"fetchRemoteTemplate");var Ce=Object.defineProperty,R=j((t,e)=>Ce(t,"name",{value:e,configurable:!0}),"a");const re=R((t,e="")=>{const r=[];for(const[s,o]of Object.entries(t)){const i=e?`${e}/${s}`:s;typeof o=="string"||Buffer.isBuffer(o)?r.push({content:o,path:i}):o&&typeof o=="object"&&r.push(...re(o,i))}return r},"flattenTree"),Fe=R(t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,"formatSize"),Le=R((t,e)=>{if(L(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=N(t,e),s=Q(t,r);if(s===".."||s.startsWith(`..${pe}`)||L(s))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},"safeJoinDestination"),Ve=R((t,e)=>{Z(Y(t)),de(t,e)},"writeOne"),Ke=R((t,e,r=!1)=>{const s=typeof t=="string"?[t]:t.commands,o=typeof t=="string"?r:t.silent??r;for(const i of s){o||l.info(`$ ${i}`);const a=ye(i,{cwd:e,shell:!0,stdio:o?"ignore":"inherit"});if(a.status!==0)return l.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},"runScript"),ze=R(t=>{const e=new Map;for(const r of t){const s=typeof r=="string"?0:r.phase??0,o=e.get(s);o?o.push(r):e.set(s,[r])}return[...e.entries()].sort(([r],[s])=>r-s)},"groupByPhase"),Ue=R(async(t,e)=>{const r={builtins:{dest_dir:e.destination,dest_rel_dir:Q(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(r),o=s.files?re(s.files):[],i=s.filesMeta??{},a=[];for(const n of o){const c=Le(e.destination,n.path);a.push({file:n,meta:i[n.path]??{},target:c})}if(e.dryRun){l.info(`${b(S("Plan"))} ${p("(dry-run, no files written)")}`);for(const n of a){const c=Buffer.isBuffer(n.file.content)?n.file.content.length:Buffer.byteLength(n.file.content,"utf8");process.stderr.write(` ${p("write")} ${n.file.path} ${p(`(${Fe(c)})`)}
|
|
10
|
+
`)}}else{Z(e.destination);let n=0,c=0;for(const g of a){const{file:m,meta:w,target:T}=g,A=_(T),O=e.force||w.force===!0;if(A&&!O){l.warn(`Skipped existing file: ${m.path} (use --force or set frontmatter force: true to overwrite)`),c+=1;continue}Ve(T,m.content),n+=1}l.success(`Wrote ${String(n)} file${n===1?"":"s"}${c>0?`, skipped ${String(c)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const n=ze(s.scripts);l.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(n.length)} phase${n.length===1?"":"s"}…`);for(const[,c]of n)if((await Promise.all(c.map(g=>Promise.resolve(Ke(g,e.destination))))).includes(!1))throw new Error("Script failed — aborting.")}if(s.suggestions&&s.suggestions.length>0){process.stderr.write(`
|
|
11
|
+
`),l.notice("Next steps:");for(const n of s.suggestions)process.stderr.write(` ${p("•")} ${n}
|
|
12
|
+
`)}},"runTemplate");var Ge=Object.defineProperty,$=j((t,e)=>Ge(t,"name",{value:e,configurable:!0}),"u");const Je=$(async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},"toListEntry"),He=$((t,e)=>{const r={default:e.default,name:t,order:e.order,prompt:e.prompt,required:e.required,type:e.type};return e.type==="enum"&&(r.multiple=e.multiple,r.values=e.values),r},"summarizeVariable"),Ye=$(async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([s,o],[i,a])=>{const n=o.order??0,c=a.order??0;return n===c?s.localeCompare(i):n-c}).map(([s,o])=>He(s,o));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},"describeTemplate"),Qe=$(t=>{if(t.length===0){l.info("No templates found."),l.notice("Create one at .vis/templates/<name>.ts (programmatic) or .vis/templates/<name>/ (moon-format with template.yml).");return}l.info("Available templates:");for(const e of t){const r=p(`(${e.source})`);process.stderr.write(` ${b(S(e.name))} ${r}
|
|
13
|
+
`)}},"printList"),Xe=$(t=>{const e={},r=[];for(const s of t){if(!s.startsWith("--")){r.push(s);continue}const o=s.indexOf("=");if(o===-1){const n=s.slice(2);n.startsWith("no-")?e[n.slice(3)]="false":e[n]="true";continue}const i=s.slice(2,o),a=s.slice(o+1);e[i]=a}return{overrides:e,remaining:r}},"parsePassthroughOverrides"),Ze=$(async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${b(S("vis generate"))} ${p("— pick a template")}
|
|
14
14
|
|
|
15
|
-
`);for(const[s,
|
|
16
|
-
`)}return new Promise((s,
|
|
17
|
-
${p(`Enter choice (1-${String(t.length)}):`)} `,i=>{const a=Number.parseInt(i.trim(),10);Number.isInteger(a)&&a>=1&&a<=t.length?s(t[a-1].name):
|
|
18
|
-
`);return}Qe(
|
|
19
|
-
`);return}if(l.info(`Template: ${b(S(d.name))} ${p(`(${d.source})`)}`),d.description&&l.info(d.description),d.destination&&l.info(`Destination: ${p(d.destination)}`),d.variables.length===0)l.info("No variables.");else{l.info("Variables:");for(const h of d.variables){const
|
|
20
|
-
`)}}return}let g=[...r??[]];if(g.length===0){const
|
|
21
|
-
`);const ie=await
|
|
22
|
-
`),l.success(`Template '${P}' applied.`))}finally{
|
|
15
|
+
`);for(const[s,o]of t.entries()){const i=b(S(` ${String(s+1)}.`));process.stderr.write(`${i} ${o.name} ${p(`(${o.source})`)}
|
|
16
|
+
`)}return new Promise((s,o)=>{r.question(`
|
|
17
|
+
${p(`Enter choice (1-${String(t.length)}):`)} `,i=>{const a=Number.parseInt(i.trim(),10);Number.isInteger(a)&&a>=1&&a<=t.length?s(t[a-1].name):o(new Error("Invalid choice."))})})}finally{r.close()}},"pickInteractive"),it=$(async({argument:t,options:e,rawUnknown:r,visConfig:s,workspaceRoot:o})=>{const i=e.cwd||o||process.cwd(),a=o??i,n=s?.generator,c=Array.isArray(t)?t:t?[t]:[];if(e.list){const u=I({extraDirectories:n?.templates??[],onWarning:$(f=>{l.warn(f)},"onWarning"),workspaceRoot:a});if(e.json){const f=await Promise.all(u.map(d=>Je(d)));process.stdout.write(`${JSON.stringify(f,null,2)}
|
|
18
|
+
`);return}Qe(u);return}if(e.describe){const u=c[0];if(!u)throw new Error("`--describe` requires a template name. Run `vis generate --list` to see available templates.");const f=I({extraDirectories:n?.templates??[],onWarning:$(h=>{l.warn(h)},"onWarning"),workspaceRoot:a}).find(h=>h.name===u);if(!f)throw new Error(`Template "${u}" not found. Run \`vis generate --list\` to see available templates.`);const d=await Ye(f);if(e.json){process.stdout.write(`${JSON.stringify(d,null,2)}
|
|
19
|
+
`);return}if(l.info(`Template: ${b(S(d.name))} ${p(`(${d.source})`)}`),d.description&&l.info(d.description),d.destination&&l.info(`Destination: ${p(d.destination)}`),d.variables.length===0)l.info("No variables.");else{l.info("Variables:");for(const h of d.variables){const q=[h.type];h.required&&q.push("required"),h.default!==void 0&&q.push(`default=${JSON.stringify(h.default)}`),h.values&&q.push(`values=${h.values.join("|")}`),process.stderr.write(` ${b(S(h.name))} ${p(`(${q.join(", ")})`)}
|
|
20
|
+
`)}}return}let g=[...r??[]];if(g.length===0){const u=process.argv.slice(2),f=u.indexOf("--");f!==-1&&(g=u.slice(f+1))}const m=c.indexOf("--"),w=m===-1?[]:c.slice(m+1),T=m===-1?c:c.slice(0,m),{overrides:A}=Xe([...w,...g]);let O,P,W;const k=T[0];let C;if(k&&Me(k)){const u=await Ae(k,{auth:n?.auth,preferOffline:!!e.preferOffline||n?.preferOffline});C=u.cleanup;try{const f=I({extraDirectories:[u.directory],workspaceRoot:a}).find(d=>d.path.startsWith(u.directory));if(!f)throw new Error(`Downloaded template at ${u.directory} contains no template.yml or *.ts entrypoint.`);O=await f.load(),P=f.name,W=O.destination}catch(f){throw C(),f}}else{const u=I({extraDirectories:n?.templates??[],onWarning:$(h=>{l.warn(h)},"onWarning"),workspaceRoot:a});if(u.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let f;if(k)f=k;else{if(e.interactive===!1||!process.stdin.isTTY)throw new Error("No template specified. Pass a template name (see `vis generate --list`) or run interactively in a terminal.");f=await Ze(u)}const d=u.find(h=>h.name===f);if(!d)throw new Error(`Template "${f}" not found. Run 'vis generate --list' to see available templates.`);O=await d.load(),P=d.name,W=O.destination}const K=e.to,z=!!e.dryRun,se=!!e.force,U=!!e.defaults,ne=!!e.skipScripts,oe=e.interactive!==!1&&!!process.stdin.isTTY&&!U;let E;K?E=K:W?E=W:E=".";const G=L(E)?E:fe(i,E);l.info(`Template: ${b(S(P))}`),l.info(`Target: ${p(G)}`),process.stderr.write(`
|
|
21
|
+
`);const ie=await qe({defaults:U,interactive:oe,overrides:A,variables:O.options??{}});try{await Ue(O,{cwd:i,destination:G,dryRun:z,force:se,options:ie,skipScripts:ne,workspaceRoot:a}),z||(process.stderr.write(`
|
|
22
|
+
`),l.success(`Template '${P}' applied.`))}finally{C?.()}},"execute");export{it as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var oe=Object.defineProperty;var E=(o,e)=>oe(o,"name",{value:e,configurable:!0});import{createRequire as ie}from"node:module";import{dim as k,bold as S,cyan as z}from"@visulima/colorize";import{projectGraphToDot as ce}from"@visulima/task-runner";import{Box as i,Text as t,ScrollView as ae,ScrollBar as pe,useApp as he,useWindowSize as ue,useInput as fe,Dialog as ge,render as me}from"@visulima/tui";import{an as W,k as xe,y as be,s as ye}from"./bin.js";import we,{useSyncExternalStore as ve,useState as O,useRef as q,useMemo as _,useCallback as U,useEffect as Ce}from"react";import{jsx as n,jsxs as r}from"react/jsx-runtime";const le=ie(import.meta.url),I=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,de=E(o=>{if(typeof I<"u"&&I.versions&&I.versions.node){const[e,l]=I.versions.node.split(".").map(Number);if(e>22||e===22&&l>=3||e===20&&l>=16)return I.getBuiltinModule(o)}return le(o)},"__cjs_getBuiltinModule"),{writeFileSync:se}=de("node:fs");var Ae=Object.defineProperty,$=E((o,e)=>Ae(o,"name",{value:e,configurable:!0}),"n");const ke=$(o=>{const e=new Map;for(const[l,d]of Object.entries(o.dependencies))for(const c of d){const s=e.get(c.target)??[];s.push(l),e.set(c.target,s)}return Object.values(o.nodes).map(l=>({deps:o.dependencies[l.name]??[],name:l.name,reverseDeps:e.get(l.name)??[],type:l.type})).sort((l,d)=>l.type!==d.type?l.type==="application"?-1:1:l.name.localeCompare(d.name))},"buildNodes"),Ee=$((o,e,l)=>{let d=o;if(e==="app"?d=d.filter(c=>c.type==="application"):e==="lib"&&(d=d.filter(c=>c.type!=="application")),l){const c=l.toLowerCase();d=d.filter(s=>s.name.toLowerCase().includes(c))}return d},"filterNodes");class Me{static{E(this,"GraphStore")}static{$(this,"GraphStore")}#e;#n=new Set;#r;constructor(e){this.#r=e;const l=ke(e);this.#e={allNodes:l,filterActive:!1,filterText:"",filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=$(()=>this.#e,"getSnapshot");subscribe=$(e=>(this.#n.add(e),()=>{this.#n.delete(e)}),"subscribe");getFilteredNodes(){return Ee(this.#e.allNodes,this.#e.filterType,this.#e.filterText)}getStats(){const e=this.#e.allNodes.filter(c=>c.type==="application").length,l=this.#e.allNodes.length,d=Object.values(this.#r.dependencies).reduce((c,s)=>c+s.length,0);return{apps:e,deps:d,libs:l-e,total:l}}setSelectedIndex(e){const l=this.getFilteredNodes(),d=l.length===0?-1:Math.max(0,Math.min(e,l.length-1));d!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:d})}setFocusedPanel(e){e!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:e})}setFilterType(e){e!==this.#e.filterType&&this.#t({...this.#e,filterType:e,selectedIndex:0})}setFilter(e){this.#t({...this.#e,filterText:e,selectedIndex:0})}setFilterActive(e){e!==this.#e.filterActive&&this.#t({...this.#e,filterActive:e,filterText:e?this.#e.filterText:"",selectedIndex:e?this.#e.selectedIndex:0})}#t(e){this.#e=e;for(const l of this.#n)try{l()}catch{}}}var Te=Object.defineProperty,Se=E((o,e)=>Te(o,"name",{value:e,configurable:!0}),"p");const je=Se(({focused:o,node:e,scrollRef:l})=>{const d=o?"white":"gray";if(!e)return n(i,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:n(t,{dimColor:!0,children:"No project selected"})});const c=e.type==="application",s=c?"yellow":"cyan",u=c?"Application":"Library";return n(i,{borderColor:d,borderStyle:"single",borderTopRightTitle:` ${u} `,borderTopTitle:` ${e.name} `,flexDirection:"column",flexGrow:1,children:r(ae,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"DEPENDS ON"}),r(t,{dimColor:!0,children:[" ","(",e.deps.length,")"]})]}),e.deps.length===0?n(i,{marginTop:1,paddingLeft:2,children:n(t,{dimColor:!0,children:"No dependencies"})}):n(i,{flexDirection:"column",marginTop:1,children:e.deps.map(a=>r(i,{gap:1,paddingLeft:2,children:[n(t,{color:"cyan",children:"→"}),n(t,{children:a.target}),a.type!=="static"&&r(t,{dimColor:!0,children:["(",a.type,")"]})]},a.target))})]}),r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"REQUIRED BY"}),r(t,{dimColor:!0,children:[" ","(",e.reverseDeps.length,")"]})]}),e.reverseDeps.length===0?n(i,{marginTop:1,paddingLeft:2,children:n(t,{dimColor:!0,children:"No reverse dependencies"})}):n(i,{flexDirection:"column",marginTop:1,children:e.reverseDeps.map(a=>r(i,{gap:1,paddingLeft:2,children:[n(t,{color:"magenta",children:"←"}),n(t,{children:a})]},a))})]}),r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"INFO"})]}),r(i,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Type:"})}),n(t,{color:s,children:u})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Dependencies:"})}),n(t,{children:String(e.deps.length)})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Required by:"})}),n(t,{children:String(e.reverseDeps.length)})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Connectivity:"})}),n(t,{children:String(e.deps.length+e.reverseDeps.length)})]})]})]})]})})},"ProjectDetailPanel");var De=Object.defineProperty,B=E((o,e)=>De(o,"name",{value:e,configurable:!0}),"g");const Ne=[{key:"all",label:"All",shortcut:"1"},{key:"app",label:"Apps",shortcut:"2"},{key:"lib",label:"Libs",shortcut:"3"}],Y=B(({isSelected:o,node:e})=>{const l=e.type==="application",d=l?"yellow":"cyan",c=l?"app":"lib";return r(i,{flexShrink:0,height:1,children:[r(t,{children:[o?"▶":" "," "]}),n(i,{flexGrow:1,children:n(t,{bold:o,inverse:o,wrap:"truncate",children:e.name})}),r(t,{color:d,children:[" ",c]}),r(t,{dimColor:!0,children:[" ","→",e.deps.length," ","←",e.reverseDeps.length]})]})},"ProjectRow"),X=B(({count:o,label:e})=>r(i,{flexShrink:0,height:1,marginTop:1,children:[r(t,{dimColor:!0,children:["▼"," "]}),n(t,{bold:!0,color:"white",children:e.toUpperCase()}),r(t,{dimColor:!0,children:[" ","(",o,")"]})]}),"TypeHeader"),Ie=B(({filterActive:o,filterText:e,filterType:l,focused:d,nodes:c,scrollOffset:s,selectedIndex:u,stats:a,viewportHeight:y})=>{const g=d?"white":"gray",v=c.filter(w=>w.type==="application"),h=c.filter(w=>w.type!=="application"),f=[];let x=0;if(v.length>0){f.push(n(X,{count:v.length,label:"Applications"},"hdr-apps"));for(const w of v){const A=x;f.push(n(Y,{isSelected:A===u,node:w},w.name)),x++}}if(h.length>0){f.push(n(X,{count:h.length,label:"Libraries"},"hdr-libs"));for(const w of h){const A=x;f.push(n(Y,{isSelected:A===u,node:w},w.name)),x++}}let C=0;v.length>0&&(C+=2+v.length),h.length>0&&(C+=2+h.length);const M=C>y&&y>0;return r(i,{borderColor:g,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[r(i,{flexShrink:0,gap:1,paddingX:1,children:[n(t,{bold:!0,inverse:!0,children:" VIS "}),r(t,{wrap:"truncate",children:[a.total," ","packages"]}),r(t,{dimColor:!0,children:["(",a.apps," ","apps,"," ",a.libs," ","libs,"," ",a.deps," ","deps)"]})]}),n(i,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:Ne.map(w=>{const A=l===w.key;return r(i,{children:[n(t,{dimColor:!A,children:"["}),n(t,{bold:A,color:A?"cyan":"gray",children:w.shortcut}),n(t,{dimColor:!A,children:"]"}),r(t,{color:A?"white":"gray",children:[" ",w.label]})]},w.key)})}),o&&r(i,{flexShrink:0,paddingX:1,children:[n(t,{bold:!0,color:"white",children:"/ "}),n(t,{children:e}),n(t,{inverse:!0,children:" "})]}),r(i,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[n(i,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:n(i,{flexDirection:"column",marginTop:-s,children:f})}),M&&n(i,{flexShrink:0,marginLeft:1,marginRight:1,children:n(pe,{contentHeight:C,placement:"inset",scrollOffset:s,style:"block",viewportHeight:y})})]})]})},"ProjectListPanel");var $e=Object.defineProperty,Pe=E((o,e)=>$e(o,"name",{value:e,configurable:!0}),"M$1");const Le=100,Oe=40,Be=10,J={1:"all",2:"app",3:"lib"},Re=Pe(({autoExitSeconds:o=0,store:e})=>{const{exit:l}=he(),{columns:d,rows:c}=ue(),s=ve(e.subscribe,e.getSnapshot),[u,a]=O(!1),y=q(null),g=q(null),[v,h]=O(0),[f,x]=O(!1),C=_(()=>e.getFilteredNodes(),[s.allNodes,s.filterType,s.filterText]),M=_(()=>e.getStats(),[s.allNodes]),w=C[s.selectedIndex]??null,A=U(m=>{const p=C.filter(T=>T.type==="application"),b=C.filter(T=>T.type!=="application");let j=0,L=0;if(p.length>0){j+=2;for(let T=0;T<p.length;T++){if(L===m)return j;j+=1,L++}}if(b.length>0){j+=2;for(let T=0;T<b.length;T++){if(L===m)return j;j+=1,L++}}return j},[C]),P=Math.max(1,c-8-(s.filterActive?1:0)),N=U(m=>{const p=A(m);h(b=>p>b+P-2?Math.max(0,p-P+2):p<b+1?Math.max(0,p-1):b)},[A,P]);if(Ce(()=>{g.current?.scrollToTop()},[w?.name]),fe((m,p)=>{if(m==="c"&&p.ctrl){l();return}if(!f){if(u){p.escape||m==="?"?a(!1):m==="q"?(a(!1),x(!0)):p.downArrow||m==="j"?y.current?.scrollBy(1):(p.upArrow||m==="k")&&y.current?.scrollBy(-1);return}if(m==="?"){a(!0);return}if(m==="q"){x(!0);return}if(p.tab){e.setFocusedPanel(s.focusedPanel==="list"?"detail":"list");return}if(J[m]){e.setFilterType(J[m]);return}if(s.filterActive){if(p.escape){e.setFilterActive(!1);return}if(p.return){e.setFilterActive(!1);return}if(p.backspace){e.setFilter(s.filterText.slice(0,-1));return}if(m&&!p.ctrl&&!p.meta){e.setFilter(s.filterText+m);return}return}if(s.focusedPanel==="list"){if(C.length===0){m==="/"&&e.setFilterActive(!0);return}if(p.downArrow||m==="j"){const b=Math.min(s.selectedIndex+1,C.length-1);e.setSelectedIndex(b),N(b);return}if(p.upArrow||m==="k"){const b=Math.max(s.selectedIndex-1,0);e.setSelectedIndex(b),N(b);return}if(p.pageDown){const b=Math.min(s.selectedIndex+10,C.length-1);e.setSelectedIndex(b),N(b);return}if(p.pageUp){const b=Math.max(s.selectedIndex-10,0);e.setSelectedIndex(b),N(b);return}if(p.home){e.setSelectedIndex(0),h(0);return}if(p.end){const b=C.length-1;e.setSelectedIndex(b),N(b);return}if(m==="/"){e.setFilterActive(!0);return}if(p.rightArrow){e.setFocusedPanel("detail");return}return}if(s.focusedPanel==="detail"){if(p.escape||p.leftArrow){e.setFocusedPanel("list");return}if(p.downArrow||m==="j"){g.current?.scrollBy(1);return}if(p.upArrow||m==="k"){g.current?.scrollBy(-1);return}if(p.pageDown){g.current?.scrollBy(10);return}if(p.pageUp){g.current?.scrollBy(-10);return}if(p.home){g.current?.scrollToTop();return}p.end&&g.current?.scrollToBottom()}}},{isActive:!0}),d<Oe||c<Be)return n(i,{alignItems:"center",height:c,justifyContent:"center",width:d,children:r(t,{color:"yellow",children:["Terminal too small (",d,"x",c,")"]})});const ne=d>=Le,R=n(i,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,children:r(i,{flexWrap:"wrap",gap:2,paddingX:1,children:[r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"q"}),n(t,{dimColor:!0,children:"QUIT"})]},"q"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"?"}),n(t,{dimColor:!0,children:"HELP"})]},"?"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"↑↓"}),n(t,{dimColor:!0,children:"NAV"})]},"nav"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"1-3 /"}),n(t,{dimColor:!0,children:"FILTER"})]},"f"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"Tab"}),n(t,{dimColor:!0,children:"PANEL"})]},"t")]})}),F=r(ge,{footer:r(t,{dimColor:!0,children:[n(t,{bold:!0,color:"white",children:"↑↓"})," ","scroll"," ",n(t,{bold:!0,color:"white",children:"?"}),"/",n(t,{bold:!0,color:"white",children:"Esc"})," ","close"]}),scrollRef:y,title:"KEYBOARD SHORTCUTS",visible:u,width:52,children:[r(i,{flexDirection:"column",marginBottom:1,children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"NAVIGATION"})]}),r(i,{children:[n(i,{width:24,children:r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","↑","/k"]}),n(t,{dimColor:!0,children:" Move up"})]})}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","↓","/j"]}),n(t,{dimColor:!0,children:" Move down"})]})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","Tab"]}),n(t,{dimColor:!0,children:" Switch panel"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","→","/","←"]}),n(t,{dimColor:!0,children:" Focus detail/list"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","PgUp/PgDn"]}),n(t,{dimColor:!0,children:" Jump 10 items"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","Home/End"]}),n(t,{dimColor:!0,children:" Jump to start/end"})]})]}),r(i,{flexDirection:"column",marginBottom:1,children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"FILTERS"})]}),r(i,{children:[n(i,{width:24,children:r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","1"]}),n(t,{dimColor:!0,children:" All"})]})}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","2"]}),n(t,{dimColor:!0,children:" Apps only"})]})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","3"]}),n(t,{dimColor:!0,children:" Libraries only"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","/"]}),n(t,{dimColor:!0,children:" Text filter"})]})]}),r(i,{flexDirection:"column",children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"ACTIONS"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","q"]}),n(t,{dimColor:!0,children:" Quit"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","?"]}),n(t,{dimColor:!0,children:" Toggle help"})]})]})]}),H=n(Ie,{filterActive:s.filterActive,filterText:s.filterText,filterType:s.filterType,focused:s.focusedPanel==="list",nodes:C,scrollOffset:v,selectedIndex:s.selectedIndex,stats:M,viewportHeight:P}),G=n(je,{focused:s.focusedPanel==="detail",node:w,scrollRef:g});if(ne){const m=Math.floor(d*.35);return r(i,{flexDirection:"column",height:c,width:d,children:[r(i,{flexDirection:"row",flexGrow:1,children:[n(i,{flexGrow:1,children:H}),n(i,{width:m,children:G})]}),R,n(W,{autoExitSeconds:o??3,onCancel:E(()=>{x(!1)},"onCancel"),visible:f}),F]})}const re=Math.floor(c*.55);return r(i,{flexDirection:"column",height:c,width:d,children:[n(i,{height:re,children:H}),n(i,{flexGrow:1,children:G}),R,n(W,{autoExitSeconds:o??3,onCancel:E(()=>{x(!1)},"onCancel"),visible:f}),F]})},"VisGraphApp");var V=Object.freeze,ee=Object.defineProperty,D=E((o,e)=>ee(o,"name",{value:e,configurable:!0}),"x"),Fe=E((o,e)=>V(ee(o,"raw",{value:V(e||o.slice())})),"C");const te=D((o,e,l,d,c,s,u,a)=>{const y=l?k("└── "):k("├── "),g=c.has(o),v=g?k(" (*)"):"",h=d.get(o),f=h?.type==="application"?S(o):o;if(s.push(`${e}${y}${f}${v}`),g)return;c.add(o);const x=h?.deps??[],C=l?`${e} `:`${e}${k("│")} `;if(a>=u&&x.length>0){s.push(`${C}${k(`... ${x.length} more`)}`);return}for(let M=0;M<x.length;M++){const w=x[M];w&&te(w.target,C,M===x.length-1,d,c,s,u,a+1)}},"printDepsTree"),Q=D((o,e,l,d,c,s)=>{const u=e.get(o),a=u?.type==="application"?S(o):o;d.push(`${s}${a}`),l.add(o);const y=u?.deps??[];if(y.length===0){d.push(`${s} ${k("(no dependencies)")}`);return}if(c<=0){d.push(`${s} ${k(`... ${y.length} dependencies`)}`);return}for(let g=0;g<y.length;g++){const v=y[g];v&&te(v.target,s,g===y.length-1,e,l,d,c,1)}},"printRootProject"),K=D((o,e)=>{const l=new Map;for(const[h,f]of Object.entries(o.nodes))l.set(h,{deps:(o.dependencies[h]??[]).map(x=>({target:x.target,type:x.type})),name:h,type:f.type});const d=[],c=[];for(const[h,f]of l)f.type==="application"?d.push(h):c.push(h);d.sort(),c.sort();const s=d.length+c.length,u=Object.values(o.dependencies).reduce((h,f)=>h+f.length,0),a=[S("Project Dependency Graph"),""];if(d.length>0){a.push(` ${S(z(`Applications (${d.length})`))}`,"");for(const h of d)Q(h,l,new Set,a,e," "),a.push("")}if(c.length>0){a.push(` ${S(z(`Libraries (${c.length})`))}`,"");for(const h of c)Q(h,l,new Set,a,e," "),a.push("")}const y=process.stdout.columns||80;a.push(k("─".repeat(Math.min(y,60)))),a.push(`${S(String(s))} packages ${k("·")} ${S(String(u))} dependencies ${k("·")} ${S(String(d.length))} apps${k(",")} ${S(String(c.length))} libraries`);const g=new Set;let v=!1;for(const h of[...d,...c]){const f=l.get(h)?.deps??[];for(const x of f)g.has(x.target)&&(v=!0),g.add(x.target);g.add(h)}return v&&a.push(k("(*) = already shown above")),a.join(`
|
|
1
|
+
var oe=Object.defineProperty;var E=(o,e)=>oe(o,"name",{value:e,configurable:!0});import{createRequire as ie}from"node:module";import{aA as z,E as k,j as S,q as W,y as ce,m as ae,s as pe}from"./bin.js";import{projectGraphToDot as he}from"@visulima/task-runner";import{Box as i,Text as t,ScrollView as ue,ScrollBar as fe,useApp as ge,useWindowSize as me,useInput as xe,Dialog as be,render as ye}from"@visulima/tui";import we,{useSyncExternalStore as ve,useState as O,useRef as q,useMemo as _,useCallback as U,useEffect as Ce}from"react";import{jsx as n,jsxs as r}from"react/jsx-runtime";const le=ie(import.meta.url),I=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,de=E(o=>{if(typeof I<"u"&&I.versions&&I.versions.node){const[e,l]=I.versions.node.split(".").map(Number);if(e>22||e===22&&l>=3||e===20&&l>=16)return I.getBuiltinModule(o)}return le(o)},"__cjs_getBuiltinModule"),{writeFileSync:se}=de("node:fs");var Ae=Object.defineProperty,$=E((o,e)=>Ae(o,"name",{value:e,configurable:!0}),"n");const ke=$(o=>{const e=new Map;for(const[l,d]of Object.entries(o.dependencies))for(const c of d){const s=e.get(c.target)??[];s.push(l),e.set(c.target,s)}return Object.values(o.nodes).map(l=>({deps:o.dependencies[l.name]??[],name:l.name,reverseDeps:e.get(l.name)??[],type:l.type})).sort((l,d)=>l.type!==d.type?l.type==="application"?-1:1:l.name.localeCompare(d.name))},"buildNodes"),Ee=$((o,e,l)=>{let d=o;if(e==="app"?d=d.filter(c=>c.type==="application"):e==="lib"&&(d=d.filter(c=>c.type!=="application")),l){const c=l.toLowerCase();d=d.filter(s=>s.name.toLowerCase().includes(c))}return d},"filterNodes");class Me{static{E(this,"GraphStore")}static{$(this,"GraphStore")}#e;#n=new Set;#r;constructor(e){this.#r=e;const l=ke(e);this.#e={allNodes:l,filterActive:!1,filterText:"",filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=$(()=>this.#e,"getSnapshot");subscribe=$(e=>(this.#n.add(e),()=>{this.#n.delete(e)}),"subscribe");getFilteredNodes(){return Ee(this.#e.allNodes,this.#e.filterType,this.#e.filterText)}getStats(){const e=this.#e.allNodes.filter(c=>c.type==="application").length,l=this.#e.allNodes.length,d=Object.values(this.#r.dependencies).reduce((c,s)=>c+s.length,0);return{apps:e,deps:d,libs:l-e,total:l}}setSelectedIndex(e){const l=this.getFilteredNodes(),d=l.length===0?-1:Math.max(0,Math.min(e,l.length-1));d!==this.#e.selectedIndex&&this.#t({...this.#e,selectedIndex:d})}setFocusedPanel(e){e!==this.#e.focusedPanel&&this.#t({...this.#e,focusedPanel:e})}setFilterType(e){e!==this.#e.filterType&&this.#t({...this.#e,filterType:e,selectedIndex:0})}setFilter(e){this.#t({...this.#e,filterText:e,selectedIndex:0})}setFilterActive(e){e!==this.#e.filterActive&&this.#t({...this.#e,filterActive:e,filterText:e?this.#e.filterText:"",selectedIndex:e?this.#e.selectedIndex:0})}#t(e){this.#e=e;for(const l of this.#n)try{l()}catch{}}}var Te=Object.defineProperty,Se=E((o,e)=>Te(o,"name",{value:e,configurable:!0}),"p");const je=Se(({focused:o,node:e,scrollRef:l})=>{const d=o?"white":"gray";if(!e)return n(i,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:n(t,{dimColor:!0,children:"No project selected"})});const c=e.type==="application",s=c?"yellow":"cyan",u=c?"Application":"Library";return n(i,{borderColor:d,borderStyle:"single",borderTopRightTitle:` ${u} `,borderTopTitle:` ${e.name} `,flexDirection:"column",flexGrow:1,children:r(ue,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"DEPENDS ON"}),r(t,{dimColor:!0,children:[" ","(",e.deps.length,")"]})]}),e.deps.length===0?n(i,{marginTop:1,paddingLeft:2,children:n(t,{dimColor:!0,children:"No dependencies"})}):n(i,{flexDirection:"column",marginTop:1,children:e.deps.map(a=>r(i,{gap:1,paddingLeft:2,children:[n(t,{color:"cyan",children:"→"}),n(t,{children:a.target}),a.type!=="static"&&r(t,{dimColor:!0,children:["(",a.type,")"]})]},a.target))})]}),r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"REQUIRED BY"}),r(t,{dimColor:!0,children:[" ","(",e.reverseDeps.length,")"]})]}),e.reverseDeps.length===0?n(i,{marginTop:1,paddingLeft:2,children:n(t,{dimColor:!0,children:"No reverse dependencies"})}):n(i,{flexDirection:"column",marginTop:1,children:e.reverseDeps.map(a=>r(i,{gap:1,paddingLeft:2,children:[n(t,{color:"magenta",children:"←"}),n(t,{children:a})]},a))})]}),r(i,{flexDirection:"column",marginTop:1,children:[r(i,{children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"INFO"})]}),r(i,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Type:"})}),n(t,{color:s,children:u})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Dependencies:"})}),n(t,{children:String(e.deps.length)})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Required by:"})}),n(t,{children:String(e.reverseDeps.length)})]}),r(i,{children:[n(i,{width:16,children:n(t,{dimColor:!0,children:"Connectivity:"})}),n(t,{children:String(e.deps.length+e.reverseDeps.length)})]})]})]})]})})},"ProjectDetailPanel");var De=Object.defineProperty,B=E((o,e)=>De(o,"name",{value:e,configurable:!0}),"g");const Ne=[{key:"all",label:"All",shortcut:"1"},{key:"app",label:"Apps",shortcut:"2"},{key:"lib",label:"Libs",shortcut:"3"}],Y=B(({isSelected:o,node:e})=>{const l=e.type==="application",d=l?"yellow":"cyan",c=l?"app":"lib";return r(i,{flexShrink:0,height:1,children:[r(t,{children:[o?"▶":" "," "]}),n(i,{flexGrow:1,children:n(t,{bold:o,inverse:o,wrap:"truncate",children:e.name})}),r(t,{color:d,children:[" ",c]}),r(t,{dimColor:!0,children:[" ","→",e.deps.length," ","←",e.reverseDeps.length]})]})},"ProjectRow"),X=B(({count:o,label:e})=>r(i,{flexShrink:0,height:1,marginTop:1,children:[r(t,{dimColor:!0,children:["▼"," "]}),n(t,{bold:!0,color:"white",children:e.toUpperCase()}),r(t,{dimColor:!0,children:[" ","(",o,")"]})]}),"TypeHeader"),Ie=B(({filterActive:o,filterText:e,filterType:l,focused:d,nodes:c,scrollOffset:s,selectedIndex:u,stats:a,viewportHeight:y})=>{const g=d?"white":"gray",v=c.filter(w=>w.type==="application"),h=c.filter(w=>w.type!=="application"),f=[];let x=0;if(v.length>0){f.push(n(X,{count:v.length,label:"Applications"},"hdr-apps"));for(const w of v){const A=x;f.push(n(Y,{isSelected:A===u,node:w},w.name)),x++}}if(h.length>0){f.push(n(X,{count:h.length,label:"Libraries"},"hdr-libs"));for(const w of h){const A=x;f.push(n(Y,{isSelected:A===u,node:w},w.name)),x++}}let C=0;v.length>0&&(C+=2+v.length),h.length>0&&(C+=2+h.length);const M=C>y&&y>0;return r(i,{borderColor:g,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[r(i,{flexShrink:0,gap:1,paddingX:1,children:[n(t,{bold:!0,inverse:!0,children:" VIS "}),r(t,{wrap:"truncate",children:[a.total," ","packages"]}),r(t,{dimColor:!0,children:["(",a.apps," ","apps,"," ",a.libs," ","libs,"," ",a.deps," ","deps)"]})]}),n(i,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:Ne.map(w=>{const A=l===w.key;return r(i,{children:[n(t,{dimColor:!A,children:"["}),n(t,{bold:A,color:A?"cyan":"gray",children:w.shortcut}),n(t,{dimColor:!A,children:"]"}),r(t,{color:A?"white":"gray",children:[" ",w.label]})]},w.key)})}),o&&r(i,{flexShrink:0,paddingX:1,children:[n(t,{bold:!0,color:"white",children:"/ "}),n(t,{children:e}),n(t,{inverse:!0,children:" "})]}),r(i,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[n(i,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:n(i,{flexDirection:"column",marginTop:-s,children:f})}),M&&n(i,{flexShrink:0,marginLeft:1,marginRight:1,children:n(fe,{contentHeight:C,placement:"inset",scrollOffset:s,style:"block",viewportHeight:y})})]})]})},"ProjectListPanel");var $e=Object.defineProperty,Pe=E((o,e)=>$e(o,"name",{value:e,configurable:!0}),"M$1");const Le=100,Oe=40,Be=10,J={1:"all",2:"app",3:"lib"},Re=Pe(({autoExitSeconds:o=0,store:e})=>{const{exit:l}=ge(),{columns:d,rows:c}=me(),s=ve(e.subscribe,e.getSnapshot),[u,a]=O(!1),y=q(null),g=q(null),[v,h]=O(0),[f,x]=O(!1),C=_(()=>e.getFilteredNodes(),[s.allNodes,s.filterType,s.filterText]),M=_(()=>e.getStats(),[s.allNodes]),w=C[s.selectedIndex]??null,A=U(m=>{const p=C.filter(T=>T.type==="application"),b=C.filter(T=>T.type!=="application");let j=0,L=0;if(p.length>0){j+=2;for(let T=0;T<p.length;T++){if(L===m)return j;j+=1,L++}}if(b.length>0){j+=2;for(let T=0;T<b.length;T++){if(L===m)return j;j+=1,L++}}return j},[C]),P=Math.max(1,c-8-(s.filterActive?1:0)),N=U(m=>{const p=A(m);h(b=>p>b+P-2?Math.max(0,p-P+2):p<b+1?Math.max(0,p-1):b)},[A,P]);if(Ce(()=>{g.current?.scrollToTop()},[w?.name]),xe((m,p)=>{if(m==="c"&&p.ctrl){l();return}if(!f){if(u){p.escape||m==="?"?a(!1):m==="q"?(a(!1),x(!0)):p.downArrow||m==="j"?y.current?.scrollBy(1):(p.upArrow||m==="k")&&y.current?.scrollBy(-1);return}if(m==="?"){a(!0);return}if(m==="q"){x(!0);return}if(p.tab){e.setFocusedPanel(s.focusedPanel==="list"?"detail":"list");return}if(J[m]){e.setFilterType(J[m]);return}if(s.filterActive){if(p.escape){e.setFilterActive(!1);return}if(p.return){e.setFilterActive(!1);return}if(p.backspace){e.setFilter(s.filterText.slice(0,-1));return}if(m&&!p.ctrl&&!p.meta){e.setFilter(s.filterText+m);return}return}if(s.focusedPanel==="list"){if(C.length===0){m==="/"&&e.setFilterActive(!0);return}if(p.downArrow||m==="j"){const b=Math.min(s.selectedIndex+1,C.length-1);e.setSelectedIndex(b),N(b);return}if(p.upArrow||m==="k"){const b=Math.max(s.selectedIndex-1,0);e.setSelectedIndex(b),N(b);return}if(p.pageDown){const b=Math.min(s.selectedIndex+10,C.length-1);e.setSelectedIndex(b),N(b);return}if(p.pageUp){const b=Math.max(s.selectedIndex-10,0);e.setSelectedIndex(b),N(b);return}if(p.home){e.setSelectedIndex(0),h(0);return}if(p.end){const b=C.length-1;e.setSelectedIndex(b),N(b);return}if(m==="/"){e.setFilterActive(!0);return}if(p.rightArrow){e.setFocusedPanel("detail");return}return}if(s.focusedPanel==="detail"){if(p.escape||p.leftArrow){e.setFocusedPanel("list");return}if(p.downArrow||m==="j"){g.current?.scrollBy(1);return}if(p.upArrow||m==="k"){g.current?.scrollBy(-1);return}if(p.pageDown){g.current?.scrollBy(10);return}if(p.pageUp){g.current?.scrollBy(-10);return}if(p.home){g.current?.scrollToTop();return}p.end&&g.current?.scrollToBottom()}}},{isActive:!0}),d<Oe||c<Be)return n(i,{alignItems:"center",height:c,justifyContent:"center",width:d,children:r(t,{color:"yellow",children:["Terminal too small (",d,"x",c,")"]})});const ne=d>=Le,R=n(i,{borderBottom:!1,borderColor:"gray",borderLeft:!1,borderRight:!1,borderStyle:"single",flexShrink:0,children:r(i,{flexWrap:"wrap",gap:2,paddingX:1,children:[r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"q"}),n(t,{dimColor:!0,children:"QUIT"})]},"q"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"?"}),n(t,{dimColor:!0,children:"HELP"})]},"?"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"↑↓"}),n(t,{dimColor:!0,children:"NAV"})]},"nav"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"1-3 /"}),n(t,{dimColor:!0,children:"FILTER"})]},"f"),r(i,{gap:1,children:[n(t,{bold:!0,color:"white",children:"Tab"}),n(t,{dimColor:!0,children:"PANEL"})]},"t")]})}),F=r(be,{footer:r(t,{dimColor:!0,children:[n(t,{bold:!0,color:"white",children:"↑↓"})," ","scroll"," ",n(t,{bold:!0,color:"white",children:"?"}),"/",n(t,{bold:!0,color:"white",children:"Esc"})," ","close"]}),scrollRef:y,title:"KEYBOARD SHORTCUTS",visible:u,width:52,children:[r(i,{flexDirection:"column",marginBottom:1,children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"NAVIGATION"})]}),r(i,{children:[n(i,{width:24,children:r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","↑","/k"]}),n(t,{dimColor:!0,children:" Move up"})]})}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","↓","/j"]}),n(t,{dimColor:!0,children:" Move down"})]})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","Tab"]}),n(t,{dimColor:!0,children:" Switch panel"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","→","/","←"]}),n(t,{dimColor:!0,children:" Focus detail/list"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","PgUp/PgDn"]}),n(t,{dimColor:!0,children:" Jump 10 items"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","Home/End"]}),n(t,{dimColor:!0,children:" Jump to start/end"})]})]}),r(i,{flexDirection:"column",marginBottom:1,children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"FILTERS"})]}),r(i,{children:[n(i,{width:24,children:r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","1"]}),n(t,{dimColor:!0,children:" All"})]})}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","2"]}),n(t,{dimColor:!0,children:" Apps only"})]})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","3"]}),n(t,{dimColor:!0,children:" Libraries only"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","/"]}),n(t,{dimColor:!0,children:" Text filter"})]})]}),r(i,{flexDirection:"column",children:[r(i,{marginBottom:1,children:[n(t,{dimColor:!0,children:"── "}),n(t,{bold:!0,color:"white",children:"ACTIONS"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","q"]}),n(t,{dimColor:!0,children:" Quit"})]}),r(t,{children:[r(t,{bold:!0,color:"white",children:[" ","?"]}),n(t,{dimColor:!0,children:" Toggle help"})]})]})]}),H=n(Ie,{filterActive:s.filterActive,filterText:s.filterText,filterType:s.filterType,focused:s.focusedPanel==="list",nodes:C,scrollOffset:v,selectedIndex:s.selectedIndex,stats:M,viewportHeight:P}),G=n(je,{focused:s.focusedPanel==="detail",node:w,scrollRef:g});if(ne){const m=Math.floor(d*.35);return r(i,{flexDirection:"column",height:c,width:d,children:[r(i,{flexDirection:"row",flexGrow:1,children:[n(i,{flexGrow:1,children:H}),n(i,{width:m,children:G})]}),R,n(z,{autoExitSeconds:o??3,onCancel:E(()=>{x(!1)},"onCancel"),visible:f}),F]})}const re=Math.floor(c*.55);return r(i,{flexDirection:"column",height:c,width:d,children:[n(i,{height:re,children:H}),n(i,{flexGrow:1,children:G}),R,n(z,{autoExitSeconds:o??3,onCancel:E(()=>{x(!1)},"onCancel"),visible:f}),F]})},"VisGraphApp");var V=Object.freeze,ee=Object.defineProperty,D=E((o,e)=>ee(o,"name",{value:e,configurable:!0}),"x"),Fe=E((o,e)=>V(ee(o,"raw",{value:V(e||o.slice())})),"C");const te=D((o,e,l,d,c,s,u,a)=>{const y=l?k("└── "):k("├── "),g=c.has(o),v=g?k(" (*)"):"",h=d.get(o),f=h?.type==="application"?S(o):o;if(s.push(`${e}${y}${f}${v}`),g)return;c.add(o);const x=h?.deps??[],C=l?`${e} `:`${e}${k("│")} `;if(a>=u&&x.length>0){s.push(`${C}${k(`... ${x.length} more`)}`);return}for(let M=0;M<x.length;M++){const w=x[M];w&&te(w.target,C,M===x.length-1,d,c,s,u,a+1)}},"printDepsTree"),Q=D((o,e,l,d,c,s)=>{const u=e.get(o),a=u?.type==="application"?S(o):o;d.push(`${s}${a}`),l.add(o);const y=u?.deps??[];if(y.length===0){d.push(`${s} ${k("(no dependencies)")}`);return}if(c<=0){d.push(`${s} ${k(`... ${y.length} dependencies`)}`);return}for(let g=0;g<y.length;g++){const v=y[g];v&&te(v.target,s,g===y.length-1,e,l,d,c,1)}},"printRootProject"),K=D((o,e)=>{const l=new Map;for(const[h,f]of Object.entries(o.nodes))l.set(h,{deps:(o.dependencies[h]??[]).map(x=>({target:x.target,type:x.type})),name:h,type:f.type});const d=[],c=[];for(const[h,f]of l)f.type==="application"?d.push(h):c.push(h);d.sort(),c.sort();const s=d.length+c.length,u=Object.values(o.dependencies).reduce((h,f)=>h+f.length,0),a=[S("Project Dependency Graph"),""];if(d.length>0){a.push(` ${S(W(`Applications (${d.length})`))}`,"");for(const h of d)Q(h,l,new Set,a,e," "),a.push("")}if(c.length>0){a.push(` ${S(W(`Libraries (${c.length})`))}`,"");for(const h of c)Q(h,l,new Set,a,e," "),a.push("")}const y=process.stdout.columns||80;a.push(k("─".repeat(Math.min(y,60)))),a.push(`${S(String(s))} packages ${k("·")} ${S(String(u))} dependencies ${k("·")} ${S(String(d.length))} apps${k(",")} ${S(String(c.length))} libraries`);const g=new Set;let v=!1;for(const h of[...d,...c]){const f=l.get(h)?.deps??[];for(const x of f)g.has(x.target)&&(v=!0),g.add(x.target);g.add(h)}return v&&a.push(k("(*) = already shown above")),a.join(`
|
|
2
2
|
`)},"projectGraphToAscii"),He=D(o=>{const e=Object.values(o.nodes).map(l=>({name:l.name,type:l.type}));return{edges:Object.values(o.dependencies).flat(),nodes:e}},"projectGraphToJson");var Z;const Ge=D(o=>{const e=Object.values(o.nodes).map(u=>({name:u.name,type:u.type})),l=[];for(const u of Object.values(o.dependencies))for(const a of u)l.push({source:a.source,target:a.target,type:a.type});const d=e.filter(u=>u.type==="application"),c=e.filter(u=>u.type!=="application"),s={apps:d.length,edges:l,libs:c.length,nodes:e};return String.raw(Z||(Z=Fe([`<!DOCTYPE html>
|
|
3
3
|
<html lang="en">
|
|
4
4
|
<head>
|
|
@@ -425,4 +425,4 @@ nodes.forEach(n => {
|
|
|
425
425
|
});
|
|
426
426
|
<\/script>
|
|
427
427
|
</body>
|
|
428
|
-
</html>`])),s.apps,s.libs,s.edges.length,JSON.stringify(s).replaceAll("</",String.raw`<\/`))},"projectGraphToHtml"),
|
|
428
|
+
</html>`])),s.apps,s.libs,s.edges.length,JSON.stringify(s).replaceAll("</",String.raw`<\/`))},"projectGraphToHtml"),Je=D(async({logger:o,options:e,visConfig:l,workspaceRoot:d})=>{if(!d)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const c=d,{packageJsons:s,workspace:u}=ce(c,l),a=ae(c,u,s),y=!!process.stdout.isTTY&&!pe,g=e.format??(y?"tui":"ascii"),v=e.output,h=e.depth??1/0;let f;switch(g){case"dot":{f=he(a);break}case"html":{f=Ge(a);break}case"json":{f=JSON.stringify(He(a),void 0,2);break}case"tui":{if(!y){f=K(a,h);break}const x=l?.tui?.autoExit===!0?3:typeof l?.tui?.autoExit=="number"?l.tui.autoExit:0;process.stdin.isTTY&&typeof process.stdin.setRawMode=="function"&&(process.stdin.setRawMode(!0),process.stdin.ref(),process.stdin.resume());const C=setInterval(()=>{},1e3),M=new Me(a);await ye(we.createElement(Re,{autoExitSeconds:x,store:M}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit(),clearInterval(C);return}default:f=K(a,h)}v?(se(v,f,"utf8"),o.info(`Graph written to ${v}`)):o.info(f)},"execute");export{Je as default};
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
var re=Object.defineProperty;var b=(e,t)=>re(e,"name",{value:t,configurable:!0});import{createRequire as ne}from"node:module";import{dim as v,cyan as se,yellow as E,red as oe,green as W}from"@visulima/colorize";import{isAccessibleSync as D,readJsonSync as ae,writeFileSync as ce,readFileSync as le}from"@visulima/fs";import{isAbsolute as C,relative as H,resolve as j,join as B}from"@visulima/path";import{redact as de}from"@visulima/redact";import{fingerprint as k,listRules as K,listRequiredValidators as ue,scan as Q,scanFiles as fe,inspectRuleset as pe}from"@visulima/secret-scanner";import{p as m}from"./bin.js";import{InteractiveManager as ge,InteractiveStreamHook as V}from"@visulima/interactive-manager";import{Spinner as me}from"@visulima/spinner";const ie=ne(import.meta.url),F=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=b(e=>{if(typeof F<"u"&&F.versions&&F.versions.node){const[t,i]=F.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return F.getBuiltinModule(e)}return ie(e)},"__cjs_getBuiltinModule"),{pathToFileURL:X}=G("node:url"),{execFileSync:he}=G("node:child_process");var we=Object.defineProperty,ve=b((e,t)=>we(e,"name",{value:t,configurable:!0}),"r$1");const Y=ve((e={})=>{const t=new ge(new V(process.stdout),new V(process.stderr));return new me(e,t)},"createSpinner");var $e=Object.defineProperty,I=b((e,t)=>$e(e,"name",{value:t,configurable:!0}),"s");const ye=I((e,t)=>{if(!C(e))return e;const i=H(t,e);return i===""||i.startsWith("..")?e:i},"toRelative"),A=I((e,t)=>{const i=ye(e.file,t);return i===e.file?e:{...e,file:i}},"toRelativeFinding"),Z=I(e=>{if(!D(e))return[];try{const t=ae(e);return Array.isArray(t)?t:[]}catch{return[]}},"readBaseline"),Se=I((e,t,i)=>{const n=Z(t).map(o=>A(o,i)),r=new Set(n.map(o=>k(o))),a=e.map(o=>A(o,i)),l=new Set(a.map(o=>k(o)));return{fresh:a.filter(o=>!r.has(k(o))),resolved:n.filter(o=>!l.has(k(o))),surviving:a.filter(o=>r.has(k(o)))}},"diffBaseline"),ee=I((e,t,i,n={})=>{const r=e.map(l=>A(l,i));let a;if(n.replace)a=r;else{const l=Z(t).map(s=>A(s,i)),o=new Set;a=[];for(const s of[...l,...r]){const c=k(s);o.has(c)||(o.add(c),a.push(s))}}return ce(t,`${JSON.stringify(a,null,4)}
|
|
2
|
-
`),
|
|
3
|
-
`)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
${n.
|
|
7
|
-
`),n.keywords.length>0){const l=`keywords: ${n.keywords.slice(0,6).join(", ")}${n.keywords.length>6?", ...":""}`;process.stdout.write(` ${t?v(l):l}
|
|
8
|
-
`)}process.stdout.write(`
|
|
9
|
-
`)}},"printListRules"),Ne=f(async(e,t)=>{const i=await ue(e);if(i.length===0){process.stdout.write(t?`${v("No non-HTTP validators required by the current ruleset.")}
|
|
10
|
-
`:`No non-HTTP validators required by the current ruleset.
|
|
11
|
-
`);return}process.stdout.write(`${String(i.length)} non-HTTP validator type(s) referenced by the current ruleset:
|
|
12
|
-
|
|
13
|
-
`);for(const n of i){const r=t?E(n.displayName):n.displayName,a=`(${n.type}, ${String(n.ruleCount)} rule${n.ruleCount===1?"":"s"})`;process.stdout.write(`${r} ${t?v(a):a}
|
|
14
|
-
`),process.stdout.write(` ${n.summary}
|
|
15
|
-
`);const l=n.packageName?`install: npm add ${n.packageName}`:"no driver — bespoke implementation required";process.stdout.write(` ${t?v(l):l}
|
|
16
|
-
|
|
17
|
-
`)}},"printListValidators"),Oe=f(async(e,t,i)=>{const n=B(e,M);if(!i&&D(n)){m.warn(`Detected existing ${M} — refusing to overwrite. Delete it first to re-init.`),process.exitCode=1;return}m.info(i?"[dry-run] Previewing init — no files will be written.":"Scanning workspace to seed baseline…");const r=Y();r.start("scanning");let a;try{a=await Q([e],t),r.succeed()}catch(o){throw r.failed(),o}if(i){m.info(`[dry-run] Would create ${M} with ${String(a.length)} finding(s).`);return}const l=ee(a,n,e,{replace:!0});m.success(`Wrote ${M} (${String(l)} findings).`),m.notice("Commit it. Use `vis secrets --baseline .secrets-baseline.json` in CI. Add path patterns to .gitignore to exclude directories from scanning.")},"runInit"),Ee=f((e,t,i)=>{const n=t??{},r=f(u=>u?j(i,u):void 0,"resolvePath"),a=f((u,R)=>{const $=J(u);return $.length>0?$:R},"pickList"),l=a(e.enableRule,n.rules?.enable),o=a(e.excludeRule,n.rules?.exclude),s=a(e.includeRule,n.rules?.include),c=a(e.exclude,n.walk?.excludePatterns),p=J(e.excludeFrom).map(u=>j(i,u)),d=p.length>0?p:n.walk?.excludeFromFiles?.map(u=>j(i,u)),x=r(e.baseline)??r(n.baseline),S=r(e.config)??r(n.config?.path),w=qe(e.minConfidence??n.config?.minConfidence);return{baseline:x,concurrency:e.concurrency,config:{extendBundled:e.noExtendBundled?!1:n.config?.extendBundled,inline:n.config?.inline,minConfidence:w,onlyVerified:e.onlyVerified??n.config?.onlyVerified??!1,path:S,validate:e.validate??n.config?.validate??!1},redact:e.redact??n.redact,rules:{enable:l,exclude:o,include:s},verbose:e.verbose??!1,walk:{excludeFromFiles:d,excludePatterns:c,gitignore:e.noGitignore?!1:n.walk?.gitignore??!0,includeHidden:e.includeHidden??n.walk?.includeHidden,maxFileSize:e.maxSize??n.walk?.maxFileSize}}},"resolveScanOptions"),Pe=f(e=>{process.stderr.write(`${v("baseline diff: ")}${W(`+${String(e.fresh.length)} new`)} · ${E(`${String(e.surviving.length)} unchanged`)} · ${v(`-${String(e.resolved.length)} resolved`)}
|
|
18
|
-
`)},"printDiff"),_e=f(async(e,t,i)=>{if(e.staged){if(!P(i))throw new Error("--staged requires a git working tree, and none was detected.");return{files:Ae(i)}}if(e.since){if(!P(i))throw new Error("--since requires a git working tree, and none was detected.");return{files:z(i,e.since)}}if(e.affected){if(!P(i))return m.warn("--affected requires git; falling back to full scan"),{paths:t&&t.length>0?t.map(r=>j(i,r)):[i]};const n=process.env.VIS_BASE??"HEAD~1";return{files:z(i,n)}}return{paths:t&&t.length>0?t.map(n=>j(i,n)):[i]}},"chooseScanPaths"),De=f((e,t,i,n,r,a,l)=>{switch(t){case"json":{const o=e.map(s=>A(s,i));process.stdout.write(`${JSON.stringify(o,null,2)}
|
|
19
|
-
`);break}case"sarif":{process.stdout.write(`${Me(e,r,i,a)}
|
|
20
|
-
`);break}default:process.stdout.write(`${Ce(e,i,n,{redact:l})}
|
|
21
|
-
`)}},"emitFindings"),Ye=f(async({argument:e,options:t,visConfig:i,workspaceRoot:n})=>{const r=t,a=e,l=n??process.cwd(),o=!r.quiet&&process.stdout.isTTY,s=i?.secrets,c=Ee(r,s,l),p="0.0.0-alpha";if(r.listRules){await Le(c,o);return}if(r.listValidators){await Ne(c,o);return}if(r.init){await Oe(l,c,r.dryRun??!1);return}const d=await _e(r,a??[],l);if(d.files?.length===0){r.quiet||m.success("No files to scan.");return}const x=!r.quiet&&!["json","sarif"].includes(r.format??"text"),S=Y({verbose:x});S.start("scanning for secrets");let w;try{w=d.files===void 0?await Q(d.paths??[l],c):await fe(d.files,c),S.succeed()}catch(g){throw S.failed(),new Error(`secret scan failed: ${g instanceof Error?g.message:String(g)}`,{cause:g})}if(r.verbose){const g=await pe(c);if(g.length>0){m.warn(`${String(g.length)} rule(s) skipped due to invalid regex. First few:`);for(const N of g.slice(0,5))process.stderr.write(` - ${N.ruleId}: ${N.reason}
|
|
22
|
-
`)}}const u=c.baseline??B(l,M),R=!r.quiet&&D(u);if(r.updateBaseline){const g=ee(w,u,l,{replace:r.replaceBaseline});m.success(`Baseline updated: ${H(l,u)||u} now contains ${String(g)} entries.`);return}const $=Te(r.format),y=$==="sarif"?await K(c).catch(()=>[]):[],q=c.redact===!0,L=q?de(w,["match","secret"]):w;if(De(L,$,l,o,p,y,q),$==="text"&&R&&Pe(Se(w,u,l)),w.length>0){r.quiet||(m.warn(`${String(w.length)} potential secret(s) found`),m.notice("Suppress individual lines with `gitleaks:allow` / `secret-scanner:allow`, or run `vis secrets --update-baseline`.")),process.exitCode=1;return}r.quiet||m.success("No secrets detected.")},"execute");export{Ye as default};
|
|
1
|
+
var re=Object.defineProperty;var E=(e,r)=>re(e,"name",{value:r,configurable:!0});import{createRequire as te}from"node:module";import{isAccessibleSync as G,readFileSync as Q}from"@visulima/fs";import{C as se,M,z as V,Q as le}from"../packem_shared/index-OlP7U_t5.js";import{Box as a,Text as c,ScrollView as ce,ScrollBar as ae,useApp as de,useWindowSize as ue,useInput as fe,render as he}from"@visulima/tui";import{aB as ge,aC as J,aD as pe,aE as me,aF as we,aG as ye,p as k,s as xe}from"./bin.js";import be,{useSyncExternalStore as Se,useRef as F,useCallback as _}from"react";import{o as ke}from"../packem_shared/index-DH-5hsrC.js";import{sortPackageJsonStringWithOptions as Y}from"#native";import{jsxs as f,jsx as s,Fragment as ve}from"react/jsx-runtime";import{f as D}from"../packem_shared/utils-DrNg0XTR.js";const oe=te(import.meta.url),T=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,ne=E(e=>{if(typeof T<"u"&&T.versions&&T.versions.node){const[r,t]=T.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return T.getBuiltinModule(e)}return oe(e)},"__cjs_getBuiltinModule"),{writeFileSync:ie}=ne("node:fs");var $e=Object.defineProperty,I=E((e,r)=>$e(e,"name",{value:r,configurable:!0}),"i$1");const q={error:0,rewritten:1,"would-rewrite":1,unchanged:2},Pe=I(e=>[...e].sort((r,t)=>q[r.status]-q[t.status]),"sortByStatusRank"),Ee=I((e,r)=>r==="all"?e:r==="errors"?e.filter(t=>t.status==="error"):r==="rewritten"?e.filter(t=>t.status==="rewritten"||t.status==="would-rewrite"):e.filter(t=>t.status==="unchanged"),"filterEntries");class Oe{static{E(this,"a")}static{I(this,"SortPackageJsonStore")}#e;#r=new Set;constructor(r){this.#e={entries:Pe(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=I(()=>this.#e,"getSnapshot");subscribe=I(r=>(this.#r.add(r),()=>{this.#r.delete(r)}),"subscribe");getFilteredEntries=I(()=>Ee(this.#e.entries,this.#e.filterType),"getFilteredEntries");#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const t=this.getFilteredEntries();this.#e.selectedIndex=t.length===0?-1:Math.max(0,Math.min(r,t.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}var je=Object.defineProperty,Ce=E((e,r)=>je(e,"name",{value:r,configurable:!0}),"c$2");const Re=Ce(({checkMode:e,entry:r,focused:t,scrollRef:l})=>r?f(a,{borderColor:t?"white":"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,children:[s(a,{flexShrink:0,paddingTop:1,paddingX:2,children:s(c,{bold:!0,color:"white",children:r.relativePath})}),f(ce,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[s(c,{}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?s(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?s(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?s(c,{bold:!0,color:"yellow",children:"rewritten"}):s(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Path:"})}),s(c,{children:r.filePath})]}),r.error?f(ve,{children:[f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"red",children:"ERROR"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Step:"})}),s(c,{color:"yellow",children:r.error.step})]}),r.error.context&&f(a,{children:[s(a,{width:10,children:s(c,{dimColor:!0,children:"Position:"})}),s(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),s(a,{marginTop:1,children:s(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"SNIPPET"}),f(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const i=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return f(a,{children:[s(c,{color:n.isErrorLine?"red":"gray",children:i}),s(c,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&s(a,{children:s(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):f(a,{flexDirection:"column",marginTop:1,children:[s(c,{dimColor:!0,children:"── "}),s(c,{bold:!0,color:"white",children:"KEY DIFF"}),s(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?s(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(n=>{const i=n.toIndex-n.fromIndex,d=i<0?`↑ ${String(Math.abs(i))}`:`↓ ${String(i)}`,g=i<0?"green":"yellow";return f(a,{children:[s(a,{width:28,children:s(c,{wrap:"truncate",children:n.key})}),s(a,{width:10,children:f(c,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),s(c,{color:g,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&s(a,{marginTop:1,paddingLeft:2,children:s(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):s(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:s(c,{dimColor:!0,children:"No entry selected"})}),"SortDetailPanel");var Ie=Object.defineProperty,O=E((e,r)=>Ie(e,"name",{value:r,configurable:!0}),"i");const Te={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},Me={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},U={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},Fe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},De=[{count:O(e=>e.errors+e.rewrites+e.sorted,"count"),key:"all",label:"All",shortcut:"1"},{count:O(e=>e.rewrites,"count"),key:"rewritten",label:"Rewrites",shortcut:"2"},{count:O(e=>e.errors,"count"),key:"errors",label:"Errors",shortcut:"3"},{count:O(e=>e.sorted,"count"),key:"unchanged",label:"Sorted",shortcut:"4"}],Z=O(e=>{const r={errors:0,rewrites:0,sorted:0};for(const t of e)r[U[t.status]]++;return r},"computeGroupCounts"),Ne=O(({entry:e,isSelected:r})=>{const t=Te[e.status],l=Me[e.status];return f(a,{flexShrink:0,height:1,children:[s(c,{children:r?">":" "}),s(c,{children:" "}),s(c,{bold:!0,color:t,children:`[${l}]`.padEnd(10)}),s(c,{children:" "}),s(a,{flexGrow:1,children:s(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&s(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},"EntryRow"),Ae=O(({color:e,count:r,label:t})=>s(a,{flexShrink:0,height:1,children:s(c,{bold:!0,color:e,children:`${t} (${String(r)})`})}),"SectionHeader"),Be=O(({counts:e,entries:r,filterType:t,focused:l,selectedIndex:o,totalEntries:n,viewportHeight:i})=>{const d=l?"white":"gray",g=Z(r),b=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),w=t==="all"&&b>1,p=[];let m;for(const[u,y]of r.entries()){const S=U[y.status];w&&S!==m&&(m!==void 0&&p.push({kind:"spacer"}),p.push({color:S==="errors"?"red":S==="rewrites"?"yellow":"green",count:g[S],kind:"header",label:Fe[S]}),m=S),p.push({entry:y,entryIndex:u,kind:"entry"})}const v=p.findIndex(u=>u.kind==="entry"&&u.entryIndex===o),$=v!==-1,P=p.length,h=Math.max(0,P-i);let C=0;$&&i>0&&(C=Math.min(h,Math.max(0,v-i+1)));const R=P>i&&i>0;return f(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[f(a,{flexShrink:0,gap:1,paddingX:1,children:[s(c,{bold:!0,inverse:!0,children:" VIS SORT "}),f(c,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),s(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:De.map(u=>{const y=t===u.key,S=u.count(e);return f(a,{children:[s(c,{dimColor:!y,children:"["}),s(c,{bold:y,color:y?"cyan":"gray",children:u.shortcut}),s(c,{dimColor:!y,children:"]"}),f(c,{color:y?"white":"gray",children:[" ",u.label]}),f(c,{dimColor:!0,children:[" ","(",S,")"]})]},u.key)})}),f(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[s(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:s(a,{flexDirection:"column",marginTop:-C,children:p.map((u,y)=>u.kind==="spacer"?s(a,{flexShrink:0,height:1},`s-${String(y)}`):u.kind==="header"?s(Ae,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):s(Ne,{entry:u.entry,isSelected:u.entryIndex===o},u.entry.filePath))})}),R&&s(a,{flexShrink:0,marginLeft:1,marginRight:1,children:s(ae,{contentHeight:P,placement:"inset",scrollOffset:C,style:"block",viewportHeight:i})})]})]})},"SortListPanel");var Le=Object.defineProperty,Ge=E((e,r)=>Le(e,"name",{value:r,configurable:!0}),"T");const Je=100,H=10,_e=6,qe=1,z={1:"all",2:"rewritten",3:"errors",4:"unchanged"},He=Ge(({checkMode:e,store:r})=>{const{exit:t}=de(),{columns:l,rows:o}=ue(),n=Se(r.subscribe,r.getSnapshot),i=F(null),d=r.getFilteredEntries(),g=d[n.selectedIndex]??null,b=Z(n.entries),w=l>=Je,p=Math.max(0,o-qe),m=w?p:Math.floor(p/2),v=Math.max(0,m-_e),$=_(()=>{t()},[t]),P=F(0),h=F(void 0),C=F(!1),R=_((u,y)=>{P.current+=y,h.current=u,!C.current&&(C.current=!0,queueMicrotask(()=>{C.current=!1;const S=P.current,L=h.current;P.current=0,h.current=void 0,!(S===0||L===void 0)&&(L==="list"?r.selectStep(Math.sign(S)):i.current?.scrollBy(Math.sign(S)))}))},[r]);return fe((u,y)=>{if(u==="q"||y.escape){$();return}if(z[u]){r.setFilter(z[u]);return}if(y.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?y.upArrow||u==="k"?R("list",-1):(y.downArrow||u==="j")&&R("list",1):n.focusedPanel==="detail"&&(y.upArrow||u==="k"?R("detail",-1):(y.downArrow||u==="j")&&R("detail",1))}),o<H?s(a,{alignItems:"center",justifyContent:"center",children:f(c,{color:"yellow",children:["Terminal too small. Resize to at least",H," ","rows."]})}):f(a,{flexDirection:"column",height:o,width:l,children:[f(a,{flexDirection:w?"row":"column",flexGrow:1,children:[s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Be,{counts:b,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:v})}),s(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:s(Re,{checkMode:e,entry:g,focused:n.focusedPanel==="detail",scrollRef:i})})]}),s(a,{flexShrink:0,paddingX:1,children:s(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},"VisSortPackageJsonApp");var ze=Object.defineProperty,j=E((e,r)=>ze(e,"name",{value:r,configurable:!0}),"c$1");const W=["types","node-addons","node","import","require","default"],We=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Xe=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,N=j(e=>typeof e=="object"&&e!==null&&!Array.isArray(e),"isPlainObject"),B=j(e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(t=>B(t));const r={};for(const[t,l]of Object.entries(e))r[t]=B(l);return r},"cloneDeep"),Ke=j(e=>{if(!N(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},"tryFormatBugs"),Qe=j(e=>e.endsWith(".git")?e.slice(0,-4):e,"stripGitSuffix"),Ve=j(e=>{if(!N(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:t}=e;if(typeof t!="string")return{changed:!1,value:e};const l=We.exec(t)??Xe.exec(t);if(!l)return{changed:!1,value:e};const o=l[1],n=Qe(l[2]??"");if(!o||!n)return{changed:!1,value:e};const i=new Set(["type","url"]);for(const d of Object.keys(e))if(!i.has(d))return{changed:!1,value:e};return{changed:!0,value:`${o}/${n}`}},"tryFormatRepository"),Ye=j(e=>{const r=Object.keys(e),t=[],l=[];for(const i of W)Object.hasOwn(e,i)&&t.push(i);for(const i of r)W.includes(i)||l.push(i);const o=[...t,...l];if(o.length===r.length&&o.every((i,d)=>i===r[d]))return{changed:!1,value:e};const n={};for(const i of o)n[i]=e[i];return{changed:!0,value:n}},"orderConditions"),ee=j(e=>{if(!N(e))return{changed:!1,value:e};let r=!1;const t={};for(const[o,n]of Object.entries(e)){const i=ee(n);t[o]=i.value,i.changed&&(r=!0)}const l=Ye(t);return{changed:r||l.changed,value:l.value}},"sortExportsRecursive"),Ue=j((e,r)=>{const t=B(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(t,"bugs")){const o=Ke(t.bugs);o.changed&&(t.bugs=o.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(t,"repository")){const o=Ve(t.repository);o.changed&&(t.repository=o.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(t,"exports")&&N(t.exports)){const o=ee(t.exports);o.changed&&(t.exports=o.value,l=!0)}return{changed:l,pkg:t}},"formatPackageJsonFields");var Ze=Object.defineProperty,x=E((e,r)=>Ze(e,"name",{value:r,configurable:!0}),"c");const er=/at position (\d+)/,rr=/\(?line (\d+) column (\d+)\)?/,tr=x(e=>{const r=new Set,t=[],l=x(n=>{const i=se(n);!r.has(i)&&G(i)&&(r.add(i),t.push(i))},"addFile");l(M(e,"package.json"));const o=ge(e);if(o){const n=J(e,o);for(const i of n)l(M(e,i,"package.json"))}else{const n=M(e,"package.json");if(G(n)){const i=JSON.parse(Q(n)),d=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;if(d){const g=J(e,d);for(const b of g)l(M(e,b,"package.json"))}}}return t},"findPackageJsonFiles"),or=x(e=>/\n([ \t]+)/.exec(e)?.[1]??" ","detectIndent"),nr=x(e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},"resolveIndentOverride"),A=x(e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),"splitList"),ir=x(e=>e.includes(`\r
|
|
2
|
+
`)?"crlf":"lf","detectLineEnding"),sr=new Set(["auto","crlf","lf"]),lr=x(e=>{if(e===void 0||e==="")return"auto";if(sr.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},"validateLineEnding"),cr=x((e,r,t)=>r.length===0?e:e.filter(l=>{const o=V(t,l),n=le(l);return!r.some(i=>{const d=i.includes("/")?o:n;return ke(i,d)})}),"filterByIgnore"),ar=x((e,r)=>{if(r.length===0)return e;const t={},l=new Set;for(const o of r)Object.hasOwn(e,o)&&(t[o]=e[o],l.add(o));for(const o of Object.keys(e))l.has(o)||(t[o]=e[o]);return t},"applySortOrder"),dr=x((e,r,t)=>{if(t.length===0)return e;const l={...e};for(const o of t)Object.hasOwn(r,o)&&(l[o]=r[o]);return l},"restoreUnsortedSections"),ur=x((e,r)=>{let t=1,l=1;const o=Math.min(r,e.length);for(let n=0;n<o;n++)e.codePointAt(n)===10?(t++,l=1):l++;return{column:l,line:t}},"computeLineColumn"),X=x((e,r,t=2)=>{const l=e.split(`
|
|
3
|
+
`);if(r<1||r>l.length)return[];const o=Math.max(0,r-1-t),n=Math.min(l.length,r+t),i=[];for(let d=o;d<n;d++)i.push({content:l[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return i},"buildSnippet"),K=x((e,r)=>{if(!(e instanceof Error))return;const t=er.exec(e.message);if(t){const{column:o,line:n}=ur(r,Number.parseInt(t[1]??"0",10));return{column:o,line:n,snippet:X(r,n)}}const l=rr.exec(e.message);if(l){const o=Number.parseInt(l[1]??"1",10);return{column:Number.parseInt(l[2]??"1",10),line:o,snippet:X(r,o)}}},"extractParseErrorContext"),fr=x((e,r)=>{const t=Object.keys(JSON.parse(e)),l=Object.keys(JSON.parse(r)),o=new Map(t.map((i,d)=>[i,d])),n=[];for(const[i,d]of l.entries()){const g=o.get(d);g!==void 0&&g!==i&&n.push({fromIndex:g,key:d,toIndex:i})}return n},"computeKeyDiff"),hr=x((e,r,t)=>{const l=r.indent??t.indent??or(e),o=r.lineEnding==="auto"?t.lineEnding??ir(e):r.lineEnding,n=Y(e,{pretty:!1,sortScripts:r.sortScripts});let i=JSON.parse(n);if(r.unsorted.length>0){const w=JSON.parse(e);i=dr(i,w,r.unsorted)}i=ar(i,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},g=Ue(i,d);let b=JSON.stringify(g.pkg,null,l);return r.finalNewline&&(b+=`
|
|
4
|
+
`),o==="crlf"&&(b=b.replaceAll(`
|
|
5
|
+
`,`\r
|
|
6
|
+
`)),b},"sortContents"),gr=x((e,r)=>{const t=tr(e),l=pe(e),o=me({cwd:e,extraPatterns:we(l)}),n=t.filter(d=>!o.ignores(d)),i=cr(n,r,e);return{afterGitignore:n,allFiles:t,files:i}},"discoverPackageJsonFiles"),pr=x((e,{checkMode:r,cwd:t,normalized:l})=>{const o=V(t,e)||e;let n;try{n=Q(e)}catch(w){return{diff:[],error:{message:D(w),step:"read"},filePath:e,relativePath:o,status:"error"}}let i;try{i=Y(n,{pretty:!1,sortScripts:l.sortScripts})}catch(w){const p={message:D(w),step:"native-sort"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}const d=l.editorconfig?ye(e):{};let g;try{g=hr(n,l,d)}catch(w){const p={message:D(w),step:"json-parse"},m=K(w,n);return m&&(p.context=m),{diff:[],error:p,filePath:e,relativePath:o,status:"error"}}if(n===g)return{diff:[],filePath:e,relativePath:o,status:"unchanged"};let b;try{b=fr(n,i)}catch{b=[]}if(r)return{diff:b,filePath:e,relativePath:o,status:"would-rewrite"};try{ie(e,g,"utf8")}catch(w){return{diff:b,error:{message:D(w),step:"write"},filePath:e,relativePath:o,status:"error"}}return{diff:b,filePath:e,relativePath:o,status:"rewritten"}},"processFile"),mr=x(e=>{if(e.error&&(k.error(`${e.filePath}: ${e.error.message}`),k.info(` step: ${e.error.step}`),e.error.context)){k.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const t=r.isErrorLine?">":" ";k.info(` ${t} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},"printStaticError"),jr=x(async({options:e,visConfig:r,workspaceRoot:t})=>{const l=t??process.cwd(),o=r?.sortPackageJson,n=e.check||!1,i={editorconfig:e.editorconfig===!1?!1:o?.editorconfig??!0,finalNewline:e.finalNewline??o?.finalNewline??!0,formatBugs:e.formatBugs===!1?!1:o?.formatBugs??!0,formatRepository:e.formatRepository===!1?!1:o?.formatRepository??!0,ignore:[...A(e.ignore),...o?.ignore??[]],indent:nr(e.indent??o?.indent),lineEnding:lr(e.lineEnding??o?.lineEnding),sortExports:e.sortExports===!1?!1:o?.sortExports??!0,sortOrder:[...A(e.sortOrder),...o?.sortOrder??[]],sortScripts:e.sortScripts||o?.sortScripts||!1,unsorted:[...A(e.unsorted),...o?.unsorted??[]]},d=gr(l,i.ignore),{afterGitignore:g,allFiles:b,files:w}=d;if(w.length===0){b.length===0?k.info("No package.json files found."):g.length===0?k.info("All package.json files were excluded by .gitignore or workspace exclusions."):k.info("All package.json files were excluded by --ignore.");return}const p=[];for(const h of w)p.push(pr(h,{checkMode:n,cwd:l,normalized:i}));let m=0,v=0,$=0;for(const h of p)h.status==="error"?$++:h.status==="rewritten"||h.status==="would-rewrite"?m++:v++;const P=m>0||$>0;if(process.stdout.isTTY&&!xe&&P){const h=new Oe(p);await he(be.createElement(He,{checkMode:n,store:h}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const h of p)switch(h.status){case"error":{mr(h);break}case"rewritten":{k.success(`Sorted ${h.filePath}`);break}case"would-rewrite":{k.warn(`${h.filePath} is not sorted`);break}}if(n)m>0?(k.info(`${String(m)} file${m===1?"":"s"} not sorted, ${String(v)} already sorted`),process.exitCode=1):$===0&&k.info(`All ${String(v)} package.json file${v===1?" is":"s are"} sorted`);else{const h=[];m>0&&h.push(`sorted ${String(m)} file${m===1?"":"s"}`),v>0&&h.push(`${String(v)} already sorted`),$>0&&h.push(`${String($)} error${$===1?"":"s"}`),h.length>0&&k.info(h.join(", "))}$>0&&(process.exitCode=1)},"execute");export{X as buildSnippet,fr as computeKeyDiff,ur as computeLineColumn,jr as default,gr as discoverPackageJsonFiles,K as extractParseErrorContext,pr as processFile};
|