@@ -9,7 +9,8 @@ import * as api from "../../../hosting/api";
99import { FirebaseError } from "../../../error" ;
1010import { Payload } from "../../../deploy/functions/args" ;
1111
12- const FUNCTION_ID = "function" ;
12+ const FUNCTION_ID = "functionId" ;
13+ const SERVICE_ID = "function-id" ;
1314const PROJECT_ID = "project" ;
1415const REGION = "region" ;
1516
@@ -36,6 +37,9 @@ function endpoint(opts?: Partial<backend.Endpoint>): backend.Endpoint {
3637 ) {
3738 ret . httpsTrigger = { } ;
3839 }
40+ if ( opts ?. platform === "gcfv2" ) {
41+ ret . runServiceId = opts ?. id ?? SERVICE_ID ;
42+ }
3943 return ret as backend . Endpoint ;
4044}
4145
@@ -178,7 +182,7 @@ describe("convertConfig", () => {
178182 name : "defaults to a us-central1 rewrite if one is avaiable, v2 edition" ,
179183 input : { rewrites : [ { glob : "/foo" , function : { functionId : FUNCTION_ID } } ] } ,
180184 want : {
181- rewrites : [ { glob : "/foo" , run : { region : "us-central1" , serviceId : FUNCTION_ID } } ] ,
185+ rewrites : [ { glob : "/foo" , run : { region : "us-central1" , serviceId : SERVICE_ID } } ] ,
182186 } ,
183187 functionsPayload : {
184188 functions : {
@@ -192,6 +196,7 @@ describe("convertConfig", () => {
192196 region : "europe-west2" ,
193197 platform : "gcfv2" ,
194198 httpsTrigger : { } ,
199+ runServiceId : SERVICE_ID ,
195200 } ,
196201 {
197202 id : FUNCTION_ID ,
@@ -201,6 +206,7 @@ describe("convertConfig", () => {
201206 region : "us-central1" ,
202207 platform : "gcfv2" ,
203208 httpsTrigger : { } ,
209+ runServiceId : SERVICE_ID ,
204210 }
205211 ) ,
206212 haveBackend : backend . empty ( ) ,
@@ -236,7 +242,7 @@ describe("convertConfig", () => {
236242 {
237243 name : "rewrites referencing CF3v2 functions being deployed are changed to Cloud Run (during release)" ,
238244 input : { rewrites : [ { regex : "/foo$" , function : { functionId : FUNCTION_ID } } ] } ,
239- want : { rewrites : [ { regex : "/foo$" , run : { serviceId : FUNCTION_ID , region : REGION } } ] } ,
245+ want : { rewrites : [ { regex : "/foo$" , run : { serviceId : SERVICE_ID , region : REGION } } ] } ,
240246 functionsPayload : {
241247 functions : {
242248 default : {
@@ -248,6 +254,7 @@ describe("convertConfig", () => {
248254 region : REGION ,
249255 platform : "gcfv2" ,
250256 httpsTrigger : { } ,
257+ runServiceId : SERVICE_ID ,
251258 } ) ,
252259 haveBackend : backend . empty ( ) ,
253260 } ,
@@ -262,7 +269,7 @@ describe("convertConfig", () => {
262269 ] ,
263270 } ,
264271 want : {
265- rewrites : [ { regex : "/foo$" , run : { serviceId : FUNCTION_ID , region : "us-central1" } } ] ,
272+ rewrites : [ { regex : "/foo$" , run : { serviceId : SERVICE_ID , region : "us-central1" } } ] ,
266273 } ,
267274 existingBackend : backend . of ( endpoint ( { platform : "gcfv2" , region : "us-central1" } ) ) ,
268275 } ,
@@ -275,7 +282,7 @@ describe("convertConfig", () => {
275282 } ,
276283 existingBackend : backend . of ( endpoint ( { platform : "gcfv2" , region : "us-central1" } ) ) ,
277284 want : {
278- rewrites : [ { regex : "/foo$" , run : { serviceId : FUNCTION_ID , region : "us-central1" } } ] ,
285+ rewrites : [ { regex : "/foo$" , run : { serviceId : SERVICE_ID , region : "us-central1" } } ] ,
279286 } ,
280287 } ,
281288 {
0 commit comments