Skip to content

fix(deps): move pg, mysql2, mongodb to optional peer dependencies - #1069

Merged
sam-goodwin merged 1 commit into
mainfrom
claude/alchemy-dependencies-review-8f9e50
Aug 4, 2026
Merged

sam-goodwin merged 1 commit into
mainfrom
claude/alchemy-dependencies-review-8f9e50

Conversation

@sam-goodwin

Copy link
Copy Markdown
Member

Move the pg, mysql2, and mongodb drivers from hard dependencies to optional peerDependencies, matching the existing @effect/sql-pg / @effect/sql-mysql2 convention. Each driver backs a single niche feature (Neon/Planetscale migrations, DocumentDB runtime client) but was installed by every alchemy consumer. They stay in devDependencies so the repo's tests run unchanged.

All four import sites are reachable from provider barrels, so the static value imports become lazy import() at the point a client is constructed — otherwise import "alchemy/AWS" (or alchemy/Neon, alchemy/Planetscale) would crash at module load for users without the driver installed:

-import { type Db, MongoClient, type MongoClientOptions } from "mongodb";
+import type { Db, MongoClient, MongoClientOptions } from "mongodb";
+
+const importMongodb = () =>
+  import("mongodb").catch((cause) => {
+    throw new Error(
+      "Failed to load the 'mongodb' driver. Install the optional peer dependency 'mongodb' to connect to DocumentDB.",
+      { cause },
+    );
+  });

A missing driver now fails only when the feature actually runs, with an error naming the peer to install.

  • src/Neon/Migrations.ts, src/Planetscale/Postgres/PostgresMigrations.ts — lazy pg
  • src/Planetscale/MySQL/MySQLMigrations.ts — lazy mysql2/promise (SQL/MySQL.ts was already type-only)
  • src/AWS/DocDB/Mongo.ts — lazy mongodb

Existing users who rely on alchemy transitively providing these drivers must now install them explicitly.

🤖 Generated with Claude Code

The database drivers were hard dependencies installed by every alchemy
consumer, though each backs a single niche feature (Neon/Planetscale
migrations, DocumentDB runtime client). Move them to optional
peerDependencies, matching the existing @effect/sql-pg / @effect/sql-mysql2
convention, and keep them in devDependencies so the repo's tests still run.

All four import sites are reachable from provider barrels, so the static
value imports are converted to lazy import() at the point a client is
constructed — otherwise `import "alchemy/AWS"` (or alchemy/Neon,
alchemy/Planetscale) would crash at module load for users without the
driver installed. A missing driver now fails only when the feature runs,
with an error naming the peer to install.

Co-Authored-By: Claude Fable 5 <[email protected]>
@sam-goodwin
sam-goodwin merged commit 880380b into main Aug 4, 2026
4 checks passed
@sam-goodwin
sam-goodwin deleted the claude/alchemy-dependencies-review-8f9e50 branch August 4, 2026 06:40
@alchemy-version-bot

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/5da6cc4

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/5da6cc4

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/5da6cc4

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.

1 participant