Skip to content

Fix Firebase Storage injected bucket loading - #110

Merged
haydenbleasel merged 2 commits into
haydenbleasel:mainfrom
marcusschiesser:codex/firebase-injected-bucket-lazy-admin
Jul 30, 2026
Merged

Fix Firebase Storage injected bucket loading#110
haydenbleasel merged 2 commits into
haydenbleasel:mainfrom
marcusschiesser:codex/firebase-injected-bucket-lazy-admin

Conversation

@marcusschiesser

@marcusschiesser marcusschiesser commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changed

  • move Firebase Admin runtime resolution behind an internal lazy loader
  • skip both Firebase Admin entry points when an initialized Bucket is supplied
  • keep existing Firebase App, credential, and environment initialization behavior

Why

firebaseStorage({ app: bucket }) already accepts a pre-initialized Google Cloud Storage bucket, but the adapter's top-level Firebase Admin imports still required firebase-admin to resolve before that bucket could be used. This prevented consumers that discover and initialize Firebase Admin themselves from injecting the resulting bucket without also making the peer resolvable from Files SDK's module location.

Impact

This is a patch-level runtime fix with no public API changes. Firebase Admin remains an optional peer for every path that initializes or consumes a Firebase App.

Validation

  • bun test packages/files-sdk/test/firebase-storage.test.ts
  • bun run types --filter files-sdk
  • bun run check
  • bun run build --filter files-sdk
  • pre-commit full typecheck and test coverage: 3,151 passed, 14 skipped, 0 failed

Summary by CodeRabbit

  • Bug Fixes

    • Firebase Storage now avoids loading Firebase Admin when a pre-initialized bucket is provided, preventing unnecessary initialization.
    • Improves compatibility for apps that manage Firebase setup externally.
  • Tests

    • Added coverage to ensure Firebase Admin loading is not triggered when using an injected bucket.
    • Added a regression test confirming the built firebase-storage bundle does not statically import optional peer dependencies, even across dynamic imports.

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 44a6c9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
files-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
files-sdk Ready Ready Preview Jul 30, 2026 4:52am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Firebase Storage now loads Firebase Admin modules dynamically when needed. An already-initialized bucket bypasses Firebase Admin loading, with updated mocks and coverage for this behavior.

Changes

Lazy Firebase Admin loading

Layer / File(s) Summary
Lazy loader and Firebase Storage integration
packages/files-sdk/src/firebase-storage/firebase-admin-loader.ts, packages/files-sdk/src/firebase-storage/index.ts
Adds ESM-compatible loaders for Firebase Admin app and storage APIs, and uses them during bucket and app construction.
Loader mock coverage and bundle validation
packages/files-sdk/test/firebase-storage.test.ts, packages/files-sdk/test/build-output.test.ts, .changeset/lazy-firebase-admin.md
Updates Firebase Admin mocks, tests that injected buckets skip loading, verifies optional peers are not statically reached through dynamic imports, and adds a patch changeset.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant firebaseStorage
  participant firebaseAdminLoader
  participant FirebaseAdmin
  alt Injected bucket
    firebaseStorage->>firebaseStorage: Use provided Bucket
  else Build bucket
    firebaseStorage->>firebaseAdminLoader: Load Firebase Admin APIs
    firebaseAdminLoader->>FirebaseAdmin: Require app or storage module
    FirebaseAdmin-->>firebaseAdminLoader: Return module APIs
    firebaseAdminLoader-->>firebaseStorage: Provide typed APIs
  end
Loading

Possibly related PRs

  • haydenbleasel/files-sdk#109: Both PRs update the build-output regression coverage for static optional peer imports across dynamic imports.

Suggested reviewers: haydenbleasel

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately captures the main change to Firebase Storage injected bucket loading.
Description check ✅ Passed The description covers what changed, why, impact, and validation, so it is mostly complete despite missing template sections like Related Issues and Checklist.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@marcusschiesser
marcusschiesser marked this pull request as ready for review July 28, 2026 15:13
@haydenbleasel

Copy link
Copy Markdown
Owner

nice fix — pushed a small addition (44a6c9a) that adds the firebase-storage bundle to the build-output guard in test/build-output.test.ts, same as the r2 one from #105. the createRequire loader is invisible to the static-graph scan anyway, so this just makes sure a top-level firebase-admin import can't sneak back in later. thanks!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/files-sdk/test/build-output.test.ts`:
- Around line 156-157: Update ensureBuilt() to also verify the firebase-storage
bundle at dist/firebase-storage/index.js before skipping the build. Keep the
existing cliBundle and loaderBundle checks, and ensure the test’s firebaseBundle
path matches the artifact required by the readiness check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 22f9b299-889e-4610-b83d-c8f03ab378ff

📥 Commits

Reviewing files that changed from the base of the PR and between 8f76423 and 44a6c9a.

📒 Files selected for processing (1)
  • packages/files-sdk/test/build-output.test.ts

Comment thread packages/files-sdk/test/build-output.test.ts
@haydenbleasel
haydenbleasel merged commit 82c198e into haydenbleasel:main Jul 30, 2026
16 checks passed
@marcusschiesser

Copy link
Copy Markdown
Contributor Author

thanks! agentpond's firebase package is now directly using files sdk: https://github.com/marcusschiesser/agentpond/releases/tag/agentpond%400.10.0

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