auth 1.5.3 → 1.5.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 CHANGED
@@ -23,6 +23,7 @@ import babelPresetReact from "@babel/preset-react";
23
23
  import babelPresetTypeScript from "@babel/preset-typescript";
24
24
  import { BetterAuthError } from "@better-auth/core/error";
25
25
  import { loadConfig } from "c12";
26
+ import { getTsconfig, parseTsconfig } from "get-tsconfig";
26
27
  import * as os$1 from "node:os";
27
28
  import os from "node:os";
28
29
  import open from "open";
@@ -919,23 +920,6 @@ const reserved = new Set([
919
920
  "instanceof"
920
921
  ]);
921
922
 
922
- //#endregion
923
- //#region src/utils/get-tsconfig-info.ts
924
- function stripJsonComments(jsonString) {
925
- return jsonString.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m).replace(/,(?=\s*[}\]])/g, "");
926
- }
927
- function getTsconfigInfo(cwd, flatPath) {
928
- let tsConfigPath;
929
- if (flatPath) tsConfigPath = flatPath;
930
- else tsConfigPath = cwd ? path.join(cwd, "tsconfig.json") : path.join("tsconfig.json");
931
- try {
932
- const text = fs.readFileSync(tsConfigPath, "utf-8");
933
- return JSON.parse(stripJsonComments(text));
934
- } catch (error) {
935
- throw error;
936
- }
937
- }
938
-
939
923
  //#endregion
940
924
  //#region src/utils/get-config.ts
941
925
  let possiblePaths$1 = [
@@ -966,49 +950,63 @@ possiblePaths$1 = [
966
950
  ...possiblePaths$1.map((it) => `src/${it}`),
967
951
  ...possiblePaths$1.map((it) => `app/${it}`)
968
952
  ];
969
- function resolveReferencePath(configDir, refPath) {
970
- const resolvedPath = path.resolve(configDir, refPath);
971
- if (refPath.endsWith(".json")) return resolvedPath;
972
- if (fs.existsSync(resolvedPath)) try {
973
- if (fs.statSync(resolvedPath).isFile()) return resolvedPath;
974
- } catch {}
975
- return path.resolve(configDir, refPath, "tsconfig.json");
953
+ function mergeAliases(target, source) {
954
+ for (const [alias, aliasPath] of Object.entries(source)) if (!(alias in target)) target[alias] = aliasPath;
976
955
  }
977
- function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set()) {
978
- if (visited.has(tsconfigPath)) return {};
979
- visited.add(tsconfigPath);
980
- if (!fs.existsSync(tsconfigPath)) {
981
- console.warn(`Referenced tsconfig not found: ${tsconfigPath}`);
982
- return {};
956
+ function extractAliases(tsconfig) {
957
+ const { paths = {}, baseUrl } = tsconfig.config.compilerOptions ?? {};
958
+ const result = {};
959
+ const configDir = path.dirname(tsconfig.path);
960
+ const resolvedBaseUrl = baseUrl ? path.resolve(configDir, baseUrl) : configDir;
961
+ for (const [alias, aliasPaths = []] of Object.entries(paths)) for (const aliasedPath of aliasPaths) {
962
+ const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
963
+ const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
964
+ result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath);
983
965
  }
966
+ return result;
967
+ }
968
+ /**
969
+ * Reads raw tsconfig JSON to get `references` (which get-tsconfig strips out).
970
+ */
971
+ function readRawTsconfigReferences(tsconfigPath) {
984
972
  try {
985
- const tsConfig = getTsconfigInfo(void 0, tsconfigPath);
986
- const { paths = {}, baseUrl = "." } = tsConfig.compilerOptions || {};
987
- const result = {};
988
- const configDir = path.dirname(tsconfigPath);
989
- const obj = Object.entries(paths);
990
- for (const [alias, aliasPaths] of obj) for (const aliasedPath of aliasPaths) {
991
- const resolvedBaseUrl = path.resolve(configDir, baseUrl);
992
- const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
993
- const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
994
- result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath);
995
- }
996
- if (tsConfig.references) for (const ref of tsConfig.references) {
997
- const refAliases = getPathAliasesRecursive(resolveReferencePath(configDir, ref.path), visited);
998
- for (const [alias, aliasPath] of Object.entries(refAliases)) if (!(alias in result)) result[alias] = aliasPath;
973
+ const stripped = fs.readFileSync(tsconfigPath, "utf-8").replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m).replace(/,(?=\s*[}\]])/g, "");
974
+ return JSON.parse(stripped).references;
975
+ } catch {
976
+ return;
977
+ }
978
+ }
979
+ /**
980
+ * Collect path aliases from tsconfig references recursively.
981
+ */
982
+ function collectReferencesAliases(tsconfigPath, visited = /* @__PURE__ */ new Set()) {
983
+ const result = {};
984
+ const refs = readRawTsconfigReferences(tsconfigPath);
985
+ if (!refs) return result;
986
+ const configDir = path.dirname(tsconfigPath);
987
+ for (const ref of refs) {
988
+ const resolvedRef = path.resolve(configDir, ref.path);
989
+ const refTsconfigPath = resolvedRef.endsWith(".json") ? resolvedRef : path.join(resolvedRef, "tsconfig.json");
990
+ if (visited.has(refTsconfigPath)) continue;
991
+ visited.add(refTsconfigPath);
992
+ try {
993
+ mergeAliases(result, extractAliases({
994
+ path: refTsconfigPath,
995
+ config: parseTsconfig(refTsconfigPath)
996
+ }));
997
+ } catch {
998
+ continue;
999
999
  }
1000
- return result;
1001
- } catch (error) {
1002
- console.warn(`Error parsing tsconfig at ${tsconfigPath}: ${error}`);
1003
- return {};
1000
+ mergeAliases(result, collectReferencesAliases(refTsconfigPath, visited));
1004
1001
  }
1002
+ return result;
1005
1003
  }
1006
1004
  function getPathAliases(cwd) {
1007
- let tsConfigPath = path.join(cwd, "tsconfig.json");
1008
- if (!fs.existsSync(tsConfigPath)) tsConfigPath = path.join(cwd, "jsconfig.json");
1009
- if (!fs.existsSync(tsConfigPath)) return null;
1005
+ const tsconfig = getTsconfig(cwd, fs.existsSync(path.join(cwd, "tsconfig.json")) ? "tsconfig.json" : "jsconfig.json");
1006
+ if (!tsconfig) return null;
1010
1007
  try {
1011
- const result = getPathAliasesRecursive(tsConfigPath);
1008
+ const result = extractAliases(tsconfig);
1009
+ mergeAliases(result, collectReferencesAliases(tsconfig.path));
1012
1010
  addSvelteKitEnvModules(result);
1013
1011
  addCloudflareModules(result);
1014
1012
  return result;
@@ -6009,7 +6007,7 @@ export const auth = betterAuth({
6009
6007
  return;
6010
6008
  }
6011
6009
  if (connectResponse.connect) {
6012
- await open("https://better-auth.com/onboarding");
6010
+ await open("https://dash.better-auth.com/onboarding");
6013
6011
  console.log(chalk.cyan("\n→ ") + "Opening Better Auth onboarding in your browser...\n");
6014
6012
  }
6015
6013
  console.log(chalk.green(`\n✔ `) + chalk.bold("Success! ") + "Project setup complete.\n");