@@ -4,11 +4,10 @@ import * as fs from "fs-extra";
44
55import { FirebaseError } from "../error" ;
66import { logger } from "../logger" ;
7- import { ExtensionInstance , ExtensionSpec , Param } from "./types" ;
7+ import { ExtensionSpec , Param } from "./types" ;
88import { getFirebaseProjectParams , substituteParams } from "./extensionsHelper" ;
99import * as askUserForParam from "./askUserForParam" ;
1010import * as env from "../functions/env" ;
11- import { cloneDeep } from "../utils" ;
1211
1312const NONINTERACTIVE_ERROR_MESSAGE =
1413 "As of firebase-tools@11, `ext:install`, `ext:update` and `ext:configure` are interactive only commands. " +
@@ -61,26 +60,19 @@ export function buildBindingOptionsWithBaseValue(baseParams: { [key: string]: st
6160 * @param newDefaults a map of { PARAM_NAME: default_value }
6261 */
6362export function setNewDefaults ( params : Param [ ] , newDefaults : { [ key : string ] : string } ) : Param [ ] {
64- params . forEach ( ( param ) => {
65- if ( newDefaults [ param . param . toUpperCase ( ) ] ) {
66- param . default = newDefaults [ param . param . toUpperCase ( ) ] ;
63+ for ( const param of params ) {
64+ if ( newDefaults [ param . param ] ) {
65+ param . default = newDefaults [ param . param ] ;
66+ } else if (
67+ ( param . param = `firebaseextensions.v1beta.function/location` && newDefaults [ "LOCATION" ] )
68+ ) {
69+ // Special case handling for when we are updating from LOCATION to system param location.
70+ param . default = newDefaults [ "LOCATION" ] ;
6771 }
68- } ) ;
72+ }
6973 return params ;
7074}
7175
72- /**
73- * Returns a copy of the params for a extension instance with the defaults set to the instance's current param values
74- * @param extensionInstance the extension instance to change the default params of
75- */
76- export function getParamsWithCurrentValuesAsDefaults (
77- extensionInstance : ExtensionInstance
78- ) : Param [ ] {
79- const specParams = cloneDeep ( extensionInstance ?. config ?. source ?. spec ?. params || [ ] ) ;
80- const currentParams = cloneDeep ( extensionInstance ?. config ?. params || { } ) ;
81- return setNewDefaults ( specParams , currentParams ) ;
82- }
83-
8476/**
8577 * Gets params from the user
8678 * or prompting the user for each param.
@@ -160,15 +152,37 @@ export async function promptForNewParams(args: {
160152 return left . filter ( ( aLeft ) => ! right . find ( sameParam ( aLeft ) ) ) ;
161153 } ;
162154
155+ let combinedOldParams = args . spec . params . concat (
156+ args . spec . systemParams . filter ( ( p ) => ! p . advanced ) ?? [ ]
157+ ) ;
158+ let combinedNewParams = args . newSpec . params . concat (
159+ args . newSpec . systemParams . filter ( ( p ) => ! p . advanced ) ?? [ ]
160+ ) ;
161+
162+ // Special case for updating from LOCATION to system param location
163+ if (
164+ combinedOldParams . some ( ( p ) => p . param === "LOCATION" ) &&
165+ combinedNewParams . some ( ( p ) => p . param === "firebaseextensions.v1beta.function/location" ) &&
166+ ! ! args . currentParams [ "LOCATION" ]
167+ ) {
168+ newParamBindingOptions [ "firebaseextensions.v1beta.function/location" ] = {
169+ baseValue : args . currentParams [ "LOCATION" ] ,
170+ } ;
171+ delete newParamBindingOptions [ "LOCATION" ] ;
172+ combinedOldParams = combinedOldParams . filter ( ( p ) => p . param !== "LOCATION" ) ;
173+ combinedNewParams = combinedNewParams . filter (
174+ ( p ) => p . param !== "firebaseextensions.v1beta.function/location"
175+ ) ;
176+ }
177+
163178 // Some params are in the spec but not in currentParams, remove so we can prompt for them.
164- const oldParams = args . spec . params . filter ( ( p ) =>
179+ const oldParams = combinedOldParams . filter ( ( p ) =>
165180 Object . keys ( args . currentParams ) . includes ( p . param )
166181 ) ;
167-
168- let paramsDiffDeletions = paramDiff ( oldParams , args . newSpec . params ) ;
182+ let paramsDiffDeletions = paramDiff ( oldParams , combinedNewParams ) ;
169183 paramsDiffDeletions = substituteParams < Param [ ] > ( paramsDiffDeletions , firebaseProjectParams ) ;
170184
171- let paramsDiffAdditions = paramDiff ( args . newSpec . params , oldParams ) ;
185+ let paramsDiffAdditions = paramDiff ( combinedNewParams , oldParams ) ;
172186 paramsDiffAdditions = substituteParams < Param [ ] > ( paramsDiffAdditions , firebaseProjectParams ) ;
173187
174188 if ( paramsDiffDeletions . length ) {
0 commit comments