Skip to content

refactor(functions): introduce 3-stage kit install pipeline - #11366

Merged
wandamora merged 2 commits into
mainfrom
morawand/kits-install-refactor
Nov 6, 2026
Merged

wandamora merged 2 commits into
mainfrom
morawand/kits-install-refactor

Conversation

@wandamora

@wandamora wandamora commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Refactors Function Kits installation (src/functions/kits/install.ts and src/functions/kits/install.spec.ts) following #11370 to consume KitSourceAdapter (createNpmPackageAdapter / createDirectoryAdapter) and separate kit-level setup, instance resolution, and project configuration, with no user-facing behavior changes:

  • 3-stage linear install pipeline (install.ts): Simplifies installKitOrInstance into three source-agnostic stages:
    1. ensureKit: Resolves an existing kit via adapter.findExistingKit or validates, prepares (adapter.prepareSource), and stages the new kit in-memory (write: false).
    2. resolveOrCreateInstance: Creates a new kit instance (addInstanceToKitConfig, which persists both the staged kit and instance to firebase.json) or selects an existing unconfigured instance for the active project (promptExistingInstanceForProject).
    3. configureInstanceForProject: Seeds .env.<projectId>, discovers build parameters (discoverKitBuild), and prompts for values (promptAndWriteKitParams).
  • Orchestration & Reporting: Success logging and printKitFirstDeployReport run in installKitOrInstance after pipeline completion, branching directly on isNewKit and isNewInstance.
  • Remove legacy source helpers: Removes KitSource, resolvePackageSource, resolveDirectorySource, findExistingKit, scaffoldKit, and addKitInstanceOrConfigureProject in favor of the unified KitSourceAdapter pipeline.
  • Standardize options interfaces: Consolidates multi-argument helper signatures in install.ts (getUnconfiguredInstancesForProject, promptExistingInstanceForProject, discoverKitBuild, printKitFirstDeployReport, promptAndWriteKitParams) into explicit *Options interfaces.

Scenarios Tested

  • Unit tests across src/functions/kits/**/*.spec.ts, src/commands/functions-kits-install.spec.ts, and src/extensions/migrate.spec.ts.
  • Installing a new kit from an npm package (--package) and from a local directory (--directory).
  • Adding a second instance to an already-installed kit and configuring an existing unconfigured instance for another project.
  • Atomic rollback and cleanup when installation or parameter resolution fails mid-flow.

Sample Commands

No CLI flags or commands changed:

firebase functions:kits:install --package @firebase-function-kits/firestore-bigquery-export
firebase functions:kits:install --directory ./my-local-kit

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the function kits installation logic by extracting source-specific handling into a modular adapter pattern under src/functions/kits/sources/. It introduces KitSourceAdapter implementations for both local directory and NPM package sources, simplifying install.ts into a clean three-stage orchestration flow. Feedback on the changes highlights several potential TypeError vulnerabilities where fs.readJson could return null and cause crashes on property access. Additionally, multiple functions accepting more than three arguments violate the repository style guide and should be refactored to accept a single options object.

Comment thread src/functions/kits/sources/directory.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
Comment thread src/functions/kits/sources/npm.ts Resolved
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from e1d8f63 to 7b78ce8 Compare October 26, 2026 21:37
@wandamora wandamora changed the title refactor(functions): extract kit source adapters and simplify install… refactor(functions): extract kit source adapters and simplify install flow Oct 26, 2026
@wandamora
wandamora requested a review from ajperel October 26, 2026 21:46
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 7b78ce8 to 8faa839 Compare October 27, 2026 18:08
@wandamora
wandamora changed the base branch from main to morawand/kits-extract-sources October 27, 2026 18:08
@wandamora
wandamora added this pull request to stack #11369 October 27, 2026 18:09
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 8faa839 to 8dc4ddb Compare October 27, 2026 18:30
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 8dc4ddb to d10a1b9 Compare October 27, 2026 20:27
@wandamora
wandamora removed this pull request from stack #11369 October 27, 2026 20:33
@wandamora
wandamora changed the base branch from morawand/kits-extract-sources to morawand/kits-source-adapters October 27, 2026 20:33
@wandamora
wandamora added this pull request to stack #11371 October 27, 2026 20:34
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch 3 times, most recently from 618d7bf to 4950a70 Compare October 27, 2026 22:38
@wandamora wandamora changed the title refactor(functions): extract kit source adapters and simplify install flow refactor(functions): introduce 3-stage kit install pipeline Oct 27, 2026
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch 2 times, most recently from 59020b5 to e95c030 Compare October 29, 2026 20:11
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from e95c030 to de5819c Compare October 29, 2026 20:37
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from de5819c to 0b41d76 Compare October 29, 2026 21:27

@ajperel ajperel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we pushed a bit too much into the different stage methods and shouldn't need action and isNewKit in them, but overall, I think this is a good improvement. Thanks for taking the time to do it.

Comment thread src/functions/kits/install.ts Resolved
Comment thread src/functions/kits/install.ts Resolved
Comment thread src/functions/kits/install.ts Resolved
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 0b41d76 to 9ba8139 Compare November 5, 2026 18:47
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 9ba8139 to 8fb4285 Compare November 5, 2026 20:52
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 8fb4285 to 903fd03 Compare November 5, 2026 21:14
Base automatically changed from morawand/kits-source-adapters to main November 5, 2026 21:23
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch 2 times, most recently from dcc2b1f to 36e8e4e Compare November 5, 2026 22:52

@ajperel ajperel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was probably a bit stingy not just approving with my last round of comments so just doing it now. Haven't re-reviewed. I trust you to address the feedback.

@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 36e8e4e to 807beba Compare November 6, 2026 00:40
@wandamora
wandamora force-pushed the morawand/kits-install-refactor branch from 807beba to 970e27f Compare November 6, 2026 01:09
@wandamora
wandamora merged commit 4369678 into main Nov 6, 2026
51 checks passed
@wandamora
wandamora deleted the morawand/kits-install-refactor branch November 6, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants