better-auth 0.2.9-beta.2 → 0.2.9-beta.3
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/adapters/drizzle.js +1 -2
- package/dist/cli.js +85 -34
- package/package.json +1 -1
package/dist/adapters/drizzle.js
CHANGED
|
@@ -172,7 +172,7 @@ var getAuthTables = (options) => {
|
|
|
172
172
|
|
|
173
173
|
// src/adapters/drizzle-adapter/index.ts
|
|
174
174
|
import { existsSync } from "fs";
|
|
175
|
-
import
|
|
175
|
+
import "fs/promises";
|
|
176
176
|
|
|
177
177
|
// src/error/better-auth-error.ts
|
|
178
178
|
var BetterAuthError = class extends Error {
|
|
@@ -306,7 +306,6 @@ var drizzleAdapter = (db, options) => {
|
|
|
306
306
|
let code = `import { ${databaseType}Table, text, ${int}, ${timestampAndBoolean} } from "drizzle-orm/${databaseType}-core";
|
|
307
307
|
`;
|
|
308
308
|
const fileExist = existsSync(filePath);
|
|
309
|
-
let fileContent = fileExist ? await fs.readFile(filePath, "utf-8") : "";
|
|
310
309
|
for (const table in tables) {
|
|
311
310
|
let getType2 = function(name, type) {
|
|
312
311
|
if (type === "string") {
|
package/dist/cli.js
CHANGED
|
@@ -56,6 +56,20 @@ var logger = createLogger();
|
|
|
56
56
|
import path from "path";
|
|
57
57
|
import babelPresetTypescript from "@babel/preset-typescript";
|
|
58
58
|
import babelPresetReact from "@babel/preset-react";
|
|
59
|
+
import fs from "fs";
|
|
60
|
+
|
|
61
|
+
// src/error/better-auth-error.ts
|
|
62
|
+
var BetterAuthError = class extends Error {
|
|
63
|
+
constructor(message, cause) {
|
|
64
|
+
super(message);
|
|
65
|
+
this.name = "BetterAuthError";
|
|
66
|
+
this.message = message;
|
|
67
|
+
this.cause = cause;
|
|
68
|
+
this.stack = "";
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/cli/get-config.ts
|
|
59
73
|
var possiblePaths = ["auth.ts", "auth.tsx"];
|
|
60
74
|
possiblePaths = [
|
|
61
75
|
...possiblePaths,
|
|
@@ -63,16 +77,55 @@ possiblePaths = [
|
|
|
63
77
|
...possiblePaths.map((it) => `utils/${it}`)
|
|
64
78
|
];
|
|
65
79
|
possiblePaths = [...possiblePaths, ...possiblePaths.map((it) => `src/${it}`)];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
80
|
+
function stripJsonComments(jsonString) {
|
|
81
|
+
return jsonString.replace(
|
|
82
|
+
/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,
|
|
83
|
+
(m, g) => g ? "" : m
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function getPathAliases(cwd) {
|
|
87
|
+
const tsConfigPath = path.join(cwd, "tsconfig.json");
|
|
88
|
+
if (!fs.existsSync(tsConfigPath)) {
|
|
89
|
+
logger.warn("[#better-auth]: tsconfig.json not found.");
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
const tsConfigContent = fs.readFileSync(tsConfigPath, "utf8");
|
|
94
|
+
const strippedTsConfigContent = stripJsonComments(tsConfigContent);
|
|
95
|
+
const tsConfig = JSON.parse(strippedTsConfigContent);
|
|
96
|
+
const { paths = {} } = tsConfig.compilerOptions || {};
|
|
97
|
+
const result = {};
|
|
98
|
+
const obj = Object.entries(paths);
|
|
99
|
+
for (const [alias, aliasPaths] of obj) {
|
|
100
|
+
for (const _ of aliasPaths) {
|
|
101
|
+
result[alias[0]] = "../";
|
|
102
|
+
}
|
|
73
103
|
}
|
|
74
|
-
|
|
75
|
-
|
|
104
|
+
return result;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
throw new BetterAuthError("Error parsing tsconfig.json");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
var jitiOptions = (cwd) => {
|
|
110
|
+
const alias = getPathAliases(cwd) || {};
|
|
111
|
+
return {
|
|
112
|
+
transformOptions: {
|
|
113
|
+
babel: {
|
|
114
|
+
presets: [
|
|
115
|
+
[
|
|
116
|
+
babelPresetTypescript,
|
|
117
|
+
{
|
|
118
|
+
isTSX: true,
|
|
119
|
+
allExtensions: true
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
[babelPresetReact, { runtime: "automatic" }]
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
127
|
+
alias
|
|
128
|
+
};
|
|
76
129
|
};
|
|
77
130
|
async function getConfig({
|
|
78
131
|
cwd,
|
|
@@ -81,10 +134,11 @@ async function getConfig({
|
|
|
81
134
|
try {
|
|
82
135
|
let configFile = null;
|
|
83
136
|
if (configPath) {
|
|
137
|
+
const alias = getPathAliases(cwd);
|
|
84
138
|
const { config } = await loadConfig({
|
|
85
139
|
configFile: path.join(cwd, configPath),
|
|
86
140
|
dotenv: true,
|
|
87
|
-
jitiOptions
|
|
141
|
+
jitiOptions: jitiOptions(cwd)
|
|
88
142
|
});
|
|
89
143
|
if (!config.auth && !config.default) {
|
|
90
144
|
logger.error(
|
|
@@ -99,7 +153,7 @@ async function getConfig({
|
|
|
99
153
|
try {
|
|
100
154
|
const { config } = await loadConfig({
|
|
101
155
|
configFile: possiblePath,
|
|
102
|
-
jitiOptions
|
|
156
|
+
jitiOptions: jitiOptions(cwd)
|
|
103
157
|
});
|
|
104
158
|
const hasConfig = Object.keys(config).length > 0;
|
|
105
159
|
if (hasConfig) {
|
|
@@ -547,17 +601,6 @@ async function getMigrations(config) {
|
|
|
547
601
|
return { toBeCreated, toBeAdded, runMigrations, compileMigrations };
|
|
548
602
|
}
|
|
549
603
|
|
|
550
|
-
// src/error/better-auth-error.ts
|
|
551
|
-
var BetterAuthError = class extends Error {
|
|
552
|
-
constructor(message, cause) {
|
|
553
|
-
super(message);
|
|
554
|
-
this.name = "BetterAuthError";
|
|
555
|
-
this.message = message;
|
|
556
|
-
this.cause = cause;
|
|
557
|
-
this.stack = "";
|
|
558
|
-
}
|
|
559
|
-
};
|
|
560
|
-
|
|
561
604
|
// src/cli/utils/install-dep.ts
|
|
562
605
|
import ora from "ora";
|
|
563
606
|
import prompts from "prompts";
|
|
@@ -844,14 +887,14 @@ async function getAdapter(options, isCli) {
|
|
|
844
887
|
}
|
|
845
888
|
|
|
846
889
|
// src/cli/commands/generate.ts
|
|
847
|
-
import
|
|
890
|
+
import fs3 from "fs/promises";
|
|
848
891
|
import chalk2 from "chalk";
|
|
849
892
|
|
|
850
893
|
// src/adapters/prisma-adapter/generate-cli.ts
|
|
851
894
|
import { produceSchema } from "@mrleebo/prisma-ast";
|
|
852
895
|
import { existsSync as existsSync2 } from "fs";
|
|
853
896
|
import path3 from "path";
|
|
854
|
-
import
|
|
897
|
+
import fs2 from "fs/promises";
|
|
855
898
|
|
|
856
899
|
// src/utils/misc.ts
|
|
857
900
|
function capitalizeFirstLetter(str) {
|
|
@@ -869,7 +912,7 @@ async function generatePrismaSchema({
|
|
|
869
912
|
const schemaPrismaExist = existsSync2(path3.join(process.cwd(), filePath));
|
|
870
913
|
let schemaPrisma = "";
|
|
871
914
|
if (schemaPrismaExist) {
|
|
872
|
-
schemaPrisma = await
|
|
915
|
+
schemaPrisma = await fs2.readFile(
|
|
873
916
|
path3.join(process.cwd(), filePath),
|
|
874
917
|
"utf-8"
|
|
875
918
|
);
|
|
@@ -961,7 +1004,6 @@ var generate = new Command2("generate").option(
|
|
|
961
1004
|
config: z2.string().optional(),
|
|
962
1005
|
output: z2.string().optional()
|
|
963
1006
|
}).parse(opts);
|
|
964
|
-
const spinner = ora3("preparing schema...").start();
|
|
965
1007
|
const cwd = path4.resolve(options.cwd);
|
|
966
1008
|
if (!existsSync3(cwd)) {
|
|
967
1009
|
logger.error(`The directory "${cwd}" does not exist.`);
|
|
@@ -977,6 +1019,7 @@ var generate = new Command2("generate").option(
|
|
|
977
1019
|
);
|
|
978
1020
|
return;
|
|
979
1021
|
}
|
|
1022
|
+
const spinner = ora3("preparing schema...").start();
|
|
980
1023
|
const adapter = await getAdapter(config, true).catch((e) => {
|
|
981
1024
|
logger.error(e.message);
|
|
982
1025
|
process.exit(1);
|
|
@@ -1019,10 +1062,16 @@ var generate = new Command2("generate").option(
|
|
|
1019
1062
|
)} the schema to the file?`
|
|
1020
1063
|
});
|
|
1021
1064
|
if (confirm2) {
|
|
1065
|
+
const exist = existsSync3(path4.join(cwd, fileName));
|
|
1066
|
+
if (!exist) {
|
|
1067
|
+
await fs3.mkdir(path4.dirname(path4.join(cwd, fileName)), {
|
|
1068
|
+
recursive: true
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1022
1071
|
if (overwrite) {
|
|
1023
|
-
await
|
|
1072
|
+
await fs3.writeFile(path4.join(cwd, fileName), code);
|
|
1024
1073
|
} else {
|
|
1025
|
-
await
|
|
1074
|
+
await fs3.appendFile(path4.join(cwd, fileName), code);
|
|
1026
1075
|
}
|
|
1027
1076
|
logger.success(`\u{1F680} schema was appended successfully!`);
|
|
1028
1077
|
process.exit(0);
|
|
@@ -1042,13 +1091,15 @@ var generate = new Command2("generate").option(
|
|
|
1042
1091
|
logger.error("Schema generation aborted.");
|
|
1043
1092
|
process.exit(1);
|
|
1044
1093
|
}
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1094
|
+
if (!options.output) {
|
|
1095
|
+
const dirExist = existsSync3(path4.dirname(path4.join(cwd, fileName)));
|
|
1096
|
+
if (!dirExist) {
|
|
1097
|
+
await fs3.mkdir(path4.dirname(path4.join(cwd, fileName)), {
|
|
1098
|
+
recursive: true
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1050
1101
|
}
|
|
1051
|
-
await
|
|
1102
|
+
await fs3.writeFile(options.output || path4.join(cwd, fileName), code);
|
|
1052
1103
|
logger.success(`\u{1F680} schema was generated successfully!`);
|
|
1053
1104
|
process.exit(0);
|
|
1054
1105
|
});
|