var fe=Object.defineProperty;var C=(r,e)=>fe(r,"name",{value:e,configurable:!0});import{createRequire as ue}from"node:module";import"../packem_shared/_commonjsHelpers-CLblCigl.js";import{r as xe}from"../packem_shared/glob-D_7bct6p-D8itOHsr.js";import{M as N,l as W,B as G,C as ye}from"../packem_shared/readFileSync-DseCu8sg-DEq4Fn3a.js";import{E as M,s as te}from"./config.js";import{t as ve,aV as je,a7 as t,a8 as m,n as c,aH as ke,aI as we,aJ as be,aG as $e,x as I,ah as Ce,aL as Oe,V as Se,u as X,p as j,k as Pe,R as Ee,s as Ne}from"./bin.js";import _e from"module-replacements/manifests/micro-utilities.json"with{type:"json"};import Te from"module-replacements/manifests/native.json"with{type:"json"};import De from"module-replacements/manifests/preferred.json"with{type:"json"};import{s as ne,A as Ae,y as Re}from"../packem_shared/pm-runner-DmKT2FqF.js";import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
const require = __cjs_mod__.createRequire(import.meta.url);
const me=ue(import.meta.url),R=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,he=C(r=>{if(typeof R<"u"&&R.versions&&R.versions.node){const[e,n]=R.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return R.getBuiltinModule(r)}return me(r)},"__cjs_getBuiltinModule"),{writeFileSync:ge}=he("node:fs");var Ie=Object.defineProperty,E=C((r,e)=>Ie(r,"name",{value:e,configurable:!0}),"d$1");const Me=["dependencies","devDependencies","peerDependencies","peerDependenciesMeta","optionalDependencies","bundleDependencies"],Fe=["overrides","pnpm","resolutions"],Ge=["engines","files"],Le=E(r=>{const e=ne.coerce(r)?.major;return e!==void 0&&e>=10},"isPnpmV10Plus"),qe=E(r=>{const e=N(r,"pnpm-workspace.yaml");if(!W(e))return{overrides:{},source:"pnpm-workspace.yaml"};try{return{overrides:ve(e)?.overrides??{},source:"pnpm-workspace.yaml"}}catch{return{overrides:{},source:"pnpm-workspace.yaml"}}},"readPnpmWorkspaceOverrides"),Ue=E((r,e)=>{let n={};return e==="deno"?{overrides:{},source:"package.json"}:(e==="pnpm"?n=r.pnpm?.overrides??{}:e==="yarn"||e==="bun"?n=r.resolutions??{}:n=r.overrides??{},{overrides:n,source:"package.json"})},"readPkgJsonOverrides"),ze=E((r,e,n)=>n.name==="pnpm"&&Le(n.version)?qe(r):Ue(e,n.name),"readOverrides"),K=E((r,e)=>{const n=e;for(const a of Fe){const i=r.indexOf(a);if(i!==-1&&a!==n)return n==="overrides"?i:i+1}let o=-1;for(const a of Me){const i=r.indexOf(a);i>o&&(o=i)}if(o!==-1)return o+1;for(const a of Ge){const i=r.indexOf(a);if(i!==-1)return i}return r.length},"findInsertIndex"),Je=E((r,e)=>{const n=N(r,"pnpm-workspace.yaml");if(!W(n))throw new Error(`pnpm-workspace.yaml not found at ${n}. Cannot write overrides for pnpm v10+.`);let o=G(n);const a=`overrides:
${Object.entries(e).map(([i,l])=>`  '${i}': '${l}'`).join(`
`)}
`;o=/^overrides:\s*$/m.test(o)||/^overrides:\s*\n/m.test(o)?o.replace(/^overrides:\s*\n(?:(?:[ \t].*)?\n)*/m,a):`${o.trimEnd()}

${a}`,M(n,o)},"writePnpmWorkspaceOverrides"),Be=E((r,e,n,o,a)=>{const i=G(r),l=je(r,i,{useEditorconfig:a});if(o==="pnpm"){const x=e.pnpm??{};if(x.overrides=n,e.pnpm)e.pnpm=x,M(r,`${JSON.stringify(e,null,l)}
`);else{const k=Object.keys(e),v=K(k,"pnpm"),y=Object.entries(e);y.splice(v,0,["pnpm",x]),M(r,`${JSON.stringify(Object.fromEntries(y),null,l)}
`)}}else{const x=o==="yarn"||o==="bun"?"resolutions":"overrides";if(e[x])e[x]=n,M(r,`${JSON.stringify(e,null,l)}
`);else{const k=Object.keys(e),v=K(k,x),y=Object.entries(e);y.splice(v,0,[x,n]),M(r,`${JSON.stringify(Object.fromEntries(y),null,l)}
`)}}},"writePkgJsonOverrides"),He=E((r,e,n,o,a)=>{if(o.name==="deno")return{added:[],updated:[]};const i=G(e),l=JSON.parse(i),{overrides:x,source:k}=ze(r,l,o),v=[],y=[],s=new Set;if(o.name==="npm")for(const p of["dependencies","devDependencies"]){const h=l[p];if(h)for(const g of Object.keys(h))s.add(g)}for(const p of n){const h=x[p.original];if(typeof h=="object")continue;let g=p.spec;o.name==="npm"&&s.has(p.original)&&(g=`$${p.original}`),h!==g&&(h?y.push(p.original):v.push(p.original),x[p.original]=g)}if(v.length===0&&y.length===0)return{added:v,updated:y};const f=Object.fromEntries(Object.entries(x).sort(([p],[h])=>p.localeCompare(h)));return k==="pnpm-workspace.yaml"?Je(r,f):Be(e,l,f,o.name,a),{added:v,updated:y}},"applyOverrides"),Ve=E((r,e)=>{const n={bun:["bun.lock"],deno:["deno.lock"],npm:["npm-shrinkwrap.json","package-lock.json"],pnpm:["pnpm-lock.yaml"],yarn:["yarn.lock"]};for(const o of n[e]??[]){const a=N(r,o);try{return G(a)}catch{continue}}return""},"readLockfileText"),We=E((r,e,n)=>{if(!r)return!1;const o=e.replaceAll(/[.*+?^${}()|[\]\\]/g,String.raw`\$&`);switch(n){case"bun":return r.includes(`"${e}":`)||new RegExp(String.raw`(^|\s|[",])${o}@`,"m").test(r);case"deno":return r.includes(`"${e}"`)||r.includes(`"npm:${e}@`)||r.includes(`"jsr:${e}@`);case"npm":return r.includes(`"${e}":`)||r.includes(`"node_modules/${e}":`);case"pnpm":return new RegExp(String.raw`(^|\s|['"/])${o}(@|['"]?:)`,"m").test(r);case"yarn":return new RegExp(String.raw`(^|\s|[",])${o}@`,"m").test(r);default:return!1}},"lockfileContainsPackage");var B={exports:{}},H,Y;function Q(){if(Y)return H;Y=1;var r=Object.defineProperty,e=C((s,f)=>r(s,"name",{value:f,configurable:!0}),"t"),n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,l=e((s,f)=>{for(var p in f)n(s,p,{get:f[p],enumerable:!0})},"__export"),x=e((s,f,p,h)=>{if(f&&typeof f=="object"||typeof f=="function")for(let g of a(f))!i.call(s,g)&&g!==p&&n(s,g,{get:e(()=>f[g],"get"),enumerable:!(h=o(f,g))||h.enumerable});return s},"__copyProps"),k=e(s=>x(n({},"__esModule",{value:!0}),s),"__toCommonJS"),v={};l(v,{PURL_Type:e(()=>y,"PURL_Type")}),H=k(v);var y=(s=>(s.APK="apk",s.BITBUCKET="bitbucket",s.COCOAPODS="cocoapods",s.CARGO="cargo",s.CHROME="chrome",s.COMPOSER="composer",s.CONAN="conan",s.CONDA="conda",s.CRAN="cran",s.DEB="deb",s.DOCKER="docker",s.GEM="gem",s.GENERIC="generic",s.GITHUB="github",s.GOLANG="golang",s.HACKAGE="hackage",s.HEX="hex",s.HUGGINGFACE="huggingface",s.MAVEN="maven",s.MLFLOW="mlflow",s.NPM="npm",s.NUGET="nuget",s.OCI="oci",s.PUB="pub",s.PYPI="pypi",s.QPKG="qpkg",s.RPM="rpm",s.SWID="swid",s.SWIFT="swift",s.VCS="vcs",s))(y||{});return H}C(Q,"requireTypes");var Z;function Xe(){return Z||(Z=1,(function(r){var e=Object.defineProperty,n=C((f,p)=>e(f,"name",{value:p,configurable:!0}),"a"),o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,l=Object.prototype.hasOwnProperty,x=n((f,p)=>{for(var h in p)o(f,h,{get:p[h],enumerable:!0})},"__export"),k=n((f,p,h,g)=>{if(p&&typeof p=="object"||typeof p=="function")for(let u of i(p))!l.call(f,u)&&u!==h&&o(f,u,{get:n(()=>p[u],"get"),enumerable:!(g=a(p,u))||g.enumerable});return f},"__copyProps"),v=n((f,p,h)=>(k(f,p,"default"),h&&k(h,p,"default")),"__reExport"),y={};x(y,{getManifestData:n(()=>s,"getManifestData")}),v(y,Q(),r.exports);function s(f,p){try{const h=require("../manifest.json");if(!f)return h;const g=h[f];if(!g)return;if(!p)return g;const u=g.find(([b,$])=>$.package===p);return u?u[1]:void 0}catch{return}}C(s,"getManifestData"),n(s,"getManifestData"),r.exports={getManifestData:s,...Q()}})(B)),B.exports}C(Xe,"requireDist");var Ke=Xe(),Ye=Object.defineProperty,F=C((r,e)=>Ye(r,"name",{value:e,configurable:!0}),"s");const Qe=F((r,e,n)=>{let o=r;if(e!=="all"&&(o=o.filter(a=>a.category===e)),n){const a=n.toLowerCase();o=o.filter(i=>i.packageName.toLowerCase().includes(a))}return o},"filterEntries");class Ze{static{C(this,"h")}static{F(this,"OptimizeStore")}#e;#t=new Set;constructor(e){this.#e={applyProgress:null,checkedEntries:new Set,entries:e,error:null,filterActive:!1,filterText:"",filterType:"all",focusedPanel:"list",phase:"browsing",selectedIndex:0}}getSnapshot=F(()=>this.#e,"getSnapshot");subscribe=F(e=>(this.#t.add(e),()=>{this.#t.delete(e)}),"subscribe");getFilteredEntries=F(()=>Qe(this.#e.entries,this.#e.filterType,this.#e.filterText),"getFilteredEntries");#r(){this.#e={...this.#e};for(const e of this.#t)e()}select(e){const n=this.getFilteredEntries();this.#e.selectedIndex=n.length===0?-1:Math.max(0,Math.min(e,n.length-1)),this.#r()}toggleCheck(e){const n=new Set(this.#e.checkedEntries);n.has(e)?n.delete(e):n.add(e),this.#e.checkedEntries=n,this.#r()}toggleAll(){const e=this.getFilteredEntries(),n=new Set(this.#e.checkedEntries);if(e.every(o=>n.has(o.packageName)))for(const o of e)n.delete(o.packageName);else for(const o of e)n.add(o.packageName);this.#e.checkedEntries=n,this.#r()}setFilter(e){this.#e.filterType=e,this.#e.selectedIndex=0,this.#r()}setFilterText(e){this.#e.filterText=e,this.#e.selectedIndex=0,this.#r()}setFilterActive(e){this.#e.filterActive=e,this.#r()}setFocusedPanel(e){this.#e.focusedPanel=e,this.#r()}setPhase(e){this.#e.phase=e,this.#r()}setProgress(e,n){this.#e.applyProgress={current:e,total:n},this.#r()}setError(e){this.#e.error=e,this.#e.phase="error",this.#r()}getCheckedEntries(){return this.#e.entries.filter(e=>this.#e.checkedEntries.has(e.packageName))}}const oe={"micro-utility":"gray",native:"green",preferred:"yellow",socket:"cyan"},er={"micro-utility":"MICRO",native:"NATIVE",preferred:"PREF",socket:"SOCKET"},rr={"micro-utility":"Trivial utility package that can be replaced with inline code.",native:"Polyfill for a native JS/Node.js API. Use the built-in instead.",preferred:"A lighter or faster alternative package exists.",socket:"Security-hardened replacement from Socket.dev's @socketregistry."};var tr=Object.defineProperty,nr=C((r,e)=>tr(r,"name",{value:e,configurable:!0}),"d");const or=nr(({entry:r,focused:e,scrollRef:n})=>{const o=e?"white":"gray";if(!r)return t.jsx(m,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(c,{dimColor:!0,children:"No entry selected"})});const a=oe[r.category]??"gray";return t.jsxs(m,{borderColor:o,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(m,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(c,{bold:!0,color:"white",children:r.packageName})}),t.jsxs(ke,{flexGrow:1,flexShrink:1,paddingX:2,ref:n,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(c,{}),t.jsxs(m,{children:[t.jsx(m,{width:14,children:t.jsx(c,{dimColor:!0,children:"Category:"})}),t.jsx(c,{bold:!0,color:a,children:r.category})]}),t.jsxs(m,{children:[t.jsx(m,{width:14,children:t.jsx(c,{dimColor:!0,children:"Replace with:"})}),t.jsx(c,{children:r.replacement})]}),r.overrideSpec&&t.jsxs(m,{children:[t.jsx(m,{width:14,children:t.jsx(c,{dimColor:!0,children:"Override:"})}),t.jsx(c,{color:"cyan",children:r.overrideSpec})]}),t.jsxs(m,{children:[t.jsx(m,{width:14,children:t.jsx(c,{dimColor:!0,children:"Codemod:"})}),t.jsx(c,{color:r.hasCodemod?"green":"gray",children:r.hasCodemod?"available ⚙":"not available"})]}),t.jsxs(m,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"DESCRIPTION"}),t.jsx(m,{marginTop:1,paddingLeft:2,children:t.jsx(c,{children:rr[r.category]??""})})]}),r.category==="native"&&t.jsxs(m,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"green",children:"ACTION"}),t.jsx(m,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.hasCodemod?t.jsxs(t.Fragment,{children:[t.jsxs(c,{color:"green",children:["✓"," ","Codemod will rewrite imports to use native API."]}),t.jsx(c,{dimColor:!0,children:" The package can then be removed from dependencies."})]}):t.jsxs(t.Fragment,{children:[t.jsxs(c,{color:"yellow",children:["ℹ"," ","No automated codemod available."]}),t.jsx(c,{dimColor:!0,children:" Manual migration required — replace usage with native equivalent."})]})})]}),r.category==="socket"&&t.jsxs(m,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"cyan",children:"ACTION"}),t.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(c,{color:"cyan",children:["✓"," ","Override will redirect resolution to the hardened package."]}),t.jsx(c,{dimColor:!0,children:" No source code changes needed — drop-in replacement."})]})]}),(r.category==="preferred"||r.category==="micro-utility")&&t.jsxs(m,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"yellow",children:"ACTION"}),t.jsx(m,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.hasCodemod?t.jsxs(t.Fragment,{children:[t.jsxs(c,{color:"green",children:["✓"," ","Codemod will rewrite imports to the recommended alternative."]}),t.jsx(c,{dimColor:!0,children:" The original package can then be removed from dependencies."})]}):t.jsxs(t.Fragment,{children:[t.jsxs(c,{color:"yellow",children:["ℹ"," ","Manual migration required."]}),r.docUrl?t.jsx(c,{dimColor:!0,children:" Open the migration guide below for the recommended alternative and steps."}):t.jsx(c,{dimColor:!0,children:" Consult the package's docs or the e18e module-replacements guide for an alternative."})]})})]}),t.jsxs(m,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"LINKS"}),t.jsxs(m,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(c,{color:"cyan",underline:!0,children:["https://npmx.dev/",r.packageName]}),r.docUrl&&t.jsx(c,{color:"cyan",underline:!0,children:r.docUrl})]})]})]})]})},"OptimizeDetailPanel");var ir=Object.defineProperty,ie=C((r,e)=>ir(r,"name",{value:e,configurable:!0}),"b$1");const sr=[{key:"all",label:"All",shortcut:"1"},{key:"native",label:"Native",shortcut:"2"},{key:"preferred",label:"Preferred",shortcut:"3"},{key:"micro-utility",label:"Micro",shortcut:"4"},{key:"socket",label:"Socket",shortcut:"5"}],ar=ie(({checked:r,entry:e,isSelected:n})=>{const o=oe[e.category]??"white",a=er[e.category]??e.category,i=r?"☑":"☐",l=e.hasCodemod?"⚙":" ";return t.jsxs(m,{flexShrink:0,height:1,children:[t.jsx(c,{children:n?">":" "}),t.jsxs(c,{color:r?"white":"gray",children:[" ",i," "]}),t.jsx(c,{bold:!0,color:o,children:`[${a}]`.padEnd(9)}),t.jsxs(c,{children:[" ",l," "]}),t.jsx(m,{flexGrow:1,children:t.jsx(c,{bold:n,inverse:n,wrap:"truncate",children:e.packageName})}),t.jsx(c,{dimColor:!0,children:" → "}),t.jsx(c,{wrap:"truncate",children:e.replacement})]})},"EntryRow"),cr=ie(({checkedEntries:r,entries:e,filterActive:n,filterText:o,filterType:a,focused:i,isDryRun:l,scrollOffset:x,selectedIndex:k,totalEntries:v,viewportHeight:y})=>{const s=i?"white":"gray";let f=0,p=0,h=0,g=0;for(const d of e)switch(d.category){case"micro-utility":{h++;break}case"native":{f++;break}case"preferred":{p++;break}case"socket":{g++;break}}const u=[];f>0&&u.push(`${f} native`),p>0&&u.push(`${p} preferred`),h>0&&u.push(`${h} micro`),g>0&&u.push(`${g} socket`);const b=u.length>0?` (${u.join(", ")})`:"",$=r.size,_=[];for(const[d,O]of e.entries())_.push(t.jsx(ar,{checked:r.has(O.packageName),entry:O,isSelected:d===k},O.packageName));const T=e.length,A=T>y&&y>0;return t.jsxs(m,{borderColor:s,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(m,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(c,{bold:!0,inverse:!0,children:" VIS OPTIMIZE "}),t.jsxs(c,{wrap:"truncate",children:[v," ","optimizations",b]}),!l&&$>0&&t.jsxs(c,{dimColor:!0,children:[" ","—",$," ","selected"]})]}),t.jsx(m,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:sr.map(d=>{const O=a===d.key;return t.jsxs(m,{children:[t.jsx(c,{dimColor:!O,children:"["}),t.jsx(c,{bold:O,color:O?"cyan":"gray",children:d.shortcut}),t.jsx(c,{dimColor:!O,children:"]"}),t.jsxs(c,{color:O?"white":"gray",children:[" ",d.label]})]},d.key)})}),n&&t.jsxs(m,{flexShrink:0,paddingX:1,children:[t.jsx(c,{bold:!0,color:"white",children:"/ "}),t.jsx(c,{children:o}),t.jsx(c,{inverse:!0,children:" "})]}),t.jsxs(m,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(m,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(m,{flexDirection:"column",marginTop:-x,children:_})}),A&&t.jsx(m,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(we,{contentHeight:T,placement:"inset",scrollOffset:x,style:"block",viewportHeight:y})})]})]})},"OptimizeListPanel");var lr=Object.defineProperty,dr=C((r,e)=>lr(r,"name",{value:e,configurable:!0}),"I$1");const pr=100,ee=10,re={1:"all",2:"native",3:"preferred",4:"micro-utility",5:"socket"},fr=dr(({isDryRun:r,store:e})=>{const{exit:n}=be(),{columns:o,rows:a}=$e(),i=I.useSyncExternalStore(e.subscribe,e.getSnapshot),l=I.useRef(null),[x,k]=I.useState(0),[v,y]=I.useState(!1),s=e.getFilteredEntries(),f=s[i.selectedIndex]??null,p=o>=pr,h=Math.max(0,a-5),g=I.useCallback(u=>{n(u)},[n]);return Ce((u,b)=>{if(v){u==="y"||u==="Y"?g():y(!1);return}if(i.filterActive){b.escape?(e.setFilterActive(!1),e.setFilterText("")):b.return?e.setFilterActive(!1):b.backspace||b.delete?e.setFilterText(i.filterText.slice(0,-1)):u&&!b.ctrl&&!b.meta&&e.setFilterText(i.filterText+u);return}if(u==="q"){!r&&i.checkedEntries.size>0?y(!0):g();return}if(u==="/"){e.setFilterActive(!0);return}if(re[u]){e.setFilter(re[u]);return}if(b.tab){e.setFocusedPanel(i.focusedPanel==="list"?"detail":"list");return}if(i.focusedPanel==="list")if(b.upArrow||u==="k"){const $=Math.max(0,i.selectedIndex-1);e.select($),$<x&&k($)}else if(b.downArrow||u==="j"){const $=Math.min(s.length-1,i.selectedIndex+1);e.select($),$>=x+h&&k($-h+1)}else u===" "?f&&e.toggleCheck(f.packageName):u==="a"?e.toggleAll():b.return&&!r&&i.checkedEntries.size>0&&g(e.getCheckedEntries());else i.focusedPanel==="detail"&&(b.upArrow||u==="k"?l.current?.scrollBy(-1):(b.downArrow||u==="j")&&l.current?.scrollBy(1))},{isActive:i.phase==="browsing"}),a<ee?t.jsx(m,{alignItems:"center",justifyContent:"center",children:t.jsxs(c,{color:"yellow",children:["Terminal too small. Resize to at least",ee," ","rows."]})}):t.jsxs(m,{flexDirection:"column",height:a,width:o,children:[t.jsxs(m,{flexDirection:p?"row":"column",flexGrow:1,children:[t.jsx(m,{flexBasis:p?"50%":void 0,flexGrow:1,children:t.jsx(cr,{checkedEntries:i.checkedEntries,entries:s,filterActive:i.filterActive,filterText:i.filterText,filterType:i.filterType,focused:i.focusedPanel==="list",isDryRun:r,scrollOffset:x,selectedIndex:i.selectedIndex,totalEntries:i.entries.length,viewportHeight:h})}),t.jsx(m,{flexBasis:p?"50%":void 0,flexGrow:1,children:t.jsx(or,{entry:f,focused:i.focusedPanel==="detail",scrollRef:l})})]}),t.jsx(m,{flexShrink:0,paddingX:1,children:t.jsxs(c,{dimColor:!0,children:[r?"Preview mode":"space:toggle a:all enter:apply"," ","| tab:switch panel /: filter q:quit |","⚙","=codemod available"]})}),t.jsx(Oe,{autoExitSeconds:3,onCancel:C(()=>{y(!1)},"onCancel"),visible:v})]})},"VisOptimizeApp");var ur=Object.defineProperty,S=C((r,e)=>ur(r,"name",{value:e,configurable:!0}),"p");const V=S((r,e)=>{const n=new Set;try{const o=te(r),a=e?[o.dependencies,o.optionalDependencies]:[o.dependencies,o.devDependencies,o.peerDependencies,o.optionalDependencies];for(const i of a)if(i)for(const l of Object.keys(i))n.add(l)}catch{}return n},"collectDepsFromPkgJson"),se=S(r=>{const e=Se(r);if(e)return X(r,e);const n=N(r,"package.json");if(!W(n))return[];try{const o=te(n),a=Array.isArray(o.workspaces)?o.workspaces:o.workspaces?.packages;return a?X(r,a):[]}catch{return[]}},"discoverWorkspacePackages"),mr="https://github.com/es-tooling/module-replacements/blob/main/docs/modules",hr=S(r=>`${mr}/${r}.md`,"buildE18eDocUrl"),gr=S(r=>{if(r.type==="simple"&&r.replacement)return r.replacement;if(r.type==="native"){const e=r.nodeVersion?` (Node ${r.nodeVersion}+)`:"";return r.replacement?`${r.replacement}${e}`:`Native API${e}`}return r.type==="documented"&&r.docPath?"see migration guide":""},"e18eReplacementHint"),ae=S(r=>{const e=[],n=S((o,a)=>{const i=o.moduleReplacements;if(Array.isArray(i))for(const l of i)r.has(l.moduleName)&&e.push({category:a,docUrl:l.type==="documented"&&l.docPath?hr(l.docPath):void 0,hasCodemod:!1,overrideSpec:void 0,packageName:l.moduleName,replacement:gr(l)})},"scanManifest");return n(Te,"native"),n(De,"preferred"),n(_e,"micro-utility"),e},"buildE18eEntries"),ce=S((r,e,n,o)=>{const a=Ke.getManifestData("npm")??[],i=[];for(const[,l]of a){if(l.deprecated)continue;const x=r.has(l.package),k=e?We(e,l.package,n.name):!1;if(!x&&!k)continue;const v=ne.coerce(l.version)?.major;if(v===void 0)continue;const y=o?`npm:${l.name}@${l.version}`:`npm:${l.name}@^${String(v)}`;i.push({category:"socket",hasCodemod:!1,overrideSpec:y,packageName:l.package,replacement:l.name})}return i},"buildSocketEntries");let z;const le=S(async()=>{if(z)return z;try{return z=(await import("module-replacements-codemods")).codemods,z}catch{return{}}},"loadCodemods"),de=S(async r=>{try{const e=await le();for(const n of r)n.category!=="socket"&&e[n.packageName]&&(n.hasCodemod=!0)}catch{}},"markCodemodAvailability"),pe=S(async(r,e)=>{let n=0;try{const o=(await le())[e];if(!o)return{filesChanged:0,packageName:e};const a=o({}),i=await xr(r);for(const l of i){const x=G(l);if(x.includes(e))try{const k=await a.transform({file:{filename:l,source:x}});k!==x&&(ge(l,k,"utf8"),n++)}catch(k){process.stderr.write(`warn: codemod transform failed for ${l}: ${k instanceof Error?k.message:String(k)}
`)}}}catch{}return{filesChanged:n,packageName:e}},"runCodemod"),xr=S(async r=>xe("**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}",{absolute:!0,cwd:r,ignore:["**/.*/**","**/.*","**/node_modules/**","**/dist/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"]}),"collectSourceFiles"),yr=S(async({logger:r,options:e,visConfig:n,workspaceRoot:o})=>{if(!o)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const a=Ae(o),i=!!e.dryRun,l=!!e.prod,x=!!e.pin;j.info(`Detected ${a.name} v${a.version}.`);const k=V(N(o,"package.json"),l),v=se(o),y=new Set(k);for(const d of v){const O=V(N(ye(o,d),"package.json"),l);for(const D of O)y.add(D)}v.length>0&&j.info(`Scanned ${String(v.length)} workspace package${v.length===1?"":"s"}.`),j.info(`Scanning dependencies...
`);const s=Ve(o,a.name),f=ae(y),p=ce(y,s,a,x),h=new Set(f.map(d=>d.packageName)),g=p.filter(d=>!h.has(d.packageName)),u=[...f,...g];if(await de(u),u.length===0){j.info("No optimizations found for your dependencies.");return}const b=!!process.stdout.isTTY&&!Ne,$=e.format==="json"||!!e.json;if(b&&!i&&!$){const d=new Ze(u),O=await Pe(Ee.createElement(fr,{isDryRun:!1,store:d}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit(),D=Array.isArray(O)?O:[];if(D.length===0){j.info("No optimizations selected.");return}const L=D.filter(w=>w.category!=="socket"&&w.hasCodemod),q=D.filter(w=>w.category!=="socket"&&!w.hasCodemod),J=D.filter(w=>w.category==="socket");if(L.length>0){j.info(`
Running ${String(L.length)} codemod${L.length===1?"":"s"}...
`);for(const w of L){const P=await pe(o,w.packageName);P.filesChanged>0?j.success(`  ${w.packageName}: ${String(P.filesChanged)} file${P.filesChanged===1?"":"s"} updated`):j.info(`  ${w.packageName}: no files changed`)}}if(q.length>0){j.warn(`
${String(q.length)} selected replacement${q.length===1?"":"s"} require manual migration (no codemod available):`);for(const w of q)j.info(`  ${w.packageName} → ${w.replacement}`);j.notice("  Replace usage in your source code, then remove from dependencies.")}if(J.length>0){const w=J.filter(U=>U.overrideSpec).map(U=>({original:U.packageName,spec:U.overrideSpec})),P=He(o,N(o,"package.json"),w,a,n?.editorconfig??!0);P.added.length>0&&j.success(`
Added ${String(P.added.length)} override${P.added.length===1?"":"s"}.`),P.updated.length>0&&j.success(`Updated ${String(P.updated.length)} override${P.updated.length===1?"":"s"}.`)}if(J.length>0&&e.install!==!1){j.info(`
Running ${a.name} install to update lockfile...`);const w=Re(a,{dev:!1,filter:[],force:!1,frozenLockfile:!1,ignoreScripts:!1,lockfileOnly:!1,noOptional:!1,offline:!1,prod:!1,recursive:!1,silent:!1,workspaceRoot:!1},o,r);w!==0&&j.warn(`${a.name} install exited with code ${String(w)}. Run it manually.`)}j.info(""),j.success("Optimization complete.");return}if($){process.stdout.write(`${JSON.stringify({e18e:f.map(d=>({category:d.category,hasCodemod:d.hasCodemod,packageName:d.packageName,replacement:d.replacement})),packageManager:a.name,socket:g.map(d=>({overrideSpec:d.overrideSpec,packageName:d.packageName,replacement:d.replacement})),total:u.length,workspaces:v.length},void 0,2)}
`);return}const _=f.filter(d=>d.category==="native"),T=f.filter(d=>d.category==="preferred"),A=f.filter(d=>d.category==="micro-utility");if(_.length>0){j.info(`Native replacements (${String(_.length)}):`);for(const d of _)j.info(`  ${d.hasCodemod?"⚙":" "} ${d.packageName} → ${d.replacement}`)}if(T.length>0){j.info(`
Preferred alternatives (${String(T.length)}):`);for(const d of T)j.info(`  ${d.hasCodemod?"⚙":" "} ${d.packageName} → ${d.replacement}`)}if(A.length>0){j.info(`
Micro-utilities (${String(A.length)}):`);for(const d of A)j.info(`  ${d.hasCodemod?"⚙":" "} ${d.packageName} → ${d.replacement}`)}if(g.length>0){j.info(`
Socket.dev overrides (${String(g.length)}):`);for(const d of g)j.info(`  ${d.packageName} → ${d.overrideSpec}`)}j.info(`
Total: ${String(u.length)} optimizations available (⚙ = codemod available).`),i&&j.notice("Run without --dry-run for interactive selection.")},"execute"),Nr=Object.defineProperty({__proto__:null,buildE18eEntries:ae,buildSocketEntries:ce,collectDepsFromPkgJson:V,default:yr,discoverWorkspacePackages:se,markCodemodAvailability:de,runCodemod:pe},Symbol.toStringTag,{value:"Module"});export{se as A,ae as F,pe as I,Ve as L,ce as T,de as U,He as a,Nr as h,V as x};
