import{detectProjectResolution,mergeProjectResolution}from"../project-resolution.js";import{requireProjectPath}from"../state.js";import{linkProject,resolveProjectByNameOrId,unresolvedProject}from"../vercel-project.js";import{createPromptCommandOutput}from"#setup/cli/index.js";function linkVercelProject(o){let s=o.deps??{linkProject,detectProjectResolution,resolveProjectByNameOrId,unresolvedProject};return{id:`link-project`,shouldRun(e){return e.vercelProject.kind!==`none`},async gather(){return null},async perform({state:e}){let t=e.vercelProject;if(t.kind===`none`)return s.unresolvedProject();let r=requireProjectPath(e),i=createPromptCommandOutput(o.prompter.log);if(!await s.linkProject(o.prompter,r,t,i))throw Error("Vercel project provisioning did not complete. Run `vercel link` manually, or re-run and choose not to deploy to Vercel.");let a=await s.detectProjectResolution(r);if(a.kind===`unresolved`)throw Error(`Linked the directory, but could not resolve the Vercel project from .vercel/project.json.`);let c=await s.resolveProjectByNameOrId(r,t.team,t.project);if(c===null||a.projectId!==c.id)throw Error(`Linked project identity did not match the planned Vercel project "${t.project}".`);return a},apply(e,n){return{...e,project:mergeProjectResolution(e.project,n)}}}}export{linkVercelProject};