feat(ext:migrate): export configs into functions env and invoke kit init - #11007
feat(ext:migrate): export configs into functions env and invoke kit init#11007inlined wants to merge 33 commits into
Conversation
### Description Integrates configuration exporting and kit scaffolding into `ext:migrate`: - Exports Extension parameters and system parameters into Functions environment variables (`functionsEnvFromInstance`), mapping `EXT_MIGRATED_SYSTEM_LOCATION` to `DEFAULT_FUNCTION_REGION`. - Adds `migrateSecrets` helper to transfer extension secrets to Functions management (with early return if no secrets exist and IAM administrator guidance on permission denial). - Passes exported environment variables into `installKitOrInstance` to seed `.env.<projectId>` during kit installation. - Refactors kit install helper APIs to accept intrinsic arrays (`string[]`) instead of Sets per codebase convention (intrinsics only in module APIs). - Updates package specifier and kit name parsing to support versions (e.g. `@1.2.3`) and tags (e.g. `@next`). ### Scenarios Tested - Unit tests in `src/extensions/export.spec.ts`, `src/extensions/migrate.spec.ts`, and `src/functions/kits/install.spec.ts`. - Tested `ext:migrate` command execution flow with exported env seeding and secret migration. - Tested `migrateSecrets` with instances containing no secrets, active secrets, and permission errors. - Tested package specifier parsing with scoped/unscoped packages, versions, and tags. ### Sample Commands - `firebase ext:migrate` - `firebase ext:migrate --extension firestore-send-email` - `firebase ext:migrate --package @firebase-function-kits/firestore-send-email@next`
There was a problem hiding this comment.
Code Review
This pull request adds support for exporting Extension parameters and initializing Function Kits during firebase ext:migrate. Key changes include verifying the project directory, migrating secrets, fetching instance specifications on demand, mapping system location parameters to DEFAULT_FUNCTION_REGION, and seeding environment variables during kit installation. The review feedback highlights several improvement opportunities, including adding a warning if the extension specification fails to load, reusing the existing getInstanceId utility to avoid duplicate logic, using optional chaining to prevent a potential runtime TypeError when accessing existingKit.instances, and removing or populating several empty JSDoc blocks.
- Throw blocking error when extension specification cannot be loaded in ext:migrate. - Reuse getInstanceId helper in migrateSecrets. - Use optional chaining on existingKit.instances. - Remove redundant empty JSDoc blocks in extensionsHelper.ts.
… helpers ### Description Refactors function kit installation helper APIs (`extractExistingFunctionsInfo`, `promptKitInstanceId`, `promptKitId`, `generateUniqueId`, and `ExistingFunctionsInfo`) to use standard `string[]` arrays instead of `Set<string>` per codebase conventions (using intrinsic arrays in module APIs). ### Scenarios Tested - Unit tests in `src/functions/kits/install.spec.ts` (`npm run mocha:fast -- src/functions/kits/install.spec.ts`). - Verified unique ID generation and suffix collision avoidance with string arrays. - Verified existing kit, codebase, and instance ID validation and prompt collisions. ### Sample Commands N/A (Internal refactoring)
### Description Enhances package specifier and kit name parsing to support npm version numbers (e.g. `@1.2.3`, `@^2.0.0`, `@1.0.0-rc.1`) and distribution tags (e.g. `@next`, `@latest`): - Updates `parseNpmPackageSpecifier` to properly handle empty versions vs defined versions. - Updates `validateNpmPackageName` to allow specifiers with versions/tags while rejecting trailing `@` without a version. - Updates `sanitizePackageNameToKitName` to parse the specifier first and extract the unscoped package name before sanitizing to avoid baking versions/tags into default kit IDs. - Updates `isThirdPartyPackage` to extract the base package name before evaluating scope. ### Scenarios Tested - Added unit tests for scoped and unscoped package specifiers with versions and tags. - Verified validation and error cases for trailing `@` and malformed names. - Ran full test suite in `src/functions/kits/install.spec.ts`. ### Sample Commands - `firebase functions:kits:install --package @firebase-function-kits/firestore-bigquery-export@next` - `firebase functions:kits:install --package my-kit@1.2.3`
…dd ensureInstanceSpec ### Description - Updates `ExtensionConfig` interface to make `source?: ExtensionSource` optional, reflecting runtime API behavior for published extension instances. - Adds `ensureInstanceSpec` in `extensionsHelper.ts` to fetch an extension version's specification on demand when `instance.config.source?.spec` is absent. - Adds defensive guards when accessing `instance.config.source?.spec` in `secretsUtils.ts` and `export.ts`. ### Scenarios Tested - Added unit tests in `src/extensions/export.spec.ts` for `ensureInstanceSpec`: - Returns instance unchanged when spec is already present. - Fetches spec on demand from the Extension publisher API when missing. - Verified TypeScript compilation and ESLint checks. ### Sample Commands - `npm test`
### Description - Adds `skipReport` option to `InstallKitOrInstanceOptions` and `ExistingKitInstallOptions` to allow callers (such as migration tooling) to suppress the first-deploy report. - Supports `seedEnv` in `addKitInstanceOrConfigureProject` when configuring an existing kit instance for an environment/project. - Suppresses `printKitFirstDeployReport` when `skipReport: true` is provided. ### Scenarios Tested - Added unit test in `src/functions/kits/install.spec.ts` verifying `seedEnv` writes `.env.<projectId>` during existing instance configuration. - Added unit test verifying `skipReport: true` suppresses `printKitFirstDeployReport`. - Ran full test suite in `src/functions/kits/install.spec.ts`. ### Sample Commands - `npm test`
…lback extensionRef - Use optional chaining for instance.config?.source?.spec in getManagedSecrets. - Fall back to top-level instance.extensionRef and instance.extensionVersion in ensureInstanceSpec. - Add unit test verifying top-level instance.extensionRef spec fetch.
…lvePackageSource - Pass rawPkgName to validateNpmPackageName before destructuring packageName. - Simplify validateNpmPackageName condition. - Add unit test for malformed specifiers in resolvePackageSource.
…rror bubbling - Remove silent error suppression; allow errors from getExtensionVersion to bubble up. - Flatten control flow with early returns. - Populate real source metadata from ExtensionVersion instead of placeholder fields. - Update unit tests.
…nto feat_kit_seed_env_skip_report
…ig_init and reconcile secret ejection changes
…tance ID - Add defaultInstanceId option to InstallKitOrInstanceOptions and ExistingKitInstallOptions. - Pass plan.instanceId as defaultInstanceId in ext:migrate command. - Add unit tests verifying defaultInstanceId suggestion and ext:migrate wiring.
- Rename DEFAULT_FUNCTION_REGION to FUNCTION_DEFAULT_REGION in functionsEnvFromInstance. - Use ref.version from parsed extensionRef if top-level extensionVersion is unset in ensureInstanceSpec. - Co-locate ensureInstanceSpec unit tests in extensionsHelper.spec.ts.
…to fix_ext_ensure_instance_spec
Description
Integrates configuration exporting and kit scaffolding into
ext:migrate:functionsEnvFromInstance), mappingEXT_MIGRATED_SYSTEM_LOCATIONtoDEFAULT_FUNCTION_REGION.migrateSecretshelper to transfer extension secrets to Functions management (with early return if no secrets exist and IAM administrator guidance on permission denial).installKitOrInstanceto seed.env.<projectId>during kit installation.string[]) instead of Sets per codebase convention (intrinsics only in module APIs).@1.2.3) and tags (e.g.@next).Scenarios Tested
src/extensions/export.spec.ts,src/extensions/migrate.spec.ts, andsrc/functions/kits/install.spec.ts.ext:migratecommand execution flow with exported env seeding and secret migration.migrateSecretswith instances containing no secrets, active secrets, and permission errors.Sample Commands
firebase ext:migratefirebase ext:migrate --extension firestore-send-emailfirebase ext:migrate --package @firebase-function-kits/firestore-send-email@next