@@ -5,7 +5,7 @@ import fs from "node:fs";
55import os from "node:os" ;
66import path from "node:path" ;
77import { randomUUID } from "node:crypto" ;
8- import { findDeployment , waitForDeployment } from "./deployment-status.mjs" ;
8+ import { activateDeployment , findDeployment , waitForDeployment } from "./deployment-status.mjs" ;
99
1010const root = path . resolve ( import . meta. dirname , ".." ) ;
1111const localStaging = process . argv . includes ( "--local-staging" ) ;
@@ -46,7 +46,7 @@ function vercel(args, cwd, project, token, json = true) {
4646 encoding : "utf8" , windowsHide : true , timeout : 12 * 60 * 1000 ,
4747 maxBuffer : 8 * 1024 * 1024 ,
4848 } ) ;
49- if ( result . status !== 0 ) throw new Error ( " Vercel command failed. Inspect the deployment in the project dashboard." ) ;
49+ if ( result . status !== 0 ) throw new Error ( ` Vercel ${ args [ 0 ] } command failed. Inspect the deployment in the project dashboard.` ) ;
5050 if ( ! json ) return ;
5151 let data ;
5252 try { data = JSON . parse ( result . stdout ) ; } catch { /* Never dump raw provider logs. */ }
@@ -60,15 +60,18 @@ function authentication(tokenKey) {
6060 return requireValue ( tokenKey ) ;
6161}
6262
63- async function providerApi ( endpoint , cwd , project , token , label ) {
63+ async function providerApi ( endpoint , cwd , project , token , label , method = "GET" ) {
6464 const url = new URL ( endpoint , "https://api.vercel.com" ) ;
6565 url . searchParams . set ( "teamId" , requireValue ( "VERCEL_ORG_ID" ) ) ;
6666 if ( ! token ) return vercel ( [ "api" , `${ url . pathname } ${ url . search } ` , "--method" , "GET" ] , cwd , project ) ;
6767 const response = await fetch ( url , {
68- headers : { Authorization : `Bearer ${ token } ` } ,
68+ method,
69+ headers : { Authorization : `Bearer ${ token } ` , ...( method === "POST" ? { "Content-Type" : "application/json" } : { } ) } ,
70+ ...( method === "POST" ? { body : "{}" } : { } ) ,
6971 signal : AbortSignal . timeout ( 30_000 ) ,
7072 } ) ;
7173 if ( ! response . ok ) throw new Error ( `${ label } provider lookup failed (${ response . status } ).` ) ;
74+ if ( response . status === 204 ) return { } ;
7275 return response . json ( ) ;
7376}
7477
@@ -92,14 +95,13 @@ async function confirmReady(cwd, project, token, label, commit, run) {
9295async function promote ( deployment , cwd , project , token , label ) {
9396 // A previous rollback can leave domains pinned to an older build. Activate only
9497 // this invocation's verified production build, then confirm the canonical target.
95- vercel ( [ "promote" , deployment . id , "--yes" ] , cwd , project , token , false ) ;
96- for ( let attempt = 0 ; attempt < 5 ; attempt ++ ) {
97- const current = await providerApi ( `/v9/projects/${ project } ` , cwd , project , token , label ) ;
98- if ( current . id !== project ) throw new Error ( `${ label } target belongs to a different project.` ) ;
99- if ( current . targets ?. production ?. id === deployment . id ) return ;
100- if ( attempt < 4 ) await new Promise ( resolve => setTimeout ( resolve , 2000 ) ) ;
101- }
102- throw new Error ( `${ label } canonical target does not serve the checked deployment.` ) ;
98+ await activateDeployment ( deployment . id , {
99+ project, label,
100+ read : ( ) => providerApi ( `/v9/projects/${ project } ` , cwd , project , token , label ) ,
101+ promote : ( ) => token
102+ ? providerApi ( `/v10/projects/${ project } /promote/${ deployment . id } ` , cwd , project , token , `${ label } promotion` , "POST" )
103+ : vercel ( [ "promote" , deployment . id , "--yes" ] , cwd , project , token , false ) ,
104+ } ) ;
103105}
104106
105107function deploySource ( ) {
0 commit comments