appflare 0.2.31 → 0.2.32

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/cli/generate.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { mkdir } from "node:fs/promises";
1
+ import { mkdir, readdir, rm } from "node:fs/promises";
2
2
  import { existsSync } from "node:fs";
3
- import { relative, resolve } from "node:path";
3
+ import { join, relative, resolve } from "node:path";
4
4
  import { generateAuthConfigSource } from "./templates/auth/config";
5
5
  import { generateClientArtifacts } from "./templates/core/client.artifacts";
6
6
  import { generateDrizzleConfigSource } from "./templates/core/drizzle";
@@ -156,9 +156,74 @@ export async function generateArtifacts(
156
156
  throw new Error(`better-auth generation failed with exit code ${exitCode}`);
157
157
  }
158
158
 
159
+ const generatedTsconfig = {
160
+ compilerOptions: {
161
+ lib: ["es2024"],
162
+ types: ["@types/node", "bun", "@cloudflare/workers-types/2023-07-01"],
163
+ module: "es2022",
164
+ target: "es2024",
165
+ moduleResolution: "bundler",
166
+ strictNullChecks: true,
167
+ skipLibCheck: true,
168
+ declaration: true,
169
+ emitDeclarationOnly: true,
170
+ jsx: "react-jsx",
171
+ paths: {
172
+ "_generated/*": ["./*"],
173
+ },
174
+ },
175
+ include: ["*.ts", "client/*.ts"],
176
+ };
177
+
178
+ const generatedTsconfigPath = resolve(outDirAbs, "tsconfig.json");
179
+ await Bun.write(
180
+ generatedTsconfigPath,
181
+ `${JSON.stringify(generatedTsconfig, null, 2)}\n`,
182
+ );
183
+
184
+ const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
185
+ const generatedBuild = Bun.spawn(
186
+ [npxCmd, "--yes", "-p", "typescript", "tsc", "-p", generatedTsconfigPath],
187
+ {
188
+ cwd: outDirAbs,
189
+ stdout: "inherit",
190
+ stderr: "inherit",
191
+ },
192
+ );
193
+
194
+ const generatedBuildExitCode = await generatedBuild.exited;
195
+ if (generatedBuildExitCode !== 0) {
196
+ throw new Error(
197
+ `Generated code build failed with exit code ${generatedBuildExitCode}`,
198
+ );
199
+ }
200
+
201
+ const generatedDirPrefix = outDirAbs + "/";
202
+ async function cleanDtsOutside(dir: string): Promise<void> {
203
+ const entries = await readdir(dir, { withFileTypes: true });
204
+ for (const entry of entries) {
205
+ const fullPath = join(dir, entry.name);
206
+ if (entry.isDirectory()) {
207
+ if (
208
+ entry.name === "node_modules" ||
209
+ entry.name.startsWith(".") ||
210
+ fullPath === outDirAbs
211
+ ) {
212
+ continue;
213
+ }
214
+ await cleanDtsOutside(fullPath);
215
+ } else if (
216
+ entry.name.endsWith(".d.ts") &&
217
+ !fullPath.startsWith(generatedDirPrefix)
218
+ ) {
219
+ await rm(fullPath);
220
+ }
221
+ }
222
+ }
223
+ await cleanDtsOutside(configDir);
224
+
159
225
  const tsconfigPath = resolve(configDir, "tsconfig.json");
160
226
  if (loadedConfig.config.build && existsSync(tsconfigPath)) {
161
- const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
162
227
  const tsBuild = Bun.spawn(
163
228
  [npxCmd, "--yes", "-p", "typescript", "tsc", "--build"],
164
229
  {