@better-auth/cli 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +53 -23
- package/package.json +6 -7
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
+
import * as fs$2 from "node:fs";
|
|
4
|
+
import fs, { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import fs$1 from "node:fs/promises";
|
|
6
|
+
import * as path$1 from "node:path";
|
|
7
|
+
import path from "node:path";
|
|
3
8
|
import { BetterAuthError, capitalizeFirstLetter, createTelemetry, getTelemetryAuthConfig, logger } from "better-auth";
|
|
4
9
|
import { getAdapter, getAuthTables, getMigrations } from "better-auth/db";
|
|
5
10
|
import chalk from "chalk";
|
|
6
|
-
import * as fs$2 from "fs";
|
|
7
|
-
import fs, { existsSync, readFileSync } from "fs";
|
|
8
|
-
import fs$1 from "fs/promises";
|
|
9
|
-
import * as path$1 from "path";
|
|
10
|
-
import path from "path";
|
|
11
11
|
import prompts from "prompts";
|
|
12
12
|
import yoctoSpinner from "yocto-spinner";
|
|
13
13
|
import * as z from "zod/v4";
|
|
@@ -17,13 +17,13 @@ import { produceSchema } from "@mrleebo/prisma-ast";
|
|
|
17
17
|
import babelPresetReact from "@babel/preset-react";
|
|
18
18
|
import babelPresetTypeScript from "@babel/preset-typescript";
|
|
19
19
|
import { loadConfig } from "c12";
|
|
20
|
-
import { exec, execSync } from "child_process";
|
|
21
|
-
import * as os$1 from "os";
|
|
22
|
-
import os from "os";
|
|
20
|
+
import { exec, execSync } from "node:child_process";
|
|
21
|
+
import * as os$1 from "node:os";
|
|
22
|
+
import os from "node:os";
|
|
23
23
|
import { cancel, confirm, intro, isCancel, log, multiselect, outro, select, spinner, text } from "@clack/prompts";
|
|
24
24
|
import { parse } from "dotenv";
|
|
25
25
|
import semver from "semver";
|
|
26
|
-
import Crypto from "crypto";
|
|
26
|
+
import Crypto from "node:crypto";
|
|
27
27
|
import { createAuthClient } from "better-auth/client";
|
|
28
28
|
import { deviceAuthorizationClient } from "better-auth/client/plugins";
|
|
29
29
|
import open from "open";
|
|
@@ -80,7 +80,7 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
|
|
|
80
80
|
mysql: `mysqlEnum([${type.map((x) => `'${x}'`).join(", ")}])`
|
|
81
81
|
}[databaseType];
|
|
82
82
|
else throw new TypeError(`Invalid field type for field ${name} in model ${modelName}`);
|
|
83
|
-
|
|
83
|
+
const dbTypeMap = {
|
|
84
84
|
string: {
|
|
85
85
|
sqlite: `text('${name}')`,
|
|
86
86
|
pg: `text('${name}')`,
|
|
@@ -116,7 +116,9 @@ const generateDrizzleSchema = async ({ options, file, adapter }) => {
|
|
|
116
116
|
pg: `jsonb('${name}')`,
|
|
117
117
|
mysql: `json('${name}')`
|
|
118
118
|
}
|
|
119
|
-
}[type]
|
|
119
|
+
}[type];
|
|
120
|
+
if (!dbTypeMap) throw new Error(`Unsupported field type '${field.type}' for field '${name}'.`);
|
|
121
|
+
return dbTypeMap[databaseType];
|
|
120
122
|
}
|
|
121
123
|
let id = "";
|
|
122
124
|
const useNumberId = options.advanced?.database?.useNumberId || options.advanced?.database?.generateId === "serial";
|
|
@@ -274,6 +276,24 @@ const generateMigrations = async ({ options, file }) => {
|
|
|
274
276
|
};
|
|
275
277
|
};
|
|
276
278
|
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/utils/get-package-info.ts
|
|
281
|
+
function getPackageInfo(cwd) {
|
|
282
|
+
const packageJsonPath = cwd ? path.join(cwd, "package.json") : path.join("package.json");
|
|
283
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
284
|
+
}
|
|
285
|
+
function getPrismaVersion(cwd) {
|
|
286
|
+
try {
|
|
287
|
+
const packageInfo = getPackageInfo(cwd);
|
|
288
|
+
const prismaVersion = packageInfo.dependencies?.prisma || packageInfo.devDependencies?.prisma || packageInfo.dependencies?.["@prisma/client"] || packageInfo.devDependencies?.["@prisma/client"];
|
|
289
|
+
if (!prismaVersion) return null;
|
|
290
|
+
const match = prismaVersion.match(/(\d+)/);
|
|
291
|
+
return match ? parseInt(match[1], 10) : null;
|
|
292
|
+
} catch (error) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
277
297
|
//#endregion
|
|
278
298
|
//#region src/generators/prisma.ts
|
|
279
299
|
const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
@@ -291,7 +311,15 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
291
311
|
});
|
|
292
312
|
let schemaPrisma = "";
|
|
293
313
|
if (schemaPrismaExist) schemaPrisma = await fs$1.readFile(path.join(process.cwd(), filePath), "utf-8");
|
|
294
|
-
else schemaPrisma = getNewPrisma(provider);
|
|
314
|
+
else schemaPrisma = getNewPrisma(provider, process.cwd());
|
|
315
|
+
const prismaVersion = getPrismaVersion(process.cwd());
|
|
316
|
+
if (prismaVersion && prismaVersion >= 7 && schemaPrismaExist) schemaPrisma = produceSchema(schemaPrisma, (builder) => {
|
|
317
|
+
const generator = builder.findByType("generator", { name: "client" });
|
|
318
|
+
if (generator && generator.properties) {
|
|
319
|
+
const providerProp = generator.properties.find((prop) => prop.type === "assignment" && prop.key === "provider");
|
|
320
|
+
if (providerProp && providerProp.value === "\"prisma-client-js\"") providerProp.value = "\"prisma-client\"";
|
|
321
|
+
}
|
|
322
|
+
});
|
|
295
323
|
const manyToManyRelations = /* @__PURE__ */ new Map();
|
|
296
324
|
for (const table in tables) {
|
|
297
325
|
const fields = tables[table]?.fields;
|
|
@@ -468,14 +496,17 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
|
|
|
468
496
|
overwrite: schemaPrismaExist && schemaChanged
|
|
469
497
|
};
|
|
470
498
|
};
|
|
471
|
-
const getNewPrisma = (provider) =>
|
|
472
|
-
|
|
499
|
+
const getNewPrisma = (provider, cwd) => {
|
|
500
|
+
const prismaVersion = getPrismaVersion(cwd);
|
|
501
|
+
return `generator client {
|
|
502
|
+
provider = "${prismaVersion && prismaVersion >= 7 ? "prisma-client" : "prisma-client-js"}"
|
|
473
503
|
}
|
|
474
|
-
|
|
504
|
+
|
|
475
505
|
datasource db {
|
|
476
506
|
provider = "${provider}"
|
|
477
507
|
url = ${provider === "sqlite" ? `"file:./dev.db"` : `env("DATABASE_URL")`}
|
|
478
508
|
}`;
|
|
509
|
+
};
|
|
479
510
|
|
|
480
511
|
//#endregion
|
|
481
512
|
//#region src/generators/index.ts
|
|
@@ -748,7 +779,13 @@ let possiblePaths = [
|
|
|
748
779
|
"auth.js",
|
|
749
780
|
"auth.jsx",
|
|
750
781
|
"auth.server.js",
|
|
751
|
-
"auth.server.ts"
|
|
782
|
+
"auth.server.ts",
|
|
783
|
+
"auth/index.ts",
|
|
784
|
+
"auth/index.tsx",
|
|
785
|
+
"auth/index.js",
|
|
786
|
+
"auth/index.jsx",
|
|
787
|
+
"auth/index.server.js",
|
|
788
|
+
"auth/index.server.ts"
|
|
752
789
|
];
|
|
753
790
|
possiblePaths = [
|
|
754
791
|
...possiblePaths,
|
|
@@ -1020,13 +1057,6 @@ async function generateAction(opts) {
|
|
|
1020
1057
|
}
|
|
1021
1058
|
const generate = new Command("generate").option("-c, --cwd <cwd>", "the working directory. defaults to the current directory.", process.cwd()).option("--config <config>", "the path to the configuration file. defaults to the first configuration file found.").option("--output <output>", "the file to output to the generated schema").option("-y, --yes", "automatically answer yes to all prompts", false).option("--y", "(deprecated) same as --yes", false).action(generateAction);
|
|
1022
1059
|
|
|
1023
|
-
//#endregion
|
|
1024
|
-
//#region src/utils/get-package-info.ts
|
|
1025
|
-
function getPackageInfo(cwd) {
|
|
1026
|
-
const packageJsonPath = cwd ? path.join(cwd, "package.json") : path.join("package.json");
|
|
1027
|
-
return JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
1060
|
//#endregion
|
|
1031
1061
|
//#region src/commands/info.ts
|
|
1032
1062
|
function getSystemInfo() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The CLI for Better Auth",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"@types/better-sqlite3": "^7.6.13",
|
|
33
33
|
"@types/prompts": "^2.4.9",
|
|
34
34
|
"@types/semver": "^7.7.1",
|
|
35
|
+
"jiti": "^2.6.0",
|
|
35
36
|
"tsdown": "^0.16.0",
|
|
36
37
|
"tsx": "^4.20.6",
|
|
37
38
|
"type-fest": "^5.2.0",
|
|
38
39
|
"typescript": "^5.9.3",
|
|
39
|
-
"@better-auth/passkey": "1.4.
|
|
40
|
+
"@better-auth/passkey": "1.4.5"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"@babel/core": "^7.28.4",
|
|
@@ -53,19 +54,16 @@
|
|
|
53
54
|
"commander": "^12.1.0",
|
|
54
55
|
"dotenv": "^17.2.2",
|
|
55
56
|
"drizzle-orm": "^0.33.0",
|
|
56
|
-
"get-tsconfig": "^4.10.1",
|
|
57
|
-
"jiti": "^2.6.0",
|
|
58
57
|
"open": "^10.2.0",
|
|
59
58
|
"pg": "^8.16.3",
|
|
60
59
|
"prettier": "^3.6.2",
|
|
61
60
|
"prisma": "^5.22.0",
|
|
62
61
|
"prompts": "^2.4.2",
|
|
63
62
|
"semver": "^7.7.2",
|
|
64
|
-
"tinyexec": "^0.3.2",
|
|
65
63
|
"yocto-spinner": "^0.2.3",
|
|
66
64
|
"zod": "^4.1.12",
|
|
67
|
-
"better-auth": "1.4.
|
|
68
|
-
"@better-auth/core": "1.4.
|
|
65
|
+
"better-auth": "1.4.5",
|
|
66
|
+
"@better-auth/core": "1.4.5"
|
|
69
67
|
},
|
|
70
68
|
"files": [
|
|
71
69
|
"dist"
|
|
@@ -73,6 +71,7 @@
|
|
|
73
71
|
"scripts": {
|
|
74
72
|
"build": "tsdown",
|
|
75
73
|
"start": "node ./dist/index.mjs",
|
|
74
|
+
"lint:package": "publint run --strict",
|
|
76
75
|
"dev": "tsx ./src/index.ts",
|
|
77
76
|
"test": "vitest",
|
|
78
77
|
"typecheck": "tsc --project tsconfig.json"
|