@better-auth/cli 1.3.7-beta.3 → 1.3.7
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 +135 -7
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1667,7 +1667,8 @@ async function updateEnvs({
|
|
|
1667
1667
|
}
|
|
1668
1668
|
}
|
|
1669
1669
|
|
|
1670
|
-
function addSvelteKitEnvModules(aliases) {
|
|
1670
|
+
function addSvelteKitEnvModules(aliases, cwd) {
|
|
1671
|
+
const workingDir = process.cwd();
|
|
1671
1672
|
aliases["$env/dynamic/private"] = createDataUriModule(
|
|
1672
1673
|
createDynamicEnvModule()
|
|
1673
1674
|
);
|
|
@@ -1680,6 +1681,88 @@ function addSvelteKitEnvModules(aliases) {
|
|
|
1680
1681
|
aliases["$env/static/public"] = createDataUriModule(
|
|
1681
1682
|
createStaticEnvModule(filterPublicEnv("PUBLIC_", ""))
|
|
1682
1683
|
);
|
|
1684
|
+
const svelteKitAliases = getSvelteKitPathAliases(workingDir);
|
|
1685
|
+
Object.assign(aliases, svelteKitAliases);
|
|
1686
|
+
}
|
|
1687
|
+
function getSvelteKitPathAliases(cwd) {
|
|
1688
|
+
const aliases = {};
|
|
1689
|
+
const packageJsonPath = path.join(cwd, "package.json");
|
|
1690
|
+
const svelteConfigPath = path.join(cwd, "svelte.config.js");
|
|
1691
|
+
const svelteConfigTsPath = path.join(cwd, "svelte.config.ts");
|
|
1692
|
+
let isSvelteKitProject = false;
|
|
1693
|
+
if (fs$2.existsSync(packageJsonPath)) {
|
|
1694
|
+
try {
|
|
1695
|
+
const packageJson = JSON.parse(fs$2.readFileSync(packageJsonPath, "utf-8"));
|
|
1696
|
+
const deps = {
|
|
1697
|
+
...packageJson.dependencies,
|
|
1698
|
+
...packageJson.devDependencies
|
|
1699
|
+
};
|
|
1700
|
+
isSvelteKitProject = !!deps["@sveltejs/kit"];
|
|
1701
|
+
} catch {
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (!isSvelteKitProject) {
|
|
1705
|
+
isSvelteKitProject = fs$2.existsSync(svelteConfigPath) || fs$2.existsSync(svelteConfigTsPath);
|
|
1706
|
+
}
|
|
1707
|
+
if (!isSvelteKitProject) {
|
|
1708
|
+
return aliases;
|
|
1709
|
+
}
|
|
1710
|
+
const libPaths = [path.join(cwd, "src", "lib"), path.join(cwd, "lib")];
|
|
1711
|
+
for (const libPath of libPaths) {
|
|
1712
|
+
if (fs$2.existsSync(libPath)) {
|
|
1713
|
+
aliases["$lib"] = libPath;
|
|
1714
|
+
const commonSubPaths = ["server", "utils", "components", "stores"];
|
|
1715
|
+
for (const subPath of commonSubPaths) {
|
|
1716
|
+
const subDir = path.join(libPath, subPath);
|
|
1717
|
+
if (fs$2.existsSync(subDir)) {
|
|
1718
|
+
aliases[`$lib/${subPath}`] = subDir;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
aliases["$app/server"] = createDataUriModule(createAppServerModule());
|
|
1725
|
+
const customAliases = getSvelteConfigAliases(cwd);
|
|
1726
|
+
Object.assign(aliases, customAliases);
|
|
1727
|
+
return aliases;
|
|
1728
|
+
}
|
|
1729
|
+
function getSvelteConfigAliases(cwd) {
|
|
1730
|
+
const aliases = {};
|
|
1731
|
+
const configPaths = [
|
|
1732
|
+
path.join(cwd, "svelte.config.js"),
|
|
1733
|
+
path.join(cwd, "svelte.config.ts")
|
|
1734
|
+
];
|
|
1735
|
+
for (const configPath of configPaths) {
|
|
1736
|
+
if (fs$2.existsSync(configPath)) {
|
|
1737
|
+
try {
|
|
1738
|
+
const content = fs$2.readFileSync(configPath, "utf-8");
|
|
1739
|
+
const aliasMatch = content.match(/alias\s*:\s*\{([^}]+)\}/);
|
|
1740
|
+
if (aliasMatch && aliasMatch[1]) {
|
|
1741
|
+
const aliasContent = aliasMatch[1];
|
|
1742
|
+
const aliasMatches = aliasContent.matchAll(
|
|
1743
|
+
/['"`](\$[^'"`]+)['"`]\s*:\s*['"`]([^'"`]+)['"`]/g
|
|
1744
|
+
);
|
|
1745
|
+
for (const match of aliasMatches) {
|
|
1746
|
+
const [, alias, target] = match;
|
|
1747
|
+
if (alias && target) {
|
|
1748
|
+
aliases[alias + "/*"] = path.resolve(cwd, target) + "/*";
|
|
1749
|
+
aliases[alias] = path.resolve(cwd, target);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
} catch {
|
|
1754
|
+
}
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
return aliases;
|
|
1759
|
+
}
|
|
1760
|
+
function createAppServerModule() {
|
|
1761
|
+
return `
|
|
1762
|
+
// $app/server stub for CLI compatibility
|
|
1763
|
+
export default {};
|
|
1764
|
+
// jiti dirty hack: .unknown
|
|
1765
|
+
`;
|
|
1683
1766
|
}
|
|
1684
1767
|
function createDataUriModule(module) {
|
|
1685
1768
|
return `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;
|
|
@@ -1783,24 +1866,69 @@ possiblePaths = [
|
|
|
1783
1866
|
...possiblePaths.map((it) => `src/${it}`),
|
|
1784
1867
|
...possiblePaths.map((it) => `app/${it}`)
|
|
1785
1868
|
];
|
|
1786
|
-
function
|
|
1787
|
-
const
|
|
1788
|
-
if (
|
|
1789
|
-
return
|
|
1869
|
+
function resolveReferencePath(configDir, refPath) {
|
|
1870
|
+
const resolvedPath = path.resolve(configDir, refPath);
|
|
1871
|
+
if (refPath.endsWith(".json")) {
|
|
1872
|
+
return resolvedPath;
|
|
1873
|
+
}
|
|
1874
|
+
if (fs$2.existsSync(resolvedPath)) {
|
|
1875
|
+
try {
|
|
1876
|
+
const stats = fs$2.statSync(resolvedPath);
|
|
1877
|
+
if (stats.isFile()) {
|
|
1878
|
+
return resolvedPath;
|
|
1879
|
+
}
|
|
1880
|
+
} catch {
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
return path.resolve(configDir, refPath, "tsconfig.json");
|
|
1884
|
+
}
|
|
1885
|
+
function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set()) {
|
|
1886
|
+
if (visited.has(tsconfigPath)) {
|
|
1887
|
+
return {};
|
|
1888
|
+
}
|
|
1889
|
+
visited.add(tsconfigPath);
|
|
1890
|
+
if (!fs$2.existsSync(tsconfigPath)) {
|
|
1891
|
+
logger.warn(`Referenced tsconfig not found: ${tsconfigPath}`);
|
|
1892
|
+
return {};
|
|
1790
1893
|
}
|
|
1791
1894
|
try {
|
|
1792
|
-
const tsConfig = getTsconfigInfo(
|
|
1895
|
+
const tsConfig = getTsconfigInfo(void 0, tsconfigPath);
|
|
1793
1896
|
const { paths = {}, baseUrl = "." } = tsConfig.compilerOptions || {};
|
|
1794
1897
|
const result = {};
|
|
1898
|
+
const configDir = path.dirname(tsconfigPath);
|
|
1795
1899
|
const obj = Object.entries(paths);
|
|
1796
1900
|
for (const [alias, aliasPaths] of obj) {
|
|
1797
1901
|
for (const aliasedPath of aliasPaths) {
|
|
1798
|
-
const resolvedBaseUrl = path.
|
|
1902
|
+
const resolvedBaseUrl = path.resolve(configDir, baseUrl);
|
|
1799
1903
|
const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
|
|
1800
1904
|
const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
|
|
1801
1905
|
result[finalAlias || ""] = path.join(resolvedBaseUrl, finalAliasedPath);
|
|
1802
1906
|
}
|
|
1803
1907
|
}
|
|
1908
|
+
if (tsConfig.references) {
|
|
1909
|
+
for (const ref of tsConfig.references) {
|
|
1910
|
+
const refPath = resolveReferencePath(configDir, ref.path);
|
|
1911
|
+
const refAliases = getPathAliasesRecursive(refPath, visited);
|
|
1912
|
+
for (const [alias, aliasPath] of Object.entries(refAliases)) {
|
|
1913
|
+
if (!(alias in result)) {
|
|
1914
|
+
result[alias] = aliasPath;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
return result;
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
logger.warn(`Error parsing tsconfig at ${tsconfigPath}: ${error}`);
|
|
1922
|
+
return {};
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function getPathAliases(cwd) {
|
|
1926
|
+
const tsConfigPath = path.join(cwd, "tsconfig.json");
|
|
1927
|
+
if (!fs$2.existsSync(tsConfigPath)) {
|
|
1928
|
+
return null;
|
|
1929
|
+
}
|
|
1930
|
+
try {
|
|
1931
|
+
const result = getPathAliasesRecursive(tsConfigPath);
|
|
1804
1932
|
addSvelteKitEnvModules(result);
|
|
1805
1933
|
return result;
|
|
1806
1934
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/cli",
|
|
3
|
-
"version": "1.3.7
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "The CLI for Better Auth",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"repository": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"semver": "^7.7.1",
|
|
56
56
|
"tinyexec": "^0.3.1",
|
|
57
57
|
"yocto-spinner": "^0.1.1",
|
|
58
|
-
"better-auth": "1.3.7
|
|
58
|
+
"better-auth": "1.3.7"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"zod": "3.25.0 || ^4.0.0"
|