Skip to content

Commit 5201645

Browse files
committed
fix: cli prefer npm for @better-auth/cli commands
1 parent 51e06b3 commit 5201645

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@better-auth-cloudflare/cli",
3-
"version": "0.1.15",
3+
"version": "0.1.16",
44
"description": "CLI to generate Better Auth Cloudflare projects (Hono or OpenNext.js)",
55
"author": "Zach Grimaldi",
66
"repository": {

cli/src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,20 @@ function detectPackageManager(cwd: string): PackageManager {
168168
if (existsSync(join(cwd, "bun.lockb")) && commandAvailable("bun")) return "bun";
169169
if (existsSync(join(cwd, "pnpm-lock.yaml")) && commandAvailable("pnpm")) return "pnpm";
170170
if (existsSync(join(cwd, "yarn.lock")) && commandAvailable("yarn")) return "yarn";
171+
if (commandAvailable("npm")) return "npm";
171172
if (commandAvailable("bun")) return "bun";
172173
if (commandAvailable("pnpm")) return "pnpm";
173174
if (commandAvailable("yarn")) return "yarn";
174175
return "npm";
175176
}
176177

178+
function detectPackageManagerForAuth(cwd: string): PackageManager {
179+
// Always use npm for auth commands to ensure consistency
180+
if (commandAvailable("npm")) return "npm";
181+
// Fallback to regular detection if npm is not available
182+
return detectPackageManager(cwd);
183+
}
184+
177185
function runScript(pm: PackageManager, script: string, cwd: string) {
178186
const args = pm === "bun" ? ["run", script] : pm === "yarn" ? [script] : ["run", script];
179187
return bunSpawnSync(pm, args, cwd);
@@ -687,11 +695,13 @@ async function migrate(cliArgs?: CliArgs) {
687695
}
688696
}
689697

690-
// Run auth:update
698+
// Run auth:update - use npm specifically for auth commands
691699
debugLog("Running auth:update script");
692700
const authSpinner = spinner();
693701
authSpinner.start("Running auth:update...");
694-
const authRes = runScript(pm, "auth:update", process.cwd());
702+
const authPm = detectPackageManagerForAuth(process.cwd());
703+
debugLog(`Using package manager for auth commands: ${authPm}`);
704+
const authRes = runScript(authPm, "auth:update", process.cwd());
695705
if (authRes.code === 0) {
696706
authSpinner.stop(pc.green("Auth schema updated."));
697707
} else {
@@ -1804,7 +1814,9 @@ export const verification = {} as any;`;
18041814
const genAuth = spinner();
18051815
genAuth.start("Generating auth schema...");
18061816
{
1807-
const authRes = runScript(pm, "auth:update", targetDir);
1817+
const authPm = detectPackageManagerForAuth(targetDir);
1818+
debugLog(`Using package manager for auth commands: ${authPm}`);
1819+
const authRes = runScript(authPm, "auth:update", targetDir);
18081820
if (authRes.code === 0) {
18091821
genAuth.stop(pc.green("Auth schema updated."));
18101822

examples/hono/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"build": "npx tsc --noEmit",
66
"deploy": "wrangler deploy --minify",
77
"cf-typegen": "wrangler types --env-interface CloudflareBindings",
8-
"auth:generate": "npx @better-auth/cli@latest generate --config src/auth/index.ts --output src/db/auth.schema.ts -y",
9-
"auth:format": "npx prettier --write src/db/auth.schema.ts",
10-
"auth:update": "pnpm run auth:generate && pnpm run auth:format",
8+
"auth:generate": "npx --yes @better-auth/cli@latest generate --config src/auth/index.ts --output src/db/auth.schema.ts -y",
9+
"auth:format": "npx --yes prettier --write src/db/auth.schema.ts",
10+
"auth:update": "npm run auth:generate && npm run auth:format",
1111
"db:generate": "drizzle-kit generate",
1212
"db:migrate:dev": "wrangler d1 migrations apply DATABASE --local",
1313
"db:migrate:prod": "wrangler d1 migrations apply DATABASE --remote",

examples/opennextjs/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"lint": "next lint",
1414
"deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
1515
"preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
16-
"auth:generate": "npx @better-auth/cli@latest generate --config src/auth/index.ts --output src/db/auth.schema.ts -y",
17-
"auth:format": "npx prettier --write src/db/auth.schema.ts",
18-
"auth:update": "pnpm run auth:generate && pnpm run auth:format",
16+
"auth:generate": "npx --yes @better-auth/cli@latest generate --config src/auth/index.ts --output src/db/auth.schema.ts -y",
17+
"auth:format": "npx --yes prettier --write src/db/auth.schema.ts",
18+
"auth:update": "npm run auth:generate && npm run auth:format",
1919
"db:generate": "drizzle-kit generate",
2020
"db:migrate:dev": "wrangler d1 migrations apply DATABASE --local",
2121
"db:migrate:prod": "wrangler d1 migrations apply DATABASE --remote",

0 commit comments

Comments
 (0)