@visulima/vis 1.0.0-alpha.10 → 1.0.0-alpha.12
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 +185 -42
- package/LICENSE.md +586 -0
- package/README.md +26 -4
- package/dist/config/index.d.ts +1739 -0
- package/dist/config/index.js +1 -0
- package/dist/generate/index.d.ts +1 -1
- package/dist/packem_chunks/applyDefaults.js +2 -0
- package/dist/packem_chunks/bin.js +232 -60
- package/dist/packem_chunks/doctor-probe.js +2 -0
- package/dist/packem_chunks/fix.js +11 -53
- package/dist/packem_chunks/handler.js +1 -1
- package/dist/packem_chunks/handler10.js +2 -1
- package/dist/packem_chunks/handler11.js +1 -1
- package/dist/packem_chunks/handler12.js +5 -2
- package/dist/packem_chunks/handler13.js +1 -1
- package/dist/packem_chunks/handler14.js +18 -5
- package/dist/packem_chunks/handler15.js +20 -1
- package/dist/packem_chunks/handler16.js +1 -20
- package/dist/packem_chunks/handler17.js +1 -1
- package/dist/packem_chunks/handler18.js +1 -1
- package/dist/packem_chunks/handler19.js +1 -1
- package/dist/packem_chunks/handler2.js +2 -1
- package/dist/packem_chunks/handler20.js +5 -1
- package/dist/packem_chunks/handler21.js +1 -1
- package/dist/packem_chunks/handler22.js +1 -5
- package/dist/packem_chunks/handler23.js +5 -1
- package/dist/packem_chunks/handler24.js +1 -1
- package/dist/packem_chunks/handler25.js +3 -5
- package/dist/packem_chunks/handler26.js +1 -1
- package/dist/packem_chunks/handler27.js +1 -3
- package/dist/packem_chunks/handler28.js +7 -1
- package/dist/packem_chunks/handler29.js +22 -6
- package/dist/packem_chunks/handler3.js +4 -2
- package/dist/packem_chunks/handler30.js +3 -23
- package/dist/packem_chunks/handler31.js +1 -3
- package/dist/packem_chunks/handler32.js +2 -2
- package/dist/packem_chunks/handler33.js +24 -23
- package/dist/packem_chunks/handler34.js +2 -2
- package/dist/packem_chunks/handler35.js +3 -19
- package/dist/packem_chunks/handler36.js +22 -428
- package/dist/packem_chunks/handler37.js +428 -22
- package/dist/packem_chunks/handler38.js +20 -20
- package/dist/packem_chunks/handler39.js +21 -21
- package/dist/packem_chunks/handler4.js +2 -4
- package/dist/packem_chunks/handler40.js +22 -3
- package/dist/packem_chunks/handler41.js +6 -10
- package/dist/packem_chunks/handler42.js +5 -153
- package/dist/packem_chunks/handler43.js +10 -42
- package/dist/packem_chunks/handler44.js +153 -3
- package/dist/packem_chunks/handler45.js +25 -27
- package/dist/packem_chunks/handler46.js +3 -0
- package/dist/packem_chunks/handler47.js +27 -0
- package/dist/packem_chunks/handler48.js +42 -0
- package/dist/packem_chunks/handler5.js +8 -2
- package/dist/packem_chunks/handler6.js +1 -13
- package/dist/packem_chunks/handler7.js +1 -8
- package/dist/packem_chunks/handler8.js +1 -1
- package/dist/packem_chunks/handler9.js +1 -1
- package/dist/packem_chunks/heal-accept.js +10 -0
- package/dist/packem_chunks/heal.js +14 -0
- package/dist/packem_chunks/index.js +3 -3
- package/dist/packem_chunks/tar.js +3 -0
- package/dist/packem_shared/ai-analysis-hm8d2W7z.js +67 -0
- package/dist/packem_shared/{ai-cache-Bynt6Y9x.js → ai-cache-DoiF80AR.js} +1 -1
- package/dist/packem_shared/ai-fix-nn4zOE95.js +43 -0
- package/dist/packem_shared/cache-directory-CwHlJhgx.js +1 -0
- package/dist/packem_shared/dependency-scan-COr5n63B.js +2 -0
- package/dist/packem_shared/{docker-BcfqH4Av.js → docker-D6OGr5_S.js} +1 -1
- package/dist/packem_shared/{failure-log-DqYen0LC.js → failure-log-iUVLf6ts.js} +1 -1
- package/dist/packem_shared/flakiness-D9wf0t56.js +1 -0
- package/dist/packem_shared/giget-CcEy_Elm.js +2 -0
- package/dist/packem_shared/index-DH-5hsrC.js +1 -0
- package/dist/packem_shared/otel-DxDUPJJH.js +6 -0
- package/dist/packem_shared/otelPlugin-CQq6poq8.js +1 -0
- package/dist/packem_shared/registry-CkubDdiY.js +2 -0
- package/dist/packem_shared/run-summary-utils-BfBvjzhY.js +1 -0
- package/dist/packem_shared/{runtime-check-CGHal8SO.js → runtime-check-BXZ43CBW.js} +1 -1
- package/dist/packem_shared/{selectors-CfH9ZY08.js → selectors-BylODRiM.js} +1 -1
- package/dist/packem_shared/toolchain-BgBOUHII.js +5 -0
- package/dist/packem_shared/typosquats-CcZl99B1.js +1 -0
- package/dist/packem_shared/verify-Baj5mFJ7.js +1 -0
- package/dist/packem_shared/vis-update-app-D1jl0UZZ.js +1 -0
- package/index.js +54 -53
- package/package.json +34 -26
- package/schemas/project.schema.json +739 -299
- package/schemas/vis-config.schema.json +3383 -278
- package/skills/vis/SKILL.md +96 -0
- package/templates/buildkite-ci/.buildkite/pipeline.yml.tera +85 -0
- package/templates/buildkite-ci/template.yml +20 -0
- package/dist/errors/index.d.ts +0 -26
- package/dist/errors/index.js +0 -1
- package/dist/packem_chunks/config.js +0 -2
- package/dist/packem_shared/VisConfigCycleError-CAYNC7d-.js +0 -1
- package/dist/packem_shared/VisConfigError-B5LP1zRf.js +0 -1
- package/dist/packem_shared/VisConfigLoadError-CeqBSd2Z.js +0 -2
- package/dist/packem_shared/VisConfigNotFoundError-DZ9KC527.js +0 -5
- package/dist/packem_shared/VisUpdateApp-D-L4_-Iu.js +0 -1
- package/dist/packem_shared/_commonjsHelpers-D6W6KoPK.js +0 -1
- package/dist/packem_shared/ai-analysis-CGuy7dfE.js +0 -67
- package/dist/packem_shared/cache-directory-D72ZEag2.js +0 -1
- package/dist/packem_shared/catalog-BVPerCwG.js +0 -12
- package/dist/packem_shared/dependency-scan-Du0tBu64.js +0 -2
- package/dist/packem_shared/flakiness-DSIHZGBT.js +0 -1
- package/dist/packem_shared/run-summary-utils-C24Aaf9E.js +0 -1
- package/dist/packem_shared/target-merge-DNa-6eWu.js +0 -1
- package/dist/packem_shared/toolchain-DQfTQY8E.js +0 -5
- package/dist/packem_shared/typosquats-DOR8izpX.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
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,ai as z,k as q,aj as B}from"./bin.js";import{join as W}from"@visulima/path";import{R as H,w as F,r as R,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-CkubDdiY.js";import{formatAge as te}from"./handler14.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:x,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 b=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(b?"cmd":"/bin/sh",b?["/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,S=h((e,t)=>ie(e,"name",{value:t,configurable:!0}),"t");const _=5e3,D=S(async e=>F(e.workspaceRoot,e.id,async()=>{const t=await R(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=S(async e=>F(e.workspaceRoot,e.id,async()=>{const t=await R(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=S(async(e,t)=>{M(e,"SIGTERM");const r=Date.now();for(;Date.now()-r<t;){if(!m(e))return;await new Promise(n=>{setTimeout(n,100)})}m(e)&&M(e,"SIGKILL")},"stopServiceByPid"),M=S((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 f=ce(e,i.root,c.options?.runFromWorkspaceRoot===!0),w=c.options?.envFile?B(f,c.options.envFile):{};return{command:c.command,cwd:f,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.noReadiness===!0,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"),Re=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"]),Se=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(u=>{const k=Date.parse(u.startedAt);return{ageMs:Number.isFinite(k)?p-k:null,alive:m(u.pid),command:u.command,cwd:u.cwd,env:u.env,id:u.id,logFile:u.logFile,pid:u.pid,port:u.config.readiness?.tcp.port??u.config.port??null,startedAt:u.startedAt,visVersion:u.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 u=Date.parse(p.startedAt);return{age:Number.isFinite(u)?te(u,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)),f=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(f)} ${"age".padEnd(w)} log`),e.info(` ${"-".repeat(c)} ${"-".repeat(g)} ${"-".repeat(f)} ${"-".repeat(w)} ---`);for(const p of i)e.info(` ${p.id.padEnd(c)} ${p.pid.padEnd(g)} ${p.port.padEnd(f)} ${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 R(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"),ke=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.noReadiness===!0,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 x(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 x(e).catch(()=>{});if(!c||(c.size<t&&(t=0),c.size===t))return;const g=c.size-t,f=Math.min(g,ge),w=await E(e,"r");try{const p=Buffer.alloc(f);await w.read(p,0,f,t),process.stdout.write(p),t+=f}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 f=setTimeout(g,pe);r.signal.addEventListener("abort",()=>{clearTimeout(f),g()},{once:!0})});await c.catch(()=>{}),await i().catch(()=>{})}finally{process.off("SIGINT",a),process.off("SIGTERM",o)}n&&(process.exitCode=130)},"tailLog"),xe=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 R(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{Se as serviceListExecute,xe as serviceLogsExecute,ke as serviceRestartExecute,$e as serviceStartExecute,Ee as serviceStatusExecute,Re as serviceStopExecute};
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
var
|
|
2
|
-
`);for(const[
|
|
3
|
-
`)}for(
|
|
4
|
-
${l(`Enter choice (1-${String(r.length)}):`)} `);if(o===""&&s!==void 0)return s;const a=Number.parseInt(o,10);if(Number.isInteger(a)&&a>=1&&a<=r.length)return r[a-1];const n=r.find(i=>i===o);if(n)return n;process.stderr.write(` ${l("Invalid choice. Try again.")}
|
|
5
|
-
`)}},"selectOne"),Ne=g(async(t,e,r,s)=>{process.stderr.write(` ${e} ${l("(comma-separated numbers)")}
|
|
6
|
-
`);for(const[o,a]of r.entries()){const n=b(S(` ${String(o+1)}.`)),i=s.includes(a)?l(" (default)"):"";process.stderr.write(`${n} ${a}${i}
|
|
7
|
-
`)}for(;;){const o=await W(t,`
|
|
8
|
-
${l("Enter choices:")} `);if(o===""&&s.length>0)return s;const a=o.split(",").map(n=>Number.parseInt(n.trim(),10)).filter(n=>Number.isInteger(n)&&n>=1&&n<=r.length);if(a.length>0)return a.map(n=>r[n-1]);process.stderr.write(` ${l("Invalid choice. Try again.")}
|
|
9
|
-
`)}},"selectMany"),je=g(t=>` ${l(`${t}:`)} `,"promptText"),xe=g((t,e)=>e.prompt??t,"variableLabel"),_e=g(t=>Object.entries(t).sort(([e,r],[s,o])=>{const a=r.order??0,n=o.order??0;return a!==n?a-n:e.localeCompare(s)}),"sortVariables"),Y=g((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=g((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"),Pe=g(async t=>{const{defaults:e,interactive:r,overrides:s,variables:o}=t,a={},n=r?ue({input:process.stdin,output:process.stderr}):null;try{for(const[i,c]of _e(o)){if(Object.hasOwn(s,i)){const h=Y(c,s[i]??"");F(i,c,h),a[i]=h;continue}if(e||!r||c.internal){if(c.default!==void 0){F(i,c,c.default),a[i]=c.default;continue}if(c.required)throw new Error(`Required variable "${i}" not provided. Pass --${i}=<value> or remove --defaults.`);continue}const m=xe(i,c);let p;if(c.type==="boolean")p=await Re(n,m,!!(c.default??!1));else if(c.type==="enum")if(c.multiple){const h=Array.isArray(c.default)?c.default:[];p=await Ne(n,m,c.values,h)}else{const h=typeof c.default=="string"?c.default:void 0;p=await Ee(n,m,c.values,h)}else{const h=c.default===void 0?"":` (${String(c.default)})`,$=await W(n,je(`${m}${h}`));if($===""&&c.default!==void 0)p=c.default;else if($===""){if(c.required)throw new Error(`Variable "${i}" is required`);continue}else p=Y(c,$)}F(i,c,p),a[i]=p}return a}finally{n?.close()}},"collectOptions");var De=Object.defineProperty,L=v((t,e)=>De(t,"name",{value:e,configurable:!0}),"o");const Ie=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],We=L(t=>Ie.some(e=>t.startsWith(e)),"isRemoteSource"),Be=L(async(t,e={})=>{const r=e.targetDirectory===void 0,s=e.targetDirectory??de(k(he(),"vis-generate-")),o=L(()=>{if(r)try{me(s,{force:!0,recursive:!0})}catch{}},"cleanup");f.info(`Downloading ${t}…`);try{const a=await ge(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:a.dir}}catch(a){o();const n=a instanceof Error?a.message:String(a);throw f.warn(`Failed to download template: ${n}`),a}},"fetchRemoteTemplate");var Ae=Object.defineProperty,T=v((t,e)=>Ae(t,"name",{value:e,configurable:!0}),"a");const ee=T((t,e="")=>{const r=[];for(const[s,o]of Object.entries(t)){const a=e?`${e}/${s}`:s;typeof o=="string"||Buffer.isBuffer(o)?r.push({content:o,path:a}):o&&typeof o=="object"&&r.push(...ee(o,a))}return r},"flattenTree"),Me=T(t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,"formatSize"),qe=T((t,e)=>{if(C(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=k(t,e),s=z(t,r);if(s===".."||s.startsWith(`..${ce}`)||C(s))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},"safeJoinDestination"),Fe=T((t,e)=>{Q(le(t)),pe(t,e)},"writeOne"),Ce=T((t,e,r=!1)=>{const s=typeof t=="string"?[t]:t.commands,o=typeof t=="string"?r:t.silent??r;for(const a of s){o||f.info(`$ ${a}`);const n=we(a,{cwd:e,shell:!0,stdio:o?"ignore":"inherit"});if(n.status!==0)return f.warn(`Script failed (exit ${String(n.status)}): ${a}`),!1}return!0},"runScript"),Le=T(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"),Ve=T(async(t,e)=>{const r={builtins:{dest_dir:e.destination,dest_rel_dir:z(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(r),o=s.files?ee(s.files):[],a=s.filesMeta??{},n=[];for(const i of o){const c=qe(e.destination,i.path);n.push({file:i,meta:a[i.path]??{},target:c})}if(e.dryRun){f.info(`${b(S("Plan"))} ${l("(dry-run, no files written)")}`);for(const i of n){const c=Buffer.isBuffer(i.file.content)?i.file.content.length:Buffer.byteLength(i.file.content,"utf8");process.stderr.write(` ${l("write")} ${i.file.path} ${l(`(${Me(c)})`)}
|
|
10
|
-
`)}}else{Q(e.destination);let i=0,c=0;for(const m of n){const{file:p,meta:h,target:$}=m,B=D($),y=e.force||h.force===!0;if(B&&!y){f.warn(`Skipped existing file: ${p.path} (use --force or set frontmatter force: true to overwrite)`),c+=1;continue}Fe($,p.content),i+=1}f.success(`Wrote ${String(i)} file${i===1?"":"s"}${c>0?`, skipped ${String(c)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const i=Le(s.scripts);f.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(i.length)} phase${i.length===1?"":"s"}…`);for(const[,c]of i)if((await Promise.all(c.map(m=>Promise.resolve(Ce(m,e.destination))))).includes(!1))throw new Error("Script failed — aborting.")}if(s.suggestions&&s.suggestions.length>0){process.stderr.write(`
|
|
11
|
-
`),f.notice("Next steps:");for(const i of s.suggestions)process.stderr.write(` ${l("•")} ${i}
|
|
12
|
-
`)}},"runTemplate");var Ge=Object.defineProperty,R=v((t,e)=>Ge(t,"name",{value:e,configurable:!0}),"p");const He=R(t=>{if(t.length===0){f.info("No templates found."),f.notice("Create one at .vis/templates/<name>.ts (programmatic) or .vis/templates/<name>/ (moon-format with template.yml).");return}f.info("Available templates:");for(const e of t){const r=l(`(${e.source})`);process.stderr.write(` ${b(S(e.name))} ${r}
|
|
13
|
-
`)}},"printList"),Ke=R(t=>{const e={},r=[];for(const s of t){if(!s.startsWith("--")){r.push(s);continue}const o=s.indexOf("=");if(o===-1){const i=s.slice(2);i.startsWith("no-")?e[i.slice(3)]="false":e[i]="true";continue}const a=s.slice(2,o),n=s.slice(o+1);e[a]=n}return{overrides:e,remaining:r}},"parsePassthroughOverrides"),Ue=R(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"))} ${l("— pick a template")}
|
|
14
|
-
|
|
15
|
-
`);for(const[s,o]of t.entries()){const a=b(S(` ${String(s+1)}.`));process.stderr.write(`${a} ${o.name} ${l(`(${o.source})`)}
|
|
16
|
-
`)}return new Promise((s,o)=>{r.question(`
|
|
17
|
-
${l(`Enter choice (1-${String(t.length)}):`)} `,a=>{const n=Number.parseInt(a.trim(),10);Number.isInteger(n)&&n>=1&&n<=t.length?s(t[n-1].name):o(new Error("Invalid choice."))})})}finally{r.close()}},"pickInteractive"),tt=R(async({argument:t,options:e,rawUnknown:r,visConfig:s,workspaceRoot:o})=>{const a=e.cwd||o||process.cwd(),n=o??a,i=s?.generator,c=Array.isArray(t)?t:t?[t]:[];if(e.list){const d=q({extraDirectories:i?.templates??[],onWarning:R(u=>{f.warn(u)},"onWarning"),workspaceRoot:n});He(d);return}let m=[...r??[]];if(m.length===0){const d=process.argv.slice(2),u=d.indexOf("--");u!==-1&&(m=d.slice(u+1))}const p=c.indexOf("--"),h=p===-1?[]:c.slice(p+1),$=p===-1?c:c.slice(0,p),{overrides:B}=Ke([...h,...m]);let y,x,_;const E=$[0];let P;if(E&&We(E)){const d=await Be(E,{auth:i?.auth,preferOffline:!!e.preferOffline||i?.preferOffline});P=d.cleanup;try{const u=q({extraDirectories:[d.directory],workspaceRoot:n}).find(N=>N.path.startsWith(d.directory));if(!u)throw new Error(`Downloaded template at ${d.directory} contains no template.yml or *.ts entrypoint.`);y=await u.load(),x=u.name,_=y.destination}catch(u){throw P(),P=void 0,u}}else{const d=q({extraDirectories:i?.templates??[],onWarning:R(A=>{f.warn(A)},"onWarning"),workspaceRoot:n});if(d.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let u;if(E)u=E;else{if(e.noInteractive||!process.stdin.isTTY)throw new Error("No template specified. Pass a template name (see `vis generate --list`) or run interactively in a terminal.");u=await Ue(d)}const N=d.find(A=>A.name===u);if(!N)throw new Error(`Template "${u}" not found. Run 'vis generate --list' to see available templates.`);y=await N.load(),x=N.name,_=y.destination}const V=e.to,G=!!e.dryRun,te=!!e.force,H=!!e.defaults,re=!!e.skipScripts,se=!e.noInteractive&&!!process.stdin.isTTY&&!H;let O;V?O=V:_?O=_:O=".";const K=C(O)?O:fe(a,O);f.info(`Template: ${b(S(x))}`),f.info(`Target: ${l(K)}`),process.stderr.write(`
|
|
18
|
-
`);const oe=await Pe({defaults:H,interactive:se,overrides:B,variables:y.options??{}});try{await Ve(y,{cwd:a,destination:K,dryRun:G,force:te,options:oe,skipScripts:re,workspaceRoot:n}),G||(process.stderr.write(`
|
|
19
|
-
`),f.success(`Template '${x}' applied.`))}finally{P?.()}},"execute");export{tt as default};
|
|
1
|
+
var R=Object.defineProperty;var k=(e,o)=>R(e,"name",{value:o,configurable:!0});import{createRequire as A}from"node:module";import{writeFileSync as T,writeJsonSync as I}from"@visulima/fs";import{join as w,relative as L}from"@visulima/path";import{o as M}from"../packem_shared/index-DH-5hsrC.js";import{k as U,ak as O,al as W,z as B}from"./bin.js";const x=A(import.meta.url),y=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,D=k(e=>{if(typeof y<"u"&&y.versions&&y.versions.node){const[o,t]=y.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return y.getBuiltinModule(e)}return x(e)},"__cjs_getBuiltinModule"),{readFileSync:q}=D("node:fs");var K=Object.defineProperty,C=k((e,o)=>K(e,"name",{value:o,configurable:!0}),"i");const z=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:z(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 H=Object.defineProperty,u=k((e,o)=>H(e,"name",{value:o,configurable:!0}),"s");const Q=["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"),X=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"),Z=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=X(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=k((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:[...Q]},"parseFieldsOption"),re=m((e,o)=>o.some(t=>M(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=q(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}T(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=Z(a,h,{fields:c});P.length!==0&&p.push({filePath:l,packageJsonPath:L(n,l),packageName:$,pkg:h,pkgChanges:P})}if(!d)for(const s of p)ee(s.pkg,s.pkgChanges),I(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
|
+
`);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};
|