Skip to content

Unify optional-peer handling for @aws-sdk imports in S3 adapter #196

@genu

Description

@genu

Context

Raised during review of the feat(v0.2): direct upload endpoint and server mode change (commit c3894ef).

src/runtime/server/adapters/s3.ts now top-level-imports three AWS SDK packages, all declared as optional in peerDependenciesMeta:

  • @aws-sdk/client-s3
  • @aws-sdk/s3-request-presigner
  • @aws-sdk/lib-storage (added in this change, only used inside put())

Because all three are imported statically, any consumer of S3Storage needs all three installed — even presigned-only users. This contradicts the "optional" label on the peer dep.

CodeRabbit suggested lazy-loading only lib-storage (since it's used only in put()), but that would be inconsistent with how client-s3 and s3-request-presigner are handled — the same argument applies to them.

What to address

Decide on a single consistent policy, then apply it to all three packages:

  1. Keep static top-level imports and drop the optional: true designation for all three in peerDependenciesMeta. Honest: if you import S3Storage, you need all three.
  2. Lazy-load all three inside S3Storage() so that merely importing the factory doesn't require the SDK. Each method (presignUpload, put, delete, etc.) await import(...) on first use, with a clear error message if the peer dep is missing.

Option 1 is simpler and matches reality. Option 2 enables tree-shaking for users who import from a barrel file but never construct S3Storage, which is a weak win.

Files

  • src/runtime/server/adapters/s3.ts
  • package.json (peerDependenciesMeta)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions