var $=Object.defineProperty;var j=(s,r)=>$(s,"name",{value:r,configurable:!0});import{getAffectedProjects as F}from"@visulima/task-runner";import{C as b,S as C}from"./bin.js";import{r as k}from"../packem_shared/affected-shas-BdnlfiV1.js";import{f as A}from"../packem_shared/selectors-DkgYFzdq.js";var I=Object.defineProperty,R=j((s,r)=>I(s,"name",{value:r,configurable:!0}),"j");const B=R(async({argument:s,logger:r,options:e,runtime:v,visConfig:l,workspaceRoot:h})=>{const g=s[0];if(!g)throw new Error("Missing target. Usage: vis affected <target>");if(!h)throw new Error("Could not determine workspace root. Run this command inside a monorepo.");const i=h,{packageJsons:y,workspace:c}=b(i,l),S=C(i,c,y),m=new Set(["deep","direct","none"]),d=e.downstream??"deep",u=e.upstream??"none";if(!m.has(d))throw new Error(`Invalid --downstream value: "${d}". Must be "none", "direct", or "deep".`);if(!m.has(u))throw new Error(`Invalid --upstream value: "${u}". Must be "none", "direct", or "deep".`);let{base:f}=e,{head:p}=e;if(!f||!p){const n=k({defaultBase:l?.defaultBase,workspaceRoot:i});f=f??n.base,p=p??n.head,r.info(`▸ Resolved affected refs from ${n.provider} (${n.notes.join("; ")})`)}const E={base:f,downstream:d,head:p,projectGraph:S,projects:c.projects,upstream:u,workspaceRoot:i},a=await F(E);if(a.changedFiles.length===0){r.info("No files changed. Nothing to run.");return}if(a.affectedProjects.length===0){r.info("No projects affected by the changes.");return}let{affectedProjects:o}=a;if(e.query&&(o=A(o,c,e.query),o.length===0)){r.info(`Query "${String(e.query)}" matched no affected projects.`);return}if(e.sparseCheckout){const n=[...new Set(o.map(w=>c.projects[w]?.root??w))].sort();process.stdout.write(`${n.join(`
`)}
`);return}r.info(`Affected projects: ${o.join(", ")}`),a.changedFiles.length>0&&(process.env.VIS_AFFECTED_FILES=a.changedFiles.join(`
`));const t=[g,`--projects=${o.join(",")}`];e.parallel!==void 0&&t.push(`--parallel=${String(e.parallel)}`),e.cache||t.push("--no-cache"),e.dryRun&&t.push("--dry-run"),e.partition&&t.push(`--partition=${String(e.partition)}`),e.reverse&&t.push("--reverse"),typeof e.runnerTags=="string"&&e.runnerTags!==""&&t.push(`--runner-tags=${e.runnerTags}`);try{await v.runCommand("run",{argv:t})}finally{delete process.env.VIS_AFFECTED_FILES}},"execute");export{B as default};
