appflare 0.2.31 โ†’ 0.2.34

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.
@@ -84,6 +84,15 @@ export async function runDev(
84
84
 
85
85
  const watcher = chokidar.watch(loadedConfig.scanDirAbs, {
86
86
  ignoreInitial: true,
87
+ ignored: (path: string) => {
88
+ return (
89
+ path.includes("/_generated/") ||
90
+ path.includes("/dist/") ||
91
+ path.includes("/out/") ||
92
+ path.includes("/node_modules/") ||
93
+ path.endsWith(".d.ts")
94
+ );
95
+ },
87
96
  });
88
97
 
89
98
  watcher.on("all", async (_eventName, changedPath) => {
package/cli/generate.ts CHANGED
@@ -1,6 +1,7 @@
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 { dirname, join, relative, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
4
5
  import { generateAuthConfigSource } from "./templates/auth/config";
5
6
  import { generateClientArtifacts } from "./templates/core/client.artifacts";
6
7
  import { generateDrizzleConfigSource } from "./templates/core/drizzle";
@@ -31,11 +32,26 @@ export async function generateArtifacts(
31
32
  configPath,
32
33
  );
33
34
 
35
+ const t0 = performance.now();
36
+
34
37
  await Promise.all([
35
38
  mkdir(outDirAbs, { recursive: true }),
36
39
  mkdir(clientOutDirAbs, { recursive: true }),
37
40
  mkdir(wranglerOutDirAbs, { recursive: true }),
38
41
  ]);
42
+ process.stdout.write(`๐Ÿ“ Directories (${(performance.now() - t0).toFixed(0)}ms)\n`);
43
+
44
+ const moduleDir = dirname(fileURLToPath(import.meta.url));
45
+ const tscBin = join(
46
+ dirname(Bun.resolveSync("typescript/package.json", moduleDir)),
47
+ "bin",
48
+ "tsc",
49
+ );
50
+ const betterAuthBin = join(
51
+ dirname(Bun.resolveSync("@better-auth/cli/package.json", moduleDir)),
52
+ "dist",
53
+ "index.mjs",
54
+ );
39
55
 
40
56
  const serverPath = resolve(outDirAbs, "server.ts");
41
57
  const clientPath = resolve(outDirAbs, "client.ts");
@@ -54,6 +70,9 @@ export async function generateArtifacts(
54
70
  discoveredSchema.schemaPath,
55
71
  );
56
72
  const discoveredHandlers = await discoverHandlerOperations(loadedConfig);
73
+ process.stdout.write(
74
+ `๐Ÿ” ${discoveredHandlers.length} handler(s) (${(performance.now() - t0).toFixed(0)}ms)\n`,
75
+ );
57
76
 
58
77
  const serverSource = generateServerSource(
59
78
  config.auth.basePath,
@@ -117,6 +136,7 @@ export async function generateArtifacts(
117
136
  Bun.write(wranglerPath, `${JSON.stringify(wranglerJson, null, 2)}\n`),
118
137
  Bun.write(dashboardPath, dashboardSource),
119
138
  ]);
139
+ process.stdout.write(`๐Ÿ“ Source artifacts (${(performance.now() - t0).toFixed(0)}ms)\n`);
120
140
 
121
141
  const authConfigPathFromConfigDir = relative(
122
142
  configDir,
@@ -135,8 +155,8 @@ export async function generateArtifacts(
135
155
 
136
156
  const betterAuthGenerate = Bun.spawn(
137
157
  [
138
- "npx",
139
- "@better-auth/cli",
158
+ process.execPath,
159
+ betterAuthBin,
140
160
  "generate",
141
161
  "--config",
142
162
  authConfigCliPath,
@@ -155,12 +175,103 @@ export async function generateArtifacts(
155
175
  if (exitCode !== 0) {
156
176
  throw new Error(`better-auth generation failed with exit code ${exitCode}`);
157
177
  }
178
+ process.stdout.write(`๐Ÿ” Auth schema (${(performance.now() - t0).toFixed(0)}ms)\n`);
179
+
180
+ function generatedTsconfig(overrides: Record<string, unknown> = {}) {
181
+ return {
182
+ compilerOptions: {
183
+ lib: ["es2024"],
184
+ types: ["@types/node", "bun", "@cloudflare/workers-types/2023-07-01"],
185
+ module: "es2022",
186
+ target: "es2024",
187
+ moduleResolution: "bundler",
188
+ strictNullChecks: true,
189
+ skipLibCheck: true,
190
+ declaration: true,
191
+ emitDeclarationOnly: true,
192
+ noCheck: true,
193
+ jsx: "react-jsx",
194
+ paths: {
195
+ "_generated/*": ["./*"],
196
+ },
197
+ ...overrides,
198
+ },
199
+ include: ["./*.ts", "./client/*.ts"],
200
+ };
201
+ }
202
+
203
+ const jsTsconfigPath = resolve(outDirAbs, "tsconfig.js.json");
204
+
205
+ await Promise.all([
206
+ Bun.write(
207
+ jsTsconfigPath,
208
+ `${JSON.stringify(generatedTsconfig({ declaration:true,emitDeclarationOnly: false }), null, 2)}\n`,
209
+ ),
210
+ ]);
211
+ process.stdout.write(`๐Ÿ“„ TS configs (${(performance.now() - t0).toFixed(0)}ms)\n`);
212
+
213
+ async function runTsc(configPath: string, label: string): Promise<void> {
214
+ process.stdout.write(`โš™๏ธ ${label}... (${(performance.now() - t0).toFixed(0)}ms)\n`);
215
+ const p = Bun.spawn([process.execPath, tscBin, "-p", configPath], {
216
+ cwd: outDirAbs,
217
+ stdout: "inherit",
218
+ stderr: "inherit",
219
+ });
220
+ console.log(process.execPath, tscBin, "-p", configPath, { cwd: outDirAbs });
221
+ const code = await p.exited;
222
+ if (code !== 0) throw new Error(`tsc ${label} failed with exit code ${code}`);
223
+ }
224
+
225
+ await runTsc(jsTsconfigPath, "JS files");
226
+ process.stdout.write(`โœ… JS + declarations (${(performance.now() - t0).toFixed(0)}ms)\n`);
227
+ async function removeTsFiles(dir: string): Promise<void> {
228
+ const entries = await readdir(dir, { withFileTypes: true });
229
+ for (const entry of entries) {
230
+ const fullPath = join(dir, entry.name);
231
+ if (entry.isDirectory()) {
232
+ if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
233
+ await removeTsFiles(fullPath);
234
+ } else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
235
+ await rm(fullPath);
236
+ }
237
+ }
238
+ }
239
+ await removeTsFiles(outDirAbs);
240
+ process.stdout.write(`๐Ÿ“ฆ Cleaned .ts files (${(performance.now() - t0).toFixed(0)}ms)\n`);
241
+
242
+ const generatedDirPrefix = outDirAbs + "/";
243
+ async function cleanDtsOutside(dir: string): Promise<void> {
244
+ const entries = await readdir(dir, { withFileTypes: true });
245
+ for (const entry of entries) {
246
+ const fullPath = join(dir, entry.name);
247
+ if (entry.isDirectory()) {
248
+ if (
249
+ entry.name === "node_modules" ||
250
+ entry.name.startsWith(".") ||
251
+ fullPath === outDirAbs
252
+ ) {
253
+ continue;
254
+ }
255
+ await cleanDtsOutside(fullPath);
256
+ } else if (
257
+ !fullPath.startsWith(generatedDirPrefix) && (
258
+ entry.name.endsWith(".d.ts") || (
259
+ entry.name.endsWith(".js"))
260
+ )
261
+ ) {
262
+ await rm(fullPath);
263
+ }
264
+ }
265
+ }
266
+ await cleanDtsOutside(configDir);
267
+ process.stdout.write(`๐Ÿงน Cleanup (${(performance.now() - t0).toFixed(0)}ms)\n`);
268
+
158
269
 
159
270
  const tsconfigPath = resolve(configDir, "tsconfig.json");
160
271
  if (loadedConfig.config.build && existsSync(tsconfigPath)) {
161
- const npxCmd = process.platform === "win32" ? "npx.cmd" : "npx";
272
+ process.stdout.write(`โš™๏ธ Building project... (${(performance.now() - t0).toFixed(0)}ms)\n`);
162
273
  const tsBuild = Bun.spawn(
163
- [npxCmd, "--yes", "-p", "typescript", "tsc", "--build"],
274
+ [process.execPath, tscBin, "--build"],
164
275
  {
165
276
  cwd: configDir,
166
277
  stdout: "inherit",
@@ -174,5 +285,6 @@ export async function generateArtifacts(
174
285
  `TypeScript build failed with exit code ${tsBuildExitCode}`,
175
286
  );
176
287
  }
288
+ process.stdout.write(`โœ… Build complete (${(performance.now() - t0).toFixed(0)}ms)\n`);
177
289
  }
178
290
  }