@visulima/vis 1.0.0-alpha.42 → 1.0.0-alpha.44
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 +54 -0
- package/LICENSE.md +256 -0
- package/bin/resolve-binary.mjs +85 -0
- package/bin/vis.mjs +76 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +1 -2
- package/dist/binx.js +1 -1
- package/dist/config/index.js +1 -1
- package/dist/packem_chunks/CONFIG_FILES.js +8 -0
- package/dist/packem_chunks/bloom-status.js +1 -1
- package/dist/packem_chunks/bloom-sync.js +1 -1
- package/dist/packem_chunks/catalog.js +113 -0
- package/dist/packem_chunks/cli-exec.js +1 -1
- package/dist/packem_chunks/cli-main.js +297 -434
- package/dist/packem_chunks/detect.js +3 -3
- package/dist/packem_chunks/dispatch.js +1 -1
- package/dist/packem_chunks/fix.js +1 -1
- package/dist/packem_chunks/handler.js +1 -1
- package/dist/packem_chunks/handler10.js +5 -1
- package/dist/packem_chunks/handler11.js +1 -5
- package/dist/packem_chunks/handler12.js +27 -1
- package/dist/packem_chunks/handler13.js +5 -27
- package/dist/packem_chunks/handler14.js +1 -5
- package/dist/packem_chunks/handler15.js +1 -1
- 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 +2 -5
- package/dist/packem_chunks/handler21.js +2 -2
- package/dist/packem_chunks/handler22.js +14 -2
- package/dist/packem_chunks/handler23.js +1 -5
- package/dist/packem_chunks/handler24.js +1 -1
- package/dist/packem_chunks/handler25.js +1 -1
- package/dist/packem_chunks/handler26.js +5 -1
- package/dist/packem_chunks/handler27.js +1 -5
- package/dist/packem_chunks/handler28.js +3 -1
- package/dist/packem_chunks/handler29.js +1 -3
- package/dist/packem_chunks/handler3.js +4 -1
- package/dist/packem_chunks/handler30.js +1 -1
- package/dist/packem_chunks/handler31.js +2 -1
- package/dist/packem_chunks/handler32.js +2 -2
- package/dist/packem_chunks/handler33.js +2 -2
- package/dist/packem_chunks/handler34.js +3 -2
- package/dist/packem_chunks/handler35.js +6 -3
- package/dist/packem_chunks/handler36.js +1 -6
- package/dist/packem_chunks/handler37.js +42 -1
- package/dist/packem_chunks/handler38.js +8 -42
- package/dist/packem_chunks/handler39.js +9 -8
- package/dist/packem_chunks/handler4.js +4 -4
- package/dist/packem_chunks/handler40.js +75 -9
- package/dist/packem_chunks/handler41.js +5 -75
- package/dist/packem_chunks/handler42.js +4 -5
- package/dist/packem_chunks/handler43.js +3 -4
- package/dist/packem_chunks/handler44.js +2 -3
- package/dist/packem_chunks/handler45.js +1 -2
- package/dist/packem_chunks/handler46.js +1 -1
- package/dist/packem_chunks/handler47.js +1 -1
- package/dist/packem_chunks/handler48.js +3 -1
- package/dist/packem_chunks/handler49.js +1 -3
- package/dist/packem_chunks/handler5.js +6 -4
- package/dist/packem_chunks/handler50.js +7 -1
- package/dist/packem_chunks/handler51.js +32 -6
- package/dist/packem_chunks/handler52.js +3 -33
- package/dist/packem_chunks/handler53.js +8 -3
- package/dist/packem_chunks/handler54.js +2 -6
- package/dist/packem_chunks/handler55.js +1 -4
- package/dist/packem_chunks/handler56.js +12 -1
- package/dist/packem_chunks/handler57.js +5 -12
- package/dist/packem_chunks/handler58.js +11 -5
- package/dist/packem_chunks/handler59.js +3 -11
- package/dist/packem_chunks/handler6.js +8 -6
- package/dist/packem_chunks/handler60.js +22 -3
- package/dist/packem_chunks/handler61.js +60 -21
- package/dist/packem_chunks/handler62.js +3 -61
- package/dist/packem_chunks/handler63.js +6 -3
- package/dist/packem_chunks/handler64.js +9 -6
- package/dist/packem_chunks/handler65.js +2 -9
- package/dist/packem_chunks/handler66.js +13 -13
- package/dist/packem_chunks/handler67.js +5 -5
- package/dist/packem_chunks/handler68.js +1 -1
- package/dist/packem_chunks/handler69.js +4 -4
- package/dist/packem_chunks/handler7.js +1 -8
- package/dist/packem_chunks/handler70.js +16 -17
- package/dist/packem_chunks/handler71.js +12 -12
- package/dist/packem_chunks/handler72.js +5 -5
- package/dist/packem_chunks/handler73.js +7 -7
- package/dist/packem_chunks/handler74.js +3 -3
- package/dist/packem_chunks/handler75.js +3 -3
- package/dist/packem_chunks/handler76.js +63 -63
- package/dist/packem_chunks/handler77.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 +1 -1
- package/dist/packem_chunks/heal.js +1 -1
- package/dist/packem_chunks/help-command.js +1 -1
- package/dist/packem_chunks/index2.js +2 -2
- package/dist/packem_chunks/keys-refresh.js +1 -1
- package/dist/packem_chunks/lean.js +3 -3
- package/dist/packem_chunks/list.js +1 -1
- package/dist/packem_chunks/loader.js +1 -1
- package/dist/packem_chunks/loader2.js +1 -1
- package/dist/packem_chunks/orchestrator.js +19 -19
- package/dist/packem_chunks/prune.js +1 -1
- package/dist/packem_chunks/run.js +1 -1
- package/dist/packem_chunks/status.js +1 -1
- package/dist/packem_chunks/sync.js +1 -1
- package/dist/packem_chunks/sync2.js +1 -1
- package/dist/packem_chunks/tripwire.js +1 -1
- package/dist/packem_chunks/ts-loader.js +22 -2
- package/dist/packem_chunks/verify-lockfile.js +1 -1
- package/dist/packem_chunks/version-resolver.js +1 -1
- package/dist/packem_shared/{advisories-aiDtubZQ.js → advisories-CefYKEPe.js} +1 -1
- package/dist/packem_shared/{affected-shas-C1XuRlvo.js → affected-shas-CwRY5aoc.js} +1 -1
- package/dist/packem_shared/{ai-analysis-CubpCxZJ.js → ai-analysis-CO6S0afy.js} +7 -7
- package/dist/packem_shared/{ai-fix-Btd5AnSr.js → ai-fix-CI0Vvqld.js} +9 -9
- package/dist/packem_shared/augment-DaSS2Lgs.js +4 -0
- package/dist/packem_shared/bin-P6Q5tKrP.js +1 -0
- package/dist/packem_shared/{build-scripts-Doxce2VM.js → build-scripts-MTSK6TNr.js} +1 -1
- package/dist/packem_shared/{command-runtime-RiCMa2C8.js → command-runtime-BE-vKsGH.js} +1 -1
- package/dist/packem_shared/{cyclonedx-NUJ9R2GQ.js → cyclonedx-BeUmPgfO.js} +1 -1
- package/dist/packem_shared/dependency-scan-DpOFiZuI.js +1 -0
- package/dist/packem_shared/{docker-DKlF-gk3.js → docker-CViFYtmM.js} +1 -1
- package/dist/packem_shared/env-C2ZCnfP_.js +27 -0
- package/dist/packem_shared/failure-log-jFfZRJK9.js +2 -0
- package/dist/packem_shared/glob-fqg4KepW-1S3z30c8.js +1 -0
- package/dist/packem_shared/index-B0EsgdzO.js +1 -0
- package/dist/packem_shared/index-CE6MsgcV.js +22 -0
- package/dist/packem_shared/index-CQjzW7m8.js +1 -0
- package/dist/packem_shared/{index-Cb4x6lWY.js → index-Cg0IHaFI.js} +1 -1
- package/dist/packem_shared/{index-CPhv-r4c.js → index-D7EZ612R.js} +13 -13
- package/dist/packem_shared/{lifecycle-D5roTh0a.js → lifecycle-Dyb47wbD.js} +1 -1
- package/dist/packem_shared/{lockfile-DIGyLfmF.js → lockfile-C1qCKGH6.js} +1 -1
- package/dist/packem_shared/{manifests-pLwnVmCN.js → manifests-WBnsV_Eb.js} +1 -1
- package/dist/packem_shared/{min-release-age-pUAqTiv3.js → min-release-age-C71MO72F.js} +1 -1
- package/dist/packem_shared/missing-package-json-CTF71tE5.js +1 -0
- package/dist/packem_shared/{native-config-sync-4K9wWTj5.js → native-config-sync-BFDVK9LH.js} +4 -4
- package/dist/packem_shared/{osv-bloom-OuTfu_LE.js → osv-bloom-BsQ-aFiM.js} +1 -1
- package/dist/packem_shared/packument-DquNPIq9.js +1 -0
- package/dist/packem_shared/{pm-runner-Dws_Bw1y.js → pm-runner-D4jM58Oz.js} +1 -1
- package/dist/packem_shared/prompt-DjXHVgYU.js +1 -0
- package/dist/packem_shared/provenance-DIq8KyBV.js +1 -0
- package/dist/packem_shared/readJsonSync-CvkZyKmL-ihoybKvs.js +1 -0
- package/dist/packem_shared/registry-keys-C8K11ets.js +1 -0
- package/dist/packem_shared/resolve-explicit-Dr4kIybR.js +5 -0
- package/dist/packem_shared/{resolve-runtime-CJSWV-K8.js → resolve-runtime-Tx0bvg0h.js} +1 -1
- package/dist/packem_shared/run-file-DD7Ne23Z.js +1 -0
- package/dist/packem_shared/{runtime-check-0lUJvgKt.js → runtime-check-BXehSP06.js} +1 -1
- package/dist/packem_shared/s1ngularity-CtMmtXJo.js +1 -0
- package/dist/packem_shared/scan-progress-D4yywI6P.js +2 -0
- package/dist/packem_shared/{selectors-UmnAuc26.js → selectors-D4iCvITE.js} +1 -1
- package/dist/packem_shared/{signatures-BOUhghTv.js → signatures-CE8OAK-i.js} +2 -2
- package/dist/packem_shared/spinner-DuJJvFTl.js +1 -0
- package/dist/packem_shared/tabs-CgxCvjCY.js +1 -0
- package/dist/packem_shared/target-merge-DOm6h6tW.js +11 -0
- package/dist/packem_shared/target-options-CR0OuYJr.js +1 -0
- package/dist/packem_shared/toolchain-C44mPKPu.js +5 -0
- package/dist/packem_shared/{typosquats-DBOvXwph.js → typosquats-CQz-1Y6K.js} +1 -1
- package/dist/packem_shared/use-measured-height-XK9YSwtv.js +1 -0
- package/dist/packem_shared/utils-CRueU43T.js +1 -0
- package/dist/packem_shared/verify-DStfg3nb.js +1 -0
- package/dist/packem_shared/vis-update-app-Cpme_3Du.js +1 -0
- package/dist/packem_shared/{watch-Bkp_AAbc.js → watch-BXNI7dC6.js} +1 -1
- package/dist/packem_shared/watch-loop-JfGKIgKB.js +11 -0
- package/dist/packem_shared/window-ops-DDePlWLV.js +2 -0
- package/dist/runtime/preload.js +1 -1
- package/index.js +52 -52
- package/package.json +17 -13
- package/dist/packem_chunks/config.js +0 -18
- package/dist/packem_shared/CONFIG_FILES-MsOntfYT.js +0 -1
- package/dist/packem_shared/augment-8fIWWGSc.js +0 -3
- package/dist/packem_shared/bin-CnDBuLh3.js +0 -2
- package/dist/packem_shared/dependency-scan-B0HV_qeB.js +0 -1
- package/dist/packem_shared/failure-log-C7r6UZLP.js +0 -2
- package/dist/packem_shared/glob-fqg4KepW-7Bs2kZuM.js +0 -1
- package/dist/packem_shared/index-BKFEWXU_.js +0 -1
- package/dist/packem_shared/index-OQZQyN5R.js +0 -19
- package/dist/packem_shared/missing-package-json-DhYzuKhD.js +0 -1
- package/dist/packem_shared/provenance-C0P-UYOM.js +0 -1
- package/dist/packem_shared/readJsonSync-CvkZyKmL-CY7PZob_.js +0 -4
- package/dist/packem_shared/registry-keys-D4chF-Wj.js +0 -1
- package/dist/packem_shared/resolve-explicit-Cgheka3B.js +0 -5
- package/dist/packem_shared/run-file-B4TqKa0X.js +0 -1
- package/dist/packem_shared/s1ngularity-Du1NnSFP.js +0 -1
- package/dist/packem_shared/scan-progress-CN9ONR0y.js +0 -2
- package/dist/packem_shared/spinner-lhXugSx3.js +0 -1
- package/dist/packem_shared/tabs-DTiU3usb.js +0 -1
- package/dist/packem_shared/target-options-ChWcK60i.js +0 -1
- package/dist/packem_shared/toolchain-DyCKnGch.js +0 -5
- package/dist/packem_shared/use-measured-height-CK2Co3XI.js +0 -1
- package/dist/packem_shared/utils-Cxree603.js +0 -1
- package/dist/packem_shared/verify-CVPYlUrF.js +0 -1
- package/dist/packem_shared/vis-update-app-DtHkwBca.js +0 -1
- package/dist/packem_shared/watch-loop-D9zbXzRd.js +0 -11
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
`)
|
|
3
|
-
`);
|
|
4
|
-
`);
|
|
5
|
-
|
|
6
|
-
`)
|
|
1
|
+
import{createRequire as A}from"node:module";import{w as G,k as H,p,P as J,i as S}from"./cli-main.js";import"../packem_shared/index-CE6MsgcV.js";import"../packem_shared/public-api-WqUCiyIe.js";import{g as V,R as W,a as K,V as Z,$ as T,c as a,h as Q,i as g,H as M,j as X,G as ee,F as m}from"./catalog.js";import{B as te}from"../packem_shared/env-C2ZCnfP_.js";import"../packem_shared/window-ops-DDePlWLV.js";import{I as oe}from"../packem_shared/index-B0EsgdzO.js";import{K as re,Z as se,W as ne}from"../packem_shared/ai-analysis-CO6S0afy.js";import{w as ie}from"../packem_shared/pm-runner-D4jM58Oz.js";import{U as ae,b as ce,u as N}from"../packem_shared/vis-update-app-Cpme_3Du.js";const ue=A(import.meta.url),de=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const Re=async({argument:E,logger:o,options:e,visConfig:i,workspaceRoot:C})=>{if(!C)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const u=C;if(e.securityConfig){const t=ie(u);if(G(i??{},t.name),e.sync&&t.name==="pnpm"){const r=H(i??{});if(r.length>0){p.info(`
|
|
2
|
+
Settings that would sync to pnpm-workspace.yaml:`);for(const b of r)p.success(` ${b}`)}else p.info("No security settings to sync.")}else e.sync&&t.name!=="pnpm"&&(p.info(`--sync is only available for pnpm projects. Your project uses ${t.name}.`),p.info("vis enforces security settings at the vis layer for non-pnpm projects."));if(!e.security&&!E?.length)return}const{packageManager:U}=J(u),B=V(u),c=i?.update??{},y=W(u,U,{dev:e.dev,includeInternal:e["include-internal"],peer:e.peer,prod:e.prod});if(y.size===0){o.info("No catalogs found.");return}const h=e.target??c.target??"latest";if(!["latest","minor","patch"].includes(h))throw new Error(`Invalid target "${h}". Use: latest, minor, or patch.`);const D={exclude:[...m(e.exclude),...m(c.exclude)],ignore:m(c.ignore),include:[...m(e.include),...m(c.include),...E],includeLocked:!!e.includeLocked,includePrerelease:e.prerelease||c.prerelease||!1,security:e.security!==!1,target:h};let j=0;for(const t of y.values())j+=t.size;const $=!!process.stdout.isTTY&&!oe;let l;const F=$?(t,r)=>{l?l.rerender(a.createElement(N,{current:t,total:r})):l=T(a.createElement(N,{current:t,total:r}),{interactive:!0,patchConsole:!1})}:(t,r)=>{o.info(`Checking ${String(t)}/${String(r)} dependencies...`)};$||o.info(`Checking ${String(j)} catalog dependencies against npm registry...
|
|
3
|
+
`);const w=new Set;S("socket")&&w.add("socket"),S("depsDev")&&w.add("deps-dev");const v=i?.security?.policies?.score?.minimum,I=K(i?.security,{disabled:w,minimumScore:v}),{failed:k,outdated:n}=await Z(y,D,B,F,u,I,i?.security?.acceptedRisks);if(l&&(l.clear(),l.unmount()),k.length>0&&o.warn(`Failed to fetch: ${k.join(", ")}`),n.length===0){o.info("All catalog dependencies are up to date.");return}const R=e.format??c.format??"table",P=re(e.aiType??"impact"),d=e.ai?await se(n,o,i?.ai,P):void 0;if($&&R==="table"){const t=new ae(n,d??null),r=i?.tui?.autoExit??!1,b=r===!0?3:typeof r=="number"?r:0;await T(a.createElement(ce,{autoExitSeconds:b,isDryRun:!0,store:t}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit();const q=process.stdout.columns||80;process.stdout.write(`
|
|
4
|
+
`);for(const s of n){const z=s.vulnerabilities?.length||s.socketReport&&s.socketReport.alerts.length>0,_=!!s.acceptedRisk,L=z?_?"✓":"⚠":"✓",O=_?"gray":s.updateType==="major"?"red":s.updateType==="minor"?"yellow":"green",f=s.socketReport?.score.overall,Y=f===void 0?"":` [${String(Math.round(f*100))}%]`,x=f===void 0?void 0:te(f);process.stdout.write(`${Q(a.createElement(g,null," ",a.createElement(g,{color:O},L),` ${s.packageName} ${s.currentRange} → ${s.newRange}`,a.createElement(g,{dimColor:!0},` ${s.updateType}`),x?a.createElement(g,{color:x},Y):null),{columns:q})}
|
|
5
|
+
`)}process.stdout.write(`
|
|
6
|
+
`),o.info(M(n,v))}else if(R==="json"){const t={failed:k,outdated:n};d&&(t.aiAnalysis=d),process.stdout.write(`${JSON.stringify(t,void 0,2)}
|
|
7
|
+
`)}else R==="minimal"?process.stdout.write(`${X(n)}
|
|
8
|
+
`):(ee(n,o),o.info(M(n,v)),d&&(o.info(""),o.info(ne(d))));e.exitCode&&n.length>0&&(process.exitCode=1)};export{Re as default};
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
`);
|
|
3
|
-
`)}
|
|
1
|
+
import{createRequire as te}from"node:module";import{E as u,j as g,q as y}from"../packem_shared/index.server-J83sowC4.js";import{m as T,f as j,I as V,H as G,y as K,a as L,A as P,o as se,T as ne,B as oe}from"../packem_shared/index-CE6MsgcV.js";import{f as ue}from"../packem_shared/giget-DVTFJlbR.js";import{p as l}from"./cli-main.js";const re=te(import.meta.url),R=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,E=t=>{if(typeof R<"u"&&R.versions&&R.versions.node){const[e,r]=R.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return R.getBuiltinModule(t)}return re(t)},{fileURLToPath:ie}=E("node:url"),{createInterface:ae}=E("node:readline"),{mkdtempSync:ce,rmSync:le}=E("node:fs"),{tmpdir:fe}=E("node:os"),{spawnSync:pe}=E("node:child_process"),J=[".ts",".mts",".cts",".js",".mjs",".cjs"],de="template.yml",me=[".d",".test",".spec",".config",".bench",".stories"],he=[".d.ts",".d.mts",".d.cts",".js.map",".mjs.map",".cjs.map",".ts.map"],Y=t=>{for(const e of J)if(t.endsWith(e))return t.slice(0,-e.length);return t},$e=t=>{if(he.some(r=>t.endsWith(r))||!J.some(r=>t.endsWith(r)))return!1;const e=Y(t);return!me.some(r=>e.endsWith(r))},H=(t,e)=>{const r=[];if(!j(t))return r;for(const s of V(t,{includeDirs:!1,includeSymlinks:!1,maxDepth:1})){if(!$e(s.name))continue;const n=Y(s.name);r.push({load:()=>ge(s.path),name:n,path:s.path,source:e})}return r},x=(t,e)=>{const r=[];if(!j(t))return r;for(const s of V(t,{includeFiles:!1,includeSymlinks:!1,maxDepth:1})){if(s.path===t)continue;const n=T(s.path,de);j(n)&&r.push({load:()=>ye(s.path,s.name),name:s.name,path:s.path,source:e})}return r},we=()=>{try{const t=ie(import.meta.url),e=T(G(t),"..","..","templates");return j(e)?e:void 0}catch{return}},I=t=>{const{extraDirectories:e=[],onWarning:r,workspaceRoot:s}=t,n=[...H(T(s,".vis","templates"),"native"),...x(T(s,".vis","templates"),"moon"),...x(T(s,".moon","templates"),"moon")];for(const o of e)n.push(...x(o,"config")),n.push(...H(o,"config"));const i=we();i&&n.push(...x(i,"builtin"));const a=new Map;for(const o of n){const c=a.get(o.name);if(!c){a.set(o.name,o);continue}r&&r(`Template "${o.name}" exists in multiple sources — using ${c.source} (${c.path}), ignoring ${o.source} (${o.path}).`)}return[...a.values()].sort((o,c)=>o.name.localeCompare(c.name))},ge=async t=>{const{loadNativeTemplate:e}=await import("./loader2.js");return e(t)},ye=async(t,e)=>{const{loadMoonTemplate:r}=await import("./index2.js");return r(t,e)},q=(t,e)=>new Promise(r=>{t.question(e,s=>{r(s.trim())})}),ve=async(t,e,r)=>{const s=await q(t,` ${e} ${u(r?"[Y/n]":"[y/N]")} `);return s===""?r:s.toLowerCase()==="y"||s.toLowerCase()==="yes"},be=async(t,e,r,s)=>{process.stderr.write(` ${e}
|
|
2
|
+
`);for(const[n,i]of r.entries()){const a=g(y(` ${String(n+1)}.`)),o=i===s?u(" (default)"):"";process.stderr.write(`${a} ${i}${o}
|
|
3
|
+
`)}for(;;){const n=await q(t,`
|
|
4
|
+
${u(`Enter choice (1-${String(r.length)}):`)} `);if(n===""&&s!==void 0)return s;const i=Number.parseInt(n,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(o=>o===n);if(a)return a;process.stderr.write(` ${u("Invalid choice. Try again.")}
|
|
5
|
+
`)}},Te=async(t,e,r,s)=>{process.stderr.write(` ${e} ${u("(comma-separated numbers)")}
|
|
6
|
+
`);for(const[n,i]of r.entries()){const a=g(y(` ${String(n+1)}.`)),o=s.includes(i)?u(" (default)"):"";process.stderr.write(`${a} ${i}${o}
|
|
7
|
+
`)}for(;;){const n=await q(t,`
|
|
8
|
+
${u("Enter choices:")} `);if(n===""&&s.length>0)return s;const i=n.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(` ${u("Invalid choice. Try again.")}
|
|
9
|
+
`)}},Se=t=>` ${u(`${t}:`)} `,Ne=(t,e)=>e.prompt??t,Re=t=>Object.entries(t).sort(([e,r],[s,n])=>{const i=r.order??0,a=n.order??0;return i!==a?i-a:e.localeCompare(s)}),U=(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}},B=(t,e,r)=>{if(e.type==="enum"){const s=Array.isArray(r)?r:[r];for(const n of s)if(typeof n!="string"||!e.values.includes(n))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(n)}")`)}},je=async t=>{const{defaults:e,interactive:r,overrides:s,variables:n}=t,i={},a=r?ae({input:process.stdin,output:process.stderr}):null;try{for(const[o,c]of Re(n)){if(Object.hasOwn(s,o)){const w=U(c,s[o]??"");B(o,c,w),i[o]=w;continue}if(e||!r||c.internal){if(c.default!==void 0){B(o,c,c.default),i[o]=c.default;continue}if(c.required)throw new Error(`Required variable "${o}" not provided. Pass --${o}=<value> or remove --defaults.`);continue}const m=Ne(o,c);let f;if(c.type==="boolean")f=await ve(a,m,!!(c.default??!1));else if(c.type==="enum")if(c.multiple){const w=Array.isArray(c.default)?c.default:[];f=await Te(a,m,c.values,w)}else{const w=typeof c.default=="string"?c.default:void 0;f=await be(a,m,c.values,w)}else{const w=c.default===void 0?"":` (${String(c.default)})`,v=await q(a,Se(`${m}${w}`));if(v===""&&c.default!==void 0)f=c.default;else if(v===""){if(c.required)throw new Error(`Variable "${o}" is required`);continue}else f=U(c,v)}B(o,c,f),i[o]=f}return i}finally{a?.close()}},Ee=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],ke=t=>Ee.some(e=>t.startsWith(e)),Oe=async(t,e={})=>{const r=e.targetDirectory===void 0,s=e.targetDirectory??ce(T(fe(),"vis-generate-")),n=()=>{if(r)try{le(s,{force:!0,recursive:!0})}catch{}};l.info(`Downloading ${t}…`);try{const i=await ue(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:n,directory:i.dir}}catch(i){n();const a=i instanceof Error?i.message:String(i);throw l.warn(`Failed to download template: ${a}`),i}},z=(t,e="")=>{const r=[];for(const[s,n]of Object.entries(t)){const i=e?`${e}/${s}`:s;typeof n=="string"||Buffer.isBuffer(n)?r.push({content:n,path:i}):n&&typeof n=="object"&&r.push(...z(n,i))}return r},_e=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,xe=(t,e)=>{if(P(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=T(t,e),s=K(t,r);if(s===".."||s.startsWith(`..${se}`)||P(s))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},Ie=(t,e)=>{L(G(t)),ne(t,e)},qe=(t,e,r=!1)=>{const s=typeof t=="string"?[t]:t.commands,n=typeof t=="string"?r:t.silent??r;for(const i of s){n||l.info(`$ ${i}`);const a=pe(i,{cwd:e,shell:!0,stdio:n?"ignore":"inherit"});if(a.status!==0)return l.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},De=t=>{const e=new Map;for(const r of t){const s=typeof r=="string"?0:r.phase??0,n=e.get(s);n?n.push(r):e.set(s,[r])}return[...e.entries()].sort(([r],[s])=>r-s)},We=async(t,e)=>{const r={builtins:{dest_dir:e.destination,dest_rel_dir:K(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(r),n=s.files?z(s.files):[],i=s.filesMeta??{},a=[];for(const o of n){const c=xe(e.destination,o.path);a.push({file:o,meta:i[o.path]??{},target:c})}if(e.dryRun){l.info(`${g(y("Plan"))} ${u("(dry-run, no files written)")}`);for(const o of a){const c=Buffer.isBuffer(o.file.content)?o.file.content.length:Buffer.byteLength(o.file.content,"utf8");process.stderr.write(` ${u("write")} ${o.file.path} ${u(`(${_e(c)})`)}
|
|
10
|
+
`)}}else{L(e.destination);let o=0,c=0;for(const m of a){const{file:f,meta:w,target:v}=m,D=j(v),b=e.force||w.force===!0;if(D&&!b){l.warn(`Skipped existing file: ${f.path} (use --force or set frontmatter force: true to overwrite)`),c+=1;continue}Ie(v,f.content),o+=1}l.success(`Wrote ${String(o)} file${o===1?"":"s"}${c>0?`, skipped ${String(c)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const o=De(s.scripts);l.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(o.length)} phase${o.length===1?"":"s"}…`);for(const[,c]of o)if((await Promise.all(c.map(m=>Promise.resolve(qe(m,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 o of s.suggestions)process.stderr.write(` ${u("•")} ${o}
|
|
12
|
+
`)}},Be=async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},Pe=(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},Ae=async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([s,n],[i,a])=>{const o=n.order??0,c=a.order??0;return o===c?s.localeCompare(i):o-c}).map(([s,n])=>Pe(s,n));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},Ce=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=u(`(${e.source})`);process.stderr.write(` ${g(y(e.name))} ${r}
|
|
13
|
+
`)}},Me=(t,e)=>{const r={},s=[];for(let n=0;n<t.length;n++){const i=t[n];if(!i.startsWith("--")){s.push(i);continue}const a=i.indexOf("=");if(a===-1){const m=i.slice(2);if(m.startsWith("no-"))r[m.slice(3)]="false";else{r[m]="true";const f=t[n+1];f!==void 0&&!f.startsWith("-")&&e?.(`\`--${m} ${f}\` was read as boolean \`--${m}=true\` and \`${f}\` was ignored. For a string value use \`--${m}=${f}\`.`)}continue}const o=i.slice(2,a),c=i.slice(a+1);r[o]=c}return{overrides:r,remaining:s}},Fe=async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${g(y("vis generate"))} ${u("— pick a template")}
|
|
14
|
+
|
|
15
|
+
`);for(const[s,n]of t.entries()){const i=g(y(` ${String(s+1)}.`));process.stderr.write(`${i} ${n.name} ${u(`(${n.source})`)}
|
|
16
|
+
`)}return new Promise((s,n)=>{r.question(`
|
|
17
|
+
${u(`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):n(new Error("Invalid choice."))})})}finally{r.close()}},Le=async({argument:t,options:e,rawUnknown:r,visConfig:s,workspaceRoot:n})=>{const i=e.cwd||n||process.cwd(),a=n??i,o=s?.generator,c=Array.isArray(t)?t:t?[t]:[];if(e.list){const p=I({extraDirectories:o?.templates??[],onWarning:d=>{l.warn(d)},workspaceRoot:a});if(e.json){const d=await Promise.all(p.map(h=>Be(h)));process.stdout.write(`${JSON.stringify(d,null,2)}
|
|
18
|
+
`);return}Ce(p);return}if(e.describe){const p=c[0];if(!p)throw new Error("`--describe` requires a template name. Run `vis generate --list` to see available templates.");const d=I({extraDirectories:o?.templates??[],onWarning:$=>{l.warn($)},workspaceRoot:a}).find($=>$.name===p);if(!d)throw new Error(`Template "${p}" not found. Run \`vis generate --list\` to see available templates.`);const h=await Ae(d);if(e.json){process.stdout.write(`${JSON.stringify(h,null,2)}
|
|
19
|
+
`);return}if(l.info(`Template: ${g(y(h.name))} ${u(`(${h.source})`)}`),h.description&&l.info(h.description),h.destination&&l.info(`Destination: ${u(h.destination)}`),h.variables.length===0)l.info("No variables.");else{l.info("Variables:");for(const $ of h.variables){const _=[$.type];$.required&&_.push("required"),$.default!==void 0&&_.push(`default=${JSON.stringify($.default)}`),$.values&&_.push(`values=${$.values.join("|")}`),process.stderr.write(` ${g(y($.name))} ${u(`(${_.join(", ")})`)}
|
|
20
|
+
`)}}return}let m=[...r??[]];if(m.length===0){const p=process.argv.slice(2),d=p.indexOf("--");d!==-1&&(m=p.slice(d+1))}const f=c.indexOf("--"),w=f===-1?[]:c.slice(f+1),v=f===-1?c:c.slice(0,f),{overrides:D}=Me([...w,...m],p=>{l.warn(p)});let b,k,O;const N=v[0];let W;if(N&&ke(N)){const p=await Oe(N,{auth:o?.auth,preferOffline:!!e.preferOffline||o?.preferOffline});W=p.cleanup;try{const d=I({extraDirectories:[p.directory],workspaceRoot:a}).find(h=>h.path.startsWith(p.directory));if(!d)throw new Error(`Downloaded template at ${p.directory} contains no template.yml or *.ts entrypoint.`);b=await d.load(),k=d.name,O=b.destination}catch(d){throw W(),d}}else{const p=I({extraDirectories:o?.templates??[],onWarning:$=>{l.warn($)},workspaceRoot:a});if(p.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let d;if(N)d=N;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.");d=await Fe(p)}const h=p.find($=>$.name===d);if(!h)throw new Error(`Template "${d}" not found. Run 'vis generate --list' to see available templates.`);b=await h.load(),k=h.name,O=b.destination}const A=e.to,C=!!e.dryRun,Q=!!e.force,M=!!e.defaults,X=!!e.skipScripts,Z=e.interactive!==!1&&!!process.stdin.isTTY&&!M;let S;A?S=A:O?S=O:S=".";const F=P(S)?S:oe(i,S);l.info(`Template: ${g(y(k))}`),l.info(`Target: ${u(F)}`),process.stderr.write(`
|
|
21
|
+
`);const ee=await je({defaults:M,interactive:Z,overrides:D,variables:b.options??{}});try{await We(b,{cwd:i,destination:F,dryRun:C,force:Q,options:ee,skipScripts:X,workspaceRoot:a}),C||(process.stderr.write(`
|
|
22
|
+
`),l.success(`Template '${k}' applied.`))}finally{W?.()}};export{Le as default};
|
|
@@ -1,22 +1,61 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)
|
|
3
|
-
`)}
|
|
4
|
-
${f(`Enter choice (1-${String(r.length)}):`)} `);if(n===""&&s!==void 0)return s;const i=Number.parseInt(n,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(o=>o===n);if(a)return a;process.stderr.write(` ${f("Invalid choice. Try again.")}
|
|
5
|
-
`)}},Te=async(t,e,r,s)=>{process.stderr.write(` ${e} ${f("(comma-separated numbers)")}
|
|
6
|
-
`);for(const[n,i]of r.entries()){const a=g(y(` ${String(n+1)}.`)),o=s.includes(i)?f(" (default)"):"";process.stderr.write(`${a} ${i}${o}
|
|
7
|
-
`)}for(;;){const n=await q(t,`
|
|
8
|
-
${f("Enter choices:")} `);if(n===""&&s.length>0)return s;const i=n.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(` ${f("Invalid choice. Try again.")}
|
|
9
|
-
`)}},Se=t=>` ${f(`${t}:`)} `,Ee=(t,e)=>e.prompt??t,Ne=t=>Object.entries(t).sort(([e,r],[s,n])=>{const i=r.order??0,a=n.order??0;return i!==a?i-a:e.localeCompare(s)}),U=(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}},W=(t,e,r)=>{if(e.type==="enum"){const s=Array.isArray(r)?r:[r];for(const n of s)if(typeof n!="string"||!e.values.includes(n))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(n)}")`)}},Re=async t=>{const{defaults:e,interactive:r,overrides:s,variables:n}=t,i={},a=r?ae({input:process.stdin,output:process.stderr}):null;try{for(const[o,c]of Ne(n)){if(Object.hasOwn(s,o)){const w=U(c,s[o]??"");W(o,c,w),i[o]=w;continue}if(e||!r||c.internal){if(c.default!==void 0){W(o,c,c.default),i[o]=c.default;continue}if(c.required)throw new Error(`Required variable "${o}" not provided. Pass --${o}=<value> or remove --defaults.`);continue}const $=Ee(o,c);let m;if(c.type==="boolean")m=await ve(a,$,!!(c.default??!1));else if(c.type==="enum")if(c.multiple){const w=Array.isArray(c.default)?c.default:[];m=await Te(a,$,c.values,w)}else{const w=typeof c.default=="string"?c.default:void 0;m=await be(a,$,c.values,w)}else{const w=c.default===void 0?"":` (${String(c.default)})`,v=await q(a,Se(`${$}${w}`));if(v===""&&c.default!==void 0)m=c.default;else if(v===""){if(c.required)throw new Error(`Variable "${o}" is required`);continue}else m=U(c,v)}W(o,c,m),i[o]=m}return i}finally{a?.close()}},je=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],ke=t=>je.some(e=>t.startsWith(e)),_e=async(t,e={})=>{const r=e.targetDirectory===void 0,s=e.targetDirectory??ce(T(fe(),"vis-generate-")),n=()=>{if(r)try{le(s,{force:!0,recursive:!0})}catch{}};l.info(`Downloading ${t}…`);try{const i=await pe(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:n,directory:i.dir}}catch(i){n();const a=i instanceof Error?i.message:String(i);throw l.warn(`Failed to download template: ${a}`),i}},Q=(t,e="")=>{const r=[];for(const[s,n]of Object.entries(t)){const i=e?`${e}/${s}`:s;typeof n=="string"||Buffer.isBuffer(n)?r.push({content:n,path:i}):n&&typeof n=="object"&&r.push(...Q(n,i))}return r},Oe=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,xe=(t,e)=>{if(P(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=T(t,e),s=K(t,r);if(s===".."||s.startsWith(`..${se}`)||P(s))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},Ie=(t,e)=>{L(G(t)),oe(t,e)},qe=(t,e,r=!1)=>{const s=typeof t=="string"?[t]:t.commands,n=typeof t=="string"?r:t.silent??r;for(const i of s){n||l.info(`$ ${i}`);const a=ue(i,{cwd:e,shell:!0,stdio:n?"ignore":"inherit"});if(a.status!==0)return l.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},De=t=>{const e=new Map;for(const r of t){const s=typeof r=="string"?0:r.phase??0,n=e.get(s);n?n.push(r):e.set(s,[r])}return[...e.entries()].sort(([r],[s])=>r-s)},Be=async(t,e)=>{const r={builtins:{dest_dir:e.destination,dest_rel_dir:K(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(r),n=s.files?Q(s.files):[],i=s.filesMeta??{},a=[];for(const o of n){const c=xe(e.destination,o.path);a.push({file:o,meta:i[o.path]??{},target:c})}if(e.dryRun){l.info(`${g(y("Plan"))} ${f("(dry-run, no files written)")}`);for(const o of a){const c=Buffer.isBuffer(o.file.content)?o.file.content.length:Buffer.byteLength(o.file.content,"utf8");process.stderr.write(` ${f("write")} ${o.file.path} ${f(`(${Oe(c)})`)}
|
|
10
|
-
`)}}else{L(e.destination);let o=0,c=0;for(const $ of a){const{file:m,meta:w,target:v}=$,D=R(v),b=e.force||w.force===!0;if(D&&!b){l.warn(`Skipped existing file: ${m.path} (use --force or set frontmatter force: true to overwrite)`),c+=1;continue}Ie(v,m.content),o+=1}l.success(`Wrote ${String(o)} file${o===1?"":"s"}${c>0?`, skipped ${String(c)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const o=De(s.scripts);l.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(o.length)} phase${o.length===1?"":"s"}…`);for(const[,c]of o)if((await Promise.all(c.map($=>Promise.resolve(qe($,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 o of s.suggestions)process.stderr.write(` ${f("•")} ${o}
|
|
12
|
-
`)}},We=async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},Pe=(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},Ae=async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([s,n],[i,a])=>{const o=n.order??0,c=a.order??0;return o===c?s.localeCompare(i):o-c}).map(([s,n])=>Pe(s,n));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},Ce=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=f(`(${e.source})`);process.stderr.write(` ${g(y(e.name))} ${r}
|
|
13
|
-
`)}},Me=t=>{const e={},r=[];for(const s of t){if(!s.startsWith("--")){r.push(s);continue}const n=s.indexOf("=");if(n===-1){const o=s.slice(2);o.startsWith("no-")?e[o.slice(3)]="false":e[o]="true";continue}const i=s.slice(2,n),a=s.slice(n+1);e[i]=a}return{overrides:e,remaining:r}},Fe=async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${g(y("vis generate"))} ${f("— pick a template")}
|
|
1
|
+
import{v as F,H as P,y as S,m as b,T as I,O as U,a as T}from"../packem_shared/index-CE6MsgcV.js";import _ from"./index.js";import{b as J,l as M}from"./catalog.js";import{n as q}from"../packem_shared/manifests-WBnsV_Eb.js";import{_ as C,a0 as B}from"./cli-main.js";import{s as H}from"../packem_shared/glob-fqg4KepW-1S3z30c8.js";const K=(e,t)=>{const o=t.replace(/^\.?\//,"");return o===""||o==="."?`/${e}/`:e===""||e==="."?`/${o}`:`/${e}/${o}`},v=(e,t,o=[])=>{const s=[],n=new Set;for(const[r,a]of Object.entries(t?.globalPaths??{}))s.push({owners:a,path:r,source:"project-json"}),n.add(r);for(const[r,a]of Object.entries(e.projects)){const i=a.owners??[];for(const c of i){const f=K(a.root??r,c.path);s.push({channel:c.channel,owners:c.owners,path:f,projectId:r,source:"project-json"}),n.add(f)}}for(const r of o)n.has(r.path)||(s.push(r),n.add(r.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((r,a)=>(r.projectId??"").localeCompare(a.projectId??"")||r.path.localeCompare(a.path)):s.sort((r,a)=>r.path.localeCompare(a.path)),s},z="Update each project's project.json `owners` field and re-run the command.",Y=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${z}`,""],W=e=>{const t=[];for(const o of e){const s=o.owners.join(" "),n=o.channel?` # notify: ${o.channel}`:"";t.push(`${o.path} ${s}${n}`)}return t},Q=(e,t={})=>[...Y(t.regenerationCommand),...W(e),""].join(`
|
|
2
|
+
`),O={begin:"# BEGIN vis-codeowners",end:"# END vis-codeowners"},V=(e,t=O,o={})=>{const s=o.regenerationCommand?`# Generated by vis sync codeowners — re-run with: ${o.regenerationCommand}`:"# Generated by `vis sync codeowners` — do not edit by hand.";return[t.begin,s,...W(e),t.end].join(`
|
|
3
|
+
`)},X=(e,t,o=O)=>{const s=e.indexOf(o.begin),n=e.indexOf(o.end);if(s!==-1&&n!==-1&&n>s){const a=e.slice(0,s),i=n+o.end.length,c=e.slice(i);return`${a}${t}${c}`}const r=e.replace(/\s+$/u,"");return`${r.length===0?"":`${r}
|
|
14
4
|
|
|
15
|
-
`
|
|
16
|
-
`)}return new
|
|
17
|
-
|
|
18
|
-
`);return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
`}${t}
|
|
6
|
+
`},Z=["**/CODEOWNERS"],ee=["**/node_modules/**","**/dist/**","**/build/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"],te=e=>{const t=[];for(const o of e.split(/\r?\n/u)){const s=o.indexOf("#"),n=(s===-1?o:o.slice(0,s)).trim();if(n.length===0)continue;const r=n.split(/\s+/u);if(r.length<2)continue;const[a,...i]=r,c=i.filter(f=>f.length>0);!a||c.length===0||t.push({owners:c,path:a})}return t},oe=(e,t)=>{const o=t.replace(/^\.\/?/,"").replace(/\/$/,"");return e.startsWith("/")?o===""?e:`/${o}${e}`:o===""?`/${e}`:`/${o}/${e}`},ne=async(e,t,o)=>{const s=t&&t.length>0?[...t]:[...Z],n=[...ee];if(o){const i=o.replace(/^\.\/?/,"").replace(/^\/+/,"");i.length>0&&n.push(i)}const r=await H(s,{absolute:!0,cwd:e,ignore:n}),a=[];for(const i of r){let c;try{c=F(i)}catch{continue}const f=P(i),h=S(e,f);for(const p of te(c))a.push({owners:p.owners,path:oe(p.path,h)})}return a},re=/^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/?#]+)/iu,se=e=>{if(!e)return;const t=e.match(re);if(!t?.[1])return;const o=t[1].trim();if(!(o===""||o.includes(" ")))return`@${o.replace(/^@/,"")}`},ie=(e,t)=>{const o=[];for(const[s,n]of Object.entries(e.projects)){if(n.owners&&n.owners.length>0)continue;const r=n.root??s,a=b(t,r,"package.json"),i=C(a);if(!i)continue;const c=q(i.maintainers);if(!c||c.length===0)continue;const f=[],h=new Set;for(const p of c){const $=se(p.url);$&&!h.has($)&&(h.add($),f.push($))}f.length!==0&&o.push({owners:f,path:r===""||r==="."?"/":`/${r}/`,projectId:s})}return o},ae=["author","bugs","homepage","license","repository","engines"],N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),E=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(const[o,s]of e.entries())if(!E(s,t[o]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){const o=Object.keys(e),s=Object.keys(t);if(o.length!==s.length)return!1;for(const n of o)if(!E(e[n],t[n]))return!1;return!0}return!1},R=e=>e===void 0?e:structuredClone(e),ce=(e,t,o)=>{if(e==="repository"&&N(t)&&N(o)){const s={};for(const[n,r]of Object.entries(t))n!=="directory"&&(s[n]=R(r));return typeof o.directory=="string"&&(s.directory=o.directory),s}return R(t)},de=(e,t,o)=>{const s=[];for(const n of o.fields){if(!Object.hasOwn(e,n))continue;const r=e[n],a=t[n],i=ce(n,r,a);E(i,a)||s.push({after:i,before:a,field:n,packageJsonPath:""})}return s},fe=(e,t)=>{for(const o of t)e[o.field]=o.after},x="Generated by `vis sync codeowners --write-guard`. Do not edit by hand.",le=e=>{const t=e.replace(/^\.?\/+/u,"").replace(/\/+$/u,"");return t===""||t==="."?"**":`${t}/**`},D=e=>{const t=new Set,o=[];for(const s of[...e].sort((n,r)=>n.name.localeCompare(r.name))){const n=le(s.root);t.has(n)||(t.add(n),o.push(n))}return o},pe=e=>{const t=D(e),o=t.map(n=>` - "${n}"`).join(`
|
|
7
|
+
`),s=t.map(n=>` ${n}`).join(`
|
|
8
|
+
`);return`# ${x}
|
|
9
|
+
name: Write Guard
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
pull_request:
|
|
13
|
+
paths:
|
|
14
|
+
${o}
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
pull-requests: read
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
write-guard:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
- uses: geritol/write-guard@v1
|
|
28
|
+
with:
|
|
29
|
+
codeowners: CODEOWNERS
|
|
30
|
+
paths: |
|
|
31
|
+
${s}
|
|
32
|
+
`},ue=e=>{const t=D(e).map(o=>` - "${o}/*"`).join(`
|
|
33
|
+
`);return`# ${x}
|
|
34
|
+
#
|
|
35
|
+
# SOFT GUARD ONLY — this job does NOT block a merge by itself.
|
|
36
|
+
# It verifies the generated CODEOWNERS is in sync and flags that a
|
|
37
|
+
# restricted path changed. GitLab CI cannot portably gate a merge on
|
|
38
|
+
# code-owner *approval* from a job, so REAL ENFORCEMENT REQUIRES the
|
|
39
|
+
# native GitLab setting:
|
|
40
|
+
# Settings -> Repository -> Protected branches ->
|
|
41
|
+
# "Require approval from Code Owners" (GitLab Premium / Ultimate)
|
|
42
|
+
# https://docs.gitlab.com/ee/user/project/codeowners/
|
|
43
|
+
# Without that setting enabled, this job is advisory only.
|
|
44
|
+
write-guard:
|
|
45
|
+
stage: test
|
|
46
|
+
image: node:22-alpine
|
|
47
|
+
rules:
|
|
48
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
49
|
+
changes:
|
|
50
|
+
${t}
|
|
51
|
+
script:
|
|
52
|
+
- corepack enable
|
|
53
|
+
- pnpm install --frozen-lockfile
|
|
54
|
+
- pnpm vis sync codeowners --check
|
|
55
|
+
- >-
|
|
56
|
+
echo "SOFT GUARD: a restricted path changed. This job does NOT enforce
|
|
57
|
+
code-owner approval. Enable 'Require approval from Code Owners' on the
|
|
58
|
+
protected branch (GitLab Premium/Ultimate) for a real merge gate:
|
|
59
|
+
https://docs.gitlab.com/ee/user/project/codeowners/"
|
|
60
|
+
`},he=e=>e.length===0?[]:[{content:pe(e),path:".github/workflows/write-guard.yml"},{content:ue(e),path:".gitlab/write-guard.gitlab-ci.yml"}],L=new Set(["nested-codeowners","package-json-maintainers","project-json"]),A=(e,t,o)=>{const s=new Set,n=[];for(const r of e??[])for(const a of r.split(",")){const i=a.trim();if(i.length===0)continue;if(o&&!o(i))throw new Error(`Unknown codeowners source: "${i}". Known: ${[...L].join(", ")}.`);const c=i;s.has(c)||(s.add(c),n.push(c))}return n.length>0?n:[...t]},ge=e=>L.has(e),G=["codeowners","package-json-fields"],me=(e,t)=>t.some(o=>_(o,e)),we=async(e,t,o,s,n)=>{const r=Object.entries(s.projects).filter(([,i])=>i.restricted===!0).map(([i,c])=>({name:i,root:c.root??i})),a=he(r);if(a.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(n){let i=!1;for(const c of a){const f=b(o,c.path);let h="";try{h=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}h.trim()!==c.content.trim()&&(t.error(`${c.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),i=!0)}i?process.exitCode=1:t.info(`Write Guard CI is up to date (${a.length} files, ${r.length} restricted projects).`);return}for(const i of a){const c=b(o,i.path);T(P(c)),I(c,i.content),t.info(`Wrote ${i.path}`)}t.info(`Write Guard CI scoped to ${r.length} restricted project${r.length===1?"":"s"}.`)},$e=async({fs:e,logger:t,options:o,visConfig:s,workspaceRoot:n})=>{const r=n,{workspace:a}=J(r,s),i=s?.codeowners;o.writeGuard===!0&&await we(e,t,r,a,o.check===!0);const c=A(o.from,i?.sources??["project-json"],ge),f=o.regenerationCommand??i?.regenerationCommand,h=o.preserveBlock===!0||i?.preserveBlock===!0,p=i?.blockMarker??O,$=o.nestedIncludes??i?.nestedIncludes,g=o.out??"CODEOWNERS",w=[];if(c.includes("nested-codeowners")){const m=await ne(r,$,g);for(const j of m)w.push({...j,source:"nested"})}if(c.includes("package-json-maintainers")){const m=ie(a,r);for(const j of m)w.push({...j,source:"maintainers"})}const l=c.includes("project-json")?v(a,i,w):v({projects:{}},i,w);if(l.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const y=b(r,g);let d="";try{d=await e.readFile(y,"utf8")}catch(m){if(m.code!=="ENOENT")throw m}const u={regenerationCommand:f},k=h?X(d,V(l,p,u),p):Q(l,u);if(o.check){if(d.trim()!==k.trim()){t.error(`${y} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${y} is up to date.`);return}I(y,k),t.info(`Wrote ${l.length} entries to ${y}`)},ke=({logger:e,options:t,visConfig:o,workspaceRoot:s})=>{const n=s,r=o?.editorconfig??!0,a=C(b(n,"package.json"));if(!a){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const i=A(t.fields,ae),c=t.ignorePackageName??[],f=t.check===!0,h=(t.format??"human").toLowerCase(),p=t.quiet===!0,$=B(n).filter(d=>d!=="."),g=[];let w=0;for(const d of $){const u=b(n,d,"package.json"),k=C(u);if(!k)continue;const m=typeof k.name=="string"?k.name:void 0;if(m!==void 0&&c.length>0&&me(m,c))continue;w+=1;const j=de(a,k,{fields:i});j.length!==0&&g.push({filePath:u,packageJsonPath:S(n,u),packageName:m,pkg:k,pkgChanges:j})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),U(d.filePath,d.pkg,{indent:M(d.filePath,{useEditorconfig:r}),overwrite:!0});const l=g.flatMap(d=>d.pkgChanges.map(u=>({after:u.after,before:u.before,field:u.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),y={changes:l,fields:i,kind:"package-json-fields",mode:f?"check":"write",totalChanges:l.length,totalPackages:w};if(h==="json")process.stdout.write(`${JSON.stringify(y,null,4)}
|
|
61
|
+
`);else if(l.length===0)e.info(`All ${w} package${w===1?"":"s"} in sync (fields: ${i.join(", ")}).`);else if(f){if(!p)for(const d of l)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${l.length} field drift${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(u=>u.field).join(", ")}`);e.info(`Synced ${l.length} field${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&l.length>0&&(process.exitCode=1)},ve=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${G.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await $e(e);return}if(t==="package-json-fields"){ke(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${G.join(", ")}.`)};export{ve as default};
|
|
@@ -1,61 +1,3 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`)
|
|
3
|
-
`)},
|
|
4
|
-
|
|
5
|
-
`}${t}
|
|
6
|
-
`},Z=["**/CODEOWNERS"],ee=["**/node_modules/**","**/dist/**","**/build/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"],te=e=>{const t=[];for(const o of e.split(/\r?\n/u)){const s=o.indexOf("#"),n=(s===-1?o:o.slice(0,s)).trim();if(n.length===0)continue;const r=n.split(/\s+/u);if(r.length<2)continue;const[i,...a]=r,c=a.filter(f=>f.length>0);!i||c.length===0||t.push({owners:c,path:i})}return t},oe=(e,t)=>{const o=t.replace(/^\.\/?/,"").replace(/\/$/,"");return e.startsWith("/")?o===""?e:`/${o}${e}`:o===""?`/${e}`:`/${o}/${e}`},ne=async(e,t,o)=>{const s=t&&t.length>0?[...t]:[...Z],n=[...ee];if(o){const a=o.replace(/^\.\/?/,"").replace(/^\/+/,"");a.length>0&&n.push(a)}const r=await H(s,{absolute:!0,cwd:e,ignore:n}),i=[];for(const a of r){let c;try{c=F(a)}catch{continue}const f=P(a),h=S(e,f);for(const p of te(c))i.push({owners:p.owners,path:oe(p.path,h)})}return i},re=/^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/?#]+)/iu,se=e=>{if(!e)return;const t=e.match(re);if(!t?.[1])return;const o=t[1].trim();if(!(o===""||o.includes(" ")))return`@${o.replace(/^@/,"")}`},ae=(e,t)=>{const o=[];for(const[s,n]of Object.entries(e.projects)){if(n.owners&&n.owners.length>0)continue;const r=n.root??s,i=b(t,r,"package.json"),a=C(i);if(!a)continue;const c=B(a.maintainers);if(!c||c.length===0)continue;const f=[],h=new Set;for(const p of c){const $=se(p.url);$&&!h.has($)&&(h.add($),f.push($))}f.length!==0&&o.push({owners:f,path:r===""||r==="."?"/":`/${r}/`,projectId:s})}return o},ie=["author","bugs","homepage","license","repository","engines"],N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),E=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(const[o,s]of e.entries())if(!E(s,t[o]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){const o=Object.keys(e),s=Object.keys(t);if(o.length!==s.length)return!1;for(const n of o)if(!E(e[n],t[n]))return!1;return!0}return!1},R=e=>e===void 0?e:structuredClone(e),ce=(e,t,o)=>{if(e==="repository"&&N(t)&&N(o)){const s={};for(const[n,r]of Object.entries(t))n!=="directory"&&(s[n]=R(r));return typeof o.directory=="string"&&(s.directory=o.directory),s}return R(t)},de=(e,t,o)=>{const s=[];for(const n of o.fields){if(!Object.hasOwn(e,n))continue;const r=e[n],i=t[n],a=ce(n,r,i);E(a,i)||s.push({after:a,before:i,field:n,packageJsonPath:""})}return s},fe=(e,t)=>{for(const o of t)e[o.field]=o.after},x="Generated by `vis sync codeowners --write-guard`. Do not edit by hand.",le=e=>{const t=e.replace(/^\.?\/+/u,"").replace(/\/+$/u,"");return t===""||t==="."?"**":`${t}/**`},D=e=>{const t=new Set,o=[];for(const s of[...e].sort((n,r)=>n.name.localeCompare(r.name))){const n=le(s.root);t.has(n)||(t.add(n),o.push(n))}return o},pe=e=>{const t=D(e),o=t.map(n=>` - "${n}"`).join(`
|
|
7
|
-
`),s=t.map(n=>` ${n}`).join(`
|
|
8
|
-
`);return`# ${x}
|
|
9
|
-
name: Write Guard
|
|
10
|
-
|
|
11
|
-
on:
|
|
12
|
-
pull_request:
|
|
13
|
-
paths:
|
|
14
|
-
${o}
|
|
15
|
-
|
|
16
|
-
permissions:
|
|
17
|
-
contents: read
|
|
18
|
-
pull-requests: read
|
|
19
|
-
|
|
20
|
-
jobs:
|
|
21
|
-
write-guard:
|
|
22
|
-
runs-on: ubuntu-latest
|
|
23
|
-
steps:
|
|
24
|
-
- uses: actions/checkout@v4
|
|
25
|
-
with:
|
|
26
|
-
fetch-depth: 0
|
|
27
|
-
- uses: geritol/write-guard@v1
|
|
28
|
-
with:
|
|
29
|
-
codeowners: CODEOWNERS
|
|
30
|
-
paths: |
|
|
31
|
-
${s}
|
|
32
|
-
`},ue=e=>{const t=D(e).map(o=>` - "${o}/*"`).join(`
|
|
33
|
-
`);return`# ${x}
|
|
34
|
-
#
|
|
35
|
-
# SOFT GUARD ONLY — this job does NOT block a merge by itself.
|
|
36
|
-
# It verifies the generated CODEOWNERS is in sync and flags that a
|
|
37
|
-
# restricted path changed. GitLab CI cannot portably gate a merge on
|
|
38
|
-
# code-owner *approval* from a job, so REAL ENFORCEMENT REQUIRES the
|
|
39
|
-
# native GitLab setting:
|
|
40
|
-
# Settings -> Repository -> Protected branches ->
|
|
41
|
-
# "Require approval from Code Owners" (GitLab Premium / Ultimate)
|
|
42
|
-
# https://docs.gitlab.com/ee/user/project/codeowners/
|
|
43
|
-
# Without that setting enabled, this job is advisory only.
|
|
44
|
-
write-guard:
|
|
45
|
-
stage: test
|
|
46
|
-
image: node:22-alpine
|
|
47
|
-
rules:
|
|
48
|
-
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
49
|
-
changes:
|
|
50
|
-
${t}
|
|
51
|
-
script:
|
|
52
|
-
- corepack enable
|
|
53
|
-
- pnpm install --frozen-lockfile
|
|
54
|
-
- pnpm vis sync codeowners --check
|
|
55
|
-
- >-
|
|
56
|
-
echo "SOFT GUARD: a restricted path changed. This job does NOT enforce
|
|
57
|
-
code-owner approval. Enable 'Require approval from Code Owners' on the
|
|
58
|
-
protected branch (GitLab Premium/Ultimate) for a real merge gate:
|
|
59
|
-
https://docs.gitlab.com/ee/user/project/codeowners/"
|
|
60
|
-
`},he=e=>e.length===0?[]:[{content:pe(e),path:".github/workflows/write-guard.yml"},{content:ue(e),path:".gitlab/write-guard.gitlab-ci.yml"}],L=new Set(["nested-codeowners","package-json-maintainers","project-json"]),A=(e,t,o)=>{const s=new Set,n=[];for(const r of e??[])for(const i of r.split(",")){const a=i.trim();if(a.length===0)continue;if(o&&!o(a))throw new Error(`Unknown codeowners source: "${a}". Known: ${[...L].join(", ")}.`);const c=a;s.has(c)||(s.add(c),n.push(c))}return n.length>0?n:[...t]},ge=e=>L.has(e),G=["codeowners","package-json-fields"],me=(e,t)=>t.some(o=>_(o,e)),we=async(e,t,o,s,n)=>{const r=Object.entries(s.projects).filter(([,a])=>a.restricted===!0).map(([a,c])=>({name:a,root:c.root??a})),i=he(r);if(i.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(n){let a=!1;for(const c of i){const f=b(o,c.path);let h="";try{h=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}h.trim()!==c.content.trim()&&(t.error(`${c.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),a=!0)}a?process.exitCode=1:t.info(`Write Guard CI is up to date (${i.length} files, ${r.length} restricted projects).`);return}for(const a of i){const c=b(o,a.path);T(P(c)),I(c,a.content),t.info(`Wrote ${a.path}`)}t.info(`Write Guard CI scoped to ${r.length} restricted project${r.length===1?"":"s"}.`)},$e=async({fs:e,logger:t,options:o,visConfig:s,workspaceRoot:n})=>{const r=n,{workspace:i}=J(r,s),a=s?.codeowners;o.writeGuard===!0&&await we(e,t,r,i,o.check===!0);const c=A(o.from,a?.sources??["project-json"],ge),f=o.regenerationCommand??a?.regenerationCommand,h=o.preserveBlock===!0||a?.preserveBlock===!0,p=a?.blockMarker??O,$=o.nestedIncludes??a?.nestedIncludes,g=o.out??"CODEOWNERS",w=[];if(c.includes("nested-codeowners")){const m=await ne(r,$,g);for(const j of m)w.push({...j,source:"nested"})}if(c.includes("package-json-maintainers")){const m=ae(i,r);for(const j of m)w.push({...j,source:"maintainers"})}const l=c.includes("project-json")?v(i,a,w):v({projects:{}},a,w);if(l.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const y=b(r,g);let d="";try{d=await e.readFile(y,"utf8")}catch(m){if(m.code!=="ENOENT")throw m}const u={regenerationCommand:f},k=h?X(d,V(l,p,u),p):Y(l,u);if(o.check){if(d.trim()!==k.trim()){t.error(`${y} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${y} is up to date.`);return}I(y,k),t.info(`Wrote ${l.length} entries to ${y}`)},ke=({logger:e,options:t,visConfig:o,workspaceRoot:s})=>{const n=s,r=o?.editorconfig??!0,i=C(b(n,"package.json"));if(!i){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const a=A(t.fields,ie),c=t.ignorePackageName??[],f=t.check===!0,h=(t.format??"human").toLowerCase(),p=t.quiet===!0,$=M(n).filter(d=>d!=="."),g=[];let w=0;for(const d of $){const u=b(n,d,"package.json"),k=C(u);if(!k)continue;const m=typeof k.name=="string"?k.name:void 0;if(m!==void 0&&c.length>0&&me(m,c))continue;w+=1;const j=de(i,k,{fields:a});j.length!==0&&g.push({filePath:u,packageJsonPath:S(n,u),packageName:m,pkg:k,pkgChanges:j})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),U(d.filePath,d.pkg,{indent:q(d.filePath,{useEditorconfig:r}),overwrite:!0});const l=g.flatMap(d=>d.pkgChanges.map(u=>({after:u.after,before:u.before,field:u.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),y={changes:l,fields:a,kind:"package-json-fields",mode:f?"check":"write",totalChanges:l.length,totalPackages:w};if(h==="json")process.stdout.write(`${JSON.stringify(y,null,4)}
|
|
61
|
-
`);else if(l.length===0)e.info(`All ${w} package${w===1?"":"s"} in sync (fields: ${a.join(", ")}).`);else if(f){if(!p)for(const d of l)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${l.length} field drift${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(u=>u.field).join(", ")}`);e.info(`Synced ${l.length} field${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&l.length>0&&(process.exitCode=1)},Oe=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${G.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await $e(e);return}if(t==="package-json-fields"){ke(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${G.join(", ")}.`)};export{Oe as default};
|
|
1
|
+
import{createRequire as G}from"node:module";import{I as q,j as Z,E as O,V as K,s as T,q as D}from"../packem_shared/index.server-J83sowC4.js";import{y as B}from"../packem_shared/index-CE6MsgcV.js";import{Z as Q}from"./cli-main.js";import{d as k,f as v,r as X,a as Y,b as ee,s as ne,c as te,e as ie,u as re,h as se,i as oe,j as ae,k as le,l as ce,m as de,n as ue,v as fe,w as ge,q as pe,t as me}from"../packem_shared/watch-loop-JfGKIgKB.js";import{p as c}from"./catalog.js";const H=G(import.meta.url),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,U=e=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[n,t]=w.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return w.getBuiltinModule(e)}return H(e)},{createHash:y}=U("node:crypto"),he={1:"warning",2:"error"},xe={argsCheck:(e,n)=>V(e,n,!1),argsFix:(e,n)=>V(e,n,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,n)=>{const t=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.eslint.packageNames[0]),i=v(e,c.eslint.configFiles);if(!(!t&&!i))return{adapter:"eslint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:n.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.messages)i.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":he[s.severity]??"warning"});return i}},V=(e,n,t)=>{const i=["--format","json","--no-error-on-unmatched-pattern"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},we=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,ke=e=>{const n=we.exec(e);if(!n)return;const[,t,i,r,s,a]=n;return{column:r===void 0?void 0:Number(r),file:t,line:Number(i),message:a,ruleId:s}},ve=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),ye={argsCheck:(e,n)=>J(e,n,!1),argsFix:(e,n)=>J(e,n,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,n)=>{const t=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=c.markdownlint.packageNames.map(r=>k(n,r)).find(r=>r!==void 0),i=v(e,c.markdownlint.configFiles);if(!(!t&&!i))return{adapter:"markdownlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,n)=>{const t=(e.stderr||e.stdout||"").trim();if(!t)return[];const i=[];for(const r of t.split(/\r?\n/)){const s=ke(r.trim());s&&i.push({adapter:"markdownlint",column:s.column,file:ve(s.file)?s.file:`${n.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return i}},J=(e,n,t)=>{const i=[];return t&&i.push("--fix"),n.extraArgs?.length&&i.push(...n.extraArgs),e.length===0?i.push("**/*.md"):i.push(...e),i},$e={advice:"info",error:"error",warning:"warning"},be={argsCheck:(e,n)=>R(e,n,!1),argsFix:(e,n)=>R(e,n,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,n)=>{const t=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.oxlint.packageNames[0]),i=v(e,c.oxlint.configFiles);if(!(!t&&!i))return{adapter:"oxlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:n.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.diagnostics??[]){const s=r.labels?.[0]?.span;i.push({adapter:"oxlint",column:s?.column,file:r.filename??n.root,fixable:!1,line:s?.line,message:r.message??"",ruleId:r.code,severity:$e[r.severity??""]??"warning"})}return i}},R=(e,n,t)=>{const i=["--format","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push(`--max-warnings=${String(n.maxWarnings)}`),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},Ae={error:"error",info:"info",style:"info",warning:"warning"},Fe=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),je=(e,n)=>e?Fe(e)?e:`${n}/${e}`:n,Ce={argsCheck:(e,n)=>L(e,n),argsFix:(e,n)=>L(e,n),bin:()=>["shellcheck"],cacheKey:(e,n)=>{const t=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.shellcheck.packageNames[0]),i=v(e,c.shellcheck.configFiles);if(!(!t&&!i))return{adapter:"shellcheck",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:n.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.comments??[])i.push({adapter:"shellcheck",column:r.column,endColumn:r.endColumn,endLine:r.endLine,file:je(r.file,n.root),fixable:!!r.fix,line:r.line,message:r.message??"",ruleId:r.code===void 0?void 0:`SC${String(r.code)}`,severity:Ae[r.level??""]??"warning"});return i}},L=(e,n)=>{const t=["--format=json1"];return n.extraArgs?.length&&t.push(...n.extraArgs),t.push(...e),t},Se={error:"error",warning:"warning"},qe={argsCheck:(e,n)=>M(e,n,!1),argsFix:(e,n)=>M(e,n,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,n)=>{const t=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.stylelint.packageNames[0]),i=v(e,c.stylelint.configFiles);if(!(!t&&!i))return{adapter:"stylelint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:n.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.warnings??[])i.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Se[s.severity??""]??"warning"});return i}},M=(e,n,t)=>{const i=["--formatter","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},We=[be,ue,xe,qe,fe,ye,Ce,ge],Be=async({logger:e,options:n,visConfig:t,workspaceRoot:i})=>{const r=i??process.cwd(),s=t?.lint,a=X(We,s?.order),j=Y(r,a),d=ee(j,a,"lint").filter(({adapter:l})=>s?.adapters?.[l.id]?.enabled!==!1);if(d.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno).");return}const C=l=>{const u=s?.adapters?.[l]?.extraArgs;return u&&u.length>0?[...u]:void 0},$={extraArgs:void 0,maxWarnings:typeof n.maxWarnings=="number"?n.maxWarnings:void 0,quiet:n.quiet??!1},b=Ne(n),P=n.fix?"fix":"check";let f;if(n.staged){if(f=ne(r),f===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(f.length===0){e.info(q("✓ lint: no staged files"));return}}else if(typeof n.since=="string"&&n.since.length>0){if(f=te(r,n.since),f===void 0)e.warn(`vis lint: could not resolve --since ${n.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(f.length===0){e.info(q(`✓ lint: no files changed since ${n.since}`));return}}const W=b.length>0?b:void 0,E=Q(r,void 0,void 0,!0),S=n.format??"human";S==="human"&&n.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const N=async l=>{const u=l!==void 0&&l.length>0&&W===void 0,m=[];for(const{adapter:o,presence:x}of d){let g;if(u){if(g=re(l,o.extensions),g.length===0)continue}else g=W??l??["."];const F=C(o.id),I={adapter:o,files:g,presence:x};F&&(I.options={...$,extraArgs:F}),m.push(I)}if(m.length===0)return;const z=await se(m,$,P,{cacheRoot:E}),A=m.map((o,x)=>{const g=z[x],F=o.adapter.parse(g,o.presence);return{adapter:o.adapter,durationMs:g.durationMs,exitCode:g.exitCode,findings:F}}),h=oe(A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,exitCode:o.exitCode,findingCount:o.findings.length,findings:o.findings}))),p=S==="human"?void 0:ae({cwd:r,target:n.output});try{switch(S){case"github":{p.write(de({runs:A.map(o=>({findings:o.findings})),workspaceRoot:r}));break}case"json":{p.write(`${JSON.stringify({findings:h.findings,runs:h.runs},null,2)}
|
|
2
|
+
`);break}case"junit":{p.write(ce({runs:A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,findings:o.findings})),workspaceRoot:r}));break}case"minimal":{Ie(h.findings,r,p);break}case"sarif":{p.write(le({runs:A.map(o=>({adapter:o.adapter.id,findings:o.findings,presence:m.find(x=>x.adapter.id===o.adapter.id)?.presence})),workspaceRoot:r}));break}default:_e(h.findings,r,e)}}finally{p?.close()}const _=me(h);_!==0&&(process.exitCode=_)};if(n.watch){const l=[...new Set(d.flatMap(({adapter:u})=>u.extensions))];await ie({extensions:l,initialFiles:f,label:"lint",log:u=>{e.info(u)},runCycle:N,workspaceRoot:r});return}await N(f)},Ne=e=>{const n=e;return[...n._??n.args??[]]},_e=(e,n,t)=>{if(e.length===0){t.info(q("✓ lint: no findings"));return}const i=pe(e);for(const[a,j]of i){t.info(Z(B(n,a)));for(const d of j){const C=Oe(d),$=Ve(d.severity),b=d.ruleId?O(` ${d.ruleId}`):"";t.info(` ${O(C)} ${$} ${d.message}${b}`)}}const r=e.filter(a=>a.severity==="error").length,s=e.filter(a=>a.severity==="warning").length;t.info(""),t.info(`${K(`${String(r)} error${r===1?"":"s"}`)}, ${T(`${String(s)} warning${s===1?"":"s"}`)}`)},Ie=(e,n,t)=>{for(const i of e){const r=B(n,i.file),s=i.line??"",a=i.column??"";t.write(`${i.adapter} ${r} ${String(s)} ${String(a)} ${i.severity} ${i.ruleId??""} ${i.message}
|
|
3
|
+
`)}},Oe=e=>e.line===void 0?"":e.column===void 0?String(e.line):`${String(e.line)}:${String(e.column)}`,Ve=e=>e==="error"?K("error"):e==="warning"?T("warn "):D("info ");export{Be as default};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import{createRequire as H}from"node:module";import{I as q,j as D,E as O,V as K,s as T,q as Q}from"../packem_shared/index.server-J83sowC4.js";import{y as B}from"../packem_shared/index-OQZQyN5R.js";import{aG as c,aH as X}from"./cli-main.js";import{d as k,f as v,r as Y,a as Z,b as ee,s as ne,c as te,e as ie,u as re,h as se,i as oe,j as ae,k as le,l as ce,m as de,n as ue,v as fe,w as ge,q as pe,t as me}from"../packem_shared/watch-loop-D9zbXzRd.js";const z=H(import.meta.url),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,U=e=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[n,t]=w.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return w.getBuiltinModule(e)}return z(e)},{createHash:y}=U("node:crypto"),he={1:"warning",2:"error"},xe={argsCheck:(e,n)=>V(e,n,!1),argsFix:(e,n)=>V(e,n,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,n)=>{const t=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.eslint.packageNames[0]),i=v(e,c.eslint.configFiles);if(!(!t&&!i))return{adapter:"eslint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:n.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.messages)i.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":he[s.severity]??"warning"});return i}},V=(e,n,t)=>{const i=["--format","json","--no-error-on-unmatched-pattern"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},we=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,ke=e=>{const n=we.exec(e);if(!n)return;const[,t,i,r,s,a]=n;return{column:r===void 0?void 0:Number(r),file:t,line:Number(i),message:a,ruleId:s}},ve=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),ye={argsCheck:(e,n)=>J(e,n,!1),argsFix:(e,n)=>J(e,n,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,n)=>{const t=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=c.markdownlint.packageNames.map(r=>k(n,r)).find(r=>r!==void 0),i=v(e,c.markdownlint.configFiles);if(!(!t&&!i))return{adapter:"markdownlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,n)=>{const t=(e.stderr||e.stdout||"").trim();if(!t)return[];const i=[];for(const r of t.split(/\r?\n/)){const s=ke(r.trim());s&&i.push({adapter:"markdownlint",column:s.column,file:ve(s.file)?s.file:`${n.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return i}},J=(e,n,t)=>{const i=[];return t&&i.push("--fix"),n.extraArgs?.length&&i.push(...n.extraArgs),e.length===0?i.push("**/*.md"):i.push(...e),i},$e={advice:"info",error:"error",warning:"warning"},be={argsCheck:(e,n)=>R(e,n,!1),argsFix:(e,n)=>R(e,n,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,n)=>{const t=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.oxlint.packageNames[0]),i=v(e,c.oxlint.configFiles);if(!(!t&&!i))return{adapter:"oxlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:n.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.diagnostics??[]){const s=r.labels?.[0]?.span;i.push({adapter:"oxlint",column:s?.column,file:r.filename??n.root,fixable:!1,line:s?.line,message:r.message??"",ruleId:r.code,severity:$e[r.severity??""]??"warning"})}return i}},R=(e,n,t)=>{const i=["--format","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push(`--max-warnings=${String(n.maxWarnings)}`),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},Ae={error:"error",info:"info",style:"info",warning:"warning"},Fe=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),je=(e,n)=>e?Fe(e)?e:`${n}/${e}`:n,Ce={argsCheck:(e,n)=>L(e,n),argsFix:(e,n)=>L(e,n),bin:()=>["shellcheck"],cacheKey:(e,n)=>{const t=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.shellcheck.packageNames[0]),i=v(e,c.shellcheck.configFiles);if(!(!t&&!i))return{adapter:"shellcheck",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:n.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.comments??[])i.push({adapter:"shellcheck",column:r.column,endColumn:r.endColumn,endLine:r.endLine,file:je(r.file,n.root),fixable:!!r.fix,line:r.line,message:r.message??"",ruleId:r.code===void 0?void 0:`SC${String(r.code)}`,severity:Ae[r.level??""]??"warning"});return i}},L=(e,n)=>{const t=["--format=json1"];return n.extraArgs?.length&&t.push(...n.extraArgs),t.push(...e),t},Se={error:"error",warning:"warning"},qe={argsCheck:(e,n)=>M(e,n,!1),argsFix:(e,n)=>M(e,n,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,n)=>{const t=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.stylelint.packageNames[0]),i=v(e,c.stylelint.configFiles);if(!(!t&&!i))return{adapter:"stylelint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:n.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.warnings??[])i.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Se[s.severity??""]??"warning"});return i}},M=(e,n,t)=>{const i=["--formatter","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},We=[be,ue,xe,qe,fe,ye,Ce,ge],Te=async({logger:e,options:n,visConfig:t,workspaceRoot:i})=>{const r=i??process.cwd(),s=t?.lint,a=Y(We,s?.order),j=Z(r,a),d=ee(j,a,"lint").filter(({adapter:l})=>s?.adapters?.[l.id]?.enabled!==!1);if(d.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno).");return}const C=l=>{const u=s?.adapters?.[l]?.extraArgs;return u&&u.length>0?[...u]:void 0},$={extraArgs:void 0,maxWarnings:typeof n.maxWarnings=="number"?n.maxWarnings:void 0,quiet:n.quiet??!1},b=Ne(n),P=n.fix?"fix":"check";let f;if(n.staged){if(f=ne(r),f===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(f.length===0){e.info(q("✓ lint: no staged files"));return}}else if(typeof n.since=="string"&&n.since.length>0){if(f=te(r,n.since),f===void 0)e.warn(`vis lint: could not resolve --since ${n.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(f.length===0){e.info(q(`✓ lint: no files changed since ${n.since}`));return}}const W=b.length>0?b:void 0,E=X(r,void 0,void 0,!0),S=n.format??"human";S==="human"&&n.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const N=async l=>{const u=l!==void 0&&l.length>0&&W===void 0,m=[];for(const{adapter:o,presence:x}of d){let g;if(u){if(g=re(l,o.extensions),g.length===0)continue}else g=W??l??["."];const F=C(o.id),I={adapter:o,files:g,presence:x};F&&(I.options={...$,extraArgs:F}),m.push(I)}if(m.length===0)return;const G=await se(m,$,P,{cacheRoot:E}),A=m.map((o,x)=>{const g=G[x],F=o.adapter.parse(g,o.presence);return{adapter:o.adapter,durationMs:g.durationMs,exitCode:g.exitCode,findings:F}}),h=oe(A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,exitCode:o.exitCode,findingCount:o.findings.length,findings:o.findings}))),p=S==="human"?void 0:ae({cwd:r,target:n.output});try{switch(S){case"github":{p.write(de({runs:A.map(o=>({findings:o.findings})),workspaceRoot:r}));break}case"json":{p.write(`${JSON.stringify({findings:h.findings,runs:h.runs},null,2)}
|
|
2
|
-
`)
|
|
3
|
-
`)}},
|
|
1
|
+
import{createRequire as V}from"node:module";import{y as L,v as _,m as P,f as M,J as z,B as Y}from"../packem_shared/index-CE6MsgcV.js";import{m as t,n as a,i as c,r as v,$ as K,c as U,k as Q,s as Z,t as ee,u as re,e as te,W as N}from"./catalog.js";import"../packem_shared/env-C2ZCnfP_.js";import"../packem_shared/window-ops-DDePlWLV.js";import{I as se}from"../packem_shared/index-B0EsgdzO.js";import oe from"./index.js";import{sortPackageJsonStringWithOptions as q}from"#native";import{U as ne,V as ie,W as le,T as ce,y as ae,p as k}from"./cli-main.js";import{o as O}from"../packem_shared/utils-CRueU43T.js";const Ke=V(import.meta.url),Ue=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const A={error:0,rewritten:1,"would-rewrite":1,unchanged:2},de=e=>[...e].sort((r,s)=>A[r.status]-A[s.status]),ue=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class fe{#e;#r=new Set;constructor(r){this.#e={entries:de(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>ue(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.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()}}const he=({checkMode:e,entry:r,focused:s,scrollRef:l})=>{const i=s?"white":"gray";return r?t.jsxs(a,{borderColor:i,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(a,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(c,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(ne,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(c,{}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(c,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Path:"})}),t.jsx(c,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Step:"})}),t.jsx(c,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Position:"})}),t.jsx(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(a,{marginTop:1,children:t.jsx(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(o=>{const n=`${o.isErrorLine?"❯":" "} ${String(o.lineNumber).padStart(4)} `;return t.jsxs(a,{children:[t.jsx(c,{color:o.isErrorLine?"red":"gray",children:n}),t.jsx(c,{color:o.isErrorLine?"white":"gray",wrap:"truncate-end",children:o.content||" "})]},o.lineNumber)}),r.error.context.column>0&&t.jsx(a,{children:t.jsx(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(o=>{const n=o.toIndex-o.fromIndex,d=n<0?`↑ ${String(Math.abs(n))}`:`↓ ${String(n)}`,g=n<0?"green":"yellow";return t.jsxs(a,{children:[t.jsx(a,{width:28,children:t.jsx(c,{wrap:"truncate",children:o.key})}),t.jsx(a,{width:10,children:t.jsxs(c,{dimColor:!0,children:[String(o.fromIndex)," → ",String(o.toIndex)]})}),t.jsx(c,{color:g,children:d})]},o.key)})}),e&&r.status==="would-rewrite"&&t.jsx(a,{marginTop:1,paddingLeft:2,children:t.jsx(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(c,{dimColor:!0,children:"No entry selected"})})},ge={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},pe={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},H={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},xe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},me=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],W=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[H[s.status]]++;return r},we=({entry:e,isSelected:r})=>{const s=ge[e.status],l=pe[e.status];return t.jsxs(a,{flexShrink:0,height:1,children:[t.jsx(c,{children:r?">":" "}),t.jsx(c,{children:" "}),t.jsx(c,{bold:!0,color:s,children:`[${l}]`.padEnd(10)}),t.jsx(c,{children:" "}),t.jsx(a,{flexGrow:1,children:t.jsx(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},je=({color:e,count:r,label:s})=>t.jsx(a,{flexShrink:0,height:1,children:t.jsx(c,{bold:!0,color:e,children:`${s} (${String(r)})`})}),ye=({counts:e,entries:r,filterType:s,focused:l,selectedIndex:i,totalEntries:o,viewportHeight:n})=>{const d=l?"white":"gray",g=W(r),m=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),y=s==="all"&&m>1,h=[];let w;for(const[u,x]of r.entries()){const b=H[x.status];y&&b!==w&&(w!==void 0&&h.push({kind:"spacer"}),h.push({color:b==="errors"?"red":b==="rewrites"?"yellow":"green",count:g[b],kind:"header",label:xe[b]}),w=b),h.push({entry:x,entryIndex:u,kind:"entry"})}const p=h.findIndex(u=>u.kind==="entry"&&u.entryIndex===i),S=p!==-1,j=h.length,$=Math.max(0,j-n);let f=0;S&&n>0&&(f=Math.min($,Math.max(0,p-n+1)));const E=j>n&&n>0;return t.jsxs(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(a,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(c,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(c,{wrap:"truncate",children:[o," ","file",o===1?"":"s"]})]}),t.jsx(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:me.map(u=>{const x=s===u.key,b=u.count(e);return t.jsxs(a,{children:[t.jsx(c,{dimColor:!x,children:"["}),t.jsx(c,{bold:x,color:x?"cyan":"gray",children:u.shortcut}),t.jsx(c,{dimColor:!x,children:"]"}),t.jsxs(c,{color:x?"white":"gray",children:[" ",u.label]}),t.jsxs(c,{dimColor:!0,children:[" ","(",b,")"]})]},u.key)})}),t.jsxs(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(a,{flexDirection:"column",marginTop:-f,children:h.map((u,x)=>u.kind==="spacer"?t.jsx(a,{flexShrink:0,height:1},`s-${String(x)}`):u.kind==="header"?t.jsx(je,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):t.jsx(we,{entry:u.entry,isSelected:u.entryIndex===i},u.entry.filePath))})}),E&&t.jsx(a,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(ie,{contentHeight:j,placement:"inset",scrollOffset:f,style:"block",viewportHeight:n})})]})]})},be=100,D=10,ke=6,Se=1,F={1:"all",2:"rewritten",3:"errors",4:"unchanged"},$e=({checkMode:e,store:r})=>{const{exit:s}=le(),{columns:l,rows:i}=ce(),o=v.useSyncExternalStore(r.subscribe,r.getSnapshot),n=v.useRef(null),d=r.getFilteredEntries(),g=d[o.selectedIndex]??null,m=W(o.entries),y=l>=be,h=Math.max(0,i-Se),w=y?h:Math.floor(h/2),p=Math.max(0,w-ke),S=v.useCallback(()=>{s()},[s]),j=v.useRef(0),$=v.useRef(void 0),f=v.useRef(!1),E=v.useCallback((u,x)=>{j.current+=x,$.current=u,!f.current&&(f.current=!0,queueMicrotask(()=>{f.current=!1;const b=j.current,T=$.current;j.current=0,$.current=void 0,!(b===0||T===void 0)&&(T==="list"?r.selectStep(Math.sign(b)):n.current?.scrollBy(Math.sign(b)))}))},[r]);return ae((u,x)=>{if(u==="q"||x.escape){S();return}if(F[u]){r.setFilter(F[u]);return}if(x.tab){r.setFocusedPanel(o.focusedPanel==="list"?"detail":"list");return}o.focusedPanel==="list"?x.upArrow||u==="k"?E("list",-1):(x.downArrow||u==="j")&&E("list",1):o.focusedPanel==="detail"&&(x.upArrow||u==="k"?E("detail",-1):(x.downArrow||u==="j")&&E("detail",1))}),i<D?t.jsx(a,{alignItems:"center",justifyContent:"center",children:t.jsxs(c,{color:"yellow",children:["Terminal too small. Resize to at least",D," ","rows."]})}):t.jsxs(a,{flexDirection:"column",height:i,width:l,children:[t.jsxs(a,{flexDirection:y?"row":"column",flexGrow:1,children:[t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(ye,{counts:m,entries:d,filterType:o.filterType,focused:o.focusedPanel==="list",selectedIndex:o.selectedIndex,totalEntries:o.entries.length,viewportHeight:p})}),t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(he,{checkMode:e,entry:g,focused:o.focusedPanel==="detail",scrollRef:n})})]}),t.jsx(a,{flexShrink:0,paddingX:1,children:t.jsx(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},B=["types","node-addons","node","import","require","default"],ve=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Ee=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),I=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>I(s));const r={};for(const[s,l]of Object.entries(e))r[s]=I(l);return r},Pe=e=>{if(!C(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}},Oe=e=>e.endsWith(".git")?e.slice(0,-4):e,Ce=e=>{if(!C(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:s}=e;if(typeof s!="string")return{changed:!1,value:e};const l=ve.exec(s)??Ee.exec(s);if(!l)return{changed:!1,value:e};const i=l[1],o=Oe(l[2]??"");if(!i||!o)return{changed:!1,value:e};const n=new Set(["type","url"]);for(const d of Object.keys(e))if(!n.has(d))return{changed:!1,value:e};return{changed:!0,value:`${i}/${o}`}},Re=e=>{const r=Object.keys(e),s=[],l=[];for(const n of B)Object.hasOwn(e,n)&&s.push(n);for(const n of r)B.includes(n)||l.push(n);const i=[...s,...l];if(i.length===r.length&&i.every((n,d)=>n===r[d]))return{changed:!1,value:e};const o={};for(const n of i)o[n]=e[n];return{changed:!0,value:o}},X=e=>{if(!C(e))return{changed:!1,value:e};let r=!1;const s={};for(const[i,o]of Object.entries(e)){const n=X(o);s[i]=n.value,n.changed&&(r=!0)}const l=Re(s);return{changed:r||l.changed,value:l.value}},Ie=(e,r)=>{const s=I(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const i=Pe(s.bugs);i.changed&&(s.bugs=i.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const i=Ce(s.repository);i.changed&&(s.repository=i.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&C(s.exports)){const i=X(s.exports);i.changed&&(s.exports=i.value,l=!0)}return{changed:l,pkg:s}},Te=/at position (\d+)/,Me=/\(?line (\d+) column (\d+)\)?/,Ne=e=>{const r=new Set,s=[],l=o=>{const n=Y(o);!r.has(n)&&M(n)&&(r.add(n),s.push(n))};l(P(e,"package.json"));const i=te(e);if(i){const o=N(e,i);for(const n of o)l(P(e,n,"package.json"))}else{const o=P(e,"package.json");if(M(o)){const n=JSON.parse(_(o)),d=Array.isArray(n.workspaces)?n.workspaces:n.workspaces?.packages;if(d){const g=N(e,d);for(const m of g)l(P(e,m,"package.json"))}}}return s},Ae=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",De=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},R=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),Fe=e=>e.includes(`\r
|
|
2
|
+
`)?"crlf":"lf",Be=new Set(["auto","crlf","lf"]),Ge=e=>{if(e===void 0||e==="")return"auto";if(Be.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},Je=(e,r,s)=>r.length===0?e:e.filter(l=>{const i=L(s,l),o=z(l);return!r.some(n=>{const d=n.includes("/")?i:o;return oe(n,d)})}),Le=(e,r)=>{if(r.length===0)return e;const s={},l=new Set;for(const i of r)Object.hasOwn(e,i)&&(s[i]=e[i],l.add(i));for(const i of Object.keys(e))l.has(i)||(s[i]=e[i]);return s},_e=(e,r,s)=>{if(s.length===0)return e;const l={...e};for(const i of s)Object.hasOwn(r,i)&&(l[i]=r[i]);return l},qe=(e,r)=>{let s=1,l=1;const i=Math.min(r,e.length);for(let o=0;o<i;o++)e.codePointAt(o)===10?(s++,l=1):l++;return{column:l,line:s}},G=(e,r,s=2)=>{const l=e.split(`
|
|
3
|
+
`);if(r<1||r>l.length)return[];const i=Math.max(0,r-1-s),o=Math.min(l.length,r+s),n=[];for(let d=i;d<o;d++)n.push({content:l[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return n},J=(e,r)=>{if(!(e instanceof Error))return;const s=Te.exec(e.message);if(s){const{column:i,line:o}=qe(r,Number.parseInt(s[1]??"0",10));return{column:i,line:o,snippet:G(r,o)}}const l=Me.exec(e.message);if(l){const i=Number.parseInt(l[1]??"1",10);return{column:Number.parseInt(l[2]??"1",10),line:i,snippet:G(r,i)}}},He=(e,r)=>{const s=Object.keys(JSON.parse(e)),l=Object.keys(JSON.parse(r)),i=new Map(s.map((n,d)=>[n,d])),o=[];for(const[n,d]of l.entries()){const g=i.get(d);g!==void 0&&g!==n&&o.push({fromIndex:g,key:d,toIndex:n})}return o},We=(e,r,s)=>{const l=r.indent??s.indent??Ae(e),i=r.lineEnding==="auto"?s.lineEnding??Fe(e):r.lineEnding,o=q(e,{pretty:!1,sortScripts:r.sortScripts});let n=JSON.parse(o);if(r.unsorted.length>0){const y=JSON.parse(e);n=_e(n,y,r.unsorted)}n=Le(n,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},g=Ie(n,d);let m=JSON.stringify(g.pkg,null,l);return r.finalNewline&&(m+=`
|
|
4
|
+
`),i==="crlf"&&(m=m.replaceAll(`
|
|
5
|
+
`,`\r
|
|
6
|
+
`)),m},Xe=(e,r)=>{const s=Ne(e),l=Q(e),i=Z({cwd:e,extraPatterns:ee(l)}),o=s.filter(d=>!i.ignores(d)),n=Je(o,r,e);return{afterGitignore:o,allFiles:s,files:n}},Ve=async(e,{checkMode:r,cwd:s,fs:l,normalized:i})=>{const o=L(s,e)||e;let n;try{n=_(e)}catch(h){return{diff:[],error:{message:O(h),step:"read"},filePath:e,relativePath:o,status:"error"}}let d;try{d=q(n,{pretty:!1,sortScripts:i.sortScripts})}catch(h){const w={message:O(h),step:"native-sort"},p=J(h,n);return p&&(w.context=p),{diff:[],error:w,filePath:e,relativePath:o,status:"error"}}const g=i.editorconfig?re(e):{};let m;try{m=We(n,i,g)}catch(h){const w={message:O(h),step:"json-parse"},p=J(h,n);return p&&(w.context=p),{diff:[],error:w,filePath:e,relativePath:o,status:"error"}}if(n===m)return{diff:[],filePath:e,relativePath:o,status:"unchanged"};let y;try{y=He(n,d)}catch{y=[]}if(r)return{diff:y,filePath:e,relativePath:o,status:"would-rewrite"};try{await l.writeFile(e,m,"utf8")}catch(h){return{diff:y,error:{message:O(h),step:"write"},filePath:e,relativePath:o,status:"error"}}return{diff:y,filePath:e,relativePath:o,status:"rewritten"}},ze=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 s=r.isErrorLine?">":" ";k.info(` ${s} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},lr=async({fs:e,options:r,visConfig:s,workspaceRoot:l})=>{const i=l??process.cwd(),o=s?.sortPackageJson,n=r.check||!1,d={editorconfig:r.editorconfig===!1?!1:o?.editorconfig??!0,finalNewline:r.finalNewline??o?.finalNewline??!0,formatBugs:r.formatBugs===!1?!1:o?.formatBugs??!0,formatRepository:r.formatRepository===!1?!1:o?.formatRepository??!0,ignore:[...R(r.ignore),...o?.ignore??[]],indent:De(r.indent??o?.indent),lineEnding:Ge(r.lineEnding??o?.lineEnding),sortExports:r.sortExports===!1?!1:o?.sortExports??!0,sortOrder:[...R(r.sortOrder),...o?.sortOrder??[]],sortScripts:r.sortScripts||o?.sortScripts||!1,unsorted:[...R(r.unsorted),...o?.unsorted??[]]},g=Xe(i,d.ignore),{afterGitignore:m,allFiles:y,files:h}=g;if(h.length===0){y.length===0?k.info("No package.json files found."):m.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 w=[];for(const f of h)w.push(await Ve(f,{checkMode:n,cwd:i,fs:e,normalized:d}));let p=0,S=0,j=0;for(const f of w)f.status==="error"?j++:f.status==="rewritten"||f.status==="would-rewrite"?p++:S++;const $=p>0||j>0;if(process.stdout.isTTY&&!se&&$){const f=new fe(w);await K(U.createElement($e,{checkMode:n,store:f}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const f of w)switch(f.status){case"error":{ze(f);break}case"rewritten":{k.success(`Sorted ${f.filePath}`);break}case"would-rewrite":{k.warn(`${f.filePath} is not sorted`);break}}if(n)p>0?(k.info(`${String(p)} file${p===1?"":"s"} not sorted, ${String(S)} already sorted`),process.exitCode=1):j===0&&k.info(`All ${String(S)} package.json file${S===1?" is":"s are"} sorted`);else{const f=[];p>0&&f.push(`sorted ${String(p)} file${p===1?"":"s"}`),S>0&&f.push(`${String(S)} already sorted`),j>0&&f.push(`${String(j)} error${j===1?"":"s"}`),f.length>0&&k.info(f.join(", "))}j>0&&(process.exitCode=1)};export{G as buildSnippet,He as computeKeyDiff,qe as computeLineColumn,lr as default,Xe as discoverPackageJsonFiles,J as extractParseErrorContext,Ve as processFile};
|