mirror of
https://github.com/better-auth/better-auth.git
synced 2026-08-22 16:42:53 -05:00
Closes #8622 When the old @better-auth/cli detects that better-auth >= 1.5.0 is installed, it now prints a warning directing users to the new `auth` CLI (`npx auth@latest`). This prevents unexpected behavior from the old CLI generating incorrect schemas for v1.5.x projects. Uses `createRequire` from the user's CWD to resolve better-auth's package.json and `semver.gte` for version comparison. Uses `chalk` for terminal colors (consistent with the rest of the CLI). Silently skips the check if better-auth is not installed.
82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { exec } from "node:child_process";
|
|
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { promisify } from "node:util";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { cliPath } from "./utils";
|
|
|
|
const execAsync = promisify(exec);
|
|
|
|
let tmpDir: string;
|
|
|
|
/**
|
|
* @see https://github.com/better-auth/better-auth/issues/8622
|
|
*/
|
|
describe("version warning for better-auth v1.5.x+", () => {
|
|
beforeEach(async () => {
|
|
const tmp = path.join(
|
|
process.cwd(),
|
|
"node_modules",
|
|
".cache",
|
|
"version_warning_test-",
|
|
);
|
|
await fs.mkdir(path.dirname(tmp), { recursive: true });
|
|
tmpDir = await fs.mkdtemp(tmp);
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await fs.rm(tmpDir, { recursive: true });
|
|
});
|
|
|
|
async function setupBetterAuth(version: string) {
|
|
const pkgDir = path.join(tmpDir, "node_modules", "better-auth");
|
|
await fs.mkdir(pkgDir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(pkgDir, "package.json"),
|
|
JSON.stringify({ name: "better-auth", version }),
|
|
);
|
|
// Create a minimal entry point so require.resolve works
|
|
await fs.writeFile(path.join(pkgDir, "index.js"), "");
|
|
}
|
|
|
|
it("should warn when better-auth >= 1.5.0 is installed", async () => {
|
|
await setupBetterAuth("1.5.0");
|
|
|
|
const { stderr } = await execAsync(`node ${cliPath} --help`, {
|
|
cwd: tmpDir,
|
|
});
|
|
|
|
expect(stderr).toContain("You are using @better-auth/cli");
|
|
expect(stderr).toContain("npx auth@latest");
|
|
});
|
|
|
|
it("should warn for better-auth 1.5.3", async () => {
|
|
await setupBetterAuth("1.5.3");
|
|
|
|
const { stderr } = await execAsync(`node ${cliPath} --help`, {
|
|
cwd: tmpDir,
|
|
});
|
|
|
|
expect(stderr).toContain("better-auth v1.5.3");
|
|
expect(stderr).toContain("npx auth@latest");
|
|
});
|
|
|
|
it("should not warn when better-auth < 1.5.0 is installed", async () => {
|
|
await setupBetterAuth("1.4.21");
|
|
|
|
const { stderr } = await execAsync(`node ${cliPath} --help`, {
|
|
cwd: tmpDir,
|
|
});
|
|
|
|
expect(stderr).not.toContain("npx auth@latest");
|
|
});
|
|
|
|
it("should not warn when better-auth is not installed", async () => {
|
|
const { stderr } = await execAsync(`node ${cliPath} --help`, {
|
|
cwd: tmpDir,
|
|
});
|
|
|
|
expect(stderr).not.toContain("npx auth@latest");
|
|
});
|
|
});
|