Adds support for optional params#10589
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for optional parameters during Cloud Functions deployment. When a .env file is present, optional parameters are resolved to their default or type-specific zero value and marked as internal to prevent them from being written to .env. However, a critical bug was identified in resolveParams where the resolved value for an optional parameter is immediately overwritten by the subsequent promptParam call. A continue statement must be added inside the conditional block to prevent prompting for these optional parameters.
| if (promptable.optional && dotEnvPresent) { | ||
| paramValues[param.name] = defaultOrZeroValue(param, paramDefault); | ||
| } | ||
| paramValues[param.name] = await promptParam(param, firebaseConfig.projectId, paramDefault); |
There was a problem hiding this comment.
The value resolved for an optional parameter when a .env file is present is immediately overwritten by the subsequent promptParam call. You should add a continue statement inside the if block to skip prompting for optional parameters.
if (promptable.optional && dotEnvPresent) {
paramValues[param.name] = defaultOrZeroValue(param, paramDefault);
continue;
}
paramValues[param.name] = await promptParam(param, firebaseConfig.projectId, paramDefault);
Params with optional = true are only prompted for on a "fresh" functions deploy, where the corresponding .env file is empty.
Otherwise, they are automatically filled in with the param's default value, or a zero value based on the param's type. This can bypass validation for param types that support validation regexes.
Optional params resolved this way are not written to .env. (Optional params resolved by prompting on a fresh deploy are).
While we're here, remove the
immutableparam configuration, which is a holdover from cargo culting Extensions params and doesn't really have any meaning in the functions world. Immutability wasn't implemented and it wasn't present in the wire format for a param from the SDK so that config flag was just totally marooned from the outside universe.